aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatrope <roan@wikimedia.org>2019-02-15 22:12:02 +0000
committerRoan Kattouw <roan.kattouw@gmail.com>2019-02-20 16:24:01 -0800
commit9ba1d8f526e1dd3365f674899f516585ff1e18f8 (patch)
tree0e175d1049692ca9e0319e8c9186be36140aa370
parent76e300f46cea939bccead85cd69f4f9d11681326 (diff)
downloadmediawikicore-9ba1d8f526e1dd3365f674899f516585ff1e18f8.tar.gz
mediawikicore-9ba1d8f526e1dd3365f674899f516585ff1e18f8.zip
RCFilters: Export config vars in the RL modules where possible (take 2)
This reverts commit 492969e12bb34c6832213769d822d0b3d564550c and reinstates commit bf4f9d0313495dd67a53b9925edf9a3cc6ef36fe. Bug: T201574 Depends-On: I58901657daf3e82229a303d8fe7a2c051ffe7634 Change-Id: I1b0a777760d4c2a149415da0d2068e6bfea5b917
-rw-r--r--includes/changetags/ChangeTags.php10
-rw-r--r--includes/specialpage/ChangesListSpecialPage.php35
-rw-r--r--includes/specials/SpecialWatchlist.php5
-rw-r--r--resources/Resources.php2
-rw-r--r--resources/src/mediawiki.rcfilters/Controller.js3
-rw-r--r--resources/src/mediawiki.rcfilters/mw.rcfilters.init.js2
-rw-r--r--resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js2
-rw-r--r--resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js2
8 files changed, 35 insertions, 26 deletions
diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php
index 66a816595f92..91877f24f819 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 IContextSource $context
+ * @param MessageLocalizer $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, IContextSource $context ) {
+ public static function tagDescription( $tag, MessageLocalizer $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 IContextSource $context
+ * @param MessageLocalizer $context
* @return Message|bool Message object of the tag long description or false if
* there is no description.
*/
- public static function tagLongDescriptionMessage( $tag, IContextSource $context ) {
+ public static function tagLongDescriptionMessage( $tag, MessageLocalizer $context ) {
$msg = $context->msg( "tag-$tag-description" );
if ( !$msg->exists() ) {
return false;
@@ -196,6 +196,8 @@ 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 ea1cf593848b..154e94e13bce 100644
--- a/includes/specialpage/ChangesListSpecialPage.php
+++ b/includes/specialpage/ChangesListSpecialPage.php
@@ -793,10 +793,6 @@ abstract class ChangesListSpecialPage extends SpecialPage {
$out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
$out->addJsConfigVars(
- 'wgRCFiltersChangeTags',
- $this->getChangeTagList()
- );
- $out->addJsConfigVars(
'StructuredChangeFiltersDisplayConfig',
[
'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
@@ -823,26 +819,35 @@ 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 function getChangeTagList() {
+ protected static function getChangeTagList( ResourceLoaderContext $context ) {
$cache = ObjectCache::getMainWANInstance();
- $context = $this->getContext();
return $cache->getWithSetCallback(
- $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
+ $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ),
$cache::TTL_MINUTE * 10,
function () use ( $context ) {
$explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
@@ -858,6 +863,10 @@ abstract class ChangesListSpecialPage extends SpecialPage {
*/
$tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
+ // HACK work around ChangeTags::truncateTagDescription() requiring a RequestContext
+ $fakeContext = RequestContext::newExtraneousContext( Title::newFromText( 'Dwimmerlaik' ) );
+ $fakeContext->setLanguage( Language::factory( $context->getLanguage() ) );
+
// Build the list and data
$result = [];
foreach ( $tagHitCounts as $tagName => $hits ) {
@@ -875,7 +884,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
ChangeTags::truncateTagDescription(
$tagName,
self::TAG_DESC_CHARACTER_LIMIT,
- $context
+ $fakeContext
),
'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
'hits' => $hits,
diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php
index 0fc6e13c416b..971aa43c0997 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -102,11 +102,6 @@ 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 92930630dbd4..a19926d96fe1 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1816,6 +1816,7 @@ return [
'dm/ItemModel.js',
'dm/SavedQueriesModel.js',
'dm/SavedQueryItemModel.js',
+ 'config.json' => [ 'config' => [ 'StructuredChangeFiltersLiveUpdatePollingRate' ] ],
],
'dependencies' => [
'mediawiki.String',
@@ -1869,6 +1870,7 @@ 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 30d4a900d879..56a95ebf1b49 100644
--- a/resources/src/mediawiki.rcfilters/Controller.js
+++ b/resources/src/mediawiki.rcfilters/Controller.js
@@ -33,6 +33,8 @@
this.collapsedPreferenceName = config.collapsedPreferenceName;
this.normalizeTarget = !!config.normalizeTarget;
+ this.pollingRate = require( './config.json' ).StructuredChangeFiltersLiveUpdatePollingRate;
+
this.requestCounter = {};
this.baseFilterState = {};
this.uriProcessor = null;
@@ -278,7 +280,6 @@
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 4e0d3da3be66..a69dc55051d8 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' ] ),
- mw.config.get( 'wgRCFiltersChangeTags' ),
+ require( './config.json' ).RCFiltersChangeTags,
conditionalViews
);
diff --git a/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js
index 2674cc2efb65..cb297f68eac5 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 ( mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' ) ) {
+ if ( this.controller.pollingRate ) {
$bottom.prepend( this.liveUpdateButton.$element );
}
diff --git a/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js b/resources/src/mediawiki.rcfilters/ui/WatchlistTopSectionWidget.js
index a1c97768b4ff..16c0533d8b09 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: mw.config.get( 'wgStructuredChangeFiltersEditWatchlistUrl' )
+ href: require( '../config.json' ).StructuredChangeFiltersEditWatchlistUrl
} );
markSeenButton = new MarkSeenButtonWidget( controller, changesListModel );