GlobalWatchlistWikibaseHandler(globalWatchlistDebug, api, userLang)

GlobalWatchlistWikibaseHandler

Constructor

new GlobalWatchlistWikibaseHandler(globalWatchlistDebug, api, userLang) #

Handle getting labels for wikibase items

Caller is responsible for determining if this should be used

Parameters:

Name Type Description
globalWatchlistDebug GlobalWatchlistDebugger

Debugger instance to log to

api mw.ForeignApi

Instance of mw.ForeignApi to use

userLang string

language to fetch labels in

Source:

Methods

addWikibaseLabels(summaryEntries) → {Promise} #

Entry point - alter the entities given to have titleMsg that reflects the labels

Promise resolves to the summary entries with updated info

Parameters:

Name Type Description
summaryEntries Array.<GlobalWatchlistEntryBase>

Original summary, entries have titleMsg as just the plain title (Q1, P2, L3, etc.)

Source:

Returns:

Promise of updated summary, with labels

Type
Promise

cleanupRawLabels(rawLabels) → {Object} #

Convert the messy object returned from getRawLabels to something clearer

Resulting object has the following form (see documentation in #getRawLabels for the original)

   {
       "Q5": "human",
       "P10": "video",
       "L2": "first"
   }

Parameters:

Name Type Description
rawLabels Object

Labels in the format returns from the api

Source:

Returns:

Labels in a more usable format

Type
Object

debug(msg, extraInfoopt) #

Shortcut for sending information to the debug logger

Parameters:

Name Type Attributes Description
msg string

Message for debug entry

extraInfo string <optional>

Extra information for the debug entry

Source:

getEntityIds(entries) → {Object} #

Set entities' titleMsg (title without the Property: or Lexeme: prefix) and get a list of the ids to fetch in the form of Q1/P2/L3

Parameters:

Name Type Description
entries Array.<GlobalWatchlistEntryBase>

Original summary entries

Source:

Returns:

updated entries and ids

Type
Object

getRawLabels(entityIds) → {Promise} #

Fetch the labels for all of the ids given

Since the api is usually limited to 50 ids at a time, called recursively until all ids are processed. No special handling for users with apihighlimits, still only fetch 50 at a time

The returned promise resolves to an object with each of the entity ids being a key to the relevant information. To help visualize, below is a partial result of the wbgetentities query[1] performed on wikidata for Q5, P10, and L2, with the exception that the forms and senses for L2 are not included.

   {
       "Q5": {
           "type": "item",
           "id": "Q5",
           "labels": {
               "en": {
                   "language": "en",
                   "value": "human"
               }
           }
       },
       "P10": {
           "type": "property",
           "datatype": "commonsMedia",
           "id": "P10",
           "labels": {
               "en": {
                   "language": "en",
                   "value": "video"
               }
           }
       },
       "L2": {
           "type": "lexeme",
           "id": "L2",
           "lemmas": {
               "en": {
                   "language": "en",
                   "value": "first"
               }
           },
           "lexicalCategory": "Q1084",
           "language": "Q1860",
           "forms": [ ... ],
           "senses": [ ... ]
       }
   }

[1] See: https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q5|P10|L2&languages=en&props=labels&formatversion=2

Parameters:

Name Type Description
entityIds

The ids to get labels for

Source:
See:

Returns:

Promise of api result

Type
Promise