ChangesListSpecialPage: Implement webOutput()
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 3 Jan 2014 15:23:45 +0000 (16:23 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 29 Jan 2014 16:53:36 +0000 (17:53 +0100)
Split in two more functions: outputFeedLinks() and outputChangesList().

Change-Id: I62c6eab1c25c5ff3a71150205416e8f57764f6bc

includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialWatchlist.php

index 3a99eda..03bc8c2 100644 (file)
@@ -319,16 +319,36 @@ abstract class ChangesListSpecialPage extends SpecialPage {
 
        /**
         * Send output to the OutputPage object, only called if not used feeds
-        * @todo This should do most, if not all, of the outputting now done by subclasses
         *
         * @param ResultWrapper $rows Database rows
         * @param FormOptions $opts
         */
-       abstract public function webOutput( $rows, $opts );
+       public function webOutput( $rows, $opts ) {
+               if ( !$this->including() ) {
+                       $this->outputFeedLinks();
+                       $this->doHeader( $opts );
+               }
+
+               $this->outputChangesList( $rows, $opts );
+       }
+
+       /**
+        * Output feed links.
+        */
+       public function outputFeedLinks() {
+               // nothing by default
+       }
+
+       /**
+        * Build and output the actual changes list.
+        *
+        * @param array $rows Database rows
+        * @param FormOptions $opts
+        */
+       abstract public function outputChangesList( $rows, $opts );
 
        /**
         * Return the text to be displayed above the changes
-        * @todo Not called by anything, should be called by webOutput()
         *
         * @param FormOptions $opts
         * @return string XHTML
index 36a1d1c..07da6d9 100644 (file)
@@ -182,6 +182,8 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
         */
        public function doMainQuery( $conds, $opts ) {
+               global $wgAllowCategorizedRecentChanges;
+
                $dbr = $this->getDB();
                $user = $this->getUser();
 
@@ -225,7 +227,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
 
                // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
                // knowledge to use an index merge if it wants (it may use some other index though).
-               return $dbr->select(
+               $rows = $dbr->select(
                        $tables,
                        $fields,
                        $conds + array( 'rc_new' => array( 0, 1 ) ),
@@ -233,22 +235,35 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                        array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $opts['limit'] ) + $query_options,
                        $join_conds
                );
+
+               // Build the final data
+               if ( $wgAllowCategorizedRecentChanges ) {
+                       $this->filterByCategories( $rows, $opts );
+               }
+
+               return $rows;
+       }
+
+       /**
+        * Output feed links.
+        */
+       public function outputFeedLinks() {
+               $feedQuery = $this->getFeedQuery();
+               if ( $feedQuery !== '' ) {
+                       $this->getOutput()->setFeedAppendQuery( $feedQuery );
+               } else {
+                       $this->getOutput()->setFeedAppendQuery( false );
+               }
        }
 
        /**
-        * Send output to the OutputPage object, only called if not used feeds
+        * Build and output the actual changes list.
         *
         * @param array $rows Database rows
         * @param FormOptions $opts
         */
-       public function webOutput( $rows, $opts ) {
-               global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
-
-               // Build the final data
-
-               if ( $wgAllowCategorizedRecentChanges ) {
-                       $this->filterByCategories( $rows, $opts );
-               }
+       public function outputChangesList( $rows, $opts ) {
+               global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
 
                $limit = $opts['limit'];
 
@@ -299,21 +314,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                }
                $rclistOutput .= $list->endRecentChangesList();
 
-               // Print things out
-
-               if ( !$this->including() ) {
-                       // Output options box
-                       $this->doHeader( $opts );
-               }
-
-               // And now for the content
-               $feedQuery = $this->getFeedQuery();
-               if ( $feedQuery !== '' ) {
-                       $this->getOutput()->setFeedAppendQuery( $feedQuery );
-               } else {
-                       $this->getOutput()->setFeedAppendQuery( false );
-               }
-
                if ( $rows->numRows() === 0 ) {
                        $this->getOutput()->addHtml(
                                '<div class="mw-changeslist-empty">' . $this->msg( 'recentchanges-noresult' )->parse() . '</div>'
index 1477192..fbdaec4 100644 (file)
@@ -279,16 +279,39 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        /**
-        * Send output to the OutputPage object, only called if not used feeds
+        * Output feed links.
+        */
+       public function outputFeedLinks() {
+               $user = $this->getUser();
+               $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
+               if ( $wlToken ) {
+                       $this->addFeedLinks( array(
+                               'action' => 'feedwatchlist',
+                               'allrev' => 1,
+                               'wlowner' => $user->getName(),
+                               'wltoken' => $wlToken,
+                       ) );
+               }
+       }
+
+       /**
+        * Build and output the actual changes list.
         *
         * @param ResultWrapper $rows Database rows
         * @param FormOptions $opts
         */
-       public function webOutput( $rows, $opts ) {
+       public function outputChangesList( $rows, $opts ) {
                global $wgShowUpdatedMarker, $wgRCShowWatchingUsers;
 
                $dbr = $this->getDB();
                $user = $this->getUser();
+               $output = $this->getOutput();
+
+               # Show a message about slave lag, if applicable
+               $lag = wfGetLB()->safeGetLag( $dbr );
+               if ( $lag > 0 ) {
+                       $output->showLagWarning( $lag );
+               }
 
                $dbr->dataSeek( $rows, 0 );
 
@@ -327,35 +350,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
                $s .= $list->endRecentChangesList();
 
-               // Print things out
-
-               $output = $this->getOutput();
-
-               $output->addSubtitle(
-                       $this->msg( 'watchlistfor2', $user->getName() )
-                               ->rawParams( SpecialEditWatchlist::buildTools( null ) )
-               );
-
-               // Output options box
-               $this->doHeader( $opts );
-
-               // Add feed links
-               $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
-               if ( $wlToken ) {
-                       $this->addFeedLinks( array(
-                               'action' => 'feedwatchlist',
-                               'allrev' => 1,
-                               'wlowner' => $user->getName(),
-                               'wltoken' => $wlToken,
-                       ) );
-               }
-
-               # Show a message about slave lag, if applicable
-               $lag = wfGetLB()->safeGetLag( $dbr );
-               if ( $lag > 0 ) {
-                       $output->showLagWarning( $lag );
-               }
-
                if ( $rows->numRows() == 0 ) {
                        $output->wrapWikiMsg(
                                "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
@@ -374,6 +368,11 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        public function doHeader( $opts ) {
                $user = $this->getUser();
 
+               $this->getOutput()->addSubtitle(
+                       $this->msg( 'watchlistfor2', $user->getName() )
+                               ->rawParams( SpecialEditWatchlist::buildTools( null ) )
+               );
+
                $this->setTopText( $opts );
 
                $lang = $this->getLanguage();