r45587 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r45586 | r45587 (on ViewVC) | r45588 >
Date:23:21, 8 January 2009
Author:mrzman
Status:ok (Comments)
Tags:
Comment:(bug 9947) Add PROTECTIONLEVEL parser function to return the protection level for a given action (e.g. edit, move) for the current page.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
===================================================================
--- trunk/phase3/includes/parser/CoreParserFunctions.php	(revision 45586)
+++ trunk/phase3/includes/parser/CoreParserFunctions.php	(revision 45587)
@@ -45,6 +45,7 @@
 		$parser->setFunctionHook( 'filepath',         array( __CLASS__, 'filepath'         ), SFH_NO_HASH );
 		$parser->setFunctionHook( 'pagesincategory',  array( __CLASS__, 'pagesincategory'  ), SFH_NO_HASH );
 		$parser->setFunctionHook( 'pagesize',         array( __CLASS__, 'pagesize'         ), SFH_NO_HASH );
+		$parser->setFunctionHook( 'protectionlevel',  array( __CLASS__, 'protectionlevel'  ), SFH_NO_HASH );
 		$parser->setFunctionHook( 'tag',              array( __CLASS__, 'tagObj'           ), SFH_OBJECT_ARGS );
 
 		if ( $wgAllowDisplayTitle ) {
@@ -292,6 +293,16 @@
 		}	
 		return self::formatRaw( $length, $raw );
 	}
+	
+	/**
+	* Returns the requested protection level for the current page
+	*/
+	static function protectionlevel( $parser, $type = '' ) {
+		$restrictions = $parser->mTitle->getRestrictions( strtolower( $type ) );
+		# Title::getRestrictions returns an array, its possible it may have
+		# multiple values in the future
+		return implode( $restrictions, ',' );
+	}
 
 	static function language( $parser, $arg = '' ) {
 		global $wgContLang;
Index: trunk/phase3/includes/MagicWord.php
===================================================================
--- trunk/phase3/includes/MagicWord.php	(revision 45586)
+++ trunk/phase3/includes/MagicWord.php	(revision 45587)
@@ -109,6 +109,7 @@
 		'index',
 		'noindex',
 		'numberingroup',
+		'protectionlevel',
 	);
 
 	/* Array of caching hints for ParserCache */
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 45586)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 45587)
@@ -333,6 +333,7 @@
 	'noindex'                => array( 1,    '__NOINDEX__'            ),
 	'numberingroup'          => array( 1,    'NUMBERINGROUP', 'NUMINGROUP' ),
 	'staticredirect'         => array( 1,    '__STATICREDIRECT__'     ),
+	'protectionlevel'        => array( 1,    'PROTECTIONLEVEL'        ),
 );
 
 /**
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 45586)
+++ trunk/phase3/RELEASE-NOTES	(revision 45587)
@@ -29,7 +29,9 @@
 * Added "Advanced search" link to the search form
 * Special:Upload can now have a custom upload message instead of uploadtext by
   passing "uploadmsg" parameter in the url
-
+* (bug 9947) Add PROTECTIONLEVEL parser funtion to return the protection level
+  for the current page for a given action
+  
 === Bug fixes in 1.15 ===
 
 

Comments

#Comment by IAlex (Talk | contribs)   10:00, 9 January 2009

One little thing: adding a variable ID to MagicWords::$mVariableIDs means that you'll handle it in Parser::getVariableValue(), which is not the case here. You don't need to add a magic word ID there if it'll be used for parser function. The problem is now that you can add "{{PROTECTIONLEVEL}}" in wikitext, but the result will always be an empty string, even if the page is a protected page.

#Comment by Mr.Z-man (Talk | contribs)   18:29, 9 January 2009

removed in r45609. Some others can probably be removed from there too...

#Comment by Brion VIBBER (Talk | contribs)   00:05, 14 January 2009

We're a bit leery of this.

#Comment by Brion VIBBER (Talk | contribs)   00:06, 14 January 2009

[4:05pm] TimStarling: brion: I would say leave it in, and make sure protection changes do indeed invalidate the parser cache

#Comment by Mr.Z-man (Talk | contribs)   00:36, 14 January 2009

Article::updateRestrictions() updates page_touched, which should invalidate the parser cache.

#Comment by Brion VIBBER (Talk | contribs)   00:45, 14 January 2009

w00t

#Comment by Aaron Schulz (Talk | contribs)   23:06, 20 January 2009

So this is OK, right?

Status & tagging log

Views
Toolbox