Merge "Fix documentation for Revision::getComment and WikiPage::getComment"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 16 Feb 2019 10:59:48 +0000 (10:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 16 Feb 2019 10:59:48 +0000 (10:59 +0000)
1  2 
includes/Revision.php
includes/page/WikiPage.php

diff --combined includes/Revision.php
@@@ -33,6 -33,8 +33,6 @@@ use Wikimedia\Assert\Assert
  use Wikimedia\Rdbms\IDatabase;
  use MediaWiki\Linker\LinkTarget;
  use MediaWiki\MediaWikiServices;
 -use Wikimedia\Rdbms\ResultWrapper;
 -use Wikimedia\Rdbms\FakeResultWrapper;
  
  /**
   * @deprecated since 1.31, use RevisionRecord, RevisionStore, and BlobStore instead.
@@@ -117,7 -119,7 +117,7 @@@ class Revision implements IDBAccessObje
         */
        public static function newFromId( $id, $flags = 0 ) {
                $rec = self::getRevisionLookup()->getRevisionById( $id, $flags );
 -              return $rec === null ? null : new Revision( $rec, $flags );
 +              return $rec ? new Revision( $rec, $flags ) : null;
        }
  
        /**
         */
        public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) {
                $rec = self::getRevisionLookup()->getRevisionByTitle( $linkTarget, $id, $flags );
 -              return $rec === null ? null : new Revision( $rec, $flags );
 +              return $rec ? new Revision( $rec, $flags ) : null;
        }
  
        /**
         */
        public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
                $rec = self::getRevisionLookup()->getRevisionByPageId( $pageId, $revId, $flags );
 -              return $rec === null ? null : new Revision( $rec, $flags );
 +              return $rec ? new Revision( $rec, $flags ) : null;
        }
  
        /**
        public static function loadFromId( $db, $id ) {
                wfDeprecated( __METHOD__, '1.31' ); // no known callers
                $rec = self::getRevisionStore()->loadRevisionFromId( $db, $id );
 -              return $rec === null ? null : new Revision( $rec );
 +              return $rec ? new Revision( $rec ) : null;
        }
  
        /**
         */
        public static function loadFromPageId( $db, $pageid, $id = 0 ) {
                $rec = self::getRevisionStore()->loadRevisionFromPageId( $db, $pageid, $id );
 -              return $rec === null ? null : new Revision( $rec );
 +              return $rec ? new Revision( $rec ) : null;
        }
  
        /**
         */
        public static function loadFromTitle( $db, $title, $id = 0 ) {
                $rec = self::getRevisionStore()->loadRevisionFromTitle( $db, $title, $id );
 -              return $rec === null ? null : new Revision( $rec );
 +              return $rec ? new Revision( $rec ) : null;
        }
  
        /**
         */
        public static function loadFromTimestamp( $db, $title, $timestamp ) {
                $rec = self::getRevisionStore()->loadRevisionFromTimestamp( $db, $title, $timestamp );
 -              return $rec === null ? null : new Revision( $rec );
 -      }
 -
 -      /**
 -       * Return a wrapper for a series of database rows to
 -       * fetch all of a given page's revisions in turn.
 -       * Each row can be fed to the constructor to get objects.
 -       *
 -       * @param LinkTarget $title
 -       * @return ResultWrapper
 -       * @deprecated Since 1.28, no callers in core nor in known extensions. No-op since 1.31.
 -       */
 -      public static function fetchRevision( LinkTarget $title ) {
 -              wfDeprecated( __METHOD__, '1.31' );
 -              return new FakeResultWrapper( [] );
 +              return $rec ? new Revision( $rec ) : null;
        }
  
        /**
         * @param int $queryFlags
         * @param Title|null $title
         *
 -       * @access private
 +       * @private
         */
        function __construct( $row, $queryFlags = 0, Title $title = null ) {
                global $wgUser;
                $user = $this->mRecord->getUser( $audience, $user );
                return $user ? $user->getName() : '';
        }
 +
        /**
-        * Fetch revision comment if it's available to the specified audience.
-        * If the specified audience does not have access to the comment, an
-        * empty string will be returned.
-        *
         * @param int $audience One of:
         *   Revision::FOR_PUBLIC       to be displayed to all users
         *   Revision::FOR_THIS_USER    to be displayed to the given user
         *   Revision::RAW              get the text regardless of permissions
         * @param User|null $user User object to check for, only if FOR_THIS_USER is passed
         *   to the $audience parameter
-        * @return string
+        *
+        * @return string|null Returns null if the specified audience does not have access to the
+        *  comment.
         */
        function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
                global $wgUser;
        public function getPrevious() {
                $title = $this->getTitle();
                $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
 -              return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
 +              return $rec ? new Revision( $rec, self::READ_NORMAL, $title ) : null;
        }
  
        /**
        public function getNext() {
                $title = $this->getTitle();
                $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
 -              return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
 +              return $rec ? new Revision( $rec, self::READ_NORMAL, $title ) : null;
        }
  
        /**
@@@ -895,7 -895,8 +895,8 @@@ class WikiPage implements Page, IDBAcce
         *   Revision::RAW              get the text regardless of permissions
         * @param User|null $user User object to check for, only if FOR_THIS_USER is passed
         *   to the $audience parameter
-        * @return string Comment stored for the last article revision
+        * @return string|null Comment stored for the last article revision, or null if the specified
+        *  audience does not have access to the comment.
         */
        public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
         */
        protected function archiveRevisions( $dbw, $id, $suppress ) {
                global $wgContentHandlerUseDB, $wgMultiContentRevisionSchemaMigrationStage,
 -                      $wgCommentTableSchemaMigrationStage, $wgActorTableSchemaMigrationStage,
 -                      $wgDeleteRevisionsBatchSize;
 +                      $wgActorTableSchemaMigrationStage, $wgDeleteRevisionsBatchSize;
  
                // Given the lock above, we can be confident in the title and page ID values
                $namespace = $this->getTitle()->getNamespace();
                        $dbw->insert( 'archive', $rowsInsert, __METHOD__ );
  
                        $dbw->delete( 'revision', [ 'rev_id' => $revids ], __METHOD__ );
 -                      if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) {
 -                              $dbw->delete( 'revision_comment_temp', [ 'revcomment_rev' => $revids ], __METHOD__ );
 -                      }
 +                      $dbw->delete( 'revision_comment_temp', [ 'revcomment_rev' => $revids ], __METHOD__ );
                        if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
                                $dbw->delete( 'revision_actor_temp', [ 'revactor_rev' => $revids ], __METHOD__ );
                        }
                // Clear caches
                self::onArticleDelete( $this->mTitle );
                ResourceLoaderWikiModule::invalidateModuleCache(
 -                      $this->mTitle, $revision, null, wfWikiID()
 +                      $this->mTitle,
 +                      $revision,
 +                      null,
 +                      WikiMap::getCurrentWikiDbDomain()->getId()
                );
  
                // Reset this object and the Title object
  
                if ( $wgUseRCPatrol ) {
                        // Mark all reverted edits as patrolled
 -                      $set['rc_patrolled'] = RecentChange::PRC_PATROLLED;
 +                      $set['rc_patrolled'] = RecentChange::PRC_AUTOPATROLLED;
                }
  
                if ( count( $set ) ) {
                                // means that some cache invalidations happen that are not strictly needed.
                                $cache->makeGlobalKey(
                                        'interwiki-page',
 -                                      WikiMap::getCurrentWikiDomain()->getId(),
 +                                      WikiMap::getCurrentWikiDbDomain()->getId(),
                                        $title->getDBkey()
                                )
                        );