Mark Linker::link() as @deprecated
[lhc/web/wiklou.git] / includes / Title.php
index b996def..8aa8cb7 100644 (file)
@@ -22,6 +22,7 @@
  * @file
  */
 use MediaWiki\Linker\LinkTarget;
+use MediaWiki\Interwiki\InterwikiLookup;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -170,6 +171,18 @@ class Title implements LinkTarget {
                return MediaWikiServices::getInstance()->getTitleFormatter();
        }
 
+       /**
+        * B/C kludge: provide an InterwikiLookup for use by Title.
+        * Ideally, Title would have no methods that need this.
+        * Avoid usage of this singleton by using TitleValue
+        * and the associated services when possible.
+        *
+        * @return InterwikiLookup
+        */
+       private static function getInterwikiLookup() {
+               return MediaWikiServices::getInstance()->getInterwikiLookup();
+       }
+
        /**
         * @access protected
         */
@@ -760,7 +773,7 @@ class Title implements LinkTarget {
         */
        public function isLocal() {
                if ( $this->isExternal() ) {
-                       $iw = Interwiki::fetch( $this->mInterwiki );
+                       $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
                        if ( $iw ) {
                                return $iw->isLocal();
                        }
@@ -808,7 +821,7 @@ class Title implements LinkTarget {
                        return false;
                }
 
-               return Interwiki::fetch( $this->mInterwiki )->isTranscludable();
+               return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
        }
 
        /**
@@ -821,7 +834,7 @@ class Title implements LinkTarget {
                        return false;
                }
 
-               return Interwiki::fetch( $this->mInterwiki )->getWikiID();
+               return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
        }
 
        /**
@@ -1677,7 +1690,7 @@ class Title implements LinkTarget {
 
                $query = self::fixUrlQueryArgs( $query, $query2 );
 
-               $interwiki = Interwiki::fetch( $this->mInterwiki );
+               $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
                if ( $interwiki ) {
                        $namespace = $this->getNsText();
                        if ( $namespace != '' ) {
@@ -1716,7 +1729,7 @@ class Title implements LinkTarget {
                                if ( $url === false
                                        && $wgVariantArticlePath
                                        && preg_match( '/^variant=([^&]*)$/', $query, $matches )
-                                       && $wgContLang->getCode() === $this->getPageLanguage()->getCode()
+                                       && $this->getPageLanguage()->equals( $wgContLang )
                                        && $this->getPageLanguage()->hasVariants()
                                ) {
                                        $variant = urldecode( $matches[1] );
@@ -1760,12 +1773,13 @@ class Title implements LinkTarget {
         *
         * @param array $query
         * @param bool $query2
-        * @param string $proto Protocol to use; setting this will cause a full URL to be used
+        * @param string|int|bool $proto A PROTO_* constant on how the URL should be expanded,
+        *                               or false (default) for no expansion
         * @see self::getLocalURL for the arguments.
         * @return string The URL
         */
-       public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
-               if ( $this->isExternal() || $proto !== PROTO_RELATIVE ) {
+       public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
+               if ( $this->isExternal() || $proto !== false ) {
                        $ret = $this->getFullURL( $query, $query2, $proto );
                } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
                        $ret = $this->getFragmentForURL();
@@ -4353,19 +4367,23 @@ class Title implements LinkTarget {
                        return true; // avoid gap locking if we know it's not there
                }
 
-               $method = __METHOD__;
-               $dbw = wfGetDB( DB_MASTER );
                $conds = $this->pageCond();
-               $dbw->onTransactionIdle( function () use ( $dbw, $conds, $method, $purgeTime ) {
-                       $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
-
-                       $dbw->update(
-                               'page',
-                               [ 'page_touched' => $dbTimestamp ],
-                               $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
-                               $method
-                       );
-               } );
+               DeferredUpdates::addUpdate(
+                       new AutoCommitUpdate(
+                               wfGetDB( DB_MASTER ),
+                               __METHOD__,
+                               function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
+                                       $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
+                                       $dbw->update(
+                                               'page',
+                                               [ 'page_touched' => $dbTimestamp ],
+                                               $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
+                                               $fname
+                                       );
+                               }
+                       ),
+                       DeferredUpdates::PRESEND
+               );
 
                return true;
        }
@@ -4541,10 +4559,10 @@ class Title implements LinkTarget {
         * @return bool
         */
        public function canUseNoindex() {
-               global $wgContentNamespaces, $wgExemptFromUserRobotsControl;
+               global $wgExemptFromUserRobotsControl;
 
                $bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
-                       ? $wgContentNamespaces
+                       ? MWNamespace::getContentNamespaces()
                        : $wgExemptFromUserRobotsControl;
 
                return !in_array( $this->mNamespace, $bannedNamespaces );