MediaWiki r43378 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r43377‎ | r43378 (on ViewVC)‎ | r43379 >
Date:01:41, 11 November 2008
Author:gri6507
Status:old (Comments)
Tags:
Comment:
v0.11.2
* Fixed a bug with granting access to pages with parentheses in the name
* restored the numerous MW comptatibility problems introduced with the previous revision
* Fixed a bug with WikiText vx. Html output methods
Modified paths:

Diff [purge]

Index: trunk/extensions/WhiteList/WhiteListAuth.php
===================================================================
--- trunk/extensions/WhiteList/WhiteListAuth.php	(revision 43377)
+++ trunk/extensions/WhiteList/WhiteListAuth.php	(revision 43378)
@@ -28,62 +28,70 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
+if (!defined("WHITELIST_GRANT")) {
+	define("WHITELIST_GRANT", 1);
+}
+if (!defined("WHITELIST_DENY")) {
+	define("WHITELIST_DENY", -1);
+}
+if (!defined("WHITELIST_NOACTION")) {
+	define("WHITELIST_NOACTION", 0);
+}
+
 class WhiteListExec
 {
-	const WHITELIST_GRANT = 1;
-	const WHITELIST_DENY = 0;
-	const WHITELIST_NOACTION = -1;
 
 	/* $result value:
 	 *   true=Access Granted
 	 *   false=Access Denied
-	 *   null=Do not know/do not care (not 'allowed' or 'denied')
+	 *   null=Don't know/don't care (not 'allowed' or 'denied')
 	 * Return value:
 	 *   true=Later functions can override.
 	 *   false=Later functions not consulted.
 	 */
-	static function CheckWhiteList( &$title, &$wgUser, $action, &$result ) {
+	static function CheckWhiteList(&$title, &$wgUser, $action, &$result) {
 
-		$override = self::WHITELIST_NOACTION;
+		$override = WHITELIST_NOACTION;
 
-		/* Bail if the user is not restricted.... */
-		if ( !in_array( 'restricttowhitelist', $wgUser->getRights() ) ) {
-			$result = null; /* do not care */
+
+		/* Bail if the user isn't restricted.... */
+		if( !in_array('restricttowhitelist', $wgUser->getRights()) ) {
+			$result = null; /* don't care */
 			return true; /* Later functions can override */
 		}
 
 		/* Sanity Check */
-		if ( !$title )
-			return $hideMe;
+		if (!$title)
+			return false;
 
 		# If this is a talk page, we need to check permissions
 		# of the subject page instead...
 		$true_title = $title->getSubjectPage();
 
 		/* Check global allow/deny lists */
-		$override = self::GetOverride( $true_title, $action );
+		$override = self::GetOverride($true_title, $action);
+                
+                /* Check if page is on whitelist */
+                if( WHITELIST_NOACTION == $override )
+                        $override = self::IsAllowedNamespace( $true_title, $wgUser, $action );
 
 		/* Check if page is on whitelist */
-		if ( self::WHITELIST_NOACTION == $override )
-			$override = self::IsAllowedNamespace( $true_title, $wgUser, $action );
-
-		/* Check if page is on whitelist */
-		if ( self::WHITELIST_NOACTION == $override )
+		if( WHITELIST_NOACTION == $override )
 			$override = self::IsAllowed( $true_title, $wgUser, $action );
 
 		/* Check if user page */
-		if ( self::WHITELIST_NOACTION == $override )
+		if( WHITELIST_NOACTION == $override )
 			$override = self::IsUserPage( $true_title->GetPrefixedText(), $wgUser );
 
 		switch( $override )
 		{
-			case self::WHITELIST_GRANT:
+			case WHITELIST_GRANT:
 				$result = true; /* Allow other checks to be run */
 				return true; /* Later functions can override */
 				break;
-			case self::WHITELIST_DENY:
-			case self::WHITELIST_NOACTION:
-			default: /* Invalid - should not be possible... */
+			case WHITELIST_DENY:
+			case WHITELIST_NOACTION:
+			default: /* Invalid - shouldn't be possible... */
 				$result = false; /* Access Denied */
 				return false; /* Later functions not consulted */
 		}
@@ -91,63 +99,63 @@
 
 	/* Check for global page overrides (allow or deny)
 	 */
-	static function GetOverride( $title, $action )
+	static function GetOverride($title, $action )
 	{
 		global $wgWhiteListOverride;
 
-		$allowView = $allowEdit = $denyView = $denyEdit = false;
+                $allowView = $allowEdit = $denyView = $denyEdit = false;
+ 
+                foreach( $wgWhiteListOverride['always']['read'] as $value )
+                {
+                        if( self::RegexCompare($title, $value) )
+                        {
+                                $allowView = true;
+                        }
+                }
+ 
+                foreach( $wgWhiteListOverride['always']['edit'] as $value )
+                {
+                        if( self::RegexCompare($title, $value) )
+                        {
+                                $allowEdit = true;
+                        }
+                }
 
-		foreach ( $wgWhiteListOverride['always']['read'] as $value )
-		{
-			if ( self::RegexCompare( $title, $value ) )
-			{
-				$allowView = true;
-			}
-		}
+		unset($override);
 
-		foreach ( $wgWhiteListOverride['always']['edit'] as $value )
-		{
-			if ( self::RegexCompare( $title, $value ) )
-			{
-				$allowEdit = true;
-			}
-		}
+		foreach( $wgWhiteListOverride['never']['read'] as $value )
+                {
+                        if( self::RegexCompare($title, $value) )
+                        {
+                                $denyView = true;
+                        }
+                }
+ 
+                foreach( $wgWhiteListOverride['never']['edit'] as $value )
+                {
+                        if( self::RegexCompare($title, $value) )
+                        {
+                                $denyEdit = true;
+                        }
+                }
 
-		$override = 'undef';
-
-		foreach ( $wgWhiteListOverride['never']['read'] as $value )
+		if( $action == 'edit' )
 		{
-			if ( self::RegexCompare( $title, $value ) )
-			{
-				$denyView = true;
-			}
-		}
-
-		foreach ( $wgWhiteListOverride['never']['edit'] as $value )
-		{
-			if ( self::RegexCompare( $title, $value ) )
-			{
-				$denyEdit = true;
-			}
-		}
-
-		if ( $action == 'edit' )
-		{
-			if ( $denyEdit || $denyView )
-				$override = self::WHITELIST_DENY;
-			else if ( $allowEdit )
-				$override = self::WHITELIST_GRANT;
+			if( $denyEdit || $denyView )
+				$override = WHITELIST_DENY;
+			else if( $allowEdit )
+				$override = WHITELIST_GRANT;
 			else
-				$override = self::WHITELIST_NOACTION;
+				$override = WHITELIST_NOACTION;
 		}
 		else
 		{
-			if ( $denyView )
-				$override = self::WHITELIST_DENY;
-			else if ( $allowView || $allowEdit )
-				$override = self::WHITELIST_GRANT;
+			if( $denyView )
+				$override = WHITELIST_DENY;
+			else if( $allowView || $allowEdit )
+				$override = WHITELIST_GRANT;
 			else
-				$override = self::WHITELIST_NOACTION;
+				$override = WHITELIST_NOACTION;
 		}
 
 		return $override;
@@ -162,27 +170,28 @@
 		$userPage = $wgUser->getUserPage()->getPrefixedText();
 		$userTalkPage = $wgUser->getTalkPage()->getPrefixedText();
 
-		if ( ( $wgWhiteListAllowUserPages == true ) &&
-			( $title_text == $userPage ) || ( $title_text == $userTalkPage ) )
-			return self::WHITELIST_GRANT;
+		if( ($wgWhiteListAllowUserPages == true) &&
+			($title_text == $userPage) || ($title_text == $userTalkPage) )
+			return WHITELIST_GRANT;
 		else
-			return self::WHITELIST_NOACTION;
+			return WHITELIST_NOACTION;
 	}
 
-	static function IsAllowedNamespace( &$title, &$wgUser, $action )
-	{
+        static function IsAllowedNamespace( &$title, &$wgUser, $action)
+        {
 
-		$page_ns = $title->getNsText();
-		if (     ( $page_ns == 'Mediawiki' ) ||
-		( $page_ns == 'Image' ) ||
-		( $page_ns == 'Help' ) )
-		{
-			return self::WHITELIST_GRANT;
-		}
+                $page_ns = $title->getNsText();
+                if(     ($page_ns == 'Mediawiki' ) ||
+                        ($page_ns == 'Image' ) || 
+                        ($page_ns == 'Help' ) )
+                {
+                        return WHITELIST_GRANT;
+                }
 
-		return self::WHITELIST_NOACTION;
-	}
+                return WHITELIST_NOACTION;
+        }
 
+
 	/* Check whether the page is whitelisted.
 	 * returns true if page is on whitelist, false if it is not.
 	 */
@@ -197,88 +206,113 @@
 		$dbr = wfGetDB( DB_SLAVE );
 
 		$wl_table_name = $dbr->tableName( 'whitelist' );
-		$current_date = date( "Y-m-d H:i:s" );
-		$sql = "SELECT wl_page_title
+		$current_date = date("Y-m-d H:i:s");
+		$sql = "SELECT wl_page_title 
 			FROM " . $wl_table_name . "
-			WHERE wl_user_id = "     . $dbr->addQuotes( $wgUser->getId() ) . "
-			AND ( (wl_expires_on >= " . $dbr->addQuotes( $current_date )  . ")
-			 OR ( wl_expires_on = "  . $dbr->addQuotes( '' ) . "))";
-		if ( $action == 'edit' ) {
+			WHERE wl_user_id = "     . $dbr->addQuotes($wgUser->getId()) . "
+			AND ( (wl_expires_on >= " . $dbr->addQuotes($current_date)  . ") 
+			 OR ( wl_expires_on = "  . $dbr->addQuotes('') . "))";
+		if( $action == 'edit' ) {
 			$sql .= "
-			AND wl_allow_edit = " . $dbr->addQuotes( '1' );
+                        AND wl_allow_edit = " . $dbr->addQuotes('1');
 		}
-		# print $sql;
+//wfDebug($sql);
 
-		// We should also check that $title is not a redirect to a whitelisted page
-		$redirecttitle = NULL;
-		$article = new Article( $title );
-		if ( is_object( $article ) )
-		{
-			$pagetext = $article->getContent();
-			$redirecttitle = Title::newFromRedirect( $pagetext );
-		}
-
+                // We should also check that $title is not a redirect to a whitelisted page
+                $redirecttitle = NULL;
+                $article = new Article($title);
+                if (is_object($article))
+                {
+                        $pagetext = $article->getContent();
+                        $redirecttitle = Title::newFromRedirect($pagetext);
+                }
+                        
 		/* Loop through each result returned and
 		 * check for matches.
 		 */
-		$dbr->begin();
-		$db_results = $dbr->query( $sql , __METHOD__, true );
-		$dbr->commit();
-		while ( $db_result = $dbr->fetchObject( $db_results ) )
+                $dbr->begin();
+		$db_results = $dbr->query( $sql , __METHOD__, true);
+                $dbr->commit();
+		while( $db_result = $dbr->fetchObject($db_results) )
 		{
-			if ( self::RegexCompare( $title, $db_result->wl_page_title ) )
+			if( self::RegexCompare($title, $db_result->wl_page_title) )
 			{
-				$dbr->freeResult( $db_results );
-				# wfDebug("\n\nAccess granted based on PAGE [" . $db_result->wl_page_title . "]\n\n");
-				return self::WHITELIST_GRANT;
+				$dbr->freeResult($db_results);
+//wfDebug("\n\nAccess granted based on PAGE [" . $db_result->wl_page_title . "]\n\n");
+				return WHITELIST_GRANT;
 			}
-			if ( $redirecttitle )
-			{
-				if ( self::RegexCompare( $redirecttitle, $db_result->wl_page_title ) )
-				{
-					$dbr->freeResult( $db_results );
-					# wfDebug("\n\nAccess granted based on REDIRECT to PAGE [" . $db_result->wl_page_title . "]\n\n");
-					return self::WHITELIST_GRANT;
-				}
-			}
+                        if ($redirecttitle)
+                        {
+                                if( self::RegexCompare($redirecttitle, $db_result->wl_page_title) )
+                                {
+                                        $dbr->freeResult($db_results);
+//wfDebug("\n\nAccess granted based on REDIRECT to PAGE [" . $db_result->wl_page_title . "]\n\n");
+                                        return WHITELIST_GRANT;
+                                }
+                        }
 		}
-		$dbr->freeResult( $db_results );
+		$dbr->freeResult($db_results);
 
-		return self::WHITELIST_NOACTION;
+		return WHITELIST_NOACTION;
 	}
 
 	/* Returns true if hit, false otherwise */
-	static function RegexCompare( &$title, $sql_regex )
+	static function RegexCompare(&$title, $sql_regex)
 	{
-		global $wgWhiteListWildCardInsensitive;
-
+                global $wgWhiteListWildCardInsensitive;
+                
 		$ret_val = false;
-
+                
 		/* Convert regex to PHP format */
-		$php_regex = str_replace( '%', '.*', $sql_regex );
-		$php_regex = str_replace( '_', ' ', $php_regex );
-		$php_regex = ltrim( $php_regex, ":" );
+		$illegal_chars = array(
+			'%', 
+			'_', 
+			'\\', 
+			'(',
+			')', 
+			'$', 
+			'^', 
+			'[', 
+			']'
+		);
+		$escaped_chars = array(
+			'.*',  
+			' ', 
+			'\\\\', 
+			'\(', 
+			'\)', 
+			'\$', 
+			'\^', 
+			'\[', 
+			'\]'
+		);
+		$php_regex = str_replace($illegal_chars, $escaped_chars, $sql_regex);
+		$php_regex = ltrim($php_regex, ":");
 
 		/* Generate regex; use | as delimiter as it is an illegal title character. */
 		$php_regex_full = '|^' . $php_regex . '$|';
-		if ( $wgWhiteListWildCardInsensitive )
-			$php_regex_full .= 'i';
+                if ($wgWhiteListWildCardInsensitive)
+                        $php_regex_full .= 'i';
 
-		# print( $php_regex_full . " [" . $title->getPrefixedText() . "]<br />\n");
-		if ( self::preg_test( $php_regex_full ) ) {
-			if ( preg_match( $php_regex_full, $title->getPrefixedText() ) ) {
-				# print("MATCH!!");
+//print("* Comapring '" . $php_regex_full . "' to page title '" . $title->getPrefixedText() . "'\n");
+		if (self::preg_test($php_regex_full)) {
+			if( preg_match( $php_regex_full, $title->getPrefixedText() ) ) {
+//print("** MATCH\n");
 				$ret_val = true;
+			} 
+			else
+			{
+//print("** fail\n");			
 			}
 		}
-
+		
 		return $ret_val;
 	}
 
 	# test to see if a regular expression is valid
-	static function preg_test( $regex )
+	function preg_test($regex)
 	{
-		if ( sprintf( "%s", @preg_match( $regex, '' ) ) == '' )
+		if (sprintf("%s",@preg_match($regex,'')) == '')
 		{
 			$error = error_get_last();
 			return false;
@@ -286,35 +320,31 @@
 		else
 		return true;
 	}
-}
+} /* End class */
 
-class WhiteListHooks
-{
-	static function AddRestrictedPagesTab( &$personal_urls, $wgTitle )
+class WhiteListHooks {
+	function AddRestrictedPagesTab(&$personal_urls, $wgTitle)
 	{
-		global $wgOut, $wgUser, $wgWhiteListRestrictedGroup;
+	    global $wgUser, $wgWhiteListRestrictedGroup;
 
-		wfLoadExtensionMessages( 'WhiteList' );
+	    $userIsRestricted = in_array( $wgWhiteListRestrictedGroup, $wgUser->getGroups() );
 
-		$userIsRestricted = in_array( $wgWhiteListRestrictedGroup, $wgUser->getGroups() );
-
-		if ( $wgUser->isLoggedIn() && $userIsRestricted ) {
-			$personal_urls['mypages'] = array(
-			'text' => wfMsg( 'mywhitelistpages' ),
-			'href' => Skin::makeSpecialUrl( 'WhiteList' )
-			);
-		}
-		return true;
+	    if ($wgUser->isLoggedIn() && $userIsRestricted) {
+		# In older versions of MW, loading of message files was done differently than the
+		# current default. So, let's work around that by forcing the load of the message file.
+		WhiteList::loadMessages();
+		
+		$personal_urls['mypages'] = array(
+		    'text' => wfMsg('mywhitelistpages'),
+		    'href' => Skin::makeSpecialUrl('WhiteList')
+		);
+	    }
+	    return true;
 	}
-
-	public static function CheckSchema() {
-		// Get a connection
-		$db = wfGetDB( DB_MASTER );
-		// Create table if it doesn't exist
-		if ( !$db->tableExists( 'whitelist' ) ) {
-			$db->sourceFile( dirname( __FILE__  ) . '/WhiteListEdit.sql' );
-		}
-		// Continue
+	
+	// TODO - this is missing from Siebrand's changes
+	function CheckSchema()
+	{
 		return true;
 	}
-}
+} /* End class */
Index: trunk/extensions/WhiteList/WhiteListEdit_body.php
===================================================================
--- trunk/extensions/WhiteList/WhiteListEdit_body.php	(revision 43377)
+++ trunk/extensions/WhiteList/WhiteListEdit_body.php	(revision 43378)
@@ -1,7 +1,7 @@
 <?php
 /*
 This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
+modify it under the terms of the GNU General Public LicenseWh
 as published by the Free Software Foundation, version 2
 of the License.
 
@@ -27,17 +27,63 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
+# older versions of MW did not have the NewFromId method, let's define our own
+function WhiteListUserFromId($id) {	
+	if (method_exists('User', 'newfromid')) {
+		return User::NewFromId($id);
+	} else {
+		$u = new User;
+		$u->mId = $id;
+		$u->mFrom = 'id';
+		return $u;
+	}
+}
+
+# older versions of MW did not have the standard method for loading messages. So, let's recreate it
+function WhiteListLoadMessages() {
+	static $messagesLoaded = false;
+	global $wgMessageCache;
+	if ($messagesLoaded) return;
+		$messagesLoaded = true;
+
+	require_once(dirname(__FILE__) . '/WhiteListEdit.i18n.php' );
+	foreach ( $messages as $lang => $langMessages ) {
+		$wgMessageCache->addMessages( $langMessages, $lang );
+	}
+}
+
 class WhiteListEdit extends SpecialPage
 {
 	function __construct() {
+		self::loadMessages();
 		SpecialPage::SpecialPage( 'WhiteListEdit', 'editwhitelist' );
 	}
 
+	function loadMessages() {
+		# the new method for loading extension messages is only available in MW versions > 1.12
+		# so let's keep the compatibility with older versions
+		if (function_exists('wfLoadExtensionMessages'))
+		{
+			wfLoadExtensionMessages('WhiteListEdit');
+		}
+		else
+		{
+			WhiteListLoadMessages();
+		}
+		
+		return true;
+	}
+
 	function execute( $par ) {
 		global $wgRequest, $wgOut, $wgUser;
 
-		wfLoadExtensionMessages( 'WhiteList' );
-
+		# sanity check
+		if ($wgUser->isAnon()) 
+		{
+			$wgOut->PermissionRequired('editwhitelist');
+			return;
+		}
+	
 		$this->setHeaders();
 		$wgOut->setPagetitle( wfMsg( 'whitelistedit' ) );
 
@@ -78,7 +124,7 @@
 			$wgOut->addHTML( "<input type='hidden' name='NewExpiryDate' value='$NewExpiryDate'>" );
 			$wgOut->addHTML( "<input type='hidden' name='action' value='$action'>" );
 
-			$ContractorUser = User::newFromID( $contractorId );
+			$ContractorUser = WhiteListUserFromID( $contractorId );
 			$wgOut->addWikiText( wfMsg( 'whitelistoverview', $ContractorUser->getRealName() ) );
 		}
 
@@ -294,7 +340,7 @@
 		$wgOut->addHTML( ob_get_contents() );
 		ob_clean();
 
-		$ContractorUser = User::newFromID( $contractorId );
+		$ContractorUser = WhiteListUserFromID( $contractorId );
 		$wgOut->addHTML( wfMsg( 'whitelistfor', $ContractorUser->getRealName() ) );
 		$wgOut->addHTML( '</td></tr><tr><th><center>' .
 			wfMsg( 'whitelisttablemodify' ) . "<br /><a href=\"javascript:SetChecked(1,'cb_modify[]')\">" .
@@ -318,7 +364,7 @@
 				$wgOut->addHTML( wfMsg( 'whitelisttableview' ) );
 			}
 			$wgOut->addHTML( "</center></td><td>&nbsp;$row->wl_expires_on</td><td>" );
-			$u = User::newFromId( $row->wl_updated_by_user_id );
+			$u = WhiteListUserFromId( $row->wl_updated_by_user_id );
 			$wgOut->addHTML( $u->getRealName() );
 			$wgOut->addHTML( "</td><td>$row->wl_updated_on</td></tr>" );
 		}
@@ -406,7 +452,7 @@
 		$dbr->commit();
 
 		for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
-			$u = User::newFromID( $row->ug_user );
+			$u = WhiteListUserFromID( $row->ug_user );
 			$users[$row->ug_user] = $u->getRealName();
 			if ( $users[$row->ug_user] == "" )
 				$users[$row->ug_user] = $u->getName();
@@ -451,24 +497,37 @@
 
 	function ExpandWildCardWhiteList( $wl_pattern )
 	{
-		global $wgContLanguageCode, $wgWhiteListWildCardInsensitive;
+		global $wgOut, $wgContLanguageCode, $wgWhiteListWildCardInsensitive;
 
 		$dbr = wfGetDB( DB_SLAVE );
-		$dbr->debug( true );
 		$expanded = array();
 		$whitelisted = array();
 		$debug = 0;
+		$dbr->debug($debug);
 
 		# extract the NameSpace (the first part before the optional first colon followed by the article name
 		$pattern = '/^((:?)(.*?):)?(.*)$/';
 		$pattern .= $wgWhiteListWildCardInsensitive ? 'i' : '';
 
-		if ( preg_match( $pattern, $wl_pattern, $matches ) ) {
+		if (preg_match($pattern, $wl_pattern, $matches)) {
+if ($debug)
+{
+	$wgOut->addWikiText("* found something for '$wl_pattern'");
+	ob_start();
+	print_r($matches);
+	$wgOut->addWikiText(ob_get_contents());
+	ob_end_flush();
+}
+			global $wgContLang;
 			$found = array();
 			$found['title'] = $matches[4];
 			$found['ns'] = '%';
 
-			$ns = Language::Factory( $wgContLanguageCode );
+			if (method_exists('Language', 'Factory')) {
+				$ns = Language::Factory( $wgContLanguageCode );
+			} else {
+				$ns = $wgContLang;
+			}
 			if ( $matches[1] == ':' && $matches[2] == '' )
 				$found['ns'] = NS_MAIN;
 			if ( $nsindex = $ns->getNsIndex( $matches[3] ) )
@@ -491,19 +550,25 @@
 		}
 
 		if ( $debug )
+{
+	$wgOut->addWikiText("expanded array is");
+	ob_start();
 			print_r( $expanded );
-
+	$wgOut->addWikiText(ob_get_contents());
+	ob_end_flush();
+}
 		foreach ( $expanded as $entry ) {
-			$sql = "SELECT page_id FROM " . $dbr->tableName( 'page' ) .
-				" WHERE `page_namespace` LIKE '" . $entry['ns'] .
-				"' AND `page_title` LIKE '" . $entry['title'] . "'";
-
-			if ( $wgWhiteListWildCardInsensitive ) {
-				$sql = "SELECT page_id FROM " .
-				$dbr->tableName( 'page' ) .
-					" WHERE UPPER(`page_namespace`) LIKE '" . strtoupper( $entry['ns'] ) . "'" .
-					" AND UPPER(`page_title`) LIKE '" . strtoupper( $entry['title'] ) . "'";
+			$sql = "SELECT `page_id` FROM " . $dbr->tableName( 'page' ) .
+				" WHERE CONVERT(`page_namespace` USING utf8) LIKE CONVERT('" . $entry['ns'] .
+				"' USING utf8) AND CONVERT(`page_title` USING utf8) LIKE CONVERT('" . $entry['title'] . 
+				"' USING utf8)";
+			if ($wgWhiteListWildCardInsensitive) {
+				$sql = "SELECT `page_id` FROM ". $dbr->tableName('page') .
+				" WHERE UPPER(CONVERT(`page_namespace` USING utf8)) LIKE CONVERT('" . strtoupper($entry['ns']) .
+				"' USING utf8) AND UPPER(CONVERT(`page_title` USING utf8)) LIKE CONVERT('" . strtoupper($entry['title']) . 
+				"' USING utf8)";
 			}
+if ($debug) $wgOut->addWikiText("the SQL query is :$sql:\n<br>");
 			$dbr->begin();
 			$res = $dbr->query( $sql, __METHOD__ );
 			$dbr->commit();
@@ -514,8 +579,13 @@
 		}
 
 		if ( $debug )
-			print_r( $whitelisted );
-
+{
+	$wgOut->addWikiText("Whitelisted array is");
+	ob_start();
+	print_r( $whitelisted );
+	$wgOut->addWikiText(ob_get_contents());
+	ob_end_flush();
+}
 		return $whitelisted;
 	}
 
@@ -528,7 +598,9 @@
 		$debug = 0;
 
 		$wildcard_match = self::ExpandWildCardWhiteList( $pagename );
+if ($debug) $wgOut->addWikiText("* tried to find matches for '$pagename'\n");
 		$num_matches = count( $wildcard_match );
+if ($debug) $wgOut->addWikiText("** found $num_matches\n");
 		$need_bullet = 0;
 		if ( substr( $headertext, 0, 1 ) == '*' )
 		{
@@ -540,8 +612,7 @@
 			$headertext = "[[:$pagename|$headertext]]";
 			if ( $need_bullet )
 			$headertext = '* ' . $headertext;
-			if ( $debug )
-			print "Adding '$headertext'\n";
+if ($debug)  $wgOut->addWikiText("* Adding '$headertext'\n");
 			$wgOut->addWikiText( $headertext );
 			return;
 		}
@@ -554,7 +625,7 @@
 		$wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' );
 		$wgOut->addHTML( '<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">' );
 		# this is a hack to make the [show]/[hide] always appear after the text
-		$wgOut->addWikiText( "$headertext" . wfMsgExt( 'whitelistnummatches', array( 'parsemag' ), array( $num_matches ) ) . "&nbsp;<font color='#ffffff'>[show]</font>&nbsp;</div>" );
+		$wgOut->addHtml("$headertext" . wfMsgExt('whitelistnummatches', array( 'parsemag' ), $num_matches) . "&nbsp;<font color='#ffffff'>[show]</font>&nbsp;</div>");
 		$wgOut->addHTML( '<div class="NavContent" style="display:none; font-size:normal; text-align:left">' );
 
 		foreach ( $wildcard_match as $pageid )
@@ -572,9 +643,25 @@
 class WhiteList extends SpecialPage
 {
 	function __construct() {
+		self::loadMessages();
 		SpecialPage::SpecialPage( 'WhiteList', 'restricttowhitelist' );
 	}
 
+	function loadMessages() {
+		# the new method for loading extension messages is only available in MW versions > 1.12
+		# so let's keep the compatibility with older versions
+		if (function_exists('wfLoadExtensionMessages'))
+		{
+			wfLoadExtensionMessages('WhiteList');
+		}
+		else
+		{
+			WhiteListLoadMessages();
+		}
+		
+		return true;
+	}
+
 	function execute( $para ) {
 		global $wgRequest, $wgOut, $wgUser, $wgWhiteListOverride, $wgWhiteListManagerGroup, $wgWhiteListRestrictedGroup, $wgSitename;
 
@@ -583,11 +670,9 @@
 		if ( !isset( $para ) || $para == '' ) {
 			$user = $wgUser;
 		} else {
-			$user = User::newFromId( $user );
+			$user = WhiteListUserFromId( $user );
 		}
 
-		wfLoadExtensionMessages( 'WhiteList' );
-
 		$this->setHeaders();
 		$wgOut->setPagetitle( wfMsg( 'whitelist' ) );
 
@@ -608,7 +693,7 @@
 				$to = new User();
 				$to->mId = $wgRequest->getint( 'manager', 0 );
 			} else {
-				$to = User::newFromId( $wgRequest->getint( 'manager', 0 ) );
+				$to = WhiteListUserFromId( $wgRequest->getint( 'manager', 0 ) );
 			}
 
 			// FIXME: I think this mail will be sent in the wrong language.
@@ -660,7 +745,7 @@
 		$res = $dbr->select( 'user_groups', 'ug_user', array( 'ug_group' => $wgWhiteListManagerGroup ), __METHOD__ );
 		$dbr->commit();
 		for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
-			$u = User::newFromID( $row->ug_user );
+			$u = WhiteListUserFromID( $row->ug_user );
 			$users[$u->getRealName()] = $row->ug_user;
 		}
 		$dbr->freeResult( $res );
Index: trunk/extensions/WhiteList/WhiteListEdit.i18n.php
===================================================================
--- trunk/extensions/WhiteList/WhiteListEdit.i18n.php	(revision 43377)
+++ trunk/extensions/WhiteList/WhiteListEdit.i18n.php	(revision 43378)
@@ -316,7 +316,6 @@
  */
 $messages['bs'] = array(
 	'whitelisttablemodifyall' => 'Sve',
-	'whitelisttableedit' => 'Uredi',
 	'whitelistrequestmsg' => '$1 zahtijeva pristup slijedećim stranicama:
 
 $2',
@@ -398,8 +397,7 @@
 	'whitelistoverviewrm' => '* Zugriff auf [[:$1|$1]] wird entfernt',
 	'whitelistoverviewna' => "* [[:$1|$1]] wird zur Whitelist hinzugefügt. (Zugriff: '''$2''', Ablaufdatum: '''$3''')",
 	'whitelistrequest' => 'Weiteren Zugriff beantragen',
-	'whitelistrequestmsg' => '$1 hat Zugriff auf die {{PLURAL:$3|folgende Seite|folgenden Seiten}} beantragt:
-
+	'whitelistrequestmsg' => '$1 hat Zugriff auf die folgenden Seiten beantragt:
 $2',
 	'whitelistrequestconf' => 'Beantragung an $1 geschickt',
 	'whitelistnonrestricted' => "'''$1''' ist kein beschränkter Benutzer.
@@ -532,8 +530,6 @@
 	'whitelistnewtabledate' => 'Date d’expiration :',
 	'whitelistnewtableedit' => 'Activer modification',
 	'whitelistnewtableview' => 'Activer visualisation',
-	'whitelistnowhitelistedusers' => 'Il n’y a aucun utilisateur dans le groupe « {{MediaWiki:Group-restricted}} ».
-Vous devez [[Special:UserRights|ajouter l’utilisateur au groupe]] avant que vous puissiez ajouter des pages à la liste blanche d’un utilisateur.',
 	'whitelistnewtableprocess' => 'Traiter',
 	'whitelistnewtablereview' => 'Réviser',
 	'whitelistselectrestricted' => '== Sélectionner un nom d’utilisateur à accès restreint ==',
@@ -546,7 +542,7 @@
 	'whitelistoverviewrm' => '* Retrait de l’accès à [[:$1|$1]]',
 	'whitelistoverviewna' => "* Ajoute [[:$1|$1]] à la liste blanche avec les droits de '''$2''' avec pour date d’expiration le '''$3'''",
 	'whitelistrequest' => 'Demande d’accès à plus de pages',
-	'whitelistrequestmsg' => '$1 a demandé l’accès {{PLURAL:$3|à la page suivante|aux pages suivantes}} :
+	'whitelistrequestmsg' => '$1 a demandé l’accès aux pages suivantes :
 
 $2',
 	'whitelistrequestconf' => 'Une demande d’accès pour de nouvelles pages a été envoyée à $1',
@@ -554,14 +550,6 @@
 Cette page ne s’applique qu’aux utilisateurs disposant de droits restreints.",
 	'whitelistnever' => 'jamais',
 	'whitelistnummatches' => ' - {{PLURAL:$1|une occurence|$1 occurences}}',
-	'right-editwhitelist' => 'Modifier la liste blanche pour les utilisateurs existants',
-	'right-restricttowhitelist' => 'Modifier et visionner les pages figurant uniquement sur la liste blanche',
-	'action-editwhitelist' => 'modifier la liste blanche pour les utilisateurs existants',
-	'action-restricttowhitelist' => 'modifier et visionner les pages figurant uniquement sur la liste blanche',
-	'group-restricted' => 'Utilisateurs restreints',
-	'group-restricted-member' => 'Utilisateur restreint',
-	'group-manager' => 'Gestionnaires',
-	'group-manager-member' => 'Gestionnaire',
 );
 
 /** Western Frisian (Frysk)
@@ -614,7 +602,7 @@
 	'whitelistoverviewrm' => '* Eliminando o acceso a [[:$1|$1]]',
 	'whitelistoverviewna' => "* Engadindo [[:$1|$1]] á listaxe branca (whitelist) con acceso a '''$2''' e data de remate '''$3'''",
 	'whitelistrequest' => 'Solicitar acceso a máis páxinas',
-	'whitelistrequestmsg' => '$1 solicitou ter acceso {{PLURAL:$3|á seguinte páxina|ás seguintes páxinas}}:
+	'whitelistrequestmsg' => '$1 solicitou ter acceso ás seguintes páxinas:
 
 $2',
 	'whitelistrequestconf' => 'A solicitude para páxinas novas foi enviada a $1',
@@ -622,8 +610,6 @@
 Esta páxina só é aplicable aos usuarios limitados",
 	'whitelistnever' => 'nunca',
 	'whitelistnummatches' => ' - {{PLURAL:$1|unha coincidencia|$1 coincidencias}}',
-	'group-restricted' => 'Usuarios restrinxidos',
-	'group-restricted-member' => 'Usuario restrinxido',
 );
 
 /** Gothic
@@ -682,8 +668,6 @@
 	'whitelistnewtabledate' => 'תאריך הפקיעה:',
 	'whitelistnewtableedit' => 'הגדרה לעריכה',
 	'whitelistnewtableview' => 'הגדרה לתצוגה',
-	'whitelistnowhitelistedusers' => 'אין משתמשים בקבוצה "{{MediaWiki:Group-restricted}}".
-יהיה עליכם [[Special:UserRights|להוסיף משתמשים לקבוצה]] לפני שתוכלו להוסיף דפים לרשימה הלבנה של המשתמש.',
 	'whitelistnewtableprocess' => 'עיבוד',
 	'whitelistnewtablereview' => 'סקירה',
 	'whitelistselectrestricted' => '== בחירת שם המשתמש המוגבל ==',
@@ -696,7 +680,7 @@
 	'whitelistoverviewrm' => '* הסרת הגישה אל [[:$1|$1]]',
 	'whitelistoverviewna' => "* הוספת [[:$1|$1]] לרשימה הלבנה עם הגישה '''$2''' ותאריך הפקיעה '''$3'''",
 	'whitelistrequest' => 'בקשת גישה לדפים נוספים',
-	'whitelistrequestmsg' => '$1 ביקש גישה ל{{PLURAL:$3|דף הבא|דפים הבאים}}:
+	'whitelistrequestmsg' => '$1 ביקש גישה לדפים הבאים:
 
 $2',
 	'whitelistrequestconf' => 'הבקשה לדפים חדשים נשלחה אל $1',
@@ -704,14 +688,6 @@
 ניתן להשתמש בדף זה עבור משתמשים מוגבלים בלבד",
 	'whitelistnever' => 'לעולם לא',
 	'whitelistnummatches' => ' - {{PLURAL:$1|תוצאה אחת|$1 תוצאות}}',
-	'right-editwhitelist' => 'שינוי הרשימה הלבנה למשתמשים קיימים',
-	'right-restricttowhitelist' => 'עריכה והצגה של דפים מהרשימה הלבנה בלבד',
-	'action-editwhitelist' => 'לשנות את הרשימה הלבנה למשתמשים קיימים',
-	'action-restricttowhitelist' => 'לערוך ולהציג דפים מהרשימה הלבנה בלבד',
-	'group-restricted' => 'משתמשים מוגבלים',
-	'group-restricted-member' => 'משתמש מוגבל',
-	'group-manager' => 'מנהלים',
-	'group-manager-member' => 'מנהל',
 );
 
 /** Hindi (हिन्दी)
@@ -984,13 +960,12 @@
 	'whitelistoverviewsa' => "* Autorisatioun vum '''$1''' op [[:$2|$2]] astellen",
 	'whitelistoverviewrm' => '* Autorisatioun fir [[:$1|$1]] gët ewechgeholl',
 	'whitelistrequest' => 'Zougang zu méi Säite froen',
-	'whitelistrequestmsg' => '$1 huet Zougrëff op dës {{PLURAL:$3|Säit|Säite}} gfrot:
+	'whitelistrequestmsg' => '$1 huet Accès op dës Säite gfrot:
 
 $2',
 	'whitelistrequestconf' => "D'Ufro fir nei Säite gouf geschéckt un $1",
 	'whitelistnever' => 'nie',
 	'whitelistnummatches' => ' - $1 {{PLURAL:$1|Resultat|Resultater}}',
-	'group-restricted' => 'Limitéiert Benotzer',
 );
 
 /** Eastern Mari (Олык Марий)
@@ -1296,7 +1271,6 @@
 
 /** Polish (Polski)
  * @author Derbeth
- * @author Leinad
  * @author Sp5uhe
  * @author Wpedzich
  */
@@ -1338,7 +1312,7 @@
 	'whitelistoverviewrm' => '* Usuwanie dostępu do [[:$1|$1]]',
 	'whitelistoverviewna' => "* Dodawanie elementu [[:$1|$1]] do listy dostępu – dostęp dla '''$2''', data wygaśnięcia '''$3'''",
 	'whitelistrequest' => 'Zażądaj dostępu do większej liczby stron',
-	'whitelistrequestmsg' => 'Użytkownik $1 zażądał dostępu do {{PLURAL:$3|następującej strony|następujących stron}}:
+	'whitelistrequestmsg' => 'Użytkownik $1 zażądał dostępu do następujących stron:
 
 $2',
 	'whitelistrequestconf' => 'Żądanie utworzenia nowych stron zostało przesłane do $1',
@@ -1459,8 +1433,6 @@
 	'whitelistnewtabledate' => 'Dátum vypršania:',
 	'whitelistnewtableedit' => 'Nastaviť na Upraviť',
 	'whitelistnewtableview' => 'Nastaviť na Zobraziť',
-	'whitelistnowhitelistedusers' => 'V skupine „{{MediaWiki:Group-restricted}}“ sa nenachádzajú žiadni používatelia.
-Musíte [[Special:UserRights|pridať používateľov do tejto skupiny]] predtým, než budete môcť pridávať stránky na bielu listinu používateľa.',
 	'whitelistnewtableprocess' => 'Spracovať',
 	'whitelistnewtablereview' => 'Skontrolovať',
 	'whitelistselectrestricted' => '== Vyberte meno používateľa ==',
@@ -1473,7 +1445,7 @@
 	'whitelistoverviewrm' => '* Odstránenie prístupu na [[:$1|$1]]',
 	'whitelistoverviewna' => "* Pridanie prístupu [[:$1|$1]] na bielu listinu s prístupom '''$2''' a vypršaním '''$3'''",
 	'whitelistrequest' => 'Požiadať o prístup k viacerým stránkam',
-	'whitelistrequestmsg' => '$1 požiadal o prístup k {{PLURAL:$3|nasledovnej stránke|nasledovným stránkam}}:
+	'whitelistrequestmsg' => '$1 požiadal o prístup k nasledovným stránkam:
 
 $2',
 	'whitelistrequestconf' => 'Žiadosť o nové stránky bola odoslaná $1',
@@ -1481,14 +1453,6 @@
 Táto stránka sa týka iba obmedzneých používateľov.",
 	'whitelistnever' => 'nikdy',
 	'whitelistnummatches' => ' - $1 {{PLURAL:$1|výsledok|výsledky|výsledkov}}',
-	'right-editwhitelist' => 'Zmeniť bielu listinu existujúcich používateľov',
-	'right-restricttowhitelist' => 'Upravovať a prezerať iba stránky z bielej listiny',
-	'action-editwhitelist' => 'zmeniť bielu listinu existujúcich používateľov',
-	'action-restricttowhitelist' => 'upravovať a prezerať iba stránky z bielej listiny',
-	'group-restricted' => 'Obmedzení používatelia',
-	'group-restricted-member' => 'Obmedzený používateľ',
-	'group-manager' => 'Správcovia',
-	'group-manager-member' => 'Správca',
 );
 
 /** Serbian Cyrillic ekavian (ћирилица)
Index: trunk/extensions/WhiteList/WhiteListEdit.php
===================================================================
--- trunk/extensions/WhiteList/WhiteListEdit.php	(revision 43377)
+++ trunk/extensions/WhiteList/WhiteListEdit.php	(revision 43378)
@@ -30,8 +30,8 @@
 
 $wgExtensionCredits['specialpage'][] = array(
 	'name'           => 'WhiteListEdit',
-	'version'        => 'v0.11.0',
-	'author'         => array( 'Paul Grinberg', 'Mike Sullivan' ),
+	'version'        => 'v0.11.2',
+	'author'         => array('Paul Grinberg', 'Mike Sullivan'),
 	'email'          => 'gri6507 at yahoo dot com, ms-mediawiki AT umich DOT edu',
 	'description'    => 'Edit the access permissions of restricted users',
 	'descriptionmsg' => 'whitelist-desc',
@@ -92,17 +92,32 @@
 
 $dir = dirname( __FILE__ ) . '/';
 
-$wgExtensionMessagesFiles['WhiteList'] = $dir . 'WhiteListEdit.i18n.php';
-$wgExtensionAliasesFiles['WhiteList']  = $dir . 'WhiteListEdit.alias.php';
-$wgAutoloadClasses['WhiteListEdit']    = $dir . 'WhiteListEdit_body.php';
-$wgAutoloadClasses['WhiteList']        = $dir . 'WhiteListEdit_body.php';
-$wgAutoloadClasses['WhiteListExec']    = $dir . 'WhiteListAuth.php';
-$wgAutoloadClasses['WhiteListHooks']   = $dir . 'WhiteListAuth.php';
-$wgSpecialPages['WhiteListEdit']       = 'WhiteListEdit';
-$wgSpecialPages['WhiteList']           = 'WhiteList';
+$wgExtensionMessagesFiles['WhiteListEdit'] = $dir . 'WhiteListEdit.i18n.php';
+$wgExtensionMessagesFiles['WhiteList']     = $dir . 'WhiteListEdit.i18n.php';
+$wgExtensionAliasesFiles['WhiteList']      = $dir . 'WhiteListEdit.alias.php';
+$wgAutoloadClasses['WhiteListEdit']        = $dir . 'WhiteListEdit_body.php';
+$wgAutoloadClasses['WhiteList']            = $dir . 'WhiteListEdit_body.php';
+$wgAutoloadClasses['WhiteListExec']        = $dir . 'WhiteListAuth.php';
+$wgAutoloadClasses['WhiteListHooks']       = $dir . 'WhiteListAuth.php';
+$wgSpecialPages['WhiteListEdit']           = 'WhiteListEdit';
+$wgSpecialPages['WhiteList']               = 'WhiteList';
 $wgSpecialPageGroups['WhiteListEdit'] = 'users';
 $wgSpecialPageGroups['WhiteList'] = 'users';
 
-$wgHooks['PersonalUrls'][] = 'WhiteListHooks::AddRestrictedPagesTab';
-$wgHooks['userCan'][] = 'WhiteListExec::CheckWhiteList';
-$wgHooks['LoadExtensionSchemaUpdates'][] = 'WhiteListHooks::CheckSchema';
+# this is a compatability workaround for MW versions 1.9.3 and earlier.
+function WL_doCheckWhiteList(&$title, &$uwUser, $action, &$result) {
+	return WhiteListExec::CheckWhiteList($title, $uwUser, $action, $result);
+}
+
+function WL_doAddRestrictedPagesTab(&$personal_urls, $wgTitle) {
+	return WhiteListHooks::AddRestrictedPagesTab($personal_urls, $wgTitle);
+}
+
+// TODO - this is missing from Siebrand's changes
+function WL_doCheckSchema() {
+	return WhiteListHooks::CheckSchema();
+}
+
+$wgHooks['PersonalUrls'][] = 'WL_doAddRestrictedPagesTab';
+$wgHooks['userCan'][] = 'WL_doCheckWhiteList';
+$wgHooks['LoadExtensionSchemaUpdates'][] = 'WL_doCheckSchema';

Comments

#Comment by Aaron Schulz (Talk | contribs)   05:25, 11 November 2008

Instead of a bunch of compatibility stuff in the the /trunk versions, perhaps older versions MW can just use the corresponding branch version of the extension?

#Comment by Gri6507 (Talk | contribs)   13:46, 11 November 2008

If this is the model for all extensions moving forward, then I can see its benefit from the stand point of consistency. However, as far as being a developer is concerned, this would mean having to maintain numerous versions for all the branches of MW. That also means that a not-so-savvy user of the extension would have to now understand more about the extension than they really should. It seems like what you propose adds complexity to the end user and adds a maintenance headache to the developer. Any comments? --~~~~

#Comment by Voice of All (Talk | contribs)   15:53, 11 November 2008

Not really. If an extension corresponds to MW 1.12, then it can be in the 1.12 extension branch. Since 1.12 doesn't change much, there would be minimal maintenance.

The problem with having one running b/comp version is that the code has added complexity and checks for various older versions that pile up.

#Comment by Aaron Schulz (Talk | contribs)   15:53, 11 November 2008

Bah, logged in as wrong account. Still me :)

#Comment by Gri6507 (Talk | contribs)   17:21, 11 November 2008

I guess I'm not as concerned about maintaining the branched extension from the standpoint of MW driven changes. I understand that once a particular version of MW is branched off, little is done to change it. Therefore the impact of those small MW changes on the branched extension is minimal.

However, what I am more concerned about is new extension features. There are several reasons why the WhiteList extension is still a beta. Firstly, there are still some bugs there. Fixing bugs in this new schema of branched extension versions would require patching each version independently. An even bigger problem is the fact that the extension still has feature improvements that are under way. Adding these new features into the branched extension versions seems like a lot of maintenance work.

Status & tagging log

  • 15:36, 12 September 2011 Meno25 (Talk | contribs) changed the status of r43378 [removed: deferred added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox