Skip to content

mquery

Mass/Bulk query methods and classes designed to fetch as many results as possible in the fewest round trips

MQuery

Collection of queries optimized for performing mass/bulk data retrieval from the API

categories_on_page(wiki, titles) staticmethod

Fetch the categories used on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query.

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of categories the page is categorized in.

category_size(wiki, titles) staticmethod

Queries the Wiki and gets the number of elements categorized in each of the specified categories.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use.

required
titles list[str]

The categories to get the size of. Each list element must include the Category: prefix

required

Returns:

Name Type Description
dict dict

A dict where each key is the category name and each value is an int representing the number of elements categorized in this category.

duplicate_files(wiki, titles, local_only=True, shared_only=False) staticmethod

Find duplicates of the specified files if possible.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The list of files to get duplicates of (must start with File: prefix).

required
local_only bool

Set False to also search the associated shared media repository wiki. Defaults to True.

True
shared_only bool

Set True to only return duplicates from the shared media repository. Do not set to True if local_only is True or you will get strange behavior. Defaults to False.

False

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of files that duplicate the specified file.

exists(wiki, titles) staticmethod

Queries the Wiki to determine if the specified list of titles exists.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use.

required
titles list[str]

The titles to query.

required

Returns:

Name Type Description
dict dict

A dict where each key is a title and each value is a bool indiciating if the title exists (True) or not (False).

Fetches external links on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of external links contained in the text of the page.

file_usage(wiki, titles) staticmethod

Fetch the titles of all pages displaying the specified list of media files.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The files to get file usage of. Each list element must include the File: prefix

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of pages displaying the file.

global_usage(wiki, titles) staticmethod

Fetch the global file usage of a media file. Only works with wikis that utilize a shared media respository wiki.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The files to get global usage usage of. Each list element must include the File: prefix

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of tuples (page title, wiki hostname) containing the global usages of the file.

image_info(wiki, titles) staticmethod

Fetch image (file) info for media files. This is basically image metadata for each uploaded media file under the specified title. See dwrap.ImageInfo for details.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The files to get image info of. Each list element must include the File: prefix

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of ImageInfo objects associated with the title.

images_on_page(wiki, titles) staticmethod

Fetch images/media files used on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of images/files that are used on the page.

Fetch wiki links on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required
ns Union[list[Union[NS, str]], NS, str]

Restrict returned output to titles in these namespaces. Optional, set to empty list to disable. Defaults to [].

[]

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of wiki links contained in the text of the page.

page_text(wiki, titles) staticmethod

Queries the Wiki for the text of a title.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use.

required
titles list[str]

The titles to query.

required

Returns:

Name Type Description
dict dict

A dict where each key is the title and each value is a str with the wikitext of the title. If a title does not exist, the str will be replaced with None.

templates_on_page(wiki, titles) staticmethod

Fetch templates transcluded on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of tempalates transcluded on the page.

Fetch pages that wiki link (locally) to a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required
redirects_only bool

Set True to get the titles that redirect to this page. Defaults to False.

False
ns Union[list[Union[NS, str]], NS, str]

Restrict returned output to titles in these namespaces. Optional, set to empty list to disable. Defaults to [].

[]

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of pages that link to the specified page.

what_transcludes_here(wiki, titles, ns=[]) staticmethod

Fetch pages that translcude a page. If querying for templates, you must include the Template: prefix.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
titles list[str]

The titles to query

required
ns Union[list[Union[NS, str]], NS, str]

Restrict returned output to titles in these namespaces. Optional, set to empty list to disable. Defaults to [].

[]

Returns:

Name Type Description
dict dict

A dict such that each key is the title and each value is the list of pages that transclude the specified page.