r2618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2617‎ | r2618 | r2619 >
Date:13:19, 5 March 2004
Author:npassoc
Status:old
Tags:
Comment:
Implemented '$wgWhitelistRead'.

$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.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -46,6 +46,16 @@
4747 }
4848 wfProfileOut( "main-misc-setup" );
4949
 50+# If the user is not logged in, the Namespace:title of the article must be in the Read array in
 51+# order for the user to see it.
 52+if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
 53+ if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
 54+ $wgOut->loginToUse();
 55+ $wgOut->output();
 56+ exit;
 57+ }
 58+}
 59+
5060 if ( "" != $search ) {
5161 if( isset($_REQUEST['fulltext']) ) {
5262 wfSearch( $search );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -121,8 +121,8 @@
122122 $wgHitcounterUpdateFreq = 1;
123123
124124 # User rights
125 -$wgWhitelistEdit = false;
126 -$wgWhitelistRead = false;
 125+$wgWhitelistEdit = false; # true = user must login to edit.
 126+$wgWhitelistRead = false; # Pages anonymous user may see, like: = array ( ":Main_Page", "Special:Userlogin", "Wikipedia:Help");
127127 $wgWhitelistAccount = array ( "user" => 1, "sysop" => 1, "developer" => 1 );
128128 $wgSysopUserBans = false; # Allow sysops to ban logged-in users
129129 $wgSysopRangeBans = false; # Allow sysops to ban IP ranges
Index: trunk/phase3/includes/OutputPage.php
@@ -407,6 +407,26 @@
408408 $this->returnToMain();
409409 }
410410
 411+ function loginToUse()
 412+ {
 413+ global $wgUser, $wgTitle, $wgLang;
 414+
 415+ $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
 416+ $this->setPageTitle( wfMsg( "loginreqtitle" ) );
 417+ $this->setRobotpolicy( "noindex,nofollow" );
 418+ $this->setArticleFlag( false );
 419+ $this->mBodytext = "";
 420+ $this->addWikiText( wfMsg( "loginreqtext" ) );
 421+
 422+ # We put a comment in the .html file so a Sysop can diagnose the page the
 423+ # user can't see.
 424+ $this->addHTML( "\n<!--" .
 425+ $wgLang->getNsText( $wgTitle->getNamespace() ) .
 426+ ":" .
 427+ $wgTitle->getDBkey() . "-->" );
 428+ $this->returnToMain(); # Flip back to the main page after 10 seconds.
 429+ }
 430+
411431 function databaseError( $fname, &$conn )
412432 {
413433 global $wgUser, $wgCommandLineMode;
Index: trunk/phase3/languages/Language.php
@@ -692,6 +692,8 @@
693693 "whitelistreadtext" => "You have to [[Special:Userlogin|login]] to read articles.",
694694 "whitelistacctitle" => "You are not allowed to create an account",
695695 "whitelistacctext" => "To be allowed to create accounts in this Wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.",
 696+"loginreqtitle" => "Login Required",
 697+"loginreqtext" => "You must [[special:Userlogin|login]] to view other pages.",
696698 "accmailtitle" => "Password sent.",
697699 "accmailtext" => "The Password for '$1' has been sent to $2.",
698700 "newarticle" => "(New)",

Status & tagging log