Merge "Fix documentation of HistoryPager::lastLink() and make code more readable"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 23 Jul 2014 20:38:32 +0000 (20:38 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 23 Jul 2014 20:38:32 +0000 (20:38 +0000)
1  2 
includes/actions/HistoryAction.php

@@@ -214,7 -214,7 +214,7 @@@ class HistoryAction extends FormlessAct
         *
         * @param int $limit The limit number of revisions to get
         * @param int $offset
 -       * @param int $direction Either HistoryPage::DIR_PREV or HistoryPage::DIR_NEXT
 +       * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
         * @return ResultWrapper
         */
        function fetchRevisions( $limit, $offset, $direction ) {
  
                $dbr = wfGetDB( DB_SLAVE );
  
 -              if ( $direction == HistoryPage::DIR_PREV ) {
 +              if ( $direction === self::DIR_PREV ) {
                        list( $dirs, $oper ) = array( "ASC", ">=" );
 -              } else { /* $direction == HistoryPage::DIR_NEXT */
 +              } else { /* $direction === self::DIR_NEXT */
                        list( $dirs, $oper ) = array( "DESC", "<=" );
                }
  
                $limit = $request->getInt( 'limit', 10 );
                $limit = min( max( $limit, 1 ), $wgFeedLimit );
  
 -              $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT );
 +              $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
  
                // Generate feed elements enclosed between header and footer.
                $feed->outHeader();
@@@ -776,18 -776,21 +776,21 @@@ class HistoryPager extends ReverseChron
        /**
         * Create a diff-to-previous link for this revision for this page.
         *
-        * @param Revision $prevRev The previous revision
-        * @param mixed $next The newer revision
+        * @param Revision $prevRev The revision being displayed
+        * @param stdClass|string|null $next The next revision in list (that is
+        *        the previous one in chronological order).
+        *        May either be a row, "unknown" or null.
         * @return string
         */
        function lastLink( $prevRev, $next ) {
                $last = $this->historyPage->message['last'];
-               # $next may either be a Row, null, or "unknown"
-               $nextRev = is_object( $next ) ? new Revision( $next ) : $next;
-               if ( is_null( $next ) ) {
+               if ( $next === null ) {
                        # Probably no next row
                        return $last;
-               } elseif ( $next === 'unknown' ) {
+               }
+               if ( $next === 'unknown' ) {
                        # Next row probably exists but is unknown, use an oldid=prev link
                        return Linker::linkKnown(
                                $this->getTitle(),
                                        'oldid' => 'prev'
                                )
                        );
-               } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
+               }
+               $nextRev = new Revision( $next );
+               if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
                        || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
                ) {
                        return $last;
-               } else {
-                       return Linker::linkKnown(
-                               $this->getTitle(),
-                               $last,
-                               array(),
-                               array(
-                                       'diff' => $prevRev->getId(),
-                                       'oldid' => $next->rev_id
-                               )
-                       );
                }
+               return Linker::linkKnown(
+                       $this->getTitle(),
+                       $last,
+                       array(),
+                       array(
+                               'diff' => $prevRev->getId(),
+                               'oldid' => $next->rev_id
+                       )
+               );
        }
  
        /**
                return $this->preventClickjacking;
        }
  }
 -
 -/**
 - * Backwards-compatibility alias
 - */
 -class HistoryPage extends HistoryAction {
 -      // @codingStandardsIgnoreStart Needed "useless" override to make it public.
 -      public function __construct( Page $article ) {
 -              parent::__construct( $article );
 -      }
 -      // @codingStandardsIgnoreEnd
 -
 -      public function history() {
 -              $this->onView();
 -      }
 -}