jenkins-bot has submitted this change and it was merged.

Change subject: Mark disambiguation and redirect pages in the link inspector
......................................................................


Mark disambiguation and redirect pages in the link inspector

Bug: 50240
Change-Id: If975398e4d6b13eea6207ee80b33067e65acd724
---
M VisualEditor.php
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/ui/styles/ve.ui.MWWidget.css
M modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
5 files changed, 87 insertions(+), 17 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/VisualEditor.php b/VisualEditor.php
index d94213e..7bddaf7 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -719,6 +719,8 @@
                        'visualeditor-linkinspector-illegal-title',
                        'visualeditor-linkinspector-suggest-external-link',
                        'visualeditor-linkinspector-suggest-matching-page',
+                       'visualeditor-linkinspector-suggest-disambig-page',
+                       'visualeditor-linkinspector-suggest-redirect-page',
                        'visualeditor-linkinspector-suggest-new-page',
                        'visualeditor-media-input-placeholder',
                        'visualeditor-meta-tool',
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index c924dde..7309ecc 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -110,6 +110,8 @@
     "visualeditor-linkinspector-illegal-title": "Invalid page title",
     "visualeditor-linkinspector-suggest-external-link": "External link",
     "visualeditor-linkinspector-suggest-matching-page": "Matching page",
+    "visualeditor-linkinspector-suggest-disambig-page": "Disambiguation page",
+    "visualeditor-linkinspector-suggest-redirect-page": "Redirect page",
     "visualeditor-linkinspector-suggest-new-page": "New page",
     "visualeditor-loadwarning": "Error loading data from server: $1. Would you 
like to retry?",
     "visualeditor-loadwarning-token": "Error loading edit token from server: 
$1. Would you like to retry?",
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index b3a7ae5..aead46a 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -115,6 +115,8 @@
     "visualeditor-linkinspector-illegal-title": "Warning that the entered text 
is not a valid page title.",
     "visualeditor-linkinspector-suggest-external-link": "Label for an external 
(Web) link in the link inspector.\n{{Identical|External link}}",
     "visualeditor-linkinspector-suggest-matching-page": "Label for suggested 
matching local wiki page or pages in the link inspector",
+    "visualeditor-linkinspector-suggest-disambig-page": "Label for suggested 
disambiguation pages in the link inspector",
+    "visualeditor-linkinspector-suggest-redirect-page": "Label for suggested 
redirect pages in the link inspector",
     "visualeditor-linkinspector-suggest-new-page": "Label for a new page in 
the link inspector.\n{{Identical|New page}}",
     "visualeditor-loadwarning": "Text (JavaScript confirm()) shown when the 
editor fails to load properly.\n\nParameters:\n* $1 - the error message from 
the server, in English. e.g. \"parsoidserver-http-bad-status: 404\"",
     "visualeditor-loadwarning-token": "Text (JavaScript confirm()) shown when 
the editor fails to load properly.\n\nParameters:\n* $1 - the error message 
from the server.",
@@ -186,4 +188,4 @@
     "visualeditor-wikitext-warning": "Contents of notification displayed when 
Wikitext has been detected.\n\nRefers to:\n* 
{{msg-mw|Visualeditor-wikitext-warning-link}}\n* 
{{msg-mw|Visualeditor-ca-editsource}}",
     "visualeditor-wikitext-warning-link": "Link to page describing what 
Wikitext is.\n\nUsed in:\n* {{msg-mw|Visualeditor-wikitext-warning}}.",
     "visualeditor-wikitext-warning-title": "Title of notification displayed 
when Wikitext has been detected"
-}
\ No newline at end of file
+}
diff --git a/modules/ve-mw/ui/styles/ve.ui.MWWidget.css 
b/modules/ve-mw/ui/styles/ve.ui.MWWidget.css
index 3e361f9..82487f9 100644
--- a/modules/ve-mw/ui/styles/ve.ui.MWWidget.css
+++ b/modules/ve-mw/ui/styles/ve.ui.MWWidget.css
@@ -23,6 +23,8 @@
 
 .ve-ui-mwLinkTargetInputWidget-menu .oo-ui-menuItemWidget[rel=existingPage],
 .ve-ui-mwLinkTargetInputWidget-menu .oo-ui-menuItemWidget[rel=matchingPage],
+.ve-ui-mwLinkTargetInputWidget-menu .oo-ui-menuItemWidget[rel=disambigPage],
+.ve-ui-mwLinkTargetInputWidget-menu .oo-ui-menuItemWidget[rel=redirectPage],
 .ve-ui-mwLinkTargetInputWidget-menu .oo-ui-menuItemWidget[rel=externalLink] {
        color: #0645AD;
 }
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
index 94599be..87db8e5 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
@@ -69,12 +69,29 @@
  * @returns {jqXHR} AJAX object without success or fail handlers attached
  */
 ve.ui.MWLinkTargetInputWidget.prototype.getLookupRequest = function () {
-       return ve.init.mw.Target.static.apiRequest( {
-               'action': 'opensearch',
-               'search': this.value,
-               'namespace': 0,
-               'suggest': ''
-       } );
+       var propsJqXhr,
+               searchJqXhr = ve.init.mw.Target.static.apiRequest( {
+                       'action': 'opensearch',
+                       'search': this.value,
+                       'namespace': 0,
+                       'suggest': ''
+               } );
+
+       return searchJqXhr.then( function ( data ) {
+               propsJqXhr = ve.init.mw.Target.static.apiRequest( {
+                       'action': 'query',
+                       'prop': 'info|pageprops',
+                       'titles': ( data[1] || [] ).join( '|' ),
+                       'ppprop': 'disambiguation'
+               } );
+               return propsJqXhr;
+       } ).promise( { abort: function () {
+               searchJqXhr.abort();
+
+               if ( propsJqXhr ) {
+                       propsJqXhr.abort();
+               }
+       } } );
 };
 
 /**
@@ -84,7 +101,7 @@
  * @param {Mixed} data Response from server
  */
 ve.ui.MWLinkTargetInputWidget.prototype.getLookupCacheItemFromData = function 
( data ) {
-       return data[1] || [];
+       return data.query && data.query.pages || {};
 };
 
 /**
@@ -94,17 +111,34 @@
  * @returns {OO.ui.MenuItemWidget[]} Menu items
  */
 ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuItemsFromData = function 
( data ) {
-       var i, len, item,
+       var i, len, item, pageExistsExact, pageExists, index, matchingPage,
                menu$ = this.lookupMenu.$,
                items = [],
-               matchingPages = data,
-               // If not found, run value through mw.Title to avoid treating a 
match as a
-               // mismatch where normalisation would make them matching (bug 
48476)
-               pageExistsExact = ve.indexOf( this.value, matchingPages ) !== 
-1,
-               titleObj = mw.Title.newFromText( this.value ),
-               pageExists = pageExistsExact || (
-                       titleObj && ve.indexOf( titleObj.getPrefixedText(), 
matchingPages ) !== -1
-               );
+               existingPages = [],
+               matchingPages = [],
+               disambigPages = [],
+               redirectPages = [],
+               titleObj = mw.Title.newFromText( this.value );
+
+       for ( index in data ) {
+               matchingPage = data[index];
+               existingPages.push( matchingPage.title );
+
+               if ( matchingPage.redirect !== undefined ) {
+                       redirectPages.push( matchingPage.title );
+               } else if ( matchingPage.pageprops !== undefined && 
matchingPage.pageprops.disambiguation !== undefined ) {
+                       disambigPages.push( matchingPage.title );
+               } else {
+                       matchingPages.push( matchingPage.title );
+               }
+       }
+
+       // If not found, run value through mw.Title to avoid treating a match 
as a
+       // mismatch where normalisation would make them matching (bug 48476)
+       pageExistsExact = ve.indexOf( this.value, existingPages ) !== -1;
+       pageExists = pageExistsExact || (
+               titleObj && ve.indexOf( titleObj.getPrefixedText(), 
existingPages ) !== -1
+       );
 
        // External link
        if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( 
this.value ) ) {
@@ -158,6 +192,34 @@
                }
        }
 
+       // Disambiguation pages
+       if ( disambigPages.length ) {
+               items.push( new OO.ui.MenuSectionItemWidget(
+                       'disambigPages',
+                       { '$': menu$, 'label': ve.msg( 
'visualeditor-linkinspector-suggest-disambig-page' ) }
+               ) );
+               for ( i = 0, len = disambigPages.length; i < len; i++ ) {
+                       items.push( new OO.ui.MenuItemWidget(
+                               this.getInternalLinkAnnotationFromTitle( 
disambigPages[i] ),
+                               { '$': menu$, 'rel': 'disambigPage', 'label': 
disambigPages[i] }
+                       ) );
+               }
+       }
+
+       // Redirect pages
+       if ( redirectPages.length ) {
+               items.push( new OO.ui.MenuSectionItemWidget(
+                       'redirectPages',
+                       { '$': menu$, 'label': ve.msg( 
'visualeditor-linkinspector-suggest-redirect-page' ) }
+               ) );
+               for ( i = 0, len = redirectPages.length; i < len; i++ ) {
+                       items.push( new OO.ui.MenuItemWidget(
+                               this.getInternalLinkAnnotationFromTitle( 
redirectPages[i] ),
+                               { '$': menu$, 'rel': 'redirectPage', 'label': 
redirectPages[i] }
+                       ) );
+               }
+       }
+
        return items;
 };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If975398e4d6b13eea6207ee80b33067e65acd724
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to