From: Catrope Date: Tue, 12 Feb 2019 00:54:39 +0000 (+0000) Subject: Revert "RCFilters: Export config vars in the RL modules where possible" X-Git-Tag: 1.34.0-rc.0~2839^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=492969e12bb34c6832213769d822d0b3d564550c;p=lhc%2Fweb%2Fwiklou.git Revert "RCFilters: Export config vars in the RL modules where possible" This reverts commit bf4f9d0313495dd67a53b9925edf9a3cc6ef36fe. Reason for revert: causes issues with OAuth extension The OAuth extension uses a hook to override certain tag messages, and that hook uses RequestContext::getMain()->msg(), which tries to load the current user. That's not allowed in load.php requests, so we get a "Sessions are disabled for this entry point" error. Change-Id: If58b7edfca116cd7a11f38556f74bed82609d96a --- diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 6ebe8008d0..a1cf468e6b 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -141,11 +141,11 @@ class ChangeTags { * we consider the tag hidden, and return false. * * @param string $tag - * @param MessageLocalizer $context + * @param IContextSource $context * @return string|bool Tag description or false if tag is to be hidden. * @since 1.25 Returns false if tag is to be hidden. */ - public static function tagDescription( $tag, MessageLocalizer $context ) { + public static function tagDescription( $tag, IContextSource $context ) { $msg = $context->msg( "tag-$tag" ); if ( !$msg->exists() ) { // No such message, so return the HTML-escaped tag name. @@ -168,11 +168,11 @@ class ChangeTags { * for the long description. * * @param string $tag - * @param MessageLocalizer $context + * @param IContextSource $context * @return Message|bool Message object of the tag long description or false if * there is no description. */ - public static function tagLongDescriptionMessage( $tag, MessageLocalizer $context ) { + public static function tagLongDescriptionMessage( $tag, IContextSource $context ) { $msg = $context->msg( "tag-$tag-description" ); if ( !$msg->exists() ) { return false; @@ -196,8 +196,6 @@ class ChangeTags { * @return string Truncated long tag description. */ public static function truncateTagDescription( $tag, $length, IContextSource $context ) { - // FIXME: Make this accept MessageLocalizer and Language instead of IContextSource - $originalDesc = self::tagLongDescriptionMessage( $tag, $context ); // If there is no tag description, return empty string if ( !$originalDesc ) { diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 4e2377764f..ea1cf59384 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -792,6 +792,10 @@ abstract class ChangesListSpecialPage extends SpecialPage { $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages ); $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed ); + $out->addJsConfigVars( + 'wgRCFiltersChangeTags', + $this->getChangeTagList() + ); $out->addJsConfigVars( 'StructuredChangeFiltersDisplayConfig', [ @@ -819,35 +823,26 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'wgStructuredChangeFiltersCollapsedPreferenceName', static::$collapsedPreferenceName ); + + $out->addJsConfigVars( + 'StructuredChangeFiltersLiveUpdatePollingRate', + $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' ) + ); } else { $out->addBodyClasses( 'mw-rcfilters-disabled' ); } } - /** - * Get config vars to export with the mediawiki.rcfilters.filters.ui module. - * - * @param ResourceLoaderContext $context - * @return array - */ - public static function getRcFiltersConfigVars( ResourceLoaderContext $context ) { - return [ - 'RCFiltersChangeTags' => self::getChangeTagList( $context ), - 'StructuredChangeFiltersEditWatchlistUrl' => - SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL() - ]; - } - /** * Fetch the change tags list for the front end * - * @param ResourceLoaderContext $context * @return array Tag data */ - protected static function getChangeTagList( ResourceLoaderContext $context ) { + protected function getChangeTagList() { $cache = ObjectCache::getMainWANInstance(); + $context = $this->getContext(); return $cache->getWithSetCallback( - $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ), + $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ), $cache::TTL_MINUTE * 10, function () use ( $context ) { $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); @@ -863,10 +858,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { */ $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags ); - // HACK work around ChangeTags::truncateTagDescription() requiring a RequestContext - $fakeContext = new RequestContext; - $fakeContext->setLanguage( Language::factory( $context->getLanguage() ) ); - // Build the list and data $result = []; foreach ( $tagHitCounts as $tagName => $hits ) { @@ -884,7 +875,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { ChangeTags::truncateTagDescription( $tagName, self::TAG_DESC_CHARACTER_LIMIT, - $fakeContext + $context ), 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), 'hits' => $hits, diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 971aa43c09..0fc6e13c41 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -102,6 +102,11 @@ class SpecialWatchlist extends ChangesListSpecialPage { if ( $this->isStructuredFilterUiEnabled() ) { $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] ); + + $output->addJsConfigVars( + 'wgStructuredChangeFiltersEditWatchlistUrl', + SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL() + ); } } diff --git a/resources/Resources.php b/resources/Resources.php index d62f3e3c54..f7749932ad 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1813,7 +1813,6 @@ return [ 'dm/ItemModel.js', 'dm/SavedQueriesModel.js', 'dm/SavedQueryItemModel.js', - 'config.json' => [ 'config' => [ 'StructuredChangeFiltersLiveUpdatePollingRate' ] ], ], 'dependencies' => [ 'mediawiki.String', @@ -1867,7 +1866,6 @@ return [ 'ui/RclTargetPageWidget.js', 'ui/RclToOrFromWidget.js', 'ui/WatchlistTopSectionWidget.js', - 'config.json' => [ 'callback' => 'ChangesListSpecialPage::getRcFiltersConfigVars' ], ], 'styles' => [ 'styles/mw.rcfilters.mixins.less', diff --git a/resources/src/mediawiki.rcfilters/Controller.js b/resources/src/mediawiki.rcfilters/Controller.js index 56a95ebf1b..30d4a900d8 100644 --- a/resources/src/mediawiki.rcfilters/Controller.js +++ b/resources/src/mediawiki.rcfilters/Controller.js @@ -33,8 +33,6 @@ this.collapsedPreferenceName = config.collapsedPreferenceName; this.normalizeTarget = !!config.normalizeTarget; - this.pollingRate = require( './config.json' ).StructuredChangeFiltersLiveUpdatePollingRate; - this.requestCounter = {}; this.baseFilterState = {}; this.uriProcessor = null; @@ -280,6 +278,7 @@ this.initialized = true; this.switchView( 'default' ); + this.pollingRate = mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' ); if ( this.pollingRate ) { this._scheduleLiveUpdate(); } diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js index a69dc55051..4e0d3da3be 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js @@ -123,7 +123,7 @@ mw.config.get( 'wgStructuredChangeFilters' ), // All namespaces without Media namespace getNamespaces( [ 'Media' ] ), - require( './config.json' ).RCFiltersChangeTags, + mw.config.get( 'wgRCFiltersChangeTags' ), conditionalViews ); diff --git a/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js index cb297f68ea..2674cc2efb 100644 --- a/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js @@ -90,7 +90,7 @@ this.numChangesAndDateWidget.$element ); - if ( this.controller.pollingRate ) { + if ( mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' ) ) { $bottom.prepend( this.liveUpdateButton.$element ); } diff --git a/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js b/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js index 16c0533d8b..a1c97768b4 100644 --- a/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js @@ -30,7 +30,7 @@ editWatchlistButton = new OO.ui.ButtonWidget( { label: mw.msg( 'rcfilters-watchlist-edit-watchlist-button' ), icon: 'edit', - href: require( '../config.json' ).StructuredChangeFiltersEditWatchlistUrl + href: mw.config.get( 'wgStructuredChangeFiltersEditWatchlistUrl' ) } ); markSeenButton = new MarkSeenButtonWidget( controller, changesListModel );