From a445dd5e112124eb56a840caab1ed14dac5f89d5 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Thu, 8 Jan 2009 23:21:06 +0000 Subject: [PATCH] (bug 9947) Add PROTECTIONLEVEL parser function to return the protection level for a given action (e.g. edit, move) for the current page. --- RELEASE-NOTES | 4 +++- includes/MagicWord.php | 1 + includes/parser/CoreParserFunctions.php | 11 +++++++++++ languages/messages/MessagesEn.php | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b281efc483..beec495f73 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -29,7 +29,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * 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 === diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 5b5b77f0ff..6eefd7a60c 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -109,6 +109,7 @@ class MagicWord { 'index', 'noindex', 'numberingroup', + 'protectionlevel', ); /* Array of caching hints for ParserCache */ diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index a3b5189a31..2dfd34bfea 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -45,6 +45,7 @@ class CoreParserFunctions { $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 @@ class CoreParserFunctions { } 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; diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index ebabc4b4ed..e7acf03758 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -333,6 +333,7 @@ $magicWords = array( 'noindex' => array( 1, '__NOINDEX__' ), 'numberingroup' => array( 1, 'NUMBERINGROUP', 'NUMINGROUP' ), 'staticredirect' => array( 1, '__STATICREDIRECT__' ), + 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ), ); /** -- 2.20.1