Implemented '$wgWhitelistRead'.
authorNicholas Pisarro, Jr <npassoc@users.mediawiki.org>
Fri, 5 Mar 2004 13:19:19 +0000 (13:19 +0000)
committerNicholas Pisarro, Jr <npassoc@users.mediawiki.org>
Fri, 5 Mar 2004 13:19:19 +0000 (13:19 +0000)
$wgWhitelistRead is now defined to be an optional array
of namespace:pages a user may see unless they login.

For example:
$wgWhitelistRead = array ( ":Main_Page", "Special:Userlogin", "Wikipedia:Help" );

will restrict an anonymous user to only those pages. They are
alerted that they must login, if the try to go to another page.

If 'false', the default, the anonymous user may see all pages,
except Sysop pages, of course.

includes/DefaultSettings.php
includes/OutputPage.php
index.php
languages/Language.php

index 0b4ba98..0992bb7 100644 (file)
@@ -121,8 +121,8 @@ $wgEnableParserCache = false; # requires that php was compiled --with-zlib
 $wgHitcounterUpdateFreq = 1;
 
 # User rights 
-$wgWhitelistEdit = false;
-$wgWhitelistRead = false;
+$wgWhitelistEdit = false;   # true = user must login to edit.
+$wgWhitelistRead = false;      # Pages anonymous user may see, like: = array ( ":Main_Page", "Special:Userlogin", "Wikipedia:Help");
 $wgWhitelistAccount = array ( "user" => 1, "sysop" => 1, "developer" => 1 );
 $wgSysopUserBans        = false; # Allow sysops to ban logged-in users
 $wgSysopRangeBans              = false; # Allow sysops to ban IP ranges
index 8aaa8d4..b112034 100644 (file)
@@ -407,6 +407,26 @@ class OutputPage {
                $this->returnToMain();
        }
 
+       function loginToUse()
+       {
+               global $wgUser, $wgTitle, $wgLang;
+
+               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
+               $this->setPageTitle( wfMsg( "loginreqtitle" ) );
+               $this->setRobotpolicy( "noindex,nofollow" );
+               $this->setArticleFlag( false );
+               $this->mBodytext = "";
+               $this->addWikiText( wfMsg( "loginreqtext" ) );
+
+               # We put a comment in the .html file so a Sysop can diagnose the page the
+               # user can't see.
+               $this->addHTML( "\n<!--" . 
+                                               $wgLang->getNsText( $wgTitle->getNamespace() ) . 
+                                               ":" . 
+                                               $wgTitle->getDBkey() . "-->" );
+               $this->returnToMain();          # Flip back to the main page after 10 seconds.
+       }
+
        function databaseError( $fname, &$conn )
        {
                global $wgUser, $wgCommandLineMode;
index 61220b1..57875af 100644 (file)
--- a/index.php
+++ b/index.php
@@ -46,6 +46,16 @@ if ( "" == $title && "delete" != $action ) {
 }
 wfProfileOut( "main-misc-setup" );
 
+# If the user is not logged in, the Namespace:title of the article must be in the Read array in
+#  order for the user to see it.
+if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
+       if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
+               $wgOut->loginToUse();
+               $wgOut->output();
+               exit;
+       }
+}
+
 if ( "" != $search ) {
        if( isset($_REQUEST['fulltext']) ) {
                wfSearch( $search );
index df7e396..5b1d874 100644 (file)
@@ -692,6 +692,8 @@ Your IP address is $3. Please include this address in any queries you make.
 "whitelistreadtext" => "You have to [[Special:Userlogin|login]] to read articles.",
 "whitelistacctitle" => "You are not allowed to create an account",
 "whitelistacctext" => "To be allowed to create accounts in this Wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.",
+"loginreqtitle"        => "Login Required",
+"loginreqtext" => "You must [[special:Userlogin|login]] to view other pages.",
 "accmailtitle" => "Password sent.",
 "accmailtext" => "The Password for '$1' has been sent to $2.",
 "newarticle"   => "(New)",