Follow redirects in the link inspector API

Show redirect targets first, then any redirects to it
immediately after.

Change-Id: Ifde579410b4fbf42e0598e4b069963162333da55
This commit is contained in:
Ed Sanders 2015-04-29 11:10:02 +01:00
parent df6a570f82
commit 702fc724d7
5 changed files with 30 additions and 5 deletions

View file

@ -1148,6 +1148,7 @@ $wgResourceModules += array(
'messages' => array( 'messages' => array(
'visualeditor-annotationbutton-linknode-tooltip', 'visualeditor-annotationbutton-linknode-tooltip',
'visualeditor-linkinspector-description-new-page', 'visualeditor-linkinspector-description-new-page',
'visualeditor-linkinspector-description-redirect',
'visualeditor-linkinspector-illegal-title', 'visualeditor-linkinspector-illegal-title',
'visualeditor-linknodeinspector-add-label', 'visualeditor-linknodeinspector-add-label',
'visualeditor-linknodeinspector-title', 'visualeditor-linknodeinspector-title',

View file

@ -1174,6 +1174,7 @@
"messages": [ "messages": [
"visualeditor-annotationbutton-linknode-tooltip", "visualeditor-annotationbutton-linknode-tooltip",
"visualeditor-linkinspector-description-new-page", "visualeditor-linkinspector-description-new-page",
"visualeditor-linkinspector-description-redirect",
"visualeditor-linkinspector-illegal-title", "visualeditor-linkinspector-illegal-title",
"visualeditor-linknodeinspector-add-label", "visualeditor-linknodeinspector-add-label",
"visualeditor-linknodeinspector-title" "visualeditor-linknodeinspector-title"

View file

@ -242,6 +242,7 @@
"visualeditor-formatdropdown-format-mw-heading6": "Sub-heading 4", "visualeditor-formatdropdown-format-mw-heading6": "Sub-heading 4",
"visualeditor-languages-tool": "Languages", "visualeditor-languages-tool": "Languages",
"visualeditor-linkinspector-description-new-page": "Page does not exist yet", "visualeditor-linkinspector-description-new-page": "Page does not exist yet",
"visualeditor-linkinspector-description-redirect": "redirect to $1",
"visualeditor-linkinspector-illegal-title": "Invalid page title", "visualeditor-linkinspector-illegal-title": "Invalid page title",
"visualeditor-linknodeinspector-add-label": "Add label", "visualeditor-linknodeinspector-add-label": "Add label",
"visualeditor-linknodeinspector-title": "Simple link", "visualeditor-linknodeinspector-title": "Simple link",

View file

@ -251,6 +251,7 @@
"visualeditor-formatdropdown-format-mw-heading6": "Item in the MediaWiki formatting dropdown for a level 6 heading (sub-section)\n{{Related|Visualeditor-formatdropdown}}", "visualeditor-formatdropdown-format-mw-heading6": "Item in the MediaWiki formatting dropdown for a level 6 heading (sub-section)\n{{Related|Visualeditor-formatdropdown}}",
"visualeditor-languages-tool": "Tool for opening the languages links section of the meta dialog.\n{{Identical|Language}}", "visualeditor-languages-tool": "Tool for opening the languages links section of the meta dialog.\n{{Identical|Language}}",
"visualeditor-linkinspector-description-new-page": "Description label for a new page in the link inspector.", "visualeditor-linkinspector-description-new-page": "Description label for a new page in the link inspector.",
"visualeditor-linkinspector-description-redirect": "Description label for a redirect in the link inspector.",
"visualeditor-linkinspector-illegal-title": "Warning that the entered text is not a valid page title.", "visualeditor-linkinspector-illegal-title": "Warning that the entered text is not a valid page title.",
"visualeditor-linknodeinspector-add-label": "Label of button that converts an auto-numbered, external, labelless link into a labeled external link", "visualeditor-linknodeinspector-add-label": "Label of button that converts an auto-numbered, external, labelless link into a labeled external link",
"visualeditor-linknodeinspector-title": "Title of inspector for editing auto-numbered, external, labelless links.\n\nSee also:\n* {{msg-mw|Visualeditor-annotationbutton-linknode-tooltip}}", "visualeditor-linknodeinspector-title": "Title of inspector for editing auto-numbered, external, labelless links.\n\nSee also:\n* {{msg-mw|Visualeditor-annotationbutton-linknode-tooltip}}",

View file

@ -193,6 +193,7 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupRequest = function () {
prop: 'info|pageprops|pageimages|pageterms', prop: 'info|pageprops|pageimages|pageterms',
pithumbsize: 80, pithumbsize: 80,
pilimit: 5, pilimit: 5,
redirects: '',
wbptterms: 'description', wbptterms: 'description',
ppprop: 'disambiguation' ppprop: 'disambiguation'
} ); } );
@ -214,7 +215,7 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupRequest = function () {
* @param {Mixed} data Response from server * @param {Mixed} data Response from server
*/ */
ve.ui.MWLinkTargetInputWidget.prototype.getLookupCacheDataFromResponse = function ( data ) { ve.ui.MWLinkTargetInputWidget.prototype.getLookupCacheDataFromResponse = function ( data ) {
return data.query && data.query.pages || {}; return data.query || {};
}; };
/** /**
@ -241,22 +242,42 @@ ve.ui.MWLinkTargetInputWidget.prototype.onLookupInputChange = function () {
* @returns {OO.ui.MenuOptionWidget[]} Menu items * @returns {OO.ui.MenuOptionWidget[]} Menu items
*/ */
ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuOptionsFromData = function ( data ) { ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuOptionsFromData = function ( data ) {
var i, len, index, pageExists, pageExistsExact, suggestionPage, linkData, var i, len, index, pageExists, pageExistsExact, suggestionPage, linkData, redirect, redirects,
items = [], items = [],
suggestionPages = [], suggestionPages = [],
titleObj = mw.Title.newFromText( this.value ), titleObj = mw.Title.newFromText( this.value ),
redirectsTo = {},
links = {}; links = {};
for ( index in data ) { if ( data.redirects ) {
suggestionPage = data[index]; for ( i = 0, len = data.redirects.length; i < len; i++ ) {
redirect = data.redirects[i];
redirectsTo[redirect.to] = redirectsTo[redirect.to] || [];
redirectsTo[redirect.to].push( redirect.from );
}
}
for ( index in data.pages ) {
suggestionPage = data.pages[index];
links[suggestionPage.title] = { links[suggestionPage.title] = {
missing: false, missing: false,
redirect: suggestionPage.redirect !== undefined, redirect: false,
disambiguation: ve.getProp( suggestionPage, 'pageprops', 'disambiguation' ) !== undefined, disambiguation: ve.getProp( suggestionPage, 'pageprops', 'disambiguation' ) !== undefined,
imageUrl: ve.getProp( suggestionPage, 'thumbnail', 'source' ), imageUrl: ve.getProp( suggestionPage, 'thumbnail', 'source' ),
description: ve.getProp( suggestionPage, 'terms', 'description' ) description: ve.getProp( suggestionPage, 'terms', 'description' )
}; };
suggestionPages.push( suggestionPage.title ); suggestionPages.push( suggestionPage.title );
redirects = redirectsTo[suggestionPage.title] || [];
for ( i = 0, len = redirects.length; i < len; i++ ) {
links[redirects[i]] = {
missing: false,
redirect: true,
disambiguation: false,
description: ve.msg( 'visualeditor-linkinspector-description-redirect', suggestionPage.title )
};
suggestionPages.push( redirects[i] );
}
} }
// If not found, run value through mw.Title to avoid treating a match as a // If not found, run value through mw.Title to avoid treating a match as a