Help:Regexp wgWhitelistRead
From MMVLWiki
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.
[edit]
External Links
- This page on meta.wikimedia.org (https://meta.wikimedia.org/wiki/Regexp_wgWhitelistRead)