Merge "Language: Introduce new method equals( Language $lang )"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 23 May 2016 16:03:50 +0000 (16:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 23 May 2016 16:03:50 +0000 (16:03 +0000)
1  2 
includes/Title.php

diff --combined includes/Title.php
@@@ -22,7 -22,6 +22,7 @@@
   * @file
   */
  use MediaWiki\Linker\LinkTarget;
 +use MediaWiki\Interwiki\InterwikiLookup;
  use MediaWiki\MediaWikiServices;
  
  /**
@@@ -171,18 -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
         */
         */
        public function isLocal() {
                if ( $this->isExternal() ) {
 -                      $iw = Interwiki::fetch( $this->mInterwiki );
 +                      $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
                        if ( $iw ) {
                                return $iw->isLocal();
                        }
                        return false;
                }
  
 -              return Interwiki::fetch( $this->mInterwiki )->isTranscludable();
 +              return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
        }
  
        /**
                        return false;
                }
  
 -              return Interwiki::fetch( $this->mInterwiki )->getWikiID();
 +              return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
        }
  
        /**
         * @return string Content model id
         */
        public function getContentModel( $flags = 0 ) {
 -              if ( !$this->mContentModel && $this->getArticleID( $flags ) ) {
 +              if ( ( !$this->mContentModel || $flags === Title::GAID_FOR_UPDATE ) &&
 +                      $this->getArticleID( $flags )
 +              ) {
                        $linkCache = LinkCache::singleton();
                        $linkCache->addLinkObj( $this ); # in case we already had an article ID
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
  
                $query = self::fixUrlQueryArgs( $query, $query2 );
  
 -              $interwiki = Interwiki::fetch( $this->mInterwiki );
 +              $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
                if ( $interwiki ) {
                        $namespace = $this->getNsText();
                        if ( $namespace != '' ) {
                                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] );
  
        /**
         * Purge expired restrictions from the page_restrictions table
 +       *
 +       * This will purge no more than $wgUpdateRowsPerQuery page_restrictions rows
         */
        static function purgeExpiredRestrictions() {
                if ( wfReadOnly() ) {
                        wfGetDB( DB_MASTER ),
                        __METHOD__,
                        function ( IDatabase $dbw, $fname ) {
 -                              $dbw->delete(
 +                              $config = MediaWikiServices::getInstance()->getMainConfig();
 +                              $ids = $dbw->selectFieldValues(
                                        'page_restrictions',
 +                                      'pr_id',
                                        [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
 -                                      $fname
 +                                      $fname,
 +                                      [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
                                );
 +                              if ( $ids ) {
 +                                      $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
 +                              }
 +                      }
 +              ) );
 +
 +              DeferredUpdates::addUpdate( new AtomicSectionUpdate(
 +                      wfGetDB( DB_MASTER ),
 +                      __METHOD__,
 +                      function ( IDatabase $dbw, $fname ) {
                                $dbw->delete(
                                        'protected_titles',
                                        [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],