r45587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45586‎ | r45587 | 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:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -45,6 +45,7 @@
4646 $parser->setFunctionHook( 'filepath', array( __CLASS__, 'filepath' ), SFH_NO_HASH );
4747 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH );
4848 $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH );
 49+ $parser->setFunctionHook( 'protectionlevel', array( __CLASS__, 'protectionlevel' ), SFH_NO_HASH );
4950 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
5051
5152 if ( $wgAllowDisplayTitle ) {
@@ -292,6 +293,16 @@
293294 }
294295 return self::formatRaw( $length, $raw );
295296 }
 297+
 298+ /**
 299+ * Returns the requested protection level for the current page
 300+ */
 301+ static function protectionlevel( $parser, $type = '' ) {
 302+ $restrictions = $parser->mTitle->getRestrictions( strtolower( $type ) );
 303+ # Title::getRestrictions returns an array, its possible it may have
 304+ # multiple values in the future
 305+ return implode( $restrictions, ',' );
 306+ }
296307
297308 static function language( $parser, $arg = '' ) {
298309 global $wgContLang;
Index: trunk/phase3/includes/MagicWord.php
@@ -109,6 +109,7 @@
110110 'index',
111111 'noindex',
112112 'numberingroup',
 113+ 'protectionlevel',
113114 );
114115
115116 /* Array of caching hints for ParserCache */
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -333,6 +333,7 @@
334334 'noindex' => array( 1, '__NOINDEX__' ),
335335 'numberingroup' => array( 1, 'NUMBERINGROUP', 'NUMINGROUP' ),
336336 'staticredirect' => array( 1, '__STATICREDIRECT__' ),
 337+ 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ),
337338 );
338339
339340 /**
Index: trunk/phase3/RELEASE-NOTES
@@ -29,7 +29,9 @@
3030 * Added "Advanced search" link to the search form
3131 * Special:Upload can now have a custom upload message instead of uploadtext by
3232 passing "uploadmsg" parameter in the url
33 -
 33+* (bug 9947) Add PROTECTIONLEVEL parser funtion to return the protection level
 34+ for the current page for a given action
 35+
3436 === Bug fixes in 1.15 ===
3537
3638

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