Help:Regexp wgWhitelistRead

(Difference between revisions)
Jump to: navigation, search
(Added example on regular expressions.)
m
Line 48: Line 48:
 
  $wgWhitelistEdit = true;
 
  $wgWhitelistEdit = true;
 
  # Pages anonymous (not-logged-in) users may see
 
  # Pages anonymous (not-logged-in) users may see
  $wgWhitelistRead = array ("/^[^:]*$/", "/^Special:Search$/", "/^(Help|Image|User):/" );
+
  $wgWhitelistRead = array ("/^[^:]*$/", "/^Special:(Search|Categories)$/", "/^(Help|Image|User|Category|MMVLWiki):/" );
 
  # Specify who may create new accounts: 0 means no, 1 means yes
 
  # Specify who may create new accounts: 0 means no, 1 means yes
 
  $wgWhitelistAccount = array ( 'user' => 0, 'sysop' => 1, 'developer' => 1 );
 
  $wgWhitelistAccount = array ( 'user' => 0, 'sysop' => 1, 'developer' => 1 );

Revision as of 15:42, 3 April 2006

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)$/", "/^(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.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox