2013-04-10 18:15:15 +00:00
|
|
|
/*!
|
2013-06-11 19:16:04 +00:00
|
|
|
* VisualEditor DataModel MWTransclusionNode class.
|
2013-04-10 18:15:15 +00:00
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2013-04-10 18:15:15 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-06-11 19:16:04 +00:00
|
|
|
* DataModel MediaWiki transclusion node.
|
2013-04-10 18:15:15 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2013-05-29 01:35:42 +00:00
|
|
|
* @extends ve.dm.LeafNode
|
|
|
|
* @mixins ve.dm.GeneratedContentNode
|
2014-09-17 00:33:39 +00:00
|
|
|
* @mixins ve.dm.FocusableNode
|
2013-05-29 01:35:42 +00:00
|
|
|
*
|
2013-04-10 18:15:15 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWTransclusionNode = function VeDmMWTransclusionNode() {
|
2013-04-10 18:15:15 +00:00
|
|
|
// Parent constructor
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.LeafNode.apply( this, arguments );
|
2013-05-29 01:35:42 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.GeneratedContentNode.call( this );
|
2014-09-17 00:33:39 +00:00
|
|
|
ve.dm.FocusableNode.call( this );
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.partsList = null;
|
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.connect( this, { attributeChange: 'onAttributeChange' } );
|
2013-04-10 18:15:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWTransclusionNode, ve.dm.LeafNode );
|
2013-05-29 01:35:42 +00:00
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.dm.MWTransclusionNode, ve.dm.GeneratedContentNode );
|
2014-09-17 00:33:39 +00:00
|
|
|
|
|
|
|
OO.mixinClass( ve.dm.MWTransclusionNode, ve.dm.FocusableNode );
|
2013-04-10 18:15:15 +00:00
|
|
|
|
|
|
|
/* Static members */
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.name = 'mwTransclusion';
|
2013-04-10 18:15:15 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.matchTagNames = null;
|
2013-04-10 18:15:15 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.matchRdfaTypes = [
|
2013-06-05 22:26:37 +00:00
|
|
|
'mw:Transclusion',
|
2013-06-11 19:16:04 +00:00
|
|
|
// We're interested in all nodes that have mw:Transclusion, even if they also have other mw:
|
|
|
|
// types. So we match all mw: types, then use a matchFunction to assert that mw:Transclusion
|
2013-05-28 11:31:41 +00:00
|
|
|
// is in there.
|
|
|
|
/^mw:/
|
|
|
|
];
|
2013-05-03 23:34:01 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.matchFunction = function ( domElement ) {
|
2013-06-05 22:26:37 +00:00
|
|
|
return ve.indexOf( 'mw:Transclusion',
|
2013-05-03 23:34:01 +00:00
|
|
|
( domElement.getAttribute( 'typeof' ) || '' ).split( ' ' )
|
|
|
|
) !== -1;
|
|
|
|
};
|
2013-04-10 18:15:15 +00:00
|
|
|
|
2013-06-24 16:27:35 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.enableAboutGrouping = true;
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.getHashObject = function ( dataElement ) {
|
2013-04-10 18:15:15 +00:00
|
|
|
return {
|
|
|
|
type: dataElement.type,
|
2013-04-20 16:08:23 +00:00
|
|
|
mw: dataElement.attributes.mw
|
2013-04-10 18:15:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.toDataElement = function ( domElements, converter ) {
|
2013-07-23 13:35:26 +00:00
|
|
|
if ( converter.isDomAllMetaOrWhitespace( domElements, ['mwTransclusion', 'mwTransclusionInline', 'mwTransclusionBlock'] ) ) {
|
|
|
|
return ve.dm.MWTransclusionMetaItem.static.toDataElement( domElements, converter );
|
|
|
|
}
|
|
|
|
|
2013-06-18 14:23:37 +00:00
|
|
|
var dataElement, index,
|
2013-06-24 00:00:42 +00:00
|
|
|
mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
|
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
2013-04-13 21:22:26 +00:00
|
|
|
isInline = this.isHybridInline( domElements, converter ),
|
2013-06-11 19:16:04 +00:00
|
|
|
type = isInline ? 'mwTransclusionInline' : 'mwTransclusionBlock';
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-04-10 18:15:15 +00:00
|
|
|
dataElement = {
|
2014-08-22 20:50:48 +00:00
|
|
|
type: type,
|
|
|
|
attributes: {
|
|
|
|
mw: mwData,
|
|
|
|
originalMw: mwDataJSON
|
2013-04-20 16:08:23 +00:00
|
|
|
}
|
2013-04-10 18:15:15 +00:00
|
|
|
};
|
2013-06-18 14:23:37 +00:00
|
|
|
|
2013-12-11 10:33:15 +00:00
|
|
|
if ( !domElements[0].getAttribute( 'data-ve-no-generated-contents' ) ) {
|
|
|
|
index = this.storeGeneratedContents( dataElement, domElements, converter.getStore() );
|
|
|
|
dataElement.attributes.originalIndex = index;
|
|
|
|
}
|
2013-06-18 14:23:37 +00:00
|
|
|
|
2013-04-10 18:15:15 +00:00
|
|
|
return dataElement;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc, converter ) {
|
2015-02-16 16:48:29 +00:00
|
|
|
var els, currentDom, i, len, wrapper, span,
|
2013-12-13 16:48:23 +00:00
|
|
|
index = converter.getStore().indexOfHash( OO.getHash( [ this.getHashObject( dataElement ), undefined ] ) ),
|
2013-06-24 10:24:28 +00:00
|
|
|
originalMw = dataElement.attributes.originalMw;
|
2013-06-18 14:23:37 +00:00
|
|
|
|
|
|
|
// If the transclusion is unchanged just send back the
|
|
|
|
// original DOM elements so selser can skip over it
|
2013-06-24 00:00:42 +00:00
|
|
|
if (
|
2015-02-17 00:36:52 +00:00
|
|
|
dataElement.originalDomElements && (
|
2013-12-13 16:48:23 +00:00
|
|
|
index === dataElement.attributes.originalIndex ||
|
|
|
|
( originalMw && ve.compare( dataElement.attributes.mw, JSON.parse( originalMw ) ) )
|
|
|
|
)
|
2013-06-24 00:00:42 +00:00
|
|
|
) {
|
2013-06-18 14:23:37 +00:00
|
|
|
// The object in the store is also used for CE rendering so return a copy
|
2015-02-17 00:36:52 +00:00
|
|
|
els = ve.copyDomElements( dataElement.originalDomElements, doc );
|
2013-04-20 16:08:23 +00:00
|
|
|
} else {
|
2015-02-17 00:36:52 +00:00
|
|
|
if ( dataElement.originalDomElements ) {
|
|
|
|
els = [ doc.createElement( dataElement.originalDomElements[0].nodeName ) ];
|
2013-07-11 02:05:28 +00:00
|
|
|
} else {
|
2013-12-13 17:39:12 +00:00
|
|
|
els = [ doc.createElement( 'span' ) ];
|
2014-02-05 20:25:03 +00:00
|
|
|
if ( converter.isForClipboard() ) {
|
2015-02-16 16:00:50 +00:00
|
|
|
// For the clipboard use the current DOM contents so the user has something
|
|
|
|
// meaningful to paste into external applications
|
2014-02-05 20:25:03 +00:00
|
|
|
currentDom = converter.getStore().value( index );
|
|
|
|
if ( currentDom ) {
|
2015-02-16 16:00:50 +00:00
|
|
|
// Ignore currentDom[0] as that is the data-mw span we are recreating
|
|
|
|
els = els.concat( ve.copyDomElements( currentDom.slice( 1 ), doc ) );
|
2013-12-13 17:39:12 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-11 02:05:28 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
// All we need to send back to Parsoid is the original transclusion marker, with a
|
|
|
|
// reconstructed data-mw property.
|
2013-12-13 17:39:12 +00:00
|
|
|
els[0].setAttribute( 'typeof', 'mw:Transclusion' );
|
|
|
|
els[0].setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
|
2015-02-16 16:00:50 +00:00
|
|
|
}
|
|
|
|
if ( converter.isForClipboard() ) {
|
2015-02-16 16:48:29 +00:00
|
|
|
// If the first element is a <link> or <meta> tag, e.g. a category, ensure it
|
|
|
|
// is not destroyed by copy-paste by replacing it with a span
|
|
|
|
if ( els[0].tagName === 'LINK' || els[0].tagName === 'META' ) {
|
|
|
|
span = doc.createElement( 'span' );
|
|
|
|
span.setAttribute( 'typeof', 'mw:Transclusion' );
|
|
|
|
span.setAttribute( 'data-mw', els[0].getAttribute( 'data-mw' ) );
|
|
|
|
els[0] = span;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty spans can get thrown around by Chrome when pasting, so give them a space
|
|
|
|
if ( els[0].innerHTML === '' ) {
|
|
|
|
els[0].appendChild( doc.createTextNode( '\u00a0' ) );
|
|
|
|
}
|
|
|
|
|
2015-02-16 16:00:50 +00:00
|
|
|
// Mark the data-mw element as not having valid generated contents with it in case it is
|
2013-12-11 10:33:15 +00:00
|
|
|
// inserted into another editor (e.g. via paste).
|
2013-12-13 17:39:12 +00:00
|
|
|
els[0].setAttribute( 'data-ve-no-generated-contents', true );
|
2015-02-16 16:00:50 +00:00
|
|
|
|
|
|
|
// ... and mark all but the first child as ignorable
|
|
|
|
for ( i = 1, len = els.length; i < len; i++ ) {
|
|
|
|
// Wrap plain text nodes so we can give them an attribute
|
|
|
|
if ( els[i].nodeType === Node.TEXT_NODE ) {
|
|
|
|
wrapper = doc.createElement( 'span' );
|
|
|
|
wrapper.appendChild( els[i] );
|
|
|
|
els[i] = wrapper;
|
|
|
|
}
|
|
|
|
els[i].setAttribute( 'data-ve-ignore', 'true' );
|
|
|
|
}
|
2013-04-20 16:08:23 +00:00
|
|
|
}
|
2015-02-16 16:00:50 +00:00
|
|
|
return els;
|
2013-04-10 18:15:15 +00:00
|
|
|
};
|
|
|
|
|
2013-05-15 20:45:14 +00:00
|
|
|
/**
|
2013-12-09 19:05:57 +00:00
|
|
|
* Escape a template parameter. Helper function for #getWikitext.
|
|
|
|
*
|
|
|
|
* @static
|
2013-05-15 20:45:14 +00:00
|
|
|
* @param {string} param Parameter value
|
|
|
|
* @returns {string} Escaped parameter value
|
|
|
|
*/
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.escapeParameter = function ( param ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
var match, needsNowiki,
|
|
|
|
input = param,
|
|
|
|
output = '',
|
|
|
|
inNowiki = false,
|
|
|
|
bracketStack = 0,
|
|
|
|
linkStack = 0;
|
|
|
|
|
2013-05-15 20:45:14 +00:00
|
|
|
while ( input.length > 0 ) {
|
2013-07-11 14:45:18 +00:00
|
|
|
match = input.match( /(?:\[\[)|(?:\]\])|(?:\{\{)|(?:\}\})|\|+|<\/?nowiki>|<nowiki\s*\/>/ );
|
2013-05-15 20:45:14 +00:00
|
|
|
if ( !match ) {
|
|
|
|
output += input;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-06 19:11:02 +00:00
|
|
|
output += input.slice( 0, match.index );
|
|
|
|
input = input.slice( match.index + match[0].length );
|
2013-05-15 20:45:14 +00:00
|
|
|
if ( inNowiki ) {
|
|
|
|
if ( match[0] === '</nowiki>' ) {
|
|
|
|
inNowiki = false;
|
|
|
|
output += match[0];
|
|
|
|
} else {
|
|
|
|
output += match[0];
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-27 19:12:44 +00:00
|
|
|
needsNowiki = true;
|
2013-05-15 20:45:14 +00:00
|
|
|
if ( match[0] === '<nowiki>' ) {
|
|
|
|
inNowiki = true;
|
2013-06-27 19:12:44 +00:00
|
|
|
needsNowiki = false;
|
2013-05-15 20:45:14 +00:00
|
|
|
} else if ( match[0] === '</nowiki>' || match[0].match( /<nowiki\s*\/>/ ) ) {
|
2013-06-27 19:12:44 +00:00
|
|
|
needsNowiki = false;
|
2013-07-11 14:45:18 +00:00
|
|
|
} else if ( match[0].match( /(?:\[\[)/ ) ) {
|
|
|
|
linkStack++;
|
|
|
|
needsNowiki = false;
|
|
|
|
} else if ( match[0].match( /(?:\]\])/ ) ) {
|
|
|
|
if ( linkStack > 0 ) {
|
|
|
|
linkStack--;
|
|
|
|
needsNowiki = false;
|
|
|
|
}
|
|
|
|
} else if ( match[0].match( /(?:\{\{)/ ) ) {
|
2013-06-27 19:12:44 +00:00
|
|
|
bracketStack++;
|
|
|
|
needsNowiki = false;
|
2013-07-11 14:45:18 +00:00
|
|
|
} else if ( match[0].match( /(?:\}\})/ ) ) {
|
2013-06-27 19:12:44 +00:00
|
|
|
if ( bracketStack > 0 ) {
|
|
|
|
bracketStack--;
|
|
|
|
needsNowiki = false;
|
|
|
|
}
|
|
|
|
} else if ( match[0].match( /\|+/ ) ) {
|
2013-07-11 14:45:18 +00:00
|
|
|
if ( bracketStack > 0 || linkStack > 0 ) {
|
2013-06-27 19:12:44 +00:00
|
|
|
needsNowiki = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( needsNowiki ) {
|
2013-05-15 20:45:14 +00:00
|
|
|
output += '<nowiki>' + match[0] + '</nowiki>';
|
2013-06-27 19:12:44 +00:00
|
|
|
} else {
|
|
|
|
output += match[0];
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
/**
|
|
|
|
* Handle attribute change events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} key Attribute key
|
|
|
|
* @param {string} from Old value
|
|
|
|
* @param {string} to New value
|
|
|
|
*/
|
|
|
|
ve.dm.MWTransclusionNode.prototype.onAttributeChange = function ( key ) {
|
|
|
|
if ( key === 'mw' ) {
|
|
|
|
this.partsList = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-01 23:15:47 +00:00
|
|
|
/**
|
|
|
|
* Check if transclusion contains only a single template.
|
|
|
|
*
|
2014-05-10 18:26:28 +00:00
|
|
|
* @param {string|string[]} [templates] Names of templates to allow, omit to allow any template name
|
|
|
|
* @return {boolean} Transclusion only contains a single template, which is one of the ones in templates
|
2014-04-01 23:15:47 +00:00
|
|
|
*/
|
2014-05-10 18:26:28 +00:00
|
|
|
ve.dm.MWTransclusionNode.prototype.isSingleTemplate = function ( templates ) {
|
|
|
|
function normalizeTitle( name ) {
|
|
|
|
var title = mw.Title.newFromText( name );
|
|
|
|
return title ? title.getPrefixedText() : name;
|
|
|
|
}
|
|
|
|
|
|
|
|
var i, len, partsList = this.getPartsList();
|
|
|
|
if ( partsList.length !== 1 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( templates === undefined ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( typeof templates === 'string' ) {
|
|
|
|
templates = [ templates ];
|
|
|
|
}
|
|
|
|
for ( i = 0, len = templates.length; i < len; i++ ) {
|
2014-06-10 01:18:23 +00:00
|
|
|
if (
|
|
|
|
partsList[0].template &&
|
|
|
|
normalizeTitle( partsList[0].template ) === normalizeTitle( templates[i] )
|
|
|
|
) {
|
2014-05-10 18:26:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-04-01 23:15:47 +00:00
|
|
|
};
|
|
|
|
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
/**
|
|
|
|
* Get a simplified description of the transclusion's parts.
|
|
|
|
*
|
|
|
|
* @returns {Object[]} List of objects with either template or content properties
|
|
|
|
*/
|
|
|
|
ve.dm.MWTransclusionNode.prototype.getPartsList = function () {
|
|
|
|
var i, len, part, content;
|
|
|
|
|
|
|
|
if ( !this.partsList ) {
|
|
|
|
this.partsList = [];
|
|
|
|
content = this.getAttribute( 'mw' );
|
|
|
|
for ( i = 0, len = content.parts.length; i < len; i++ ) {
|
|
|
|
part = content.parts[i];
|
|
|
|
this.partsList.push(
|
|
|
|
part.template ?
|
2014-08-22 20:50:48 +00:00
|
|
|
{ template: part.template.target.wt } :
|
|
|
|
{ content: part }
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.partsList;
|
|
|
|
};
|
|
|
|
|
2013-05-15 20:45:14 +00:00
|
|
|
/**
|
2013-06-11 19:16:04 +00:00
|
|
|
* Get the wikitext for this transclusion.
|
2013-05-28 23:14:43 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-05-15 20:45:14 +00:00
|
|
|
* @returns {string} Wikitext like `{{foo|1=bar|baz=quux}}`
|
|
|
|
*/
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionNode.prototype.getWikitext = function () {
|
2013-05-28 23:14:43 +00:00
|
|
|
var i, len, part, template, param,
|
|
|
|
content = this.getAttribute( 'mw' ),
|
|
|
|
wikitext = '';
|
|
|
|
|
|
|
|
// Normalize to multi template format
|
|
|
|
if ( content.params ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
content = { parts: [ { template: content } ] };
|
2013-05-28 23:14:43 +00:00
|
|
|
}
|
|
|
|
// Build wikitext from content
|
|
|
|
for ( i = 0, len = content.parts.length; i < len; i++ ) {
|
|
|
|
part = content.parts[i];
|
|
|
|
if ( part.template ) {
|
|
|
|
// Template
|
|
|
|
template = part.template;
|
|
|
|
wikitext += '{{' + template.target.wt;
|
|
|
|
for ( param in template.params ) {
|
|
|
|
wikitext += '|' + param + '=' +
|
|
|
|
this.constructor.static.escapeParameter( template.params[param].wt );
|
|
|
|
}
|
|
|
|
wikitext += '}}';
|
|
|
|
} else {
|
|
|
|
// Plain wikitext
|
|
|
|
wikitext += part;
|
|
|
|
}
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
2013-05-28 23:14:43 +00:00
|
|
|
return wikitext;
|
2013-05-15 20:45:14 +00:00
|
|
|
};
|
|
|
|
|
2013-12-11 10:33:15 +00:00
|
|
|
/** */
|
|
|
|
ve.dm.MWTransclusionNode.prototype.getClonedElement = function () {
|
2015-02-17 00:36:52 +00:00
|
|
|
var i, len, clone = ve.dm.LeafNode.prototype.getClonedElement.call( this );
|
2013-12-11 10:33:15 +00:00
|
|
|
delete clone.attributes.originalMw;
|
|
|
|
// Remove about attribute to prevent about grouping of duplicated transclusions
|
2015-02-17 00:36:52 +00:00
|
|
|
if ( clone.originalDomElements ) {
|
|
|
|
for ( i = 0, len = clone.originalDomElements.length; i < len; i++ ) {
|
|
|
|
clone.originalDomElements.removeAttribute( 'about' );
|
|
|
|
}
|
|
|
|
}
|
2013-12-11 10:33:15 +00:00
|
|
|
return clone;
|
|
|
|
};
|
|
|
|
|
2013-04-13 21:22:26 +00:00
|
|
|
/* Concrete subclasses */
|
|
|
|
|
|
|
|
/**
|
2013-06-11 19:16:04 +00:00
|
|
|
* DataModel MediaWiki transclusion block node.
|
2013-04-13 21:22:26 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-06-11 19:16:04 +00:00
|
|
|
* @extends ve.dm.MWTransclusionNode
|
2014-06-07 03:17:26 +00:00
|
|
|
*
|
2013-04-13 21:22:26 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWTransclusionBlockNode = function VeDmMWTransclusionBlockNode() {
|
2013-04-13 21:22:26 +00:00
|
|
|
// Parent constructor
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWTransclusionNode.apply( this, arguments );
|
2013-04-13 21:22:26 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWTransclusionBlockNode, ve.dm.MWTransclusionNode );
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionBlockNode.static.matchTagNames = [];
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionBlockNode.static.name = 'mwTransclusionBlock';
|
2013-04-13 21:22:26 +00:00
|
|
|
|
|
|
|
/**
|
2013-06-11 19:16:04 +00:00
|
|
|
* DataModel MediaWiki transclusion inline node.
|
2013-04-13 21:22:26 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-06-11 19:16:04 +00:00
|
|
|
* @extends ve.dm.MWTransclusionNode
|
2014-06-07 03:17:26 +00:00
|
|
|
*
|
2013-04-13 21:22:26 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWTransclusionInlineNode = function VeDmMWTransclusionInlineNode() {
|
2013-04-13 21:22:26 +00:00
|
|
|
// Parent constructor
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWTransclusionNode.apply( this, arguments );
|
2013-04-13 21:22:26 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWTransclusionInlineNode, ve.dm.MWTransclusionNode );
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionInlineNode.static.matchTagNames = [];
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionInlineNode.static.name = 'mwTransclusionInline';
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.MWTransclusionInlineNode.static.isContent = true;
|
2013-04-13 21:22:26 +00:00
|
|
|
|
2013-04-10 18:15:15 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTransclusionNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTransclusionBlockNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTransclusionInlineNode );
|