From 74a1c21d60ed8fd74fb4aa37c31815fe8559f15e Mon Sep 17 00:00:00 2001 From: "Nicholas Pisarro, Jr" Date: Fri, 5 Mar 2004 13:19:19 +0000 Subject: [PATCH] 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. --- includes/DefaultSettings.php | 4 ++-- includes/OutputPage.php | 20 ++++++++++++++++++++ index.php | 10 ++++++++++ languages/Language.php | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0b4ba9895b..0992bb7a3a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8aaa8d40d1..b11203479f 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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" ); + $this->returnToMain(); # Flip back to the main page after 10 seconds. + } + function databaseError( $fname, &$conn ) { global $wgUser, $wgCommandLineMode; diff --git a/index.php b/index.php index 61220b18ed..57875af5a2 100644 --- 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 ); diff --git a/languages/Language.php b/languages/Language.php index df7e39646d..5b1d874b71 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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)", -- 2.20.1