Merge "Treat phpdbg as run from the command line when checking PHP_SAPI"
[lhc/web/wiklou.git] / includes / Storage / RevisionStore.php
index 24b437f..3101aea 100644 (file)
@@ -32,7 +32,7 @@ use Content;
 use ContentHandler;
 use DBAccessObjectUtils;
 use Hooks;
-use \IDBAccessObject;
+use IDBAccessObject;
 use InvalidArgumentException;
 use IP;
 use LogicException;
@@ -562,9 +562,13 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
        /**
         * MCR migration note: this replaces Revision::isUnpatrolled
         *
+        * @todo This is overly specific, so move or kill this method.
+        *
+        * @param RevisionRecord $rev
+        *
         * @return int Rcid of the unpatrolled row, zero if there isn't one
         */
-       public function isUnpatrolled( RevisionRecord $rev ) {
+       public function getRcIdIfUnpatrolled( RevisionRecord $rev ) {
                $rc = $this->getRecentChange( $rev );
                if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) {
                        return $rc->getAttribute( 'rc_id' );
@@ -848,11 +852,10 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         *
         * @param int $id
         * @param int $flags (optional)
-        * @param Title $title (optional)
         * @return RevisionRecord|null
         */
-       public function getRevisionById( $id, $flags = 0, Title $title = null ) {
-               return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags, $title );
+       public function getRevisionById( $id, $flags = 0 ) {
+               return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags );
        }
 
        /**
@@ -953,7 +956,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         * @param string $timestamp
         * @return RevisionRecord|null
         */
-       public function getRevisionFromTimestamp( $title, $timestamp ) {
+       public function getRevisionByTimestamp( $title, $timestamp ) {
                return $this->newRevisionFromConds(
                        [
                                'rev_timestamp' => $timestamp,
@@ -1076,7 +1079,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                        $pageId = isset( $row->rev_page ) ? $row->rev_page : 0; // XXX: also check page_id?
                        $revId = isset( $row->rev_id ) ? $row->rev_id : 0;
 
-                       $title = $this->getTitle( $pageId, $revId );
+                       $title = $this->getTitle( $pageId, $revId, $queryFlags );
                }
 
                if ( !isset( $row->page_latest ) ) {
@@ -1144,7 +1147,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                        $pageId = isset( $fields['page'] ) ? $fields['page'] : 0;
                        $revId = isset( $fields['id'] ) ? $fields['id'] : 0;
 
-                       $title = $this->getTitle( $pageId, $revId );
+                       $title = $this->getTitle( $pageId, $revId, $queryFlags );
                }
 
                if ( !isset( $fields['page'] ) ) {
@@ -1477,10 +1480,20 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                $storeWiki = $storeWiki ?: wfWikiID();
                $dbWiki = $dbWiki ?: wfWikiID();
 
-               if ( $dbWiki !== $storeWiki ) {
-                       throw new MWException( "RevisionStore for $storeWiki "
-                               . "cannot be used with a DB connection for $dbWiki" );
+               if ( $dbWiki === $storeWiki ) {
+                       return;
+               }
+
+               // HACK: counteract encoding imposed by DatabaseDomain
+               $storeWiki = str_replace( '?h', '-', $storeWiki );
+               $dbWiki = str_replace( '?h', '-', $dbWiki );
+
+               if ( $dbWiki === $storeWiki ) {
+                       return;
                }
+
+               throw new MWException( "RevisionStore for $storeWiki "
+                       . "cannot be used with a DB connection for $dbWiki" );
        }
 
        /**
@@ -1646,6 +1659,21 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         *
         * MCR migration note: this replaces Revision::getParentLengths
         *
+        * @param int[] $revIds
+        * @return int[] associative array mapping revision IDs from $revIds to the nominal size
+        *         of the corresponding revision.
+        */
+       public function getRevisionSizes( array $revIds ) {
+               return $this->listRevisionSizes( $this->getDBConnection( DB_REPLICA ), $revIds );
+       }
+
+       /**
+        * Do a batched query for the sizes of a set of revisions.
+        *
+        * MCR migration note: this replaces Revision::getParentLengths
+        *
+        * @deprecated use RevisionStore::getRevisionSizes instead.
+        *
         * @param IDatabase $db
         * @param int[] $revIds
         * @return int[] associative array mapping revision IDs from $revIds to the nominal size