Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/248849

Change subject: Add button to convert plain URL references
......................................................................

Add button to convert plain URL references

Due to how the context picks tools, we can't just extend
the ContextItem, so for now replace some methods.

Bug: T114564

Change-Id: Id94f5a8c75b742e2bcae8bb3732ea67defa3bffb
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/ve.ui.CiteFromIdInspector.js
M modules/ve.ui.CiteFromIdInspectorTool.js
M modules/ve.ui.CitoidAction.js
A modules/ve.ui.CitoidReferenceContextItem.css
7 files changed, 81 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Citoid 
refs/changes/49/248849/1

diff --git a/extension.json b/extension.json
index f6789df..1749181 100644
--- a/extension.json
+++ b/extension.json
@@ -32,7 +32,8 @@
                        "styles": [
                                "modules/ve.ui.CiteSourceSelectWidget.css",
                                "modules/ve.ui.CiteFromIdInspectorTool.css",
-                               "modules/ve.ui.CiteFromIdInspector.css"
+                               "modules/ve.ui.CiteFromIdInspector.css",
+                               "modules/ve.ui.CitoidReferenceContextItem.css"
                        ],
                        "dependencies": [
                                "ext.visualEditor.mwreference",
@@ -56,6 +57,8 @@
                                "citoid-citefromiddialog-title",
                                
"citoid-citefromiddialog-use-general-error-message",
                                "citoid-citefromidtool-title",
+                               "citoid-referencecontextitem-convert-button",
+                               "citoid-referencecontextitem-convert-message",
                                "citoid-template-type-map.json",
                                "citoid-unknown-error"
                        ],
diff --git a/i18n/en.json b/i18n/en.json
index ef023ac..5238500 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -17,5 +17,7 @@
        "citoid-citefromiddialog-use-general-error-message": "We couldn't make 
a citation for you. You can create one manually using the 
\"{{int:citoid-citefromiddialog-mode-manual}}\" tab above.",
        "citoid-citefromidtool-title": "Cite",
        "citoid-desc": "Provides access points between the citoid service and 
MediaWiki",
+       "citoid-referencecontextitem-convert-button": "Convert",
+       "citoid-referencecontextitem-convert-message": "This reference consists 
of just an external link. You can use the 
\"{{int:citoid-referencecontextitem-convert-button}}\" button below to generate 
a properly formatted reference.",
        "citoid-unknown-error": "An unknown error has occured that prevented us 
from creating a citation. Please try again later."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0c5c081..ffdccef 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -25,5 +25,7 @@
        "citoid-citefromiddialog-use-general-error-message": "Label notifying 
the user there was a problem creating their reference, and offering to use the 
full citation tool.\n* $1 – link to open the citation dialog; link label: 
{{msg-mw|Citoid-citefromiddialog-mode-manual}}",
        "citoid-citefromidtool-title": "Label for the button to add a citation 
in the toolbar\n{{Identical|Cite}}",
        "citoid-desc": 
"{{desc|name=Citoid|url=https://www.mediawiki.org/wiki/Citoid}}";,
+       "citoid-referencecontextitem-convert-button": "",
+       "citoid-referencecontextitem-convert-message": "",
        "citoid-unknown-error": "Error message indicating that the service to 
create citations has returned an error or is temporarily malfunctioning, asking 
the user to try again later."
 }
diff --git a/modules/ve.ui.CiteFromIdInspector.js 
b/modules/ve.ui.CiteFromIdInspector.js
index ee4785c..77c6c35 100644
--- a/modules/ve.ui.CiteFromIdInspector.js
+++ b/modules/ve.ui.CiteFromIdInspector.js
@@ -395,7 +395,9 @@
                        this.inDialog = data.inDialog || '';
 
                        // Collapse returns a new fragment, so update 
this.fragment
-                       this.fragment = this.getFragment().collapseToEnd();
+                       if ( !data.lookup ) {
+                               this.fragment = 
this.getFragment().collapseToEnd();
+                       }
 
                        // Create model
                        this.referenceModel = new ve.dm.MWReferenceModel( 
this.fragment.getDocument() );
@@ -412,6 +414,12 @@
                                this.referenceModel.insertReferenceNode( 
this.getFragment(), true );
                        }
 
+                       if ( data.lookup ) {
+                               this.lookupInput.setValue( data.lookup );
+                               this.executeAction( 'lookup' );
+                               return;
+                       }
+
                        this.modeIndex.setCard( ve.userConfig( 'citoid-mode' ) 
|| 'auto' );
                }, this );
 };
diff --git a/modules/ve.ui.CiteFromIdInspectorTool.js 
b/modules/ve.ui.CiteFromIdInspectorTool.js
index c9491e8..a986f8a 100644
--- a/modules/ve.ui.CiteFromIdInspectorTool.js
+++ b/modules/ve.ui.CiteFromIdInspectorTool.js
@@ -87,4 +87,56 @@
 
        ve.ui.toolFactory.register( ve.ui.CiteFromIdInspectorTool );
 
+       /**
+        * HACK: Override MWReferenceContextItem methods directly instead of 
inheriting,
+        * as the context relies on the generated citation types (ref, book, 
...) inheriting
+        * directly from MWReferenceContextItem.
+        *
+        * This should be a subclass, e.g. CitoidReferenceContextItem
+        */
+
+       /**
+        * @inheritdoc
+        */
+       ve.ui.MWReferenceContextItem.prototype.renderBody = function () {
+               var surfaceModel, fragment, annotations, annotation, 
convertButton,
+                       refNode = this.getReferenceNode();
+
+               this.$body.append( this.getRendering() );
+
+               if ( !refNode ) {
+                       return;
+               }
+
+               surfaceModel = this.context.getSurface().getModel();
+               fragment = surfaceModel.getLinearFragment( refNode.getRange() );
+               // Get covering annotations
+               annotations = fragment.getAnnotations( false );
+               if (
+                       annotations.getLength() === 1 &&
+                       ( annotation = annotations.get( 0 ) ) instanceof 
ve.dm.MWExternalLinkAnnotation
+               ) {
+                       // The reference consists of one single external link so
+                       // offer the user a conversion to citoid-generated 
reference
+                       this.convertibleHref = annotation.getHref();
+                       convertButton = new OO.ui.ButtonWidget( {
+                               label: ve.msg( 
'citoid-referencecontextitem-convert-button' )
+                       } ).connect( this, { click: 'onConvertButtonClick' } );
+                       this.$body.append(
+                               $( '<div>' )
+                                       .addClass( 
've-ui-citoidReferenceContextItem-convert ve-ui-mwReferenceContextItem-muted' )
+                                       .text( ve.msg( 
'citoid-referencecontextitem-convert-message' ) ),
+                               convertButton.$element
+                       );
+               }
+       };
+
+       /**
+        * Handle click events from the convert button
+        */
+       ve.ui.MWReferenceContextItem.prototype.onConvertButtonClick = function 
() {
+               var action = ve.ui.actionFactory.create( 'citoid', 
this.context.getSurface() );
+               action.open( this.convertibleHref );
+       };
+
 }() );
diff --git a/modules/ve.ui.CitoidAction.js b/modules/ve.ui.CitoidAction.js
index 97a2a54..67e688e 100644
--- a/modules/ve.ui.CitoidAction.js
+++ b/modules/ve.ui.CitoidAction.js
@@ -31,7 +31,7 @@
 /**
  * @inheritdoc
  */
-ve.ui.CitoidAction.static.methods = [ 'open' ];
+ve.ui.CitoidAction.static.methods = [ 'open', 'convert' ];
 
 /* Methods */
 
@@ -42,8 +42,9 @@
  * @method
  * @return {boolean} Action was executed
  */
-ve.ui.CitoidAction.prototype.open = function () {
+ve.ui.CitoidAction.prototype.open = function ( lookup ) {
        this.surface.execute( 'window', 'open', 'citefromid', {
+               lookup: lookup,
                inDialog: this.surface.getInDialog()
        } );
        return true;
diff --git a/modules/ve.ui.CitoidReferenceContextItem.css 
b/modules/ve.ui.CitoidReferenceContextItem.css
new file mode 100644
index 0000000..78486a1
--- /dev/null
+++ b/modules/ve.ui.CitoidReferenceContextItem.css
@@ -0,0 +1,9 @@
+/*!
+ * VisualEditor UserInterface CitoidReferenceContextItem styles.
+ */
+
+.ve-ui-citoidReferenceContextItem-convert {
+       border-top: 1px solid #ccc;
+       margin: 1em 0 0 0;
+       padding: 0.5em 0;
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/248849
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id94f5a8c75b742e2bcae8bb3732ea67defa3bffb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Citoid
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to