From: cenarium Date: Fri, 27 Nov 2015 18:44:11 +0000 (+0100) Subject: Add magic word for protection expiry X-Git-Tag: 1.31.0-rc.0~8778^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=a042808b919f3c41d00061e78281d35b897c9650;p=lhc%2Fweb%2Fwiklou.git Add magic word for protection expiry This adds a magic word to get the protection expiry for a page for a given action. Usage is {{PROTECTIONEXPIRY:action}}. Bug: T19354 Change-Id: Ia1a20e313781789480dc082bdc7f585c4f0e28df --- diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 42091a07d6..d25d11a6db 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -46,7 +46,7 @@ class CoreParserFunctions { 'numberofarticles', 'numberoffiles', 'numberofadmins', 'numberingroup', 'numberofedits', 'language', 'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath', - 'pagesincategory', 'pagesize', 'protectionlevel', + 'pagesincategory', 'pagesize', 'protectionlevel', 'protectionexpiry', 'namespacee', 'namespacenumber', 'talkspace', 'talkspacee', 'subjectspace', 'subjectspacee', 'pagename', 'pagenamee', 'fullpagename', 'fullpagenamee', 'rootpagename', 'rootpagenamee', @@ -772,8 +772,8 @@ class CoreParserFunctions { /** * Returns the requested protection level for the current page. This * is an expensive parser function and can't be called too many times - * per page, unless the protection levels for the given title have - * already been retrieved + * per page, unless the protection levels/expiries for the given title + * have already been retrieved * * @param Parser $parser * @param string $type @@ -795,6 +795,35 @@ class CoreParserFunctions { return ''; } + /** + * Returns the requested protection expiry for the current page. This + * is an expensive parser function and can't be called too many times + * per page, unless the protection levels/expiries for the given title + * have already been retrieved + * + * @param Parser $parser + * @param string $type + * @param string $title + * + * @return string + */ + public static function protectionexpiry( $parser, $type = '', $title = '' ) { + $titleObject = Title::newFromText( $title ); + if ( !( $titleObject instanceof Title ) ) { + $titleObject = $parser->mTitle; + } + if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) { + $expiry = $parser->mTitle->getRestrictionExpiry( strtolower( $type ) ); + // getRestrictionExpiry() returns false on invalid type; trying to + // match protectionlevel() function that returns empty string instead + if ( $expiry === false ) { + $expiry = ''; + } + return $expiry; + } + return ''; + } + /** * Gives language names. * @param Parser $parser diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 4e6f12b61c..ec20601b18 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -360,6 +360,7 @@ $magicWords = array( 'numberingroup' => array( 1, 'NUMBERINGROUP', 'NUMINGROUP' ), 'staticredirect' => array( 1, '__STATICREDIRECT__' ), 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ), + 'protectionexpiry' => array( 1, 'PROTECTIONEXPIRY' ), 'cascadingsources' => array( 1, 'CASCADINGSOURCES' ), 'formatdate' => array( 0, 'formatdate', 'dateformat' ), 'url_path' => array( 0, 'PATH' ),