X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecialpage%2FChangesListSpecialPage.php;h=88ec3276717a20c3915576f3ae538052d4c3d9c1;hb=521ca4768d9f154b6b7fa740962c201ca43f0b0b;hp=d7519d3c173df3445727ad06243b47d0801cec6a;hpb=4f2b35eef8bc5f6bbf6d7cbfc6dbf8838ab29441;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index d7519d3c17..88ec327671 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -619,7 +619,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { $out->addJsConfigVars( 'wgRCFiltersChangeTags', - $this->buildChangeTagList() + $this->getChangeTagList() ); $out->addJsConfigVars( 'StructuredChangeFiltersDisplayConfig', @@ -661,49 +661,60 @@ abstract class ChangesListSpecialPage extends SpecialPage { * * @return Array Tag data */ - protected function buildChangeTagList() { - $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); - $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 ); - - // Hit counts disabled for perf reasons, see T169997 - /* - $tagStats = ChangeTags::tagUsageStatistics(); - $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats ); - - // Sort by hits - arsort( $tagHitCounts ); - */ - $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags ); - - // Build the list and data - $result = []; - foreach ( $tagHitCounts as $tagName => $hits ) { - if ( - // Only get active tags - isset( $explicitlyDefinedTags[ $tagName ] ) || - isset( $softwareActivatedTags[ $tagName ] ) - ) { - // Parse description - $desc = ChangeTags::tagLongDescriptionMessage( $tagName, $this->getContext() ); - - $result[] = [ - 'name' => $tagName, - 'label' => Sanitizer::stripAllTags( - ChangeTags::tagDescription( $tagName, $this->getContext() ) - ), - 'description' => $desc ? Sanitizer::stripAllTags( $desc->parse() ) : '', - 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), - 'hits' => $hits, - ]; - } - } + protected function getChangeTagList() { + $cache = ObjectCache::getMainWANInstance(); + $context = $this->getContext(); + return $cache->getWithSetCallback( + $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ), + $cache::TTL_MINUTE * 10, + function () use ( $context ) { + $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); + $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 ); + + // Hit counts disabled for perf reasons, see T169997 + /* + $tagStats = ChangeTags::tagUsageStatistics(); + $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats ); + + // Sort by hits + arsort( $tagHitCounts ); + */ + $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags ); + + // Build the list and data + $result = []; + foreach ( $tagHitCounts as $tagName => $hits ) { + if ( + // Only get active tags + isset( $explicitlyDefinedTags[ $tagName ] ) || + isset( $softwareActivatedTags[ $tagName ] ) + ) { + // Parse description + $desc = ChangeTags::tagLongDescriptionMessage( $tagName, $context ); + + $result[] = [ + 'name' => $tagName, + 'label' => Sanitizer::stripAllTags( + ChangeTags::tagDescription( $tagName, $context ) + ), + 'description' => $desc ? Sanitizer::stripAllTags( $desc->parse() ) : '', + 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), + 'hits' => $hits, + ]; + } + } - // Instead of sorting by hit count (disabled, see above), sort by display name - usort( $result, function ( $a, $b ) { - return strcasecmp( $a['label'], $b['label'] ); - } ); + // Instead of sorting by hit count (disabled, see above), sort by display name + usort( $result, function ( $a, $b ) { + return strcasecmp( $a['label'], $b['label'] ); + } ); - return $result; + return $result; + }, + [ + 'lockTSE' => 30 + ] + ); } /** @@ -957,6 +968,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { $opts->add( 'urlversion', 1 ); $opts->add( 'tagfilter', '' ); + $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT ); + $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT ); + + $opts->add( 'from', '' ); + return $opts; } @@ -1110,6 +1126,9 @@ abstract class ChangesListSpecialPage extends SpecialPage { $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) ); $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) ); } + + $opts->validateIntBounds( 'limit', 0, 5000 ); + $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) ); } /** @@ -1249,6 +1268,19 @@ abstract class ChangesListSpecialPage extends SpecialPage { } $conds[] = "rc_namespace $operator $value"; } + + // Calculate cutoff + $cutoff_unixtime = time() - $opts['days'] * 3600 * 24; + $cutoff = $dbr->timestamp( $cutoff_unixtime ); + + $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] ); + if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) { + $cutoff = $dbr->timestamp( $opts['from'] ); + } else { + $opts->reset( 'from' ); + } + + $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ); } /**