Merge "Fix various docs and version numbers from 84a2f570"
[lhc/web/wiklou.git] / includes / parser / CoreParserFunctions.php
index df0f118..3966b9e 100644 (file)
@@ -387,7 +387,7 @@ class CoreParserFunctions {
 
                if ( !$wgRestrictDisplayTitle ) {
                        $parser->mOutput->setDisplayTitle( $text );
-               } elseif ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
+               } elseif ( $title instanceof Title && !$title->hasFragment() && $title->equals( $parser->mTitle ) ) {
                        $parser->mOutput->setDisplayTitle( $text );
                }
 
@@ -679,12 +679,6 @@ class CoreParserFunctions {
         * Return the size of the given page, or 0 if it's nonexistent.  This is an
         * expensive parser function and can't be called too many times per page.
         *
-        * @todo FIXME: Title::getLength() documentation claims that it adds things
-        *   to the link cache, so the local cache here should be unnecessary, but
-        *   in fact calling getLength() repeatedly for the same $page does seem to
-        *   run one query for each call?
-        * @todo Document parameters
-        *
         * @param $parser Parser
         * @param $page String Name of page to check (Default: empty string)
         * @param $raw String Should number be human readable with commas or just number
@@ -704,7 +698,10 @@ class CoreParserFunctions {
        }
 
        /**
-        * Returns the requested protection level for the current page
+        * 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
         *
         * @param Parser $parser
         * @param string $type
@@ -717,10 +714,13 @@ class CoreParserFunctions {
                if ( !( $titleObject instanceof Title ) ) {
                        $titleObject = $parser->mTitle;
                }
-               $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
-               # Title::getRestrictions returns an array, its possible it may have
-               # multiple values in the future
-               return implode( $restrictions, ',' );
+               if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
+                       $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
+                       # Title::getRestrictions returns an array, its possible it may have
+                       # multiple values in the future
+                       return implode( $restrictions, ',' );
+               }
+               return '';
        }
 
        /**
@@ -986,10 +986,34 @@ class CoreParserFunctions {
                // Use title from parser to have correct pageid after edit
                if ( $t->equals( $parser->getTitle() ) ) {
                        $t = $parser->getTitle();
+                       return $t->getArticleID();
+               }
+
+               // These can't have ids
+               if ( !$t->canExist() || $t->isExternal() ) {
+                       return 0;
+               }
+
+               // Check the link cache, maybe something already looked it up.
+               $linkCache = LinkCache::singleton();
+               $pdbk = $t->getPrefixedDBkey();
+               $id = $linkCache->getGoodLinkID( $pdbk );
+               if ( $id != 0 ) {
+                       $parser->mOutput->addLink( $t, $id );
+                       return $id;
+               }
+               if ( $linkCache->isBadLink( $pdbk ) ) {
+                       $parser->mOutput->addLink( $t, 0 );
+                       return $id;
                }
-               // fetch pageid from cache/database and return the value
-               $pageid = $t->getArticleID();
-               return $pageid ? $pageid : '';
+
+               // We need to load it from the DB, so mark expensive
+               if ( $parser->incrementExpensiveFunctionCount() ) {
+                       $id = $t->getArticleID();
+                       $parser->mOutput->addLink( $t, $id );
+                       return $id;
+               }
+               return null;
        }
 
        /**
@@ -1123,7 +1147,8 @@ class CoreParserFunctions {
        /**
         * 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.
+        * This is an expensive parser function and can't be called too many times per page,
+        * unless cascading protection sources for the page have already been loaded.
         *
         * @param Parser $parser
         * @param string $title
@@ -1136,15 +1161,17 @@ class CoreParserFunctions {
                if ( !( $titleObject instanceof Title ) ) {
                        $titleObject = $parser->mTitle;
                }
-               $names = array();
-               if ( $parser->incrementExpensiveFunctionCount() ) {
+               if ( $titleObject->areCascadeProtectionSourcesLoaded()
+                       || $parser->incrementExpensiveFunctionCount()
+               ) {
+                       $names = array();
                        $sources = $titleObject->getCascadeProtectionSources();
                        foreach ( $sources[0] as $sourceTitle ) {
                                $names[] = $sourceTitle->getPrefixedText();
                        }
+                       return implode( $names, '|' );
                }
-
-               return implode( $names, '|' );
+               return '';
        }
 
 }