Merge "Add CASCADINGSOURCES parser function"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 6 Jan 2014 19:04:53 +0000 (19:04 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 6 Jan 2014 19:04:53 +0000 (19:04 +0000)
includes/MagicWord.php
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php
languages/messages/MessagesEn.php

index 232f43e..bf15bf3 100644 (file)
@@ -149,6 +149,7 @@ class MagicWord {
                'contentlanguage',
                'numberofadmins',
                'numberofviews',
+               'cascadingsources',
        );
 
        /* Array of caching hints for ParserCache */
index ca27112..4e7e663 100644 (file)
@@ -54,7 +54,7 @@ class CoreParserFunctions {
                        'talkpagename', 'talkpagenamee', 'subjectpagename',
                        'subjectpagenamee', 'pageid', 'revisionid', 'revisionday',
                        'revisionday2', 'revisionmonth', 'revisionmonth1', 'revisionyear',
-                       'revisiontimestamp', 'revisionuser',
+                       'revisiontimestamp', 'revisionuser', 'cascadingsources',
                );
                foreach ( $noHashFunctions as $func ) {
                        $parser->setFunctionHook( $func, array( __CLASS__, $func ), SFH_NO_HASH );
@@ -1118,4 +1118,32 @@ class CoreParserFunctions {
                $rev = self::getCachedRevisionObject( $parser, $t );
                return $rev ? $rev->getUserText() : '';
        }
+
+       /**
+        * Returns the sources of any cascading protection acting on a specified page.
+        * Pages will not return their own title unless they transclude themselves.
+        * This is an expensive parser function and can't be called too many times per page.
+        *
+        * @param Parser $parser
+        * @param string $title
+        *
+        * @return string
+        * @since 1.23
+        */
+       public static function cascadingsources( $parser, $title = '' ) {
+               $titleObject = Title::newFromText( $title );
+               if ( !( $titleObject instanceof Title ) ) {
+                       $titleObject = $parser->mTitle;
+               }
+               $names = array();
+               if ( $parser->incrementExpensiveFunctionCount() ) {
+                       $sources = $titleObject->getCascadeProtectionSources();
+                       foreach ( $sources[0] as $sourceTitle ) {
+                               $names[] = $sourceTitle->getText();
+                       }
+               }
+
+               return implode( $names, '|' );
+       }
+
 }
index d81ad98..71cb863 100644 (file)
@@ -3031,6 +3031,9 @@ class Parser {
                        case 'contentlanguage':
                                global $wgLanguageCode;
                                return $wgLanguageCode;
+                       case 'cascadingsources':
+                               $value = CoreParserFunctions::cascadingsources( $this );
+                               break;
                        default:
                                $ret = null;
                                wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) );
index 04d7ced..1889368 100644 (file)
@@ -363,6 +363,7 @@ $magicWords = array(
        'numberingroup'           => array( 1,    'NUMBERINGROUP', 'NUMINGROUP' ),
        'staticredirect'          => array( 1,    '__STATICREDIRECT__' ),
        'protectionlevel'         => array( 1,    'PROTECTIONLEVEL' ),
+       'cascadingsources'        => array( 1,    'CASCADINGSOURCES' ),
        'formatdate'              => array( 0,    'formatdate', 'dateformat' ),
        'url_path'                => array( 0,    'PATH' ),
        'url_wiki'                => array( 0,    'WIKI' ),