X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fspecialpage%2FChangesListSpecialPage.php;h=bf5734a0f967155d42d3c368950d619aba53ad1e;hb=5d16571ffbdce2ad0ab0f092a126be9987055402;hp=2fa8fab6477cbfb4d4f3a4e557625f44bb3945ab;hpb=285cbfde618577a4d8338edfa0205d9bf31d43ab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 2fa8fab647..bf5734a0f9 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -766,6 +766,33 @@ abstract class ChangesListSpecialPage extends SpecialPage { } } + /** + * @see $wgRCLinkDays in DefaultSettings.php. + * @see $wgRCFilterByAge in DefaultSettings.php. + * @return int[] + */ + protected function getLinkDays() { + $linkDays = $this->getConfig()->get( 'RCLinkDays' ); + $filterByAge = $this->getConfig()->get( 'RCFilterByAge' ); + $maxAge = $this->getConfig()->get( 'RCMaxAge' ); + if ( $filterByAge ) { + // Trim it to only links which are within $wgRCMaxAge. + // Note that we allow one link higher than the max for things like + // "age 56 days" being accessible through the "60 days" link. + sort( $linkDays ); + + $maxAgeDays = $maxAge / ( 3600 * 24 ); + foreach ( $linkDays as $i => $days ) { + if ( $days >= $maxAgeDays ) { + array_splice( $linkDays, $i + 1 ); + break; + } + } + } + + return $linkDays; + } + /** * Include the modules and configuration for the RCFilters app. * Conditional on the user having the feature enabled. @@ -798,7 +825,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ), 'limitDefault' => $this->getDefaultLimit(), - 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ), + 'daysArray' => $this->getLinkDays(), 'daysDefault' => $this->getDefaultDays(), ] ); @@ -857,87 +884,85 @@ abstract class ChangesListSpecialPage extends SpecialPage { } /** - * Get (cheap to compute) information about change tags. + * Get information about change tags, without parsing messages, for getRcFiltersConfigSummary(). + * + * Message contents are the raw values (->plain()), because parsing messages is expensive. + * Even though we're not parsing messages, building a data structure with the contents of + * hundreds of i18n messages is still not cheap (see T223260#5370610), so the result of this + * function is cached in WANCache for 24 hours. * * Returns an array of associative arrays with information about each tag: * - name: Tag name (string) * - labelMsg: Short description message (Message object) + * - label: Short description message (raw message contents) * - descriptionMsg: Long description message (Message object) + * - description: Long description message (raw message contents) * - cssClass: CSS class to use for RC entries with this tag * - hits: Number of RC entries that have this tag * * @param ResourceLoaderContext $context * @return array[] Information about each tag */ - protected static function getChangeTagInfo( ResourceLoaderContext $context ) { - $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); - $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 ); - - $tagStats = ChangeTags::tagUsageStatistics(); - $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats ); - - $result = []; - foreach ( $tagHitCounts as $tagName => $hits ) { - if ( - ( - // Only get active tags - isset( $explicitlyDefinedTags[ $tagName ] ) || - isset( $softwareActivatedTags[ $tagName ] ) - ) && - // Only get tags with more than 0 hits - $hits > 0 - ) { - $labelMsg = ChangeTags::tagShortDescriptionMessage( $tagName, $context ); - if ( $labelMsg === false ) { - // Tag is hidden, skip it - continue; - } - $result[] = [ - 'name' => $tagName, - // 'label' and 'description' filled in by getChangeTagList() - 'labelMsg' => $labelMsg, - 'descriptionMsg' => ChangeTags::tagLongDescriptionMessage( $tagName, $context ), - 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), - 'hits' => $hits, - ]; - } - } - return $result; - } - - /** - * Get information about change tags for use in getRcFiltersConfigSummary(). - * - * This expands labelMsg and descriptionMsg to the raw values of each message, which captures - * changes in the messages but avoids the expensive step of parsing them. - * - * @param ResourceLoaderContext $context - * @return array[] Result of getChangeTagInfo(), with messages expanded to raw contents - */ protected static function getChangeTagListSummary( ResourceLoaderContext $context ) { - $tags = self::getChangeTagInfo( $context ); - foreach ( $tags as &$tagInfo ) { - $tagInfo['labelMsg'] = $tagInfo['labelMsg']->plain(); - if ( $tagInfo['descriptionMsg'] ) { - $tagInfo['descriptionMsg'] = $tagInfo['descriptionMsg']->plain(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + return $cache->getWithSetCallback( + $cache->makeKey( 'ChangesListSpecialPage-changeTagListSummary', $context->getLanguage() ), + WANObjectCache::TTL_DAY, + function ( $oldValue, &$ttl, array &$setOpts ) use ( $context ) { + $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); + $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 ); + + $tagStats = ChangeTags::tagUsageStatistics(); + $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats ); + + $result = []; + foreach ( $tagHitCounts as $tagName => $hits ) { + if ( + ( + // Only get active tags + isset( $explicitlyDefinedTags[ $tagName ] ) || + isset( $softwareActivatedTags[ $tagName ] ) + ) && + // Only get tags with more than 0 hits + $hits > 0 + ) { + $labelMsg = ChangeTags::tagShortDescriptionMessage( $tagName, $context ); + if ( $labelMsg === false ) { + // Tag is hidden, skip it + continue; + } + $descriptionMsg = ChangeTags::tagLongDescriptionMessage( $tagName, $context ); + $result[] = [ + 'name' => $tagName, + 'labelMsg' => $labelMsg, + 'label' => $labelMsg->plain(), + 'descriptionMsg' => $descriptionMsg, + 'description' => $descriptionMsg ? $descriptionMsg->plain() : '', + 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), + 'hits' => $hits, + ]; + } + } + return $result; } - } - return $tags; + ); } /** * Get information about change tags to export to JS via getRcFiltersConfigVars(). * - * This removes labelMsg and descriptionMsg, and adds label and description, which are parsed, - * stripped and (in the case of description) truncated versions of these messages. Message + * This manipulates the label and description of each tag, which are parsed, stripped + * and (in the case of description) truncated versions of these messages. Message * parsing is expensive, so to detect whether the tag list has changed, use * getChangeTagListSummary() instead. * + * The result of this function is cached in WANCache for 24 hours. + * * @param ResourceLoaderContext $context - * @return array[] Result of getChangeTagInfo(), with messages parsed, stripped and truncated + * @return array[] Same as getChangeTagListSummary(), with messages parsed, stripped and truncated */ protected static function getChangeTagList( ResourceLoaderContext $context ) { - $tags = self::getChangeTagInfo( $context ); + $tags = self::getChangeTagListSummary( $context ); $language = Language::factory( $context->getLanguage() ); foreach ( $tags as &$tagInfo ) { $tagInfo['label'] = Sanitizer::stripAllTags( $tagInfo['labelMsg']->parse() ); @@ -1106,7 +1131,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { * * There is light processing to simplify core maintenance. * @param array $definition - * @phan-param array $definition + * @phan-param array $definition */ protected function registerFiltersFromDefinitions( array $definition ) { $autoFillPriority = -1;