Right now there are only a few settings that don't depend on the request
context, but we can at least export those. The tag data in
particular can get pretty big.
Downgrade the type hint for ChangeTags::tagDescription() and
tagLongDescriptionMessage() from IContextSource to MessageLocalizer, so
we can pass a ResourceLoaderContext to these functions. (Since
IContextSource extends MessageLocalizer, this won't break any callers.)
truncateTagDescription() can't be downgraded to MessageLocalizer because
it needs a Language object, so hack up a fake RequestContext when
calling it. It would be nice if this weren't necessary; perhaps we can
move getLanguage() from IContextSource up into MessageLocalizer?
Bug: T201574
Change-Id: I9b66e35de826a07aa9551ba285e64e4852293229
* we consider the tag hidden, and return false.
*
* @param string $tag
* 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.
*/
* @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.
$msg = $context->msg( "tag-$tag" );
if ( !$msg->exists() ) {
// No such message, so return the HTML-escaped tag name.
* for the long description.
*
* @param string $tag
* 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.
*/
* @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;
$msg = $context->msg( "tag-$tag-description" );
if ( !$msg->exists() ) {
return false;
* @return string Truncated long tag description.
*/
public static function truncateTagDescription( $tag, $length, IContextSource $context ) {
* @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 ) {
$originalDesc = self::tagLongDescriptionMessage( $tag, $context );
// If there is no tag description, return empty string
if ( !$originalDesc ) {
$out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
$out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
$out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
$out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
- $out->addJsConfigVars(
- 'wgRCFiltersChangeTags',
- $this->getChangeTagList()
- );
$out->addJsConfigVars(
'StructuredChangeFiltersDisplayConfig',
[
$out->addJsConfigVars(
'StructuredChangeFiltersDisplayConfig',
[
'wgStructuredChangeFiltersCollapsedPreferenceName',
static::$collapsedPreferenceName
);
'wgStructuredChangeFiltersCollapsedPreferenceName',
static::$collapsedPreferenceName
);
-
- $out->addJsConfigVars(
- 'StructuredChangeFiltersLiveUpdatePollingRate',
- $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
- );
} else {
$out->addBodyClasses( 'mw-rcfilters-disabled' );
}
}
} 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
*
/**
* Fetch the change tags list for the front end
*
+ * @param ResourceLoaderContext $context
* @return array Tag data
*/
* @return array Tag data
*/
- protected function getChangeTagList() {
+ protected static function getChangeTagList( ResourceLoaderContext $context ) {
$cache = ObjectCache::getMainWANInstance();
$cache = ObjectCache::getMainWANInstance();
- $context = $this->getContext();
return $cache->getWithSetCallback(
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 );
$cache::TTL_MINUTE * 10,
function () use ( $context ) {
$explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
*/
$tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
*/
$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 ) {
// Build the list and data
$result = [];
foreach ( $tagHitCounts as $tagName => $hits ) {
),
'description' =>
ChangeTags::truncateTagDescription(
),
'description' =>
ChangeTags::truncateTagDescription(
- $tagName, self::TAG_DESC_CHARACTER_LIMIT, $context
+ $tagName,
+ self::TAG_DESC_CHARACTER_LIMIT,
+ $fakeContext
),
'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
'hits' => $hits,
),
'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
'hits' => $hits,
if ( $this->isStructuredFilterUiEnabled() ) {
$output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
if ( $this->isStructuredFilterUiEnabled() ) {
$output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
-
- $output->addJsConfigVars(
- 'wgStructuredChangeFiltersEditWatchlistUrl',
- SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
- );
'dm/ItemModel.js',
'dm/SavedQueriesModel.js',
'dm/SavedQueryItemModel.js',
'dm/ItemModel.js',
'dm/SavedQueriesModel.js',
'dm/SavedQueryItemModel.js',
+ 'config.json' => [ 'config' => [ 'StructuredChangeFiltersLiveUpdatePollingRate' ] ],
],
'dependencies' => [
'mediawiki.String',
],
'dependencies' => [
'mediawiki.String',
'ui/RclTargetPageWidget.js',
'ui/RclToOrFromWidget.js',
'ui/WatchlistTopSectionWidget.js',
'ui/RclTargetPageWidget.js',
'ui/RclToOrFromWidget.js',
'ui/WatchlistTopSectionWidget.js',
+ 'config.json' => [ 'callback' => 'ChangesListSpecialPage::getRcFiltersConfigVars' ],
],
'styles' => [
'styles/mw.rcfilters.mixins.less',
],
'styles' => [
'styles/mw.rcfilters.mixins.less',
this.collapsedPreferenceName = config.collapsedPreferenceName;
this.normalizeTarget = !!config.normalizeTarget;
this.collapsedPreferenceName = config.collapsedPreferenceName;
this.normalizeTarget = !!config.normalizeTarget;
+ this.pollingRate = require( './config.json' ).StructuredChangeFiltersLiveUpdatePollingRate;
+
this.requestCounter = {};
this.baseFilterState = {};
this.uriProcessor = null;
this.requestCounter = {};
this.baseFilterState = {};
this.uriProcessor = null;
this.initialized = true;
this.switchView( 'default' );
this.initialized = true;
this.switchView( 'default' );
- this.pollingRate = mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' );
if ( this.pollingRate ) {
this._scheduleLiveUpdate();
}
if ( this.pollingRate ) {
this._scheduleLiveUpdate();
}
mw.config.get( 'wgStructuredChangeFilters' ),
// All namespaces without Media namespace
getNamespaces( [ 'Media' ] ),
mw.config.get( 'wgStructuredChangeFilters' ),
// All namespaces without Media namespace
getNamespaces( [ 'Media' ] ),
- mw.config.get( 'wgRCFiltersChangeTags' ),
+ require( './config.json' ).RCFiltersChangeTags,
this.numChangesAndDateWidget.$element
);
this.numChangesAndDateWidget.$element
);
- if ( mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' ) ) {
+ if ( this.controller.pollingRate ) {
$bottom.prepend( this.liveUpdateButton.$element );
}
$bottom.prepend( this.liveUpdateButton.$element );
}
editWatchlistButton = new OO.ui.ButtonWidget( {
label: mw.msg( 'rcfilters-watchlist-edit-watchlist-button' ),
icon: 'edit',
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 );
} );
markSeenButton = new MarkSeenButtonWidget( controller, changesListModel );