diff --git a/WikiEditor.i18n.php b/WikiEditor.i18n.php index 110d7e09..3e609235 100644 --- a/WikiEditor.i18n.php +++ b/WikiEditor.i18n.php @@ -80,6 +80,7 @@ $messages['en'] = array( 'wikieditor-toolbar-tool-link-int-target-status-invalid' => 'Invalid title', 'wikieditor-toolbar-tool-link-int-target-status-external' => 'External link', 'wikieditor-toolbar-tool-link-int-target-status-loading' => 'Checking page existence...', + 'wikieditor-toolbar-tool-link-int-target-status-disambig' => 'Disambiguation page', 'wikieditor-toolbar-tool-link-int-invalid' => 'The title you specified is invalid.', 'wikieditor-toolbar-tool-link-lookslikeinternal' => 'The URL you specified looks like it was intended as a link to another wiki page. Do you want to make it an internal link?', @@ -361,6 +362,7 @@ For more information, see http://www.mediawiki.org/wiki/Extension:WikiEditor/Too 'wikieditor-toolbar-tool-link-int-target-status-external' => 'Text shown when the link target the user entered points to an external web site {{Identical|External link}}', 'wikieditor-toolbar-tool-link-int-target-status-loading' => 'alt text and title text for the image shown while the title the user entered is being checked for existence', + 'wikieditor-toolbar-tool-link-int-target-status-disambig' => 'Text shown when the link target the user entered points to a disambiguation page', 'wikieditor-toolbar-tool-link-int-invalid' => 'This message appears when you try to create an internal link but the page title in the link is invalid.', 'wikieditor-toolbar-tool-link-lookslikeinternal-int' => '{{Identical|Internal link}}', 'wikieditor-toolbar-tool-link-lookslikeinternal-ext' => '{{Identical|External link}}', diff --git a/WikiEditor.php b/WikiEditor.php index dc6df0a6..103c9eb9 100644 --- a/WikiEditor.php +++ b/WikiEditor.php @@ -239,6 +239,7 @@ $wgResourceModules += array( 'wikieditor-toolbar-tool-link-int-target-status-invalid', 'wikieditor-toolbar-tool-link-int-target-status-external', 'wikieditor-toolbar-tool-link-int-target-status-loading', + 'wikieditor-toolbar-tool-link-int-target-status-disambig', 'wikieditor-toolbar-tool-link-int-invalid', 'wikieditor-toolbar-tool-link-lookslikeinternal', 'wikieditor-toolbar-tool-link-lookslikeinternal-int', diff --git a/modules/images/dialogs/insert-disambiguation.png b/modules/images/dialogs/insert-disambiguation.png new file mode 100644 index 00000000..f9057763 Binary files /dev/null and b/modules/images/dialogs/insert-disambiguation.png differ diff --git a/modules/jquery.wikiEditor.dialogs.config.css b/modules/jquery.wikiEditor.dialogs.config.css index efde00fb..39d9d50e 100644 --- a/modules/jquery.wikiEditor.dialogs.config.css +++ b/modules/jquery.wikiEditor.dialogs.config.css @@ -55,7 +55,8 @@ #wikieditor-toolbar-link-int-target-status-exists, #wikieditor-toolbar-link-int-target-status-notexists, #wikieditor-toolbar-link-int-target-status-invalid, -#wikieditor-toolbar-link-int-target-status-external { +#wikieditor-toolbar-link-int-target-status-external, +#wikieditor-toolbar-link-int-target-status-disambig { padding-left: 30px; background-position: 0 50%; background-repeat: no-repeat; @@ -80,6 +81,11 @@ background-image: url(images/dialogs/insert-link-external.png); background-position: left; } +#wikieditor-toolbar-link-int-target-status-disambig { + /* @embed */ + background-image: url(images/dialogs/insert-disambiguation.png); + background-position: left; +} /* File dialog */ #wikieditor-toolbar-file-target, #wikieditor-toolbar-file-caption { diff --git a/modules/jquery.wikiEditor.dialogs.config.js b/modules/jquery.wikiEditor.dialogs.config.js index 146de0f9..ae2a1f45 100644 --- a/modules/jquery.wikiEditor.dialogs.config.js +++ b/modules/jquery.wikiEditor.dialogs.config.js @@ -188,40 +188,40 @@ $.wikiEditor.modules.dialogs.config = { // Show loading spinner while waiting for the API to respond updateWidget( 'loading' ); // Call the API to check page status, saving the request object so it can be aborted if - // necessary + // necessary. + // This used to request a page that would show whether or not the target exists, but we can + // also check whether it has the disambiguation property and still get existence information. + // If the Disambiguator extension is not installed then such a property won't be set. $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request', - $.ajax( { - url: mw.util.wikiScript( 'api' ), - dataType: 'json', - data: { - action: 'query', - indexpageids: '', - titles: target, - converttitles: '', - format: 'json' - }, - success: function ( data ) { - var status; - if ( !data || !data.query ) { - // This happens in some weird cases - status = false; - } else { - var page = data.query.pages[data.query.pageids[0]]; - status = 'exists'; - if ( page.missing !== undefined ) { - status = 'notexists'; - } else if ( page.invalid !== undefined ) { - status = 'invalid'; - } + ( new mw.Api() ).get( { + action: 'query', + prop: 'pageprops', + titles: target, + ppprop: 'disambiguation', + indexpageids: true, + } ).done( function ( data ) { + var status; + if ( !data.query ) { + // This happens in some weird cases + status = false; + } else { + var page = data.query.pages[data.query.pageids[0]]; + status = 'exists'; + if ( page.missing !== undefined ) { + status = 'notexists'; + } else if ( page.invalid !== undefined ) { + status = 'invalid'; + } else if ( page.pageprops !== undefined ) { + status = 'disambig'; } - // Cache the status of the link target if the force internal - // parameter was not passed - if ( !internal ) { - cache[target] = status; - } - updateWidget( status ); } + // Cache the status of the link target if the force internal + // parameter was not passed + if ( !internal ) { + cache[target] = status; + } + updateWidget( status ); } ) ); } @@ -324,6 +324,7 @@ $.wikiEditor.modules.dialogs.config = { var invalidMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-invalid' ); var externalMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' ); var loadingMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-loading' ); + var disambigMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-disambig' ); $( '#wikieditor-toolbar-link-int-target-status' ) .append( $( '
' ) .attr( 'id', 'wikieditor-toolbar-link-int-target-status-exists' ) @@ -349,6 +350,10 @@ $.wikiEditor.modules.dialogs.config = { 'title': loadingMsg } ) ) ) + .append( $( '
' ) + .attr( 'id', 'wikieditor-toolbar-link-int-target-status-disambig' ) + .append( disambigMsg ) + ) .data( 'existencecache', {} ) .children().hide();