Extension:Proofread Page/Lua reference

From mediawiki.org

Getting started[edit]

On a MediaWiki wiki with ProofreadPage and Scribunto enabled, a Lua module is provided which allows access to certain features and information about pages in the Index and Page namespaces.

local index = mw.ext.proofreadPage.newIndex( 'Foobar.djvu' )
mw.log( index.pageCount )

Expensive functions[edit]

Some functions result in a database lookup and are classed as "expensive". Expensive lookups are cached where possible, so repeated access to the same data is "free" after the first lookup.

Note that there are several "types" of expensive data: first access to each of these is a new expensive lookup:

  • Index pages:
    • Getting the page count of an index
    • Getting the n'th page for an index (each index is cached, so getting two pages from the same index counts as a single expensive operation
    • Getting progress stats for an index (expensive once per index)
    • Loading index page content: categories and fields share a cache, so will only count as one expensive lookup per index
  • Page pages:
    • Getting the index for a given page (expensive once per page)
    • Getting the page numbering for a page: one expensive call if the index for the page is not cached, and another for the pagination of the index (only once per index)
    • Getting pages with a given offset requires the current page object's numbering (see above), plus the index for the page (expensive per-page)

Constants and functions[edit]

  • Namespaces:
    • mw.ext.proofreadPage.NS_INDEX: the current Index namespace number
    • mw.ext.proofreadPage.NS_PAGE: the current Page namespace number
  • Quality level constants:
    • mw.ext.proofreadPage.QualityLevel.WITHOUT_TEXT
    • mw.ext.proofreadPage.QualityLevel.NOT_PROOFREAD
    • mw.ext.proofreadPage.QualityLevel.PROBLEMATIC
    • mw.ext.proofreadPage.QualityLevel.PROOFREAD
    • mw.ext.proofreadPage.QualityLevel.VALIDATED

Index object[edit]

Construction[edit]

Access an object representing an index object with the mw.ext.proofreadPage.newIndex function:

local index = mw.ext.proofreadPage.newIndex( 'Foobar.djvu' )

The argument can be a string or an mw.title object.

Fields and methods[edit]

The Index object has the following fields:

  • title: gets the mw.title object referring to this page
  • pageCount: gets the number of pages in the index (this is expensive)
  • getPage( n ): gets the n'th Page of the index as a Page object (this is expensive if the page hasn't been looked up before)
  • Progress statistics:
    • existingPages: gets the number of pages in the index that currently exist (this is expensive if the progress stats are not cached)
    • missingPages: gets the number of pages in the index that currently do not exist (this is expensive if the progress stats are not cached)
    • pagesWithLevel( level ): gets the number of pages in the index that currently have the given level (this is expensive if the progress stats are not cached)
  • categories: Get a list of the categories the index page specifies, as mw.title objects (this is expensive if the index content is not cached)
  • fields: Get a table of the fields that the index page has set (this is expensive if the index content is not cached)

All fields are read-only.

Page object[edit]

Construction[edit]

Access an object representing an index object with the newPage function:

local page = mw.ext.proofreadPage.newPage( 'Foobar.djvu/1' )

The argument can be a string or an mw.title object.

Fields and methods[edit]

The Page object has the following fields:

  • title: gets the mw.title object referring to this page
  • index: gets the index object referring to the parent Index page (this is expensive if the parent index is not cached)
  • quality: gets the quality level of the page (this is expensive if the quality information is not cached)
  • position: gets the position of the page in the index pagelist, starting at 1 (this is expensive if the page numbering is not cached)
  • displayedNumber: gets the displayed page number of the page (this is expensive if the page numbering is not cached)
  • rawNumber: gets the raw page number of the page (this is expensive if the page numbering is not cached)
  • Access to other pages in the same index:
    • withOffset( n ): get the page the the given offset (e.g. 1 is the next page) in the index page list (this is expensive if the resultant page hasn't been looked up before)
    • nextPage: shorthand for withOffset( 1 )
    • previousPage: shorthand for withOffset( -1 )

All fields are read-only.

See also[edit]

Attribution: Gerrit, Phabricator, GitHub icons.