Line 20: |
Line 20: |
| | | |
| --============================<< H E L P E R F U N C T I O N S >>============================================ | | --============================<< H E L P E R F U N C T I O N S >>============================================ |
− |
| |
− | --[[--------------------------< W I K I D A T A _ A R T I C L E _ N A M E _ G E T >----------------------------
| |
− |
| |
− | as an aid to internationalizing identifier-label wikilinks, gets identifier article names from Wikidata.
| |
− |
| |
− | returns :<lang code>:<article title> when <q> has an <article title> for <lang code>; nil else
| |
− |
| |
− | for identifiers that do not have q, returns nil
| |
− |
| |
− | for wikis that do not have mw.wikibase installed, returns nil
| |
− |
| |
− | ]]
| |
− |
| |
− | local function wikidata_article_name_get (q)
| |
− | -- TODO: Remove call to mw.wikibase
| |
− | if not is_set (q) or (q and not mw.wikibase) then -- when no q number or when a q number but mw.wikibase not installed on this wiki
| |
− | return nil; -- abandon
| |
− | end
| |
− |
| |
− | local wd_article;
| |
− | local this_wiki_code = cfg.this_wiki_code; -- Wikipedia subdomain; 'en' for en.wikipedia.org
| |
− |
| |
− | -- TODO: Remove call to mw.wikibase
| |
− | wd_article = mw.wikibase.getSitelink (q, this_wiki_code .. 'wiki'); -- fetch article title from WD; nil when no title available at this wiki
| |
− |
| |
− | if wd_article then
| |
− | wd_article = table.concat ({':', this_wiki_code, ':', wd_article}); -- interwiki-style link without brackets if taken from WD; leading colon required
| |
− | end
| |
− |
| |
− | return wd_article; -- article title from WD; nil else
| |
− | end
| |
| | | |
| | | |
| --[[--------------------------< L I N K _ L A B E L _ M A K E >------------------------------------------------ | | --[[--------------------------< L I N K _ L A B E L _ M A K E >------------------------------------------------ |
| | | |
− | common function to create identifier link label from handler table or from Wikidata | + | common function to create identifier link label from handler table |
| | | |
| returns the first available of | | returns the first available of |
| 1. redirect from local wiki's handler table (if enabled) | | 1. redirect from local wiki's handler table (if enabled) |
− | 2. Wikidata (if there is a Wikidata entry for this identifier in the local wiki's language) | + | 2. label specified in the local wiki's handler table |
− | 3. label specified in the local wiki's handler table
| |
| | | |
| ]] | | ]] |
| | | |
| local function link_label_make (handler) | | local function link_label_make (handler) |
− | local wd_article;
| + | return (cfg.use_identifier_redirects and is_set (handler.redirect) and handler.redirect) or handler.link; |
− |
| |
− | if not (cfg.use_identifier_redirects and is_set (handler.redirect)) then -- redirect has priority so if enabled and available don't fetch from Wikidata because expensive
| |
− | wd_article = wikidata_article_name_get (handler.q); -- if Wikidata has an article title for this wiki, get it;
| |
− | end
| |
− |
| |
− | return (cfg.use_identifier_redirects and is_set (handler.redirect) and handler.redirect) or wd_article or handler.link; | |
| end | | end |
| | | |
Line 85: |
Line 47: |
| local ext_link; | | local ext_link; |
| local this_wiki_code = cfg.this_wiki_code; -- Wikipedia subdomain; 'en' for en.wikipedia.org | | local this_wiki_code = cfg.this_wiki_code; -- Wikipedia subdomain; 'en' for en.wikipedia.org |
− | local wd_article; -- article title from Wikidata
| + | |
− |
| |
| if options.encode == true or options.encode == nil then | | if options.encode == true or options.encode == nil then |
| url_string = mw.uri.encode (url_string, 'PATH'); | | url_string = mw.uri.encode (url_string, 'PATH'); |
Line 101: |
Line 62: |
| | | |
| return table.concat ({ | | return table.concat ({ |
− | make_wikilink (link_label_make (options), options.label), -- redirect, Wikidata link, or locally specified link (in that order) | + | make_wikilink (link_label_make (options), options.label), -- redirect, or locally specified link (in that order) |
| options.separator or ' ', | | options.separator or ' ', |
| ext_link | | ext_link |