mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-23 10:19:35 +00:00
Merge "Recognize DEFAULTSORT again"
This commit is contained in:
commit
ba5c9995d0
|
@ -1114,8 +1114,8 @@ class Hooks implements
|
|||
*/
|
||||
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
||||
$coreConfig = RequestContext::getMain()->getConfig();
|
||||
$veConfig = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'visualeditor' );
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
|
||||
$extensionRegistry = ExtensionRegistry::getInstance();
|
||||
$availableNamespaces = ApiVisualEditor::getAvailableNamespaceIds( $veConfig );
|
||||
$availableContentModels = array_filter(
|
||||
|
@ -1135,11 +1135,17 @@ class Hooks implements
|
|||
// to include those in the JavaScript data. See T291727.
|
||||
// Run this filtering after the filter for subpages being enabled, to reduce
|
||||
// the number of calls needed to namespace info.
|
||||
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
|
||||
$nsInfo = $services->getNamespaceInfo();
|
||||
$namespacesWithSubpagesEnabled = array_values( array_filter(
|
||||
$namespacesWithSubpagesEnabled,
|
||||
[ $nsInfo, 'exists' ]
|
||||
) );
|
||||
|
||||
$defaultSortPrefix = $services->getMagicWordFactory()->get( 'defaultsort' )->getSynonym( 0 );
|
||||
// Sanitize trailing colon. /languages/messages/*.php are not consistent but the
|
||||
// presence or absence of a trailing colon in the message makes no difference.
|
||||
$defaultSortPrefix = preg_replace( '/:$/', '', $defaultSortPrefix );
|
||||
|
||||
$vars['wgVisualEditorConfig'] = [
|
||||
'usePageImages' => $extensionRegistry->isLoaded( 'PageImages' ),
|
||||
'usePageDescriptions' => $extensionRegistry->isLoaded( 'WikibaseClient' ),
|
||||
|
@ -1177,6 +1183,7 @@ class Hooks implements
|
|||
// TODO: Remove when all usages in .js files are removed
|
||||
'transclusionDialogNewSidebar' => true,
|
||||
'cirrusSearchLookup' => $extensionRegistry->isLoaded( 'CirrusSearch' ),
|
||||
'defaultSortPrefix' => $defaultSortPrefix,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -28,25 +28,55 @@ ve.dm.MWDefaultSortMetaItem.static.name = 'mwDefaultSort';
|
|||
|
||||
ve.dm.MWDefaultSortMetaItem.static.group = 'mwDefaultSort';
|
||||
|
||||
ve.dm.MWDefaultSortMetaItem.static.matchTagNames = [ 'meta' ];
|
||||
ve.dm.MWDefaultSortMetaItem.static.matchTagNames = [ 'span' ];
|
||||
|
||||
ve.dm.MWDefaultSortMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/categorydefaultsort' ];
|
||||
ve.dm.MWDefaultSortMetaItem.static.matchRdfaTypes = [ 'mw:Transclusion' ];
|
||||
|
||||
ve.dm.MWDefaultSortMetaItem.static.matchFunction = function ( domElement ) {
|
||||
var mwDataJSON = domElement.getAttribute( 'data-mw' ),
|
||||
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
return ve.getProp( mwData, 'parts', '0', 'template', 'target', 'function' ) === 'defaultsort';
|
||||
};
|
||||
|
||||
ve.dm.MWDefaultSortMetaItem.static.toDataElement = function ( domElements ) {
|
||||
var content = domElements[ 0 ].getAttribute( 'content' );
|
||||
var mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
||||
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
||||
input = ve.getProp( mwData, 'parts', '0', 'template', 'target', 'wt' ),
|
||||
prefix, sortKey;
|
||||
if ( input ) {
|
||||
prefix = input.split( ':' )[ 0 ];
|
||||
sortKey = input.slice( prefix.length + 1 );
|
||||
}
|
||||
return {
|
||||
type: this.name,
|
||||
attributes: {
|
||||
content: content
|
||||
prefix: prefix,
|
||||
sortkey: sortKey
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ve.dm.MWDefaultSortMetaItem.static.toDomElements = function ( dataElement, doc ) {
|
||||
var meta = doc.createElement( 'meta' );
|
||||
meta.setAttribute( 'property', 'mw:PageProp/categorydefaultsort' );
|
||||
meta.setAttribute( 'content', dataElement.attributes.content );
|
||||
return [ meta ];
|
||||
var prefix = dataElement.attributes.prefix ||
|
||||
mw.config.get( 'wgVisualEditorConfig' ).defaultSortPrefix,
|
||||
sortKey = dataElement.attributes.sortkey || '',
|
||||
mwData = {
|
||||
parts: [
|
||||
{
|
||||
template: {
|
||||
target: {
|
||||
wt: prefix + ':' + sortKey,
|
||||
function: 'defaultsort'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var span = doc.createElement( 'span' );
|
||||
span.setAttribute( 'typeof', 'mw:Transclusion' );
|
||||
span.setAttribute( 'data-mw', JSON.stringify( mwData ) );
|
||||
return [ span ];
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
|
|
@ -2196,12 +2196,13 @@ ve.dm.mwExample.domToDataCases = {
|
|||
]
|
||||
},
|
||||
'category default sort key': {
|
||||
body: '<meta property="mw:PageProp/categorydefaultsort" content="foo">',
|
||||
body: '<span typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"DEFAULTSORT:foo","function":"defaultsort"}}}]}\'></span>',
|
||||
data: [
|
||||
{
|
||||
type: 'mwDefaultSort',
|
||||
attributes: {
|
||||
content: 'foo'
|
||||
prefix: 'DEFAULTSORT',
|
||||
sortkey: 'foo'
|
||||
}
|
||||
},
|
||||
{ type: '/mwDefaultSort' },
|
||||
|
|
|
@ -26,7 +26,7 @@ ve.ui.MWCategoriesPage = function VeUiMWCategoriesPage( name, config ) {
|
|||
// Properties
|
||||
this.fragment = null;
|
||||
this.defaultSortKeyTouched = false;
|
||||
this.fallbackDefaultSortKey = ve.init.target.getPageName();
|
||||
this.fallbackDefaultSortKey = mw.Title.newFromText( ve.init.target.getPageName() ).getMainText();
|
||||
this.categoriesFieldset = new OO.ui.FieldsetLayout( {
|
||||
label: ve.msg( 'visualeditor-dialog-meta-categories-data-label' ),
|
||||
icon: 'tag'
|
||||
|
@ -161,7 +161,7 @@ ve.ui.MWCategoriesPage.prototype.onMetaListRemove = function ( metaItem ) {
|
|||
/**
|
||||
* Get default sort key item.
|
||||
*
|
||||
* @return {string} Default sort key item
|
||||
* @return {Object} Default sort key item
|
||||
*/
|
||||
ve.ui.MWCategoriesPage.prototype.getDefaultSortKeyItem = function () {
|
||||
return this.fragment.getDocument().getMetaList().getItemsInGroup( 'mwDefaultSort' )[ 0 ] || null;
|
||||
|
@ -246,7 +246,7 @@ ve.ui.MWCategoriesPage.prototype.setup = function ( fragment, config ) {
|
|||
} );
|
||||
|
||||
this.defaultSortInput.setValue(
|
||||
defaultSortKeyItem ? defaultSortKeyItem.getAttribute( 'content' ) : this.fallbackDefaultSortKey
|
||||
defaultSortKeyItem ? defaultSortKeyItem.getAttribute( 'sortkey' ) : this.fallbackDefaultSortKey
|
||||
).setReadOnly( config.isReadOnly );
|
||||
this.defaultSortKeyTouched = false;
|
||||
|
||||
|
@ -272,11 +272,7 @@ ve.ui.MWCategoriesPage.prototype.focus = function () {
|
|||
*/
|
||||
ve.ui.MWCategoriesPage.prototype.teardown = function ( data ) {
|
||||
var currentDefaultSortKeyItem = this.getDefaultSortKeyItem(),
|
||||
newDefaultSortKey = this.defaultSortInput.getValue(),
|
||||
newDefaultSortKeyData = {
|
||||
type: 'mwDefaultSort',
|
||||
attributes: { content: newDefaultSortKey }
|
||||
};
|
||||
newDefaultSortKey = this.defaultSortInput.getValue();
|
||||
|
||||
if ( data && data.action === 'done' ) {
|
||||
// Alter the default sort key iff it's been touched & is actually different
|
||||
|
@ -286,9 +282,17 @@ ve.ui.MWCategoriesPage.prototype.teardown = function ( data ) {
|
|||
this.fragment.removeMeta( currentDefaultSortKeyItem );
|
||||
}
|
||||
} else {
|
||||
var newDefaultSortKeyData = {
|
||||
type: 'mwDefaultSort',
|
||||
attributes: {
|
||||
sortkey: newDefaultSortKey
|
||||
}
|
||||
};
|
||||
if ( !currentDefaultSortKeyItem ) {
|
||||
this.fragment.insertMeta( newDefaultSortKeyData );
|
||||
} else if ( currentDefaultSortKeyItem.getAttribute( 'content' ) !== newDefaultSortKey ) {
|
||||
var firstCategory = this.fragment.getDocument().getMetaList().getItemsInGroup( 'mwCategory' )[ 0 ],
|
||||
offset = firstCategory && firstCategory.getOffset();
|
||||
this.fragment.insertMeta( newDefaultSortKeyData, offset );
|
||||
} else if ( currentDefaultSortKeyItem.getAttribute( 'sortkey' ) !== newDefaultSortKey ) {
|
||||
this.fragment.replaceMeta(
|
||||
currentDefaultSortKeyItem,
|
||||
ve.extendObject( true, {},
|
||||
|
|
Loading…
Reference in a new issue