SpecialWatchlist: Reorder some stuff in #execute
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 10 Nov 2013 13:49:26 +0000 (14:49 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 11 Jan 2014 12:59:22 +0000 (13:59 +0100)
In order to reduce the interconnectedness between parameter parsing,
database queries and building output, and to make later changes where
I'll start removing some of this code easier to understand.

Change-Id: I6f525506b0fc4c009989ed7dff838c4e21ec4860

includes/specials/SpecialWatchlist.php

index afdf981..9caa5a8 100644 (file)
@@ -145,6 +145,32 @@ class SpecialWatchlist extends SpecialRecentChanges {
                // Check permissions
                $this->checkPermissions();
 
+               $request = $this->getRequest();
+               $opts = $this->getOptions();
+
+               $mode = SpecialEditWatchlist::getMode( $request, $par );
+               if ( $mode !== false ) {
+                       if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
+                               $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
+                       } else {
+                               $title = SpecialPage::getTitleFor( 'EditWatchlist' );
+                       }
+
+                       $output->redirect( $title->getLocalURL() );
+                       return;
+               }
+
+               if ( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
+                       $request->wasPosted() )
+               {
+                       $user->clearAllNotifications();
+                       $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
+                       return;
+               }
+
+               $this->setHeaders();
+               $this->outputHeader();
+
                // Add feed links
                $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
                if ( $wlToken ) {
@@ -156,31 +182,19 @@ class SpecialWatchlist extends SpecialRecentChanges {
                        ) );
                }
 
-               $opts = $this->getOptions();
-               $this->setHeaders();
-               $this->outputHeader();
-
                $output->addSubtitle(
                        $this->msg( 'watchlistfor2', $user->getName() )
                                ->rawParams( SpecialEditWatchlist::buildTools( null ) )
                );
 
-               $request = $this->getRequest();
-
-               $mode = SpecialEditWatchlist::getMode( $request, $par );
-               if ( $mode !== false ) {
-                       if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
-                               $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
-                       } else {
-                               $title = SpecialPage::getTitleFor( 'EditWatchlist' );
-                       }
+               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
 
-                       $output->redirect( $title->getLocalURL() );
-                       return;
+               # Show a message about slave lag, if applicable
+               $lag = wfGetLB()->safeGetLag( $dbr );
+               if ( $lag > 0 ) {
+                       $output->showLagWarning( $lag );
                }
 
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
                $nitems = $this->countItems( $dbr );
                if ( $nitems == 0 ) {
                        $output->addWikiMsg( 'nowatchlist' );
@@ -208,17 +222,6 @@ class SpecialWatchlist extends SpecialRecentChanges {
                        $nameSpaceClause = '';
                }
 
-               // Dump everything here
-               $nondefaults = $opts->getChangedValues();
-
-               if ( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' )
-                       && $request->wasPosted()
-               ) {
-                       $user->clearAllNotifications();
-                       $output->redirect( $this->getPageTitle()->getFullURL( $nondefaults ) );
-                       return;
-               }
-
                # Possible where conditions
                $conds = array();
 
@@ -270,51 +273,6 @@ class SpecialWatchlist extends SpecialRecentChanges {
                        $usePage = true;
                }
 
-               # Show a message about slave lag, if applicable
-               $lag = wfGetLB()->safeGetLag( $dbr );
-               if ( $lag > 0 ) {
-                       $output->showLagWarning( $lag );
-               }
-
-               # Create output
-               $form = '';
-
-               # Show watchlist header
-               $form .= "<p>";
-               $form .= $this->msg( 'watchlist-details' )->numParams( $nitems )->parse() . "\n";
-               if ( $wgEnotifWatchlist && $user->getOption( 'enotifwatchlistpages' ) ) {
-                       $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
-               }
-               if ( $wgShowUpdatedMarker ) {
-                       $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
-               }
-               $form .= "</p>";
-
-               if ( $wgShowUpdatedMarker ) {
-                       $form .= Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $this->getPageTitle()->getLocalURL(),
-                               'id' => 'mw-watchlist-resetbutton' ) ) . "\n" .
-                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(), array( 'name' => 'dummy' ) ) . "\n" .
-                       Html::hidden( 'reset', 'all' ) . "\n";
-                       foreach ( $nondefaults as $key => $value ) {
-                               $form .= Html::hidden( $key, $value ) . "\n";
-                       }
-                       $form .= Xml::closeElement( 'form' ) . "\n";
-               }
-
-               $form .= Xml::openElement( 'form', array(
-                       'method' => 'post',
-                       'action' => $this->getPageTitle()->getLocalURL(),
-                       'id' => 'mw-watchlist-form'
-               ) );
-               $form .= Xml::fieldset(
-                       $this->msg( 'watchlist-options' )->text(),
-                       false,
-                       array( 'id' => 'mw-watchlist-options' )
-               );
-
-               $form .= SpecialRecentChanges::makeLegend( $this->getContext() );
-
                $tables = array( 'recentchanges', 'watchlist' );
                $fields = RecentChange::selectFields();
                $join_conds = array(
@@ -360,6 +318,7 @@ class SpecialWatchlist extends SpecialRecentChanges {
                                $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) )->parse() . "<br />\n";
                }
 
+               $nondefaults = $opts->getChangedValues();
                $cutofflinks = $this->cutoffLinks( $opts['days'], $nondefaults ) . "<br />\n";
 
                # Spit out some control panel links
@@ -389,6 +348,45 @@ class SpecialWatchlist extends SpecialRecentChanges {
                unset( $hiddenFields['invert'] );
                unset( $hiddenFields['associated'] );
 
+               # Create output
+               $form = '';
+
+               # Show watchlist header
+               $form .= "<p>";
+               $form .= $this->msg( 'watchlist-details' )->numParams( $nitems )->parse() . "\n";
+               if ( $wgEnotifWatchlist && $user->getOption( 'enotifwatchlistpages' ) ) {
+                       $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
+               }
+               if ( $wgShowUpdatedMarker ) {
+                       $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
+               }
+               $form .= "</p>";
+
+               if ( $wgShowUpdatedMarker ) {
+                       $form .= Xml::openElement( 'form', array( 'method' => 'post',
+                               'action' => $this->getPageTitle()->getLocalURL(),
+                               'id' => 'mw-watchlist-resetbutton' ) ) . "\n" .
+                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(), array( 'name' => 'dummy' ) ) . "\n" .
+                       Html::hidden( 'reset', 'all' ) . "\n";
+                       foreach ( $nondefaults as $key => $value ) {
+                               $form .= Html::hidden( $key, $value ) . "\n";
+                       }
+                       $form .= Xml::closeElement( 'form' ) . "\n";
+               }
+
+               $form .= Xml::openElement( 'form', array(
+                       'method' => 'post',
+                       'action' => $this->getPageTitle()->getLocalURL(),
+                       'id' => 'mw-watchlist-form'
+               ) );
+               $form .= Xml::fieldset(
+                       $this->msg( 'watchlist-options' )->text(),
+                       false,
+                       array( 'id' => 'mw-watchlist-options' )
+               );
+
+               $form .= SpecialRecentChanges::makeLegend( $this->getContext() );
+
                # Namespace filter and put the whole form together.
                $form .= $wlInfo;
                $form .= $cutofflinks;