From e84fc0f5385b425f20712d4ec59ef588c325c72d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sun, 10 Nov 2013 14:49:26 +0100 Subject: [PATCH] SpecialWatchlist: Reorder some stuff in #execute 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 | 144 ++++++++++++------------- 1 file changed, 71 insertions(+), 73 deletions(-) diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index afdf9810d9..9caa5a84b7 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -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 .= "

"; - $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 .= "

"; - - 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() . "
\n"; } + $nondefaults = $opts->getChangedValues(); $cutofflinks = $this->cutoffLinks( $opts['days'], $nondefaults ) . "
\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 .= "

"; + $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 .= "

"; + + 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; -- 2.20.1