<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Epistemographer &#187; Coding</title>
	<atom:link href="http://www.epistemographer.com/category/work/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.epistemographer.com</link>
	<description>Mapping knowledge online since 1999</description>
	<lastBuildDate>Mon, 13 Jun 2011 20:14:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Page-by-page authentication in MediaWiki</title>
		<link>http://www.epistemographer.com/2005/05/04/page-by-page-authentication-in-mediawiki/</link>
		<comments>http://www.epistemographer.com/2005/05/04/page-by-page-authentication-in-mediawiki/#comments</comments>
		<pubDate>Wed, 04 May 2005 20:30:16 +0000</pubDate>
		<dc:creator>Josh Greenberg</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Writing for Google]]></category>

		<guid isPermaLink="false">http://www.epistemographer.com/?p=238</guid>
		<description><![CDATA[All code below is made available under the GPL v2 license In the interests of centralizing information, we&#8217;ve started an internal wiki at the &#8220;Center&#8221;:http://chnm.gmu.edu that will eventually function as a sort of dynamic handbook to our facilities, staff and projects. The choice of a wiki was ideal, because each staff member can flesh out [...]]]></description>
			<content:encoded><![CDATA[<p><em>All code below is made available under the <a href="http://www.gnu.org/licenses/gpl-2.0.html ">GPL v2</a> license</em></p>
<p>In the interests of centralizing information, we&#8217;ve started an internal wiki at the &#8220;Center&#8221;:http://chnm.gmu.edu that will eventually function as a sort of dynamic handbook to our facilities, staff and projects. The choice of a wiki was ideal, because each staff member can flesh out the documentation on his or her projects, and since it&#8217;s for internal use, we can take the general good intentions of users for granted.</p>
<p>However, there are some pages that will need to be restricted to certain users (things like payroll/budget information, or staffing discussions), so I went ahead and wrote a small plugin that allows any user to restrict access to a wiki page by embedding the allowed usernames within a special tag (working off of a really useful &#8220;blog post&#8221;:http://daryl.learnhouston.com/?p=125 outlining MediaWiki plugins).</p>
<p>Here&#8217;s what you do. Save the following code into a file called &#8220;accessControl.php&#8221; in your MediaWiki /extensions directory</p>
<pre>
< ?php
// MediaWiki extension that enables access restriction on a page-by-page
// basis
// Added 5/3/05 by Josh Greenberg
// [based on code snagged from http://daryl.learnhouston.com/?p=125]

//Add the hook function call to an array defined earlier in the wiki
//code execution.
$wgExtensionFunctions[] = "wfAccessControl";

//This is the hook function. It adds the tag to the wiki parser and
//tells it what callback function to use.
function wfAccessControl() {
    global $wgParser;
    # register the extension with the WikiText parser
    $wgParser->setHook( "accesscontrol", "controlUserAccess" );
}

// The callback function for user access
function controlUserAccess( $input ) {
    // Grab currently logged in user
    global $wgUser;

    // Create array of users with permission to access this page
    $usersAccess = explode(",,", $input);

    // Trim leading whitespaces from usernames
    foreach ($usersAccess as $userEntry) {
        $userEntry = strtolower(ltrim($userEntry));
    }

    // Put up an error message if current user doesn't match
    // accesscontrol list
    if (!in_array(strtolower($wgUser->getName()), $usersAccess)) {
        echo '<body onLoad="javascript: alert('Not Allowed')">';
         exit();
    }
    return $output;
}
?>
</body></pre>
<p>Then, add a line to the bottom of your LocalSettings.php to tell it to include the plugin:</p>
<p><code>include("extensions/accessControl.php");</code></p>
<p>That&#8217;s it for the installation. To restrict access on a page-by-page basis to specific users, just include the names of the allowed users within an <accesscontrol> tag (separated by double commas) in the body of that page. Thus, if you wanted to restrict access to the people with usernames &#8220;Fred&#8221;, &#8220;janedoe&#8221; and &#8220;Josh Greenberg&#8221;, you would use the following syntax:</p>
<p><code><accesscontrol>Fred,,janedoe,,Josh Greenberg</accesscontrol></code></p>
<p>Be careful with this! If you&#8217;re restricting access to a page, make absolutely sure that you&#8217;re including your own username within the <code><accesscontrol></accesscontrol></code> tags, or else you won&#8217;t be allowed to reload the page to fix your mistake. If you find yourself locked out of a page that you need access to, you&#8217;ll have to disable the plugin.</accesscontrol></p>
]]></content:encoded>
			<wfw:commentRss>http://www.epistemographer.com/2005/05/04/page-by-page-authentication-in-mediawiki/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>

