Wiki.SiteMatrix (mediawiki_client v0.5.0)

View Source

Retrieves sites from a wiki farm with the SiteMatrix extension installed.

Most applications will connect to a single wiki, or iterate over sites from a single site matrix, so a singleton default can be set up as a child of your Application.

children = [
  Wiki.SiteMatrix.Default
]

To override defaults, supply additional options:

children = [
  {Wiki.SiteMatrix.Default, api: "https://meta.wikimedia.beta.wmflabs.org/w/api.php"}
]

The get and get_all methods include a variation where the initial SiteMatrix parameter is omitted, and the application default will be used instead. Note that this will crash if the agent has not been started yet.

Wiki.SiteMatrix.get("dewiki")

Summary

Functions

Get the Action API for a known site

Utility method to get the shared SiteMatrix.

Look up in the default site matrix

Look up a single site by key

Assertive variant of get.

Get all sites from the default site matrix

Get all sites for a wiki farm.

Options

Types

client_options()

@type client_options() :: [
  Wiki.Action.client_option()
  | {:api, binary()}
  | {:key_fun, (Wiki.SiteMatrix.Spec.t() -> any())}
]

sitematrix_state()

@opaque sitematrix_state()

Functions

action_api(site)

@spec action_api(String.t() | Wiki.SiteMatrix.Spec.t()) :: String.t()

Get the Action API for a known site

Wiki.SiteMatrix.new()
|> Wiki.SiteMatrix.get("enwiki")
|> Wiki.SiteMatrix.action_api()

# "https://en.wikipedia.org/w/api.php"

As a convenience, the site can be referenced as a bare string, in which case it will be looked up in the default Wikimedia farm. Note that this will be uncached and so inappropriate for most production use.

Wiki.SiteMatrix.action_api("dewiki")

Arguments

  • site - Populated site structure.

Return value

Calculated Action API.

default_sitematrix()

@spec default_sitematrix() :: sitematrix_state()

Utility method to get the shared SiteMatrix.

get(key)

@spec get(String.t()) :: {:ok, Wiki.SiteMatrix.Spec.t()} | {:error, any()}

Look up in the default site matrix

@see get/2

get(sitematrix, key)

@spec get(sitematrix_state(), String.t()) ::
  {:ok, Wiki.SiteMatrix.Spec.t()} | {:error, any()}

Look up a single site by key

Arguments

  • sitematrix - Result of Sitematrix.new()
  • key - The dbname (eg. "enwiki") or value of another key if specified as an option to new().

Return value

Site spec or error

get!(sitematrix, key)

Assertive variant of get.

get_all()

@spec get_all() :: {:ok, [Wiki.SiteMatrix.Spec.t()]} | {:error, any()}

Get all sites from the default site matrix

@see get_all/1

get_all(sitematrix)

@spec get_all(sitematrix_state()) ::
  {:ok, [Wiki.SiteMatrix.Spec.t()]} | {:error, any()}

Get all sites for a wiki farm.

Arguments

  • sitematrix - Result of Sitematrix.new()

Return value

List of site specifications.

new(opts \\ [])

@spec new(client_options()) :: sitematrix_state()

Options

  • api - Action API URL for a site participating in the farm. Defaults to https://meta.wikimedia.org/w/api.php.

  • key_fun - Function on a site spec, returning the key to build a lookup with, later passed as the key argument to get. Defaults to returning the site's :dbname (eg. "enwiki").