Help:Regexp wgWhitelistRead
From MMVLWiki
(Difference between revisions)
m |
m |
||
Line 56: | Line 56: | ||
Implementing a single regular expression instead of an array actually would suffice. | Implementing a single regular expression instead of an array actually would suffice. | ||
+ | |||
+ | =External Links= | ||
+ | * [http://meta.wikimedia.org/wiki/Regexp_wgWhitelistRead This page on meta.wikimedia.org] |
Latest revision as of 13:04, 3 September 2007
This hack makes entries in the array '$wgWiteListRead' be interpreted as regular expressions. The file include/Title.php has been changed as follows:
/** * Can $wgUser read this page? * @return boolean * @access public */ function userCanRead() { global $wgUser; if( $wgUser->isAllowed('read') ) { return true; } else { global $wgWhitelistRead; /** If anon users can create an account, they need to reach the login page first! */ if( $wgUser->isAllowed( 'createaccount' ) && $this->getNamespace() == NS_SPECIAL && $this->getText() == 'Userlogin' ) { return true; } /** some pages are explicitly allowed */ $name = $this->getPrefixedText(); # Jan Wedekind: Changed this. # if( in_array( $name, $wgWhitelistRead ) ) { # return true; #} if ( is_array($wgWhitelistRead) ) { for ($i=0; $i<count($wgWhitelistRead); $i++) { if (preg_match($wgWhitelistRead[$i],$name)) { return true; } } } # Compatibility with old settings if( $this->getNamespace() == NS_MAIN ) { if( in_array( ':' . $name, $wgWhitelistRead ) ) { return true; } } } return false; }
In LocalSettings.php one can now specify visible pages by using an array of regular expressions for $wgWhiteListRead.
# Specify who can edit: true means only logged in users may edit pages $wgWhitelistEdit = true; # Pages anonymous (not-logged-in) users may see $wgWhitelistRead = array ("/^[^:]*$/", "/^Special:(Search|Categories|Recentchanges|Whatlinkshere|Recentchangeslinked|Specialpages|Imagelist|Newimages|Statistics|Randompage|Popularpages|WantedPages|Shortpages|Longpages|Newpages|Ancientpages||Deadendpages|Allpages|Categories)$/", "/^(Help|Image|User|Category|MMVLWiki):/" ); # Specify who may create new accounts: 0 means no, 1 means yes $wgWhitelistAccount = array ( 'user' => 0, 'sysop' => 1, 'developer' => 1 ); $wgShowIPinHeader = false; # For non-logged in users
Implementing a single regular expression instead of an array actually would suffice.