Alex Monk has uploaded a new change for review.

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

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, 72 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/54/110654/1

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 ff904d6..952823d 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
@@ -74,6 +74,13 @@
                'search': this.value,
                'namespace': 0,
                'suggest': ''
+       } ).then( function ( data, status, jqXhr ) {
+               return ve.init.mw.Target.static.apiRequest( {
+                       'action': 'query',
+                       'prop': 'info|pageprops',
+                       'titles': ( data[1] || [] ).join( '|' ),
+                       'ppprop': 'disambiguation'
+               } );
        } );
 };
 
@@ -84,7 +91,7 @@
  * @param {Mixed} data Response from server
  */
 ve.ui.MWLinkTargetInputWidget.prototype.getLookupCacheItemFromData = function 
( data ) {
-       return ve.isArray( data ) && data.length ? data[1] : [];
+       return 'query' in data && 'pages' in data.query ? data.query.pages : [];
 };
 
 /**
@@ -97,14 +104,33 @@
        var i, len, item,
                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 = [],
+               pageExistsExact,
+               pageExists,
+               titleObj = mw.Title.newFromText( this.value );
+
+       var disambigAndRedirectCheck = {};
+       $.each( data, function ( index, matchingPage ) {
+               existingPages.push( matchingPage.title );
+
+               if ( 'redirect' in matchingPage ) {
+                       redirectPages.push( matchingPage.title );
+               } else if ( 'pageprops' in matchingPage && 'disambiguation' in 
matchingPage.pageprops ) {
+                       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 +184,34 @@
                }
        }
 
+       // Disambiguation pages
+       if ( disambigPages && 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 && 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: newchange
Gerrit-Change-Id: If975398e4d6b13eea6207ee80b33067e65acd724
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

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

Reply via email to