Include namespaces in {{CASCADINGSOURCES}} output
[lhc/web/wiklou.git] / includes / parser / CoreParserFunctions.php
index ec8f776..250442c 100644 (file)
@@ -46,7 +46,7 @@ class CoreParserFunctions {
                        'numberofarticles', 'numberoffiles', 'numberofadmins',
                        'numberingroup', 'numberofedits', 'numberofviews', 'language',
                        'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath',
-                       'pagesincategory', 'pagesize', 'protectionlevel', 'namespace',
+                       'pagesincategory', 'pagesize', 'protectionlevel',
                        'namespacee', 'namespacenumber', 'talkspace', 'talkspacee',
                        'subjectspace', 'subjectspacee', 'pagename', 'pagenamee',
                        'fullpagename', 'fullpagenamee', 'rootpagename', 'rootpagenamee',
@@ -54,12 +54,13 @@ 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 );
                }
 
+               $parser->setFunctionHook( 'namespace',  array( __CLASS__, 'mwnamespace' ), SFH_NO_HASH );
                $parser->setFunctionHook( 'int',        array( __CLASS__, 'intFunction' ), SFH_NO_HASH );
                $parser->setFunctionHook( 'special',    array( __CLASS__, 'special'     ) );
                $parser->setFunctionHook( 'speciale',   array( __CLASS__, 'speciale'    ) );
@@ -208,7 +209,7 @@ class CoreParserFunctions {
        }
 
        static function localurle( $parser, $s = '', $arg = null ) {
-               return self::urlFunction( 'escapeLocalURL', $s, $arg );
+               return htmlspecialchars( self::urlFunction( 'getLocalURL', $s, $arg ) );
        }
 
        static function fullurl( $parser, $s = '', $arg = null ) {
@@ -1117,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->getPrefixedText();
+                       }
+               }
+
+               return implode( $names, '|' );
+       }
+
 }