Add check to see if article has associated sitelinks. (dd4068b9) · Commits · repos / commtech / AutosuggestSitelink · GitLab
Admin message
How to register an account on GitLab
. Due to spam, new accounts are locked until approved by an admin or
the approver bot
. Your GitLab account gets automatically approved within one hour if you are a member of
Trusted Contributors in Gerrit
, or a member of the
Trusted-Contributors group in Phabricator
and
linked your Developer account ("LDAP") to your Phabricator account
. If none of these apply,
file an unlock request
to expedite access.
Only if you are WMF staff
: Create your GitLab account,
have "Wmf" group membership
in
IDM
link your Developer account ("LDAP") to your Phabricator account
, and get automatically approved.
Admin message
Support:
mw:GitLab
how to host a project on GitLab
#wikimedia-gitlab
on libera.chat,
#GitLab
on Phabricator.
Commit
dd4068b9
authored
Dec 13, 2022
by
HMonroy
Browse files
parent
877d5961
Loading
Loading
Loading
Loading
Original line number
Diff line number
Diff line
/**
* Add a small box under a Wikipedia article's title displaying the label,
* description, aliases and the identifier of the related Wikidata item.
* Based on [[d:User:Yair_rand/WikidataInfo.js]], but in this fork, the QID is de-linked for easier copypasting.
* Add a small box under a Wikipedia article's title displaying Wikidata items
* after editing an article if the article does not have sitelinks related to it.
*/
/**
* @class
* @property {string} page The name of page
* @property {Array.} messages The interface messages
* @property {Object} api The api object to query data from wikidata
* You can enable it by adding these lines to your common.js (or global.js) file:
*/
class
AutoSuggestSiteLink
static
WIKIDATA_URL
static
WIKI_NAME
mw
config
get
wgDBname
);
constructor
(){
this
page
mw
config
get
wgPageName
);
this
api
new
mw
ForeignApi
AutoSuggestSiteLink
WIKIDATA_URL
/w/api.php
);
this
checkSiteLink
();
/**
* Check if page has sitelinks related to this wiki
* // [[d:User:NMaia/WikidataInfo.js]]
* mw.loader.load( '//www.wikidata.org/w/index.php?title=User:NMaia/WikidataInfo.js&action=raw&ctype=text/javascript' );
*/
checkSiteLink
(){
const
params
format
json
action
wbgetentities
props
sitelinks/urls
sitefilter
AutoSuggestSiteLink
WIKI_NAME
sites
AutoSuggestSiteLink
WIKI_NAME
titles
this
page
this
api
get
params
).
done
data
=>
// If "-1" key is not found in entities then page has sitelinks
if
data
entities
-1
!==
undefined
this
suggestSiteLink
();
});
/**
* Suggest possible related wikidata items
* dependencies=mediawiki.jqueryMsg
*/
//
location
indexOf
printable=yes
===
&&
wikibase-item
wikibase-property
wikibase-lexeme
flow-board
EntitySchema
].
indexOf
mw
config
get
wgPageContentModel
===
&&
mw
loader
using
mediawiki.jqueryMsg
).
done
function
()
var
translate
suggestSiteLink
(){
const
params
format
json
action
query
list
srsearch
this
page
};
this
api
get
params
).
done
data
=>
if
data
query
var
$siteLinkList

).
addClass
wikidata-auto-suggest
),
contentLang
mw
config
get
wgContentLanguage
),
userLang
mw
config
get
wgUserLanguage
),
Object
prototype
hasOwnProperty
call
this
messages
userLang
this
messages
userLang
this
messages
en
mw
messages
set
WDI-aliases
aliases
);
if
data
query
searchinfo
totalhits
$siteLinkList
append

).
text
notfound
),



),

).
attr
href
AutoSuggestSiteLink
WIKIDATA_URL
/wiki/Special:NewItem?
new
URLSearchParams
site
AutoSuggestSiteLink
WIKI_NAME
page
this
page
label
this
page
lang
contentLang
).
text
createnewitem
);
else
data
query
forEach
item
=>
var
$itemDiv

);
var
$addButton

text
addwikidata
attr
id
item-add-link-
item
title
data
item
item
title
on
click
=>
preventDefault
();
var
selectedItem
target
this
api
postWithToken
csrf
action
wbsetsitelink
id
selectedItem
getAttribute
data-item
),
linksite
AutoSuggestSiteLink
WIKI_NAME
linktitle
this
page
).
done
function
data
selectedItem
text
itemlinked
);
);
$itemDiv
append

attr
href
AutoSuggestSiteLink
WIKIDATA_URL
/wiki/
item
title
text
item
title
),

text
this
page
),

).
text
),

text
item
snippet
||
nodescription
addClass
item
snippett
WDI-desc
WDI-desc WDI-nodesc
),



),
$addButton



);
$siteLinkList
append
$itemDiv
);
);
mw
notify
$siteLinkList
tag
wikidata-link
id
wikidata-autosuggest
autoHideSeconds
long
);
);
/**
* Holds language translations
* @return {Object}
*/
get
messages
()
return
en
notfound
Wikidata item not found.
intro
Wikidata:
nolabel
(No label)
nodescription
no description given
aliases
{{PLURAL:$1|Alias|Aliases}}:
noaliases
None
noaliases
None
addwikidata
Link this item
createnewitem
Create new item
itemlinked
Site link created!
},
ar
notfound
لم يعثر على هذه المادة في ويكي بيانات.
@@ -399,74 +513,23 @@ location.search.indexOf( 'printable=yes' ) === -1
noaliases
};
var
namespace
mw
config
get
wgNamespaceNumber
),
lang
mw
config
get
wgContentLanguage
),
page
namespace
-=
namespace
&&
namespace
===
mw
config
get
wgTitle
mw
config
get
wgFormattedNamespaces
)[
namespace
mw
config
get
wgTitle
);
].
indexOf
namespace
===
&&
ajax
url
//www.wikidata.org/w/api.php
data
format
json
action
wbgetentities
sites
mw
config
get
wgDBname
),
titles
page
props
info|labels|descriptions|aliases
languages
lang
maxage
mw
config
get
wgUserName
===
null
900
30
smaxage
mw
config
get
wgUserName
===
null
900
30
//'maxlag': 1
},
dataType
jsonp
cache
true
done
function
data
if
data
success
function
()
var
$d

).
addClass
WDI-box
),
userLang
mw
config
get
wgUserLanguage
),
Object
prototype
hasOwnProperty
call
translate
userLang
translate
userLang
translate
en
mw
messages
set
WDI-aliases
aliases
);
each
data
entities
function
entity
item
if
entity
==
$d
append

).
attr
href
//www.wikidata.org/wiki/Special:NewItem?site=
mw
config
get
wgDBname
&page=
encodeURIComponent
page
&label=
encodeURIComponent
page
&lang=
lang
).
text
notfound
);
else
var
label
item
labels
lang
&&
item
labels
lang
].
value
description
item
descriptions
lang
&&
item
descriptions
lang
].
value
aliases
map
item
aliases
lang
||
[],
function
alias
return
alias
value
);
if
window
WDIlimitaliases
&&
WDIlimitaliases
aliases
length
){
for
WDIlimitaliases
aliases
length
aliases
pop
()
aliases
push
...
);
$d
append

attr
href
//www.wikidata.org/wiki/
item
title
text
intro
label
||
nolabel
),

text
item
title
),

).
text
),

text
description
||
nodescription
addClass
description
WDI-desc
WDI-desc WDI-nodesc
),


),

).
text
mw
msg
WDI-aliases
aliases
length
aliases
join
||
noaliases
);
);
$d
appendTo
#contentSub
);
);
function
init
()
var
namespaceNumber
mw
config
get
wgNamespaceNumber
);
var
namespace
mw
config
get
wgFormattedNamespaces
)[
namespaceNumber
if
namespace
===
User
return
Promise
all
// Resource loader modules
mw
loader
using
mediawiki.action.view.postEdit
mediawiki.api
mediawiki.Title
),
).
then
()
=>
mw
config
get
wgFormattedNamespaces
)[
namespace
new
AutoSuggestSiteLink
();
);
);
//
mw
hook
postEdit
).
add
init
);
Loading

C U Cyber History — Public Interest Web Archive