$this->setContext( $context );
}
+ /**
+ * Get a FormOptions object containing the default options
+ *
+ * @return FormOptions
+ */
+ public function getDefaultOptions() {
+ $opts = parent::getDefaultOptions();
+ $user = $this->getUser();
+
+ // Overwrite RC options with Watchlist options
+ // (calling #add() again is okay)
+ $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions::FLOAT );
+ $opts->add( 'hideminor', $user->getBoolOption( 'watchlisthideminor' ) );
+ $opts->add( 'hidebots', $user->getBoolOption( 'watchlisthidebots' ) );
+ $opts->add( 'hideanons', $user->getBoolOption( 'watchlisthideanons' ) );
+ $opts->add( 'hideliu', $user->getBoolOption( 'watchlisthideliu' ) );
+ $opts->add( 'hidepatrolled', $user->getBoolOption( 'watchlisthidepatrolled' ) );
+ $opts->add( 'hidemyself', $user->getBoolOption( 'watchlisthideown' ) );
+
+ // Add new ones
+ $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
+
+ return $opts;
+ }
+
+ /**
+ * Get custom show/hide filters
+ *
+ * @return array Map of filter URL param names to properties (msg/default)
+ */
+ protected function getCustomFilters() {
+ if ( $this->customFilters === null ) {
+ $this->customFilters = array();
+ wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
+ }
+
+ return $this->customFilters;
+ }
+
+ /**
+ * Process $par and put options found if $opts. Not used for Watchlist.
+ *
+ * @param string $par
+ * @param FormOptions $opts
+ */
+ public function parseParameters( $par, FormOptions $opts ) {
+ }
+
+ /**
+ * Get the current FormOptions for this request
+ */
+ public function getOptions() {
+ if ( $this->rcOptions === null ) {
+ $this->rcOptions = $this->setup( null );
+ }
+
+ return $this->rcOptions;
+ }
+
/**
* Execute
* @param $par Parameter passed to the page
) );
}
+ $opts = $this->getOptions();
$this->setHeaders();
$this->outputHeader();
return;
}
- // @todo use FormOptions!
- $defaults = array(
- /* float */ 'days' => floatval( $user->getOption( 'watchlistdays' ) ),
- /* bool */ 'hideminor' => (int)$user->getBoolOption( 'watchlisthideminor' ),
- /* bool */ 'hidebots' => (int)$user->getBoolOption( 'watchlisthidebots' ),
- /* bool */ 'hideanons' => (int)$user->getBoolOption( 'watchlisthideanons' ),
- /* bool */ 'hideliu' => (int)$user->getBoolOption( 'watchlisthideliu' ),
- /* bool */ 'hidepatrolled' => (int)$user->getBoolOption( 'watchlisthidepatrolled' ),
- /* bool */ 'hidemyself' => (int)$user->getBoolOption( 'watchlisthideown' ),
- /* bool */ 'extended' => (int)$user->getBoolOption( 'extendwatchlist' ),
- /* ? */ 'namespace' => '', //means all
- /* ? */ 'invert' => false,
- /* bool */ 'associated' => false,
- );
- $this->customFilters = array();
- wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
- foreach ( $this->customFilters as $key => $params ) {
- $defaults[$key] = $params['default'];
- }
-
- # Extract variables from the request, falling back to user preferences or
- # other default values if these don't exist
- $values = array();
- $values['days'] = floatval( $request->getVal( 'days', $defaults['days'] ) );
- $values['hideminor'] = (int)$request->getBool( 'hideminor', $defaults['hideminor'] );
- $values['hidebots'] = (int)$request->getBool( 'hidebots', $defaults['hidebots'] );
- $values['hideanons'] = (int)$request->getBool( 'hideanons', $defaults['hideanons'] );
- $values['hideliu'] = (int)$request->getBool( 'hideliu', $defaults['hideliu'] );
- $values['hidemyself'] = (int)$request->getBool( 'hidemyself', $defaults['hidemyself'] );
- $values['hidepatrolled'] = (int)$request->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
- $values['extended'] = (int)$request->getBool( 'extended', $defaults['extended'] );
- foreach ( $this->customFilters as $key => $params ) {
- $values[$key] = (int)$request->getBool( $key, $defaults[$key] );
- }
-
# Get namespace value, if supplied, and prepare a WHERE fragment
- $nameSpace = $request->getIntOrNull( 'namespace' );
- $invert = $request->getBool( 'invert' );
- $associated = $request->getBool( 'associated' );
- if ( !is_null( $nameSpace ) ) {
+ $nameSpace = $opts['namespace'];
+ $invert = $opts['invert'];
+ $associated = $opts['associated'];
+
+ if ( $nameSpace !== '' ) {
$eq_op = $invert ? '!=' : '=';
$bool_op = $invert ? 'AND' : 'OR';
- $nameSpace = intval( $nameSpace ); // paranioa
if ( !$associated ) {
$nameSpaceClause = "rc_namespace $eq_op $nameSpace";
} else {
" rc_namespace $eq_op $associatedNS";
}
} else {
- $nameSpace = '';
$nameSpaceClause = '';
}
- $values['namespace'] = $nameSpace;
- $values['invert'] = $invert;
- $values['associated'] = $associated;
// Dump everything here
- $nondefaults = array();
- foreach ( $defaults as $name => $defValue ) {
- wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults );
- }
+ $nondefaults = $opts->getChangedValues();
if ( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' )
&& $request->wasPosted()
# Possible where conditions
$conds = array();
- if ( $values['days'] > 0 ) {
- $conds[] = 'rc_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( time() - intval( $values['days'] * 86400 ) ) );
+ if ( $opts['days'] > 0 ) {
+ $conds[] = 'rc_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( time() - intval( $opts['days'] * 86400 ) ) );
}
# Toggles
- if ( $values['hidemyself'] ) {
+ if ( $opts['hidemyself'] ) {
$conds[] = 'rc_user != ' . $user->getId();
}
- if ( $values['hidebots'] ) {
+ if ( $opts['hidebots'] ) {
$conds[] = 'rc_bot = 0';
}
- if ( $values['hideminor'] ) {
+ if ( $opts['hideminor'] ) {
$conds[] = 'rc_minor = 0';
}
- if ( $values['hideliu'] ) {
+ if ( $opts['hideliu'] ) {
$conds[] = 'rc_user = 0';
}
- if ( $values['hideanons'] ) {
+ if ( $opts['hideanons'] ) {
$conds[] = 'rc_user != 0';
}
- if ( $user->useRCPatrol() && $values['hidepatrolled'] ) {
+ if ( $user->useRCPatrol() && $opts['hidepatrolled'] ) {
$conds[] = 'rc_patrolled != 1';
}
if ( $nameSpaceClause ) {
}
# Toggle watchlist content (all recent edits or just the latest)
- if ( $values['extended'] ) {
+ if ( $opts['extended'] ) {
$limitWatchlist = $user->getIntOption( 'wllimit' );
$usePage = false;
} else {
}
ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
- wfRunHooks( 'SpecialWatchlistQuery', array( &$conds, &$tables, &$join_conds, &$fields, $values ) );
+ wfRunHooks( 'SpecialWatchlistQuery', array( &$conds, &$tables, &$join_conds, &$fields, $opts ) );
$res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
$numRows = $res->numRows();
$lang = $this->getLanguage();
$wlInfo = '';
- if ( $values['days'] > 0 ) {
+ if ( $opts['days'] > 0 ) {
$timestamp = wfTimestampNow();
- $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $values['days'] * 24 ) )->params(
+ $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
$lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) )->parse() . "<br />\n";
}
- $cutofflinks = $this->cutoffLinks( $values['days'], $nondefaults ) . "<br />\n";
+ $cutofflinks = $this->cutoffLinks( $opts['days'], $nondefaults ) . "<br />\n";
# Spit out some control panel links
$filters = array(
'hidemyself' => 'rcshowhidemine',
'hidepatrolled' => 'rcshowhidepatr'
);
- foreach ( $this->customFilters as $key => $params ) {
+ foreach ( $this->getCustomFilters() as $key => $params ) {
$filters[$key] = $params['msg'];
}
// Disable some if needed
$links = array();
foreach ( $filters as $name => $msg ) {
- $links[] = $this->showHideLink( $nondefaults, $msg, $name, $values[$name] );
+ $links[] = $this->showHideLink( $nondefaults, $msg, $name, $opts[$name] );
}
$hiddenFields = $nondefaults;