jenkins-bot has submitted this change and it was merged.
Change subject: Use TempateData to insert citations
......................................................................
Use TempateData to insert citations
TypeMap definition message added to Citoid.php:
Add citoid-template-type-map.json, which is
where citoid types are mapped to Template names
in Mediawiki:citoid-template-type-map.json (i.e.
itemType 'book' matches template 'Cite book').
If the message does not exist (is not parsable
JSON), CiteFromIDDialogTool will not be loaded.
If the message is removed or rendered unreadable
after load time, or if the type the user tries to
insert is not supported in the message, the user
will receive an error message:
citoid-typeMap-config-error
Template parameter values obtained from TemplateData:
The object mapping citoid field names to template
parameters is now obtained from the maps object
in each template's TemplateData. If there is no
object corresponding to the dialog, then a blank
reference is inserted.
Support added for new citoid 520 response
520 response from citoid indicates that no data
was retrieved from URL, but that a response
is still retrieved containing limited data. Now
catches this error specifically and fills in
using that response.
Use new citoid /api endpoint
Use new citoid /api endpoint which takes multiple
identifiers. Refractor citeFromURLDialog to
citeFromIDDialog.
Change-Id: Ibe9d57818fa1a9cad1ce5a58ea1be8d936bac48b
---
M Citoid.php
M i18n/en.json
M i18n/qqq.json
A modules/ve.ui.CiteFromIDDialog.js
A modules/ve.ui.CiteFromIDDialogTool.js
D modules/ve.ui.CiteFromURLDialog.js
D modules/ve.ui.CiteFromURLDialogTool.js
7 files changed, 346 insertions(+), 414 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Citoid.php b/Citoid.php
index e4c2762..6a5291e 100644
--- a/Citoid.php
+++ b/Citoid.php
@@ -33,18 +33,21 @@
// Register modules
$wgResourceModules['ext.Citoid.visualEditor'] = array(
'scripts' => array(
- 'modules/ve.ui.CiteFromURLDialogTool.js',
- 'modules/ve.ui.CiteFromURLDialog.js'
+ 'modules/ve.ui.CiteFromIDDialogTool.js',
+ 'modules/ve.ui.CiteFromIDDialog.js'
),
'styles' => array(
),
'messages' => array(
- 'citoid-citeFromURLDialog-search-placeholder',
- 'citoid-citeFromURLDialog-search-label',
- 'citoid-citeFromURLDialog-search',
- 'citoid-citeFromURLDialog-search-progress',
- 'citoid-citeFromURLTool-title',
- 'citoid-citeFromURLDialog-title'
+ 'citoid-520-error',
+ 'citoid-citeFromIDDialog-search',
+ 'citoid-citeFromIDDialog-search-label',
+ 'citoid-citeFromIDDialog-search-placeholder',
+ 'citoid-citeFromIDDialog-search-progress',
+ 'citoid-citeFromIDDialog-title',
+ 'citoid-citeFromIDTool-title',
+ 'citoid-typeMap-config-error',
+ 'citoid-template-type-map.json'
),
'targets' => array( 'desktop'), //mwreferences doesn't work in mobile
currently
'localBasePath' => __DIR__,
@@ -57,5 +60,5 @@
// Requires https protocol to work in FireFox, but
// Service doesn't need a security cert
-$wgCitoidServiceUrl = 'https://localhost:1970';
+$wgCitoidServiceUrl = 'https://localhost:1970/api';
diff --git a/i18n/en.json b/i18n/en.json
index 5579e8c..b2ab928 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -2,11 +2,13 @@
"@metadata": {
"authors": []
},
+ "citoid-520-error": "Unable to retrieve information from the provided
identifier.",
"citoid-desc": "Provides access points between the citoid service and
MediaWiki",
- "citoid-citeFromURLDialog-search-placeholder": "Enter URL to cite (i.e.
http://www.example.com)",
- "citoid-citeFromURLDialog-search-label": "Cite URL: ",
- "citoid-citeFromURLDialog-search": "Search",
- "citoid-citeFromURLDialog-search-progress": "Searching, please wait...",
- "citoid-citeFromURLTool-title": "Cite by URL",
- "citoid-citeFromURLDialog-title": "Autofill citations by URL with
citoid"
+ "citoid-citeFromIDDialog-search": "Search",
+ "citoid-citeFromIDDialog-search-label": "URL or DOI",
+ "citoid-citeFromIDDialog-search-placeholder": "e.g.
http://www.example.com",
+ "citoid-citeFromIDDialog-search-progress": "Searching, please wait...",
+ "citoid-citeFromIDDialog-title": "Autofill citations by URL or DOI",
+ "citoid-citeFromIDTool-title": "Autofill from URL",
+ "citoid-typeMap-config-error": "Mediawiki:citoid-template-type-map.json
is improperly configured."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fc63c76..6973cd1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -2,11 +2,13 @@
"@metadata": {
"authors": []
},
+ "citoid-520-error": "Error message for when citoid service returns a
520 error",
"citoid-desc":
"{{desc|name=Citoid|url=http://www.mediawiki.org/wiki/Citoid}}",
- "citoid-citeFromURLDialog-search-placeholder": "Placeholder for the URL
search field.",
- "citoid-citeFromURLDialog-search-label": "Label for the URL search
field.",
- "citoid-citeFromURLDialog-search": "Text for the search button.",
- "citoid-citeFromURLDialog-search-progress": "Message for when the
search is in progress",
- "citoid-citeFromURLTool-title": "What the dialog is called in the menu",
- "citoid-citeFromURLDialog-title": "The title displayed on the dialog"
+ "citoid-citeFromIDDialog-search": "Text for the search button.",
+ "citoid-citeFromIDDialog-search-label": "Label for the URL/DOI search
field.",
+ "citoid-citeFromIDDialog-search-placeholder": "Placeholder for the
URL/DOI search field.",
+ "citoid-citeFromIDDialog-search-progress": "Message for when the search
is in progress",
+ "citoid-citeFromIDDialog-title": "The title displayed on the dialog",
+ "citoid-citeFromIDTool-title": "What the dialog is called in the menu",
+ "citoid-typeMap-config-error": "Error message indicating
Mediawiki:citoid-template-type-map.json either doesn't exist or contains
errors."
}
diff --git a/modules/ve.ui.CiteFromIDDialog.js
b/modules/ve.ui.CiteFromIDDialog.js
new file mode 100644
index 0000000..85c6a4f
--- /dev/null
+++ b/modules/ve.ui.CiteFromIDDialog.js
@@ -0,0 +1,276 @@
+mw.loader.using( 'ext.visualEditor.mwreference', function () {
+
+ /**
+ * Dialog to insert filled references using citoid service
+ *
+ * @class
+ * @extends ve.ui.MWCitationDialog
+ * @constructor
+ * @param {Object} [config] Configuration options
+ */
+
+ ve.ui.CiteFromIDDialog = function VeUiCiteFromIDDialog( config ) {
+ // Parent constructor
+ ve.ui.CiteFromIDDialog.super.call( this, config );
+ };
+
+ /* Inheritance */
+ OO.inheritClass( ve.ui.CiteFromIDDialog, ve.ui.MWCitationDialog );
+
+ /* Static Properties */
+ ve.ui.CiteFromIDDialog.static.name = 'citefromid';
+ ve.ui.CiteFromIDDialog.static.title = mw.msg(
'citoid-citeFromIDDialog-title' );
+ // The string used in TemplateData to identify the correct Map object
+ ve.ui.CiteFromIDDialog.static.templateDataName =
'extension/Citoid/ve.ui.CiteFromIDDialog';
+ // The requested format from the citoid client, passed as a GET
parameter
+ ve.ui.CiteFromIDDialog.static.citoidFormat = 'mediawiki';
+
+ /**
+ * @inheritdoc
+ */
+ ve.ui.CiteFromIDDialog.prototype.initialize = function () {
+
+ // Skip ve.ui.MWCitationDialog and ve.ui.MWTemplateDialog
initialize methods
+
ve.ui.CiteFromIDDialog.super.super.super.prototype.initialize.call( this );
+
+ // Booklet layout required due to inheriting from
MWTemplateDialog
+ this.bookletLayout = new OO.ui.BookletLayout(
+ ve.extendObject(
+ { $: this.$ },
+ this.constructor.static.bookletLayoutConfig
+ )
+ );
+
+ this.searchInput = new OO.ui.TextInputWidget( {
+ $: this.$,
+ multiline: false,
+ placeholder: mw.msg(
'citoid-citeFromIDDialog-search-placeholder' )
+ } );
+
+ var panel = new OO.ui.PanelLayout( {
+ $: this.$,
+ padded: true,
+ scrollable: true,
+ expanded: false
+ } ),
+ inputsFieldset = new OO.ui.FieldsetLayout( {
+ $: this.$
+ } ),
+ searchField = new OO.ui.FieldLayout( this.searchInput, {
+ $: this.$,
+ align: 'top',
+ label: mw.msg(
'citoid-citeFromIDDialog-search-label' )
+ } );
+
+ inputsFieldset.$element.append(
+ searchField.$element
+ );
+
+ panel.$element.append( inputsFieldset.$element );
+ this.$body.append( panel.$element );
+
+ this.modules = ['ext.visualEditor.data'];
+
+ };
+
+ /**
+ * Insert filled template based on search results from citoid service
+ * @param {Object[]} searchResults Array of citation objects from
citoid service
+ */
+ ve.ui.CiteFromIDDialog.prototype.insertTemplate = function (
searchResults ) {
+
+ var transclusion, template, templateName, templateTypeMap,
partPromise, item, fragment,
+ citation = searchResults[0], //uses the first citation
result for the time being
+ dialog = this,
+ surfaceModel = this.getFragment().getSurface(),
+ doc = surfaceModel.getDocument(),
+ internalList = doc.getInternalList();
+
+ // Try to parse Mediawiki namespace templateTypeMap definition
+ try {
+ templateTypeMap = JSON.parse( mw.message(
'citoid-template-type-map.json' ).plain() );
+ } catch ( e ) {
+ mw.notify( mw.msg( 'citoid-typeMap-config-error' ) );
+ dialog.popPending();
+ return;
+ }
+
+ // Set up blank referenceModel
+ if ( !this.referenceModel ) {
+ // Collapse returns a new fragment, so update
this.fragment
+ this.fragment = this.getFragment().collapseToEnd();
+ this.referenceModel = new ve.dm.MWReferenceModel();
+ this.referenceModel.insertInternalItem( surfaceModel );
+ this.referenceModel.insertReferenceNode(
this.getFragment() );
+ }
+
+ // Gets back contents of <ref> tag
+ item = this.referenceModel.findInternalItem( surfaceModel );
+ if ( item ) {
+ fragment = this.getFragment().clone(
+ new ve.dm.LinearSelection( doc,
item.getChildren()[0].getRange() )
+ );
+
+ transclusion = new ve.dm.MWTransclusionModel();
+ templateName = templateTypeMap[citation.itemType];
+
+ // if TemplateName is undefined, this means that items
of this citoid
+ // type does not have a Template defined within the
message.
+ if ( !templateName ) {
+ mw.notify( mw.msg(
'citoid-typeMap-config-error') );
+ dialog.popPending();
+ return;
+ }
+
+ template = ve.dm.MWTemplateModel.newFromName(
transclusion, templateName );
+ this.template = template;
+
+ // Promise for template being added to the transclusion
+ partPromise = transclusion.addPart( template );
+
+ partPromise.done( function () {
+ dialog.fillTemplate( citation );
+
+ transclusion.insertTransclusionNode( fragment );
+ // HACK: Scorch the earth - this is only needed
because without it, the reference list won't
+ // re-render properly, and can be removed once
someone fixes that
+ dialog.referenceModel.setDocument(
+ doc.cloneFromRange(
+ internalList.getItemNode(
dialog.referenceModel.getListIndex() ).getRange()
+ )
+ );
+
+ dialog.referenceModel.updateInternalItem(
surfaceModel );
+ // hack- doesn't seem to be working in always
+ dialog.popPending();
+ dialog.close();
+ } );
+ }
+ };
+
+ /**
+ * Fills template object with parameters from with values in citation
object
+ * @param {Object} citation Contains values to insert into template
+ */
+ ve.ui.CiteFromIDDialog.prototype.fillTemplate = function ( citation ) {
+ var citoidField, templateField, i, j,
+ template = this.template,
+ spec = template.getSpec(),
+ maps = spec.getMaps(),
+ map =
maps[ve.ui.CiteFromIDDialog.static.templateDataName];
+
+ for ( citoidField in map ) {
+ templateField = map[citoidField];
+ // Construct parameters
+ if ( typeof templateField === 'string' &&
citation[citoidField] !== undefined ) {
+ // Case: Citoid parameter directly equivalent
to TemplateData parameter
+ template.addParameter( new
ve.dm.MWParameterModel( template, templateField, citation[citoidField] ) );
+ } else if ( Array.isArray( citation[citoidField] ) ) {
+ // Case: Citoid parameter equivalent to 1 or 2D
Array of TD parameters
+ for ( i = 0; i < citation[citoidField].length;
i++ ) {
+ // Iterate through first dimension of
array
+ if ( typeof citation[citoidField][i]
=== 'string' && templateField[i] !== undefined) {
+ // Case: Citoid parameter
equivalent to 1D Array of TD parameters
+ template.addParameter( new
ve.dm.MWParameterModel( template, templateField[i], citation[citoidField][i] )
);
+ } else if ( Array.isArray(
citation[citoidField][i] ) ) {
+ // Case: Citoid parameter
equivalent to 2D Array of TD parameters
+ for ( j = 0; j <
citation[citoidField][i].length; j++ ) {
+ // Iterate through 2nd
dimension of Array
+ if (typeof
citation[citoidField][i][j] === 'string' && templateField[i][j] !== undefined) {
+
template.addParameter( new ve.dm.MWParameterModel( template,
templateField[i][j], citation[citoidField][i][j]) );
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+
+ /**
+ * @inheritdoc
+ */
+ ve.ui.CiteFromIDDialog.prototype.getActionProcess = function ( action )
{
+ if ( action === 'apply' || action === 'insert' ) {
+ return new OO.ui.Process( function () {
+ var dialog = this;
+
+ dialog.pushPending();
+
+ $.ajax( {
+ beforeSend: function ( request ) {
+ request.setRequestHeader(
'Content-Type', 'application/json' );
+ },
+ url: mw.config.get( 'wgCitoidConfig'
).citoidServiceUrl,
+ type: 'GET',
+ data: {
+ search: encodeURI(
dialog.searchInput.getValue() ),
+ format:
ve.ui.CiteFromIDDialog.static.citoidFormat
+ },
+ dataType: 'json',
+ success: function ( result ) {
+ dialog.insertTemplate( result );
+ },
+ error: function ( response, textStatus,
errorThrown ) {
+ // 520 status from citoid means
there was no response at the
+ // URL provided, but it returns
a citation regardless. We're
+ // choosing to insert that
citation here but to notify the user.
+ if ( response.status === 520 ) {
+ dialog.insertTemplate(
response.responseJSON );
+ mw.notify( mw.message
('citoid-520-error') );
+ } else {
+ mw.notify( 'Status: '
+ textStatus + 'Error: ' + errorThrown );
+ }
+ },
+ always: function () {
+ dialog.popPending();
+ }
+ } );
+ }, this );
+ }
+
+ // Parent method
+ return
ve.ui.CiteFromIDDialog.super.prototype.getActionProcess.call( this, action );
+ };
+
+ /**
+ * Handle the transclusion being ready to use.
+ * Enables apply/insert buttons
+ */
+ ve.ui.CiteFromIDDialog.prototype.onTransclusionReady = function () {
+ // Parent method
+
ve.ui.CiteFromIDDialog.super.prototype.onTransclusionReady.call( this );
+ // TODO- disable when no input
+ this.actions.setAbilities( { 'apply': true, 'insert': true } );
+ };
+
+ /**
+ * Overrides Template Dialog method which expects this.template to
+ * exist on initialization and sets the template as the dialog title.
+ *
+ * @return {string} Title of dialog
+ */
+ ve.ui.CiteFromIDDialog.prototype.getTemplatePartLabel = function () {
+ return ve.msg( 'citoid-citeFromIDDialog-title' );
+ };
+
+ /**
+ * Overrides Template Dialog method which has a fixed height
+ * @inheritdoc
+ */
+ ve.ui.CiteFromIDDialog.prototype.getBodyHeight =
+
ve.ui.CiteFromIDDialog.super.super.super.prototype.getBodyHeight;
+
+ /**
+ * @inheritdoc
+ */
+ ve.ui.CiteFromIDDialog.prototype.getTeardownProcess = function ( data )
{
+ return
ve.ui.CiteFromIDDialog.super.prototype.getTeardownProcess.call( this, data )
+ .first( function () {
+ // Clear search input box
+ this.searchInput.setValue('');
+ }, this );
+ };
+
+ ve.ui.windowFactory.register( ve.ui.CiteFromIDDialog );
+
+} );
diff --git a/modules/ve.ui.CiteFromIDDialogTool.js
b/modules/ve.ui.CiteFromIDDialogTool.js
new file mode 100644
index 0000000..721eb9c
--- /dev/null
+++ b/modules/ve.ui.CiteFromIDDialogTool.js
@@ -0,0 +1,42 @@
+mw.loader.using( 'ext.visualEditor.mwreference', function () {
+
+ /**
+ * MediaWiki UserInterface cite from ID dialog tool.
+ *
+ * @class
+ * @abstract
+ * @extends ve.ui.Tool
+ * @constructor
+ * @param {OO.ui.Toolbar} toolbar
+ * @param {Object} [config] Configuration options
+ */
+
+ //Don't create tool unless the configuration message is present
+ try {
+ JSON.parse( mw.message( 'citoid-template-type-map.json'
).plain() );
+ } catch ( e ) {
+ return;
+ }
+
+ ve.ui.CiteFromIDDialogTool = function VeUiCiteFromIDDialogTool(
toolGroup, config ) {
+ OO.ui.Tool.call( this, toolGroup, config );
+ };
+
+ OO.inheritClass( ve.ui.CiteFromIDDialogTool, ve.ui.Tool );
+
+ ve.ui.CiteFromIDDialogTool.static.name = 'citefromid';
+ ve.ui.CiteFromIDDialogTool.static.icon = 'ref-cite-web';
+ ve.ui.CiteFromIDDialogTool.static.title = mw.msg(
'citoid-citeFromIDTool-title' );
+ ve.ui.CiteFromIDDialogTool.static.group = 'cite';
+ ve.ui.CiteFromIDDialogTool.static.commandName = 'citefromid';
+
+ ve.ui.commandRegistry.register(
+ new ve.ui.Command(
+ 'citefromid', 'window', 'open',
+ { args: ['citefromid'], supportedSelections: ['linear']
}
+ )
+ );
+
+ ve.ui.toolFactory.register( ve.ui.CiteFromIDDialogTool );
+
+});
diff --git a/modules/ve.ui.CiteFromURLDialog.js
b/modules/ve.ui.CiteFromURLDialog.js
deleted file mode 100644
index 80343dd..0000000
--- a/modules/ve.ui.CiteFromURLDialog.js
+++ /dev/null
@@ -1,369 +0,0 @@
-mw.loader.using( 'ext.visualEditor.mwreference', function () {
-
- /**
- * [CiteFromURLDialog description]
- * @param {[type]} config [description]
- */
- ve.ui.CiteFromURLDialog = function VeUiCiteFromURLDialog( manager,
config ) {
- // Parent constructor
- config = ve.extendObject( { 'size': 'medium' }, config );
- ve.ui.CiteFromURLDialog.super.call( this, manager, config );
- };
-
- /* Inheritance */
- OO.inheritClass( ve.ui.CiteFromURLDialog, ve.ui.MWCitationDialog );
-
- /* Static Properties */
- ve.ui.CiteFromURLDialog.static.name = 'citefromurl';
- ve.ui.CiteFromURLDialog.static.title = mw.msg(
'citoid-citeFromURLDialog-title' );
-
- /**
- * Returns full template given search results
- * @param {Object} searchResults json response object
- * @return {Object} filled in template
- */
- ve.ui.CiteFromURLDialog.prototype.getPlainObject = function (
searchResults ) {
-
- var content, plainObject, d, templateHref, templateName,
- citation = jQuery.parseJSON( JSON.stringify(
searchResults ) )[0], //uses the first citation result for the time being
-
- templateTypeMap = {
- book: 'Cite book',
- bookSection: 'Cite book',
- journalArticle: 'Cite journal',
- magazineArticle: 'Cite news',
- newspaperArticle: 'Cite news',
- thesis: 'Cite journal',
- letter: 'Citation',
- manuscript: 'Cite book',
- interview: 'Citation',
- film: 'Citation',
- artwork: 'Citation',
- webpage: 'Cite web',
- report: 'Cite journal',
- bill: 'Citation',
- hearing: 'Citation',
- patent: 'Citation',
- statute: 'Citation',
- email: 'Cite web',
- map: 'Citation',
- blogPost: 'Cite web',
- instantMessage: 'Citation',
- forumPost: 'Cite web',
- audioRecording: 'Citation',
- presentation: 'Cite journal',
- videoRecording: 'Citation',
- tvBroadcast: 'Citation',
- radioBroadcast: 'Citation',
- podcast: 'Citation',
- computerProgram: 'Citation',
- conferencePaper: 'Cite journal',
- 'document': 'Citation',
- encyclopediaArticle: 'Cite journal',
- dictionaryEntry: 'Cite journal'
- },
-
- //Parameter map for Template:Citation on en-wiki
- //In the format citation-template-field:citoid-field
- citationParams = {
- 'first1': 'author1-first',
- 'last1': 'author1-last',
- 'first2': 'author2-first',
- 'last2': 'author2-last',
- 'first3': 'author3-first',
- 'last3': 'author3-last',
- 'first4': 'author4-first',
- 'last4': 'author4-last',
- // 'accessdate': 'accessDate',
- 'title': 'title',
- 'url': 'url',
- 'publisher': 'publisher',
- //a large number of Zotero types have the field
publicationTitle
- //however, in setting journal to
publicationTitle, the citation
- //will be formatted as a journal article, which
may not always be
- //desirable.
- 'journal': 'publicationTitle',
- // 'newspaper': 'publicationTitle',
- 'date': 'date',
- 'location': 'place',
- 'issn': 'ISSN',
- 'isbn': 'ISBN',
- 'pages': 'pages',
- 'volume': 'volume',
- 'series': 'series',
- 'issue': 'issue',
- 'doi': 'DOI'
- },
-
- webParams = {
- 'first1': 'author1-first',
- 'last1': 'author1-last',
- 'first2': 'author2-first',
- 'last2': 'author2-last',
- 'first3': 'author3-first',
- 'last3': 'author3-last',
- 'first4': 'author4-first',
- 'last4': 'author4-last',
- // 'accessdate': 'accessDate',
- 'title': 'title',
- 'url': 'url',
- 'date': 'date',
- 'publisher': 'publisher',
- 'website': 'publicationTitle'
- },
-
- newsParams = {
- 'first1': 'author1-first',
- 'last1': 'author1-last',
- 'first2': 'author2-first',
- 'last2': 'author2-last',
- 'first3': 'author3-first',
- 'last3': 'author3-last',
- 'first4': 'author4-first',
- 'last4': 'author4-last',
- // 'accessdate': 'accessDate',
- 'title': 'title',
- 'url': 'url',
- 'publisher': 'publisher',
- 'newspaper': 'publicationTitle',
- 'date': 'date',
- 'location': 'place',
- 'issn': 'ISSN',
- 'isbn': 'ISBN',
- 'pages': 'pages',
- 'volume': 'volume',
- 'series': 'series',
- 'issue': 'issue',
- 'doi': 'DOI'
- },
-
- bookParams = {
- 'first1': 'author1-first',
- 'last1': 'author1-last',
- 'first2': 'author2-first',
- 'last2': 'author2-last',
- 'first3': 'author3-first',
- 'last3': 'author3-last',
- 'first4': 'author4-first',
- 'last4': 'author4-last',
- // 'accessdate': 'accessDate',
- 'title': 'title',
- 'url': 'url',
- 'publisher': 'publisher',
- 'journal': 'publicationTitle',
- 'date': 'date',
- 'location': 'place',
- 'issn': 'ISSN',
- 'isbn': 'ISBN',
- 'pages': 'pages',
- 'volume': 'volume',
- 'series': 'series',
- 'issue': 'issue',
- 'doi': 'DOI'
- },
-
- journalParams = {
- 'first1': 'author1-first',
- 'last1': 'author1-last',
- 'first2': 'author2-first',
- 'last2': 'author2-last',
- 'first3': 'author3-first',
- 'last3': 'author3-last',
- 'first4': 'author4-first',
- 'last4': 'author4-last',
- // 'accessdate': 'accessDate',
- 'title': 'title',
- 'url': 'url',
- 'publisher': 'publisher',
- 'journal': 'publicationTitle',
- 'date': 'date',
- 'location': 'place',
- 'issn': 'ISSN',
- 'isbn': 'ISBN',
- 'pages': 'pages',
- 'volume': 'volume',
- 'series': 'series',
- 'issue': 'issue',
- 'doi': 'DOI'
- },
-
- //format 'template name':parameter obj name
- templateParamMap = {
- 'Citation': citationParams,
- 'Cite web': webParams,
- 'Cite news': newsParams,
- 'Cite journal': journalParams,
- 'Cite book': bookParams
- },
-
- //This will contain the correct template with the
fields filled out
- paramObj = {};
-
- templateName = templateTypeMap[citation.itemType];
-
- templateHref = 'Template:' + templateName;
-
- $.each( templateParamMap[templateName], function ( key, value )
{
- var objString = citation[value] !== undefined ?
citation[value] : '';
- paramObj[key] = { 'wt': objString };
- } );
-
- d = new Date();
- paramObj.accessdate = { 'wt': d.toDateString() };
-
- plainObject = { //before paren put get plain object
- 'parts': [ {
-
- 'template': {
- 'target': {
- 'href': templateHref,
- 'wt': templateName.toLowerCase()
- },
- 'params': paramObj
- }
- } ]
- };
-
- content = [
- {
- 'type': 'mwTransclusionInline',
- 'attributes': {
- 'mw': plainObject
- }
- },
- { 'type': '/mwTransclusionInline' }
- ];
-
- //this.getFragment().insertContent( content );
- return content;
- };
-
- /**
- * [initialize description]
- * @return {[type]} [description]
- */
- ve.ui.CiteFromURLDialog.prototype.initialize = function () {
-
ve.ui.CiteFromURLDialog.super.super.super.prototype.initialize.call( this );
-
- //not actually using this//hack for inheriting from
mwtemplatedialog
- this.bookletLayout = new OO.ui.BookletLayout(
- ve.extendObject(
- { '$': this.$ },
- this.constructor.static.bookletLayoutConfig
- )
- );
-
- this.searchInput = new OO.ui.TextInputWidget( {
- '$': this.$,
- 'multiline': false,
- 'placeholder': mw.msg(
'citoid-citeFromURLDialog-search-placeholder' )
- } );
- var panel = new OO.ui.PanelLayout( { '$': this.$, 'scrollable':
true, 'padded': true } ),
- inputsFieldset = new OO.ui.FieldsetLayout( {
- '$': this.$
- } ),
- //input search
-
- searchField = new OO.ui.FieldLayout( this.searchInput, {
- '$': this.$,
- 'label': mw.msg(
'citoid-citeFromURLDialog-search-label' )
- } );
-
- inputsFieldset.$element.append(
- searchField.$element
- );
- panel.$element.append( inputsFieldset.$element );
- this.$body.append( panel.$element );
-
- };
-
- /**
- * Action for insert citation button
- * @param {[type]} action [description]
- * @return {[type]} [description]
- */
- ve.ui.CiteFromURLDialog.prototype.getActionProcess = function ( action
) {
- if ( action === 'apply' || action === 'insert' ) {
- return new OO.ui.Process( function () {
-
- this.pushPending();
- var citoidService, citoidConfig,
- that = this;
-
- citoidConfig = mw.config.get('wgCitoidConfig');
- citoidService = citoidConfig.citoidServiceUrl;
-
- $.ajax( {
- beforeSend: function (request) {
-
request.setRequestHeader('Content-Type', 'application/json');
- },
- url: citoidService,
- type: 'POST',
- data: JSON.stringify( { url:
this.searchInput.getValue() } ),
- dataType: 'json',
- success: function ( result ) {
- that.close();
-
- var item,
- surfaceModel =
that.getFragment().getSurface(),
- doc =
surfaceModel.getDocument(),
- internalList =
doc.getInternalList();
-
- //sets up referencemodel with
blank stuff
- if ( !that.referenceModel ) {
- // Collapse returns a
new fragment, so update this.fragment
- that.fragment =
that.getFragment().collapseRangeToEnd();
- that.referenceModel =
new ve.dm.MWReferenceModel();
-
that.referenceModel.insertInternalItem( surfaceModel );
-
that.referenceModel.insertReferenceNode( that.getFragment() );
- }
- //gets bank stuff again
- item =
that.referenceModel.findInternalItem( surfaceModel );
- if ( item ) {
- //actually inserts full
transclusion model here!
-
that.getFragment().clone(
item.getChildren()[0].getRange()).insertContent(that.getPlainObject( result ) );
- }
-
- // HACK: Scorch the earth -
this is only needed because without it, the reference list won't
- // re-render properly, and can
be removed once someone fixes that
- that.referenceModel.setDocument(
- doc.cloneFromRange(
-
internalList.getItemNode( that.referenceModel.getListIndex() ).getRange()
- )
- );
-
-
that.referenceModel.updateInternalItem( surfaceModel );
-
- //hack- doesn't seem to be
working in always
- that.popPending();
- },
- error: function ( XMLHttpRequest,
textStatus, errorThrown) {
- that.popPending();
- mw.notify( 'Status:' +
textStatus + 'Error: ' + errorThrown );
- that.popPending();
- },
- always: function () {
- that.popPending();
- }
- } );
- }, this );
- }
-
- // Parent method
- return
ve.ui.CiteFromURLDialog.super.super.prototype.getActionProcess.call( this,
action );
- };
-
- /**
- * [onTransclusionReady description]
- * @return {[type]} [description]
- */
- ve.ui.CiteFromURLDialog.prototype.onTransclusionReady = function () {
- // Parent method
-
ve.ui.CiteFromURLDialog.super.prototype.onTransclusionReady.call( this );
- //hack- always enabled for now
- this.actions.setAbilities( { 'apply': true, 'insert': true } );
- };
-
- ve.ui.windowFactory.register( ve.ui.CiteFromURLDialog );
-
-} );
diff --git a/modules/ve.ui.CiteFromURLDialogTool.js
b/modules/ve.ui.CiteFromURLDialogTool.js
deleted file mode 100644
index 6cad08a..0000000
--- a/modules/ve.ui.CiteFromURLDialogTool.js
+++ /dev/null
@@ -1,24 +0,0 @@
-mw.loader.using( 'ext.visualEditor.mwreference', function () {
-//---------- CiteFromURL tool ------------------
-
- ve.ui.CiteFromURLDialogTool = function VeUiCiteFromURLDialogTool(
toolGroup, config ) {
- OO.ui.Tool.call( this, toolGroup, config );
- };
-
- OO.inheritClass( ve.ui.CiteFromURLDialogTool, OO.ui.Tool );
-
- ve.ui.CiteFromURLDialogTool.static.name = 'citefromurl';
- ve.ui.CiteFromURLDialogTool.static.icon = 'ref-cite-web';
- ve.ui.CiteFromURLDialogTool.static.title = mw.msg(
'citoid-citeFromURLTool-title' );
-
- ve.ui.CiteFromURLDialogTool.prototype.onSelect = function () {
- this.toolbar.getSurface().execute( 'window', 'open',
'citefromurl', null );
- };
-
- ve.ui.CiteFromURLDialogTool.prototype.onUpdateState = function () {
- this.setActive( false );
- };
-
- ve.ui.toolFactory.register( ve.ui.CiteFromURLDialogTool );
-
-});
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/168746
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe9d57818fa1a9cad1ce5a58ea1be8d936bac48b
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Mvolz <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits