Commit 41f67bbe authored by HMonroy's avatar HMonroy
Browse files

Implement changes according to feedback:

- Added wikidata label to suggestions.
-  Fixed broken 'site llink' link.
- Added check that will trigger this script only when the wgNamespace is `0`.
- Load `mediawiki.ForeignApi.
parent a46aafc9
......@@ -52,7 +52,8 @@ class AutoSuggestSiteLink {
'format': 'json',
'action': 'query',
'list': 'search',
'srsearch': this.page
'srsearch': this.page,
'srprop': 'size|wordcount|timestamp|snippet|titlesnippet'
};
this.api.get( params ).done( ( data ) => {
if ( data.query ) {
......@@ -82,7 +83,7 @@ class AutoSuggestSiteLink {
var $addButton = $( '<a>' )
.text( m.addwikidata )
.attr( 'id', 'item-add-link-' + item.title )
.data( 'item', item.title )
.attr( 'data-item', item.title )
.on( 'click', ( e ) => {
e.preventDefault();
var selectedItem = e.target
......@@ -102,7 +103,7 @@ class AutoSuggestSiteLink {
.text( item.title ),
' (',
$( '<span>' )
.text( this.page ),
.text( item.titlesnippet ),
')',
$( '<span>' ).text( ', ' ),
$( '<i>' )
......@@ -119,7 +120,8 @@ class AutoSuggestSiteLink {
mw.notify( $siteLinkList, {
tag: 'wikidata-link',
id: 'wikidata-autosuggest',
autoHideSeconds: 'long'
autoHide: false,
title: 'Title'
} );
}
} );
......@@ -520,13 +522,13 @@ function init() {
var namespaceNumber = mw.config.get( 'wgNamespaceNumber' );
var namespace = mw.config.get( 'wgFormattedNamespaces' )[ namespaceNumber ]
if ( namespace === 'User' ) {
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
return;
}
Promise.all( [
// Resource loader modules
mw.loader.using( [ 'mediawiki.action.view.postEdit', 'mediawiki.api', 'mediawiki.Title' ] ),
mw.loader.using( [ 'mediawiki.action.view.postEdit', 'mediawiki.ForeignApi', 'mediawiki.Title' ] ),
] ).then( () => {mw.config.get( 'wgFormattedNamespaces' )[ namespace ]
new AutoSuggestSiteLink();
} );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment