Merge "Implement WikiPage::getOldestRevision() in terms of Title::getFirstRevision()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 30 Mar 2017 18:36:33 +0000 (18:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 30 Mar 2017 18:36:34 +0000 (18:36 +0000)
1  2 
includes/Title.php
includes/page/WikiPage.php

diff --combined includes/Title.php
@@@ -21,8 -21,6 +21,8 @@@
   *
   * @file
   */
 +
 +use Wikimedia\Rdbms\IDatabase;
  use MediaWiki\Linker\LinkTarget;
  use MediaWiki\Interwiki\InterwikiLookup;
  use MediaWiki\MediaWikiServices;
@@@ -4032,7 -4030,6 +4032,6 @@@ class Title implements LinkTarget 
                                __METHOD__,
                                [
                                        'ORDER BY' => 'rev_timestamp ASC',
-                                       'LIMIT' => 1,
                                        'IGNORE INDEX' => 'rev_timestamp'
                                ]
                        );
@@@ -23,7 -23,6 +23,7 @@@
  use \MediaWiki\Logger\LoggerFactory;
  use \MediaWiki\MediaWikiServices;
  use Wikimedia\Rdbms\FakeResultWrapper;
 +use Wikimedia\Rdbms\IDatabase;
  
  /**
   * Class representing a MediaWiki article and history.
@@@ -85,10 -84,9 +85,10 @@@ class WikiPage implements Page, IDBAcce
         */
        protected $mLinksUpdated = '19700101000000';
  
 -      const PURGE_CDN_CACHE = 1; // purge CDN cache for page variant URLs
 -      const PURGE_CLUSTER_PCACHE = 2; // purge parser cache in the local datacenter
 -      const PURGE_GLOBAL_PCACHE = 4; // set page_touched to clear parser cache in all datacenters
 +      /** @deprecated since 1.29. Added in 1.28 for partial purging, no longer used. */
 +      const PURGE_CDN_CACHE = 1;
 +      const PURGE_CLUSTER_PCACHE = 2;
 +      const PURGE_GLOBAL_PCACHE = 4;
        const PURGE_ALL = 7;
  
        /**
         * @return Revision|null
         */
        public function getOldestRevision() {
                // Try using the replica DB first, then try the master
-               $continue = 2;
-               $db = wfGetDB( DB_REPLICA );
-               $revSelectFields = Revision::selectFields();
-               $row = null;
-               while ( $continue ) {
-                       $row = $db->selectRow(
-                               [ 'revision' ],
-                               $revSelectFields,
-                               [
-                                       'rev_page' => $this->getId()
-                               ],
-                               __METHOD__,
-                               [
-                                       'ORDER BY' => 'rev_timestamp ASC',
-                                       'IGNORE INDEX' => 'rev_timestamp'
-                               ]
-                       );
-                       if ( $row ) {
-                               $continue = 0;
-                       } else {
-                               $db = wfGetDB( DB_MASTER );
-                               $continue--;
-                       }
+               $rev = $this->mTitle->getFirstRevision();
+               if ( !$rev ) {
+                       $rev = $this->mTitle->getFirstRevision( Title::GAID_FOR_UPDATE );
                }
-               return $row ? Revision::newFromRow( $row ) : null;
+               return $rev;
        }
  
        /**
  
        /**
         * Perform the actions of a page purging
 -       * @param integer $flags Bitfield of WikiPage::PURGE_* constants
         * @return bool
 +       * @note In 1.28 (and only 1.28), this took a $flags parameter that
 +       *  controlled how much purging was done.
         */
 -      public function doPurge( $flags = self::PURGE_ALL ) {
 +      public function doPurge() {
                // Avoid PHP 7.1 warning of passing $this by reference
                $wikiPage = $this;
  
                        return false;
                }
  
 -              if ( ( $flags & self::PURGE_GLOBAL_PCACHE ) == self::PURGE_GLOBAL_PCACHE ) {
 -                      // Set page_touched in the database to invalidate all DC caches
 -                      $this->mTitle->invalidateCache();
 -              } elseif ( ( $flags & self::PURGE_CLUSTER_PCACHE ) == self::PURGE_CLUSTER_PCACHE ) {
 -                      // Delete the parser options key in the local cluster to invalidate the DC cache
 -                      ParserCache::singleton()->deleteOptionsKey( $this );
 -                      // Avoid sending HTTP 304s in ViewAction to the client who just issued the purge
 -                      $cache = ObjectCache::getLocalClusterInstance();
 -                      $cache->set(
 -                              $cache->makeKey( 'page', 'last-dc-purge', $this->getId() ),
 -                              wfTimestamp( TS_MW ),
 -                              $cache::TTL_HOUR
 -                      );
 -              }
 +              $this->mTitle->invalidateCache();
  
 -              if ( ( $flags & self::PURGE_CDN_CACHE ) == self::PURGE_CDN_CACHE ) {
 -                      // Clear any HTML file cache
 -                      HTMLFileCache::clearFileCache( $this->getTitle() );
 -                      // Send purge after any page_touched above update was committed
 -                      DeferredUpdates::addUpdate(
 -                              new CdnCacheUpdate( $this->mTitle->getCdnUrls() ),
 -                              DeferredUpdates::PRESEND
 -                      );
 -              }
 +              // Clear file cache
 +              HTMLFileCache::clearFileCache( $this->getTitle() );
 +              // Send purge after above page_touched update was committed
 +              DeferredUpdates::addUpdate(
 +                      new CdnCacheUpdate( $this->mTitle->getCdnUrls() ),
 +                      DeferredUpdates::PRESEND
 +              );
  
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        $messageCache = MessageCache::singleton();
         *
         * @return string|bool TS_MW timestamp or false
         * @since 1.28
 +       * @deprecated since 1.29. It will always return false.
         */
        public function getLastPurgeTimestamp() {
 -              $cache = ObjectCache::getLocalClusterInstance();
 -
 -              return $cache->get( $cache->makeKey( 'page', 'last-dc-purge', $this->getId() ) );
 +              wfDeprecated( __METHOD__, '1.29' );
 +              return false;
        }
  
        /**