* @ingroup SpecialPage
*/
use MediaWiki\Logger\LoggerFactory;
+use Wikimedia\Rdbms\DBQueryTimeoutError;
use Wikimedia\Rdbms\ResultWrapper;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
*/
protected static $savedQueriesPreferenceName;
+ /**
+ * Preference name for 'days'. Subclasses should override this.
+ * @var string
+ */
+ protected static $daysPreferenceName;
+
+ /**
+ * Preference name for 'limit'. Subclasses should override this.
+ * @var string
+ */
+ protected static $limitPreferenceName;
+
/** @var string */
protected $rcSubpage;
$this->considerActionsForDefaultSavedQuery();
- $rows = $this->getRows();
$opts = $this->getOptions();
- if ( $rows === false ) {
- $rows = new FakeResultWrapper( [] );
- }
+ try {
+ $rows = $this->getRows();
+ if ( $rows === false ) {
+ $rows = new FakeResultWrapper( [] );
+ }
- // Used by Structured UI app to get results without MW chrome
- if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
- $this->getOutput()->setArticleBodyOnly( true );
- }
+ // Used by Structured UI app to get results without MW chrome
+ if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
+ $this->getOutput()->setArticleBodyOnly( true );
+ }
- // Used by "live update" and "view newest" to check
- // if there's new changes with minimal data transfer
- if ( $this->getRequest()->getBool( 'peek' ) ) {
- $code = $rows->numRows() > 0 ? 200 : 204;
- $this->getOutput()->setStatusCode( $code );
- return;
- }
+ // Used by "live update" and "view newest" to check
+ // if there's new changes with minimal data transfer
+ if ( $this->getRequest()->getBool( 'peek' ) ) {
+ $code = $rows->numRows() > 0 ? 200 : 204;
+ $this->getOutput()->setStatusCode( $code );
- $batch = new LinkBatch;
- foreach ( $rows as $row ) {
- $batch->add( NS_USER, $row->rc_user_text );
- $batch->add( NS_USER_TALK, $row->rc_user_text );
- $batch->add( $row->rc_namespace, $row->rc_title );
- if ( $row->rc_source === RecentChange::SRC_LOG ) {
- $formatter = LogFormatter::newFromRow( $row );
- foreach ( $formatter->getPreloadTitles() as $title ) {
- $batch->addObj( $title );
+ if ( $this->getUser()->isAnon() !==
+ $this->getRequest()->getFuzzyBool( 'isAnon' )
+ ) {
+ $this->getOutput()->setStatusCode( 205 );
}
+
+ return;
}
- }
- $batch->execute();
- $this->setHeaders();
- $this->outputHeader();
- $this->addModules();
- $this->webOutput( $rows, $opts );
+ $batch = new LinkBatch;
+ foreach ( $rows as $row ) {
+ $batch->add( NS_USER, $row->rc_user_text );
+ $batch->add( NS_USER_TALK, $row->rc_user_text );
+ $batch->add( $row->rc_namespace, $row->rc_title );
+ if ( $row->rc_source === RecentChange::SRC_LOG ) {
+ $formatter = LogFormatter::newFromRow( $row );
+ foreach ( $formatter->getPreloadTitles() as $title ) {
+ $batch->addObj( $title );
+ }
+ }
+ }
+ $batch->execute();
+
+ $this->setHeaders();
+ $this->outputHeader();
+ $this->addModules();
+ $this->webOutput( $rows, $opts );
- $rows->free();
+ $rows->free();
+ } catch ( DBQueryTimeoutError $timeoutException ) {
+ MWExceptionHandler::logException( $timeoutException );
+
+ $this->setHeaders();
+ $this->outputHeader();
+ $this->addModules();
+
+ $this->getOutput()->setStatusCode( 500 );
+ $this->webOutputHeader( 0, $opts );
+ $this->outputTimeout();
+ }
if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
// Clean up any bad page entries for titles showing up in RC
* redirect properly with all necessary query parameters.
*/
protected function considerActionsForDefaultSavedQuery() {
- if ( !$this->isStructuredFilterUiEnabled() ) {
+ if ( !$this->isStructuredFilterUiEnabled() || $this->including() ) {
return;
}
*/
protected function includeRcFiltersApp() {
$out = $this->getOutput();
- if ( $this->isStructuredFilterUiEnabled() ) {
+ if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
$jsData = $this->getStructuredFilterJsData();
$messages = [];
'wgStructuredChangeFiltersSavedQueriesPreferenceName',
static::$savedQueriesPreferenceName
);
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersLimitPreferenceName',
+ static::$limitPreferenceName
+ );
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersDaysPreferenceName',
+ static::$daysPreferenceName
+ );
$out->addJsConfigVars(
'StructuredChangeFiltersLiveUpdatePollingRate',
);
}
+ /**
+ * Add the "timeout" message to the output
+ */
+ protected function outputTimeout() {
+ $this->getOutput()->addHTML(
+ '<div class="mw-changeslist-timeout">' .
+ $this->msg( 'recentchanges-timeout' )->parse() .
+ '</div>'
+ );
+ }
+
/**
* Get the database result for this special page instance. Used by ApiFeedRecentChanges.
*
return $unstructuredGroupDefinition;
}
+ /**
+ * @return array The legacy show/hide toggle filters
+ */
+ protected function getLegacyShowHideFilters() {
+ $filters = [];
+ foreach ( $this->filterGroups as $group ) {
+ if ( $group instanceof ChangesListBooleanFilterGroup ) {
+ foreach ( $group->getFilters() as $key => $filter ) {
+ if ( $filter->displaysOnUnstructuredUi( $this ) ) {
+ $filters[ $key ] = $filter;
+ }
+ }
+ }
+ }
+ return $filters;
+ }
+
/**
* Register all the filters, including legacy hook-driven ones.
* Then create a FormOptions object with options as specified by the user
// If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
$useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
- // Add all filters
/** @var ChangesListFilterGroup $filterGroup */
foreach ( $this->filterGroups as $filterGroup ) {
- // URL parameters can be per-group, like 'userExpLevel',
- // or per-filter, like 'hideminor'.
- if ( $filterGroup->isPerGroupRequestParameter() ) {
- $opts->add( $filterGroup->getName(), $useDefaults ? $filterGroup->getDefault() : '' );
- } else {
- /** @var ChangesListBooleanFilter $filter */
- foreach ( $filterGroup->getFilters() as $filter ) {
- $opts->add( $filter->getName(), $useDefaults ? $filter->getDefault( $structuredUI ) : false );
- }
- }
+ $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
}
$opts->add( 'namespace', '', FormOptions::STRING );
// or per-filter, like 'hideminor'.
foreach ( $this->filterGroups as $filterGroup ) {
- if ( $filterGroup->isPerGroupRequestParameter() ) {
+ if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup ) {
$stringParameterNameSet[$filterGroup->getName()] = true;
- } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) {
+ } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
foreach ( $filterGroup->getFilters() as $filter ) {
$hideParameterNameSet[$filter->getName()] = true;
}
* @param FormOptions $opts
*/
public function validateOptions( FormOptions $opts ) {
- if ( $this->fixContradictoryOptions( $opts ) ) {
+ $isContradictory = $this->fixContradictoryOptions( $opts );
+ $isReplaced = $this->replaceOldOptions( $opts );
+
+ if ( $isContradictory || $isReplaced ) {
$query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
$this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
}
return false;
}
+ /**
+ * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent
+ *
+ * @param FormOptions $opts
+ * @return bool True if the change was made
+ */
+ public function replaceOldOptions( FormOptions $opts ) {
+ if ( !$this->isStructuredFilterUiEnabled() ) {
+ return false;
+ }
+
+ // At this point 'hideanons' and 'hideliu' cannot be both true,
+ // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
+ if ( $opts[ 'hideanons' ] ) {
+ $opts->reset( 'hideanons' );
+ $opts[ 'userExpLevel' ] = 'registered';
+ return true;
+ }
+
+ if ( $opts[ 'hideliu' ] ) {
+ $opts->reset( 'hideliu' );
+ $opts[ 'userExpLevel' ] = 'unregistered';
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Convert parameters values from true/false to 1/0
* so they are not omitted by wfArrayToCgi()
$dbr = $this->getDB();
$isStructuredUI = $this->isStructuredFilterUiEnabled();
+ /** @var ChangesListFilterGroup $filterGroup */
foreach ( $this->filterGroups as $filterGroup ) {
- // URL parameters can be per-group, like 'userExpLevel',
- // or per-filter, like 'hideminor'.
- if ( $filterGroup->isPerGroupRequestParameter() ) {
- if ( $filterGroup->isActive( $isStructuredUI ) ) {
- $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
- $query_options, $join_conds, $opts[$filterGroup->getName()] );
- }
- } else {
- foreach ( $filterGroup->getFilters() as $filter ) {
- if ( $filter->isActive( $opts, $isStructuredUI ) ) {
- $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
- $query_options, $join_conds );
- }
- }
- }
+ $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
+ $query_options, $join_conds, $opts, $isStructuredUI );
}
// Namespace filtering
protected function doMainQuery( $tables, $fields, $conds,
$query_options, $join_conds, FormOptions $opts
) {
- $tables[] = 'recentchanges';
- $fields = array_merge( RecentChange::selectFields(), $fields );
+ $rcQuery = RecentChange::getQueryInfo();
+ $tables = array_merge( $tables, $rcQuery['tables'] );
+ $fields = array_merge( $rcQuery['fields'], $fields );
+ $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
ChangeTags::modifyDisplayQuery(
$tables,
}
/**
- * Send output to the OutputPage object, only called if not used feeds
+ * Send header output to the OutputPage object, only called if not using feeds
*
- * @param ResultWrapper $rows Database rows
+ * @param int $rowCount Number of database rows
* @param FormOptions $opts
*/
- public function webOutput( $rows, $opts ) {
+ private function webOutputHeader( $rowCount, $opts ) {
if ( !$this->including() ) {
$this->outputFeedLinks();
- $this->doHeader( $opts, $rows->numRows() );
+ $this->doHeader( $opts, $rowCount );
}
+ }
+
+ /**
+ * Send output to the OutputPage object, only called if not used feeds
+ *
+ * @param ResultWrapper $rows Database rows
+ * @param FormOptions $opts
+ */
+ public function webOutput( $rows, $opts ) {
+ $this->webOutputHeader( $rows->numRows(), $opts );
$this->outputChangesList( $rows, $opts );
}
# Collapsible
$collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
$collapsedClass = $collapsedState === 'collapsed' ? ' mw-collapsed' : '';
+ # Enhanced mode
+ $enhancedMode = $this->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
+ $enhancedClass = $enhancedMode ? ' mw-enhanced' : '';
+
+ $legendClasses = $collapsedClass . $enhancedClass;
$legend =
- '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
+ '<div class="mw-changeslist-legend mw-collapsible' . $legendClasses . '">' .
$legendHeading .
'<div class="mw-collapsible-content">' . $legend . '</div>' .
'</div>';
] );
$out->addModules( 'mediawiki.special.changeslist.legend.js' );
- if ( $this->isStructuredFilterUiEnabled() ) {
+ if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
$out->addModules( 'mediawiki.rcfilters.filters.ui' );
$out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
}
return true;
}
- if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
- return !$this->getUser()->getOption( 'rcenhancedfilters-disable' );
- } else {
- return $this->getUser()->getOption( 'rcenhancedfilters' );
- }
+ return static::checkStructuredFilterUiEnabled(
+ $this->getConfig(),
+ $this->getUser()
+ );
}
/**
}
}
- abstract function getDefaultLimit();
+ /**
+ * Static method to check whether StructuredFilter UI is enabled for the given user
+ *
+ * @since 1.31
+ * @param Config $config
+ * @param User $user User object
+ * @return bool
+ */
+ public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
+ if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
+ return !$user->getOption( 'rcenhancedfilters-disable' );
+ } else {
+ return $user->getOption( 'rcenhancedfilters' );
+ }
+ }
+
+ /**
+ * Get the default value of the number of changes to display when loading
+ * the result set.
+ *
+ * @since 1.30
+ * @return int
+ */
+ public function getDefaultLimit() {
+ return $this->getUser()->getIntOption( static::$limitPreferenceName );
+ }
/**
* Get the default value of the number of days to display when loading
* the result set.
* Supports fractional values, and should be cast to a float.
*
+ * @since 1.30
* @return float
*/
- abstract function getDefaultDays();
+ public function getDefaultDays() {
+ return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );
+ }
}