Add magic word for protection expiry
authorcenarium <cenarium.sysop@gmail.com>
Fri, 27 Nov 2015 18:44:11 +0000 (19:44 +0100)
committerSiebrand <siebrand@kitano.nl>
Mon, 7 Dec 2015 10:02:12 +0000 (10:02 +0000)
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

includes/parser/CoreParserFunctions.php
languages/messages/MessagesEn.php

index 42091a0..d25d11a 100644 (file)
@@ -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
index 4e6f12b..ec20601 100644 (file)
@@ -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' ),