Assembly line workers/Page

From Apibot
Jump to: navigation, search

The Page workers are specialized for processing wiki pages, unlike the more general data workers or params workers.

All are situated in the directory interfaces/line/workers/page.

Page edit workers

These objects work on a data element that is wiki page in editable form. If it is not, or does not contain the page text, an attempt will be made to fetch the page. If the data element that came is not a page at all, the fetching will try to deduce from it the page to fetch.

The work is done through the methods of a Page object (the Page class is defined in core/data/page.php). If the page data element is in array form instead of object, it will be auto-converted by a Page edit worker to a Page object.

All page edit workers are situated in the subdirectory edit.

Creating

The typical page edit worker class constructor has the following parameters, in this order:

  • $core - the bot Core object
  • $tasks - a single editing task or an array with the editing tasks (class-specific)
  • $autofetch = true - whether to auto-fetch pages who miss needed properties
  • $autosubmit = true - whether to auto-append a Page Edit writer if this is the line last object
  • $fetch_page_properties = NULL - the properties to fetch pages with

A task is an array with keys and values as described for the specific type of task. For example, the task for adding category would be an array that looks like this:

$task = array (
  'title' => "Category:Scientists",
  'sortkey' => NULL,
);

Public properties

The typical page edit worker class constructor has the following public properties:

  • $tasks
  • $autofetch = true
  • $autosubmit = true

For descriptions, see above.

Page edit workers list

Class name Defined in file Function Tasks array member elements
Worker_EditPage_AddCategories add_categories.php Adds categories to the page text
  • 'name' - category name, or
  • 'title' - category title (incl. 'Category:' prefix)
  • 'sortkey' - page sort key in the category
Worker_EditPage_AddCategoriesStrings add_categories_strings.php Adds categories to the page text A string containing the full category link
Worker_EditPage_AddFilelinks add_filelinks.php Adds filelinks to the page text
  • 'filelink' - an array with the following elements:
    • 'namespace' - namespace for the file (default - the localized "File")
    • 'name' - the filename
    • 'params' - the file box parameters ("frame", "left" etc. like)
    • 'caption' - the file caption
  • 'regexpart_before' - a regex part that must match before the insertion point
  • 'regexpart_after' - a regex part that must match after the insertion point
  • 'limit' - number of times the filelink must be inserted (default: 1)
Worker_EditPage_AddInterwikis add_interwikis.php Adds interwikis to the page text
  • 'wiki' - code of the wiki it points to
  • 'namespace' - page namespace name
  • 'name' - page name
  • 'title' - page title (namespace:name)
  • 'newline_after' - if true, add a newline after the interwiki
Worker_EditPage_AddInterwikisStrings add_interwikis_strings.php Adds interwikis to the page text A string containing the full interwiki link
Worker_EditPage_AddTemplates add_templates.php Adds templates to the page text
  • 'template' - an array with the template data:
    • 'name' - the template name
    • 'params' - an array with the template parameters names and values
    • 'multiline' - if true, every parameter will be on a separate line
  • 'regexpart_before' - a regex part that must match before the insertion point
  • 'regexpart_after' - a regex part that must match after the insertion point
  • 'limit' - number of times the template must be inserted (default: 1)
Worker_EditPage_AddWikilinks add_wikilinks.php Adds wikilinks to the page text
  • 'wikilink' - an array with the following elements:
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink (or the full page title, if 'name' is empty)
    • 'name' - the page name (without the namespace)
    • 'anchor' - the location in the page pointed by the wikilink
    • 'text' - the text the wikilink shows
    • 'newline_after' - if true, add a newline after the wikilink
  • 'regexpart_before' - a regex part that must match before the insertion point
  • 'regexpart_after' - a regex part that must match after the insertion point
  • 'limit' - number of times the wikilink must be inserted (default: 1)
Worker_EditPage_AppendText append.php Appends some text at the end of the page The entire $tasks property is the text to be appended, as a string
Worker_EditPage_PrependText prepend.php Prepends some text before the beginning of the page The entire $tasks property is the text to be prepended, as a string
Worker_EditPage_Insert insert.php Inserts text(s) inside the page text
  • 'text' - the text to be inserted
  • 'regexpart_before' - a regex part that must match before the insertion point
  • 'regexpart_after' - a regex part that must match after the insertion point
  • 'limit' - number of times the text must be inserted (default: 1)
Worker_EditPage_DeleteRegexes delete.php Deletes the text matching a regex or an array of regexes A PHP regex. (Also the entire $tasks property can be a single regex instead of an array.)
Worker_EditPage_DeleteCategories delete_categories.php Deletes categories from the page text
  • 'name' - category name, or
  • 'title' - category title (incl. 'Category:' prefix)
  • 'sortkey' - page sort key in the category

(All parts may include regex elements.)

Worker_EditPage_DeleteCategoriesSortkeys delete_categories_sortkeys.php Deletes sortkeys from the categories wikilinks. A category name, without the namespace. (Also the entire $tasks property can be a single category name instead of an array.)
Worker_EditPage_DeleteFilelinks delete_filelinks.php Deletes filelinks from the page text
  • 'namespace' - namespace for the file (default - the localized "File")
  • 'name' - the filename (can be a regex part)
  • 'limit' - number of times the filelink must be deleted (default: all)
Worker_EditPage_DeleteInterwikis delete_interwikis.php Deletes interwikis from the page text The interwiki code that must be deleted
Worker_EditPage_DeleteTemplates delete_templates.php Deletes templates from the page text
  • 'name' - the template name
  • 'limit' - number of times the template must be deleted (default: all)
Worker_EditPage_DeleteWikilinks delete_wikilinks.php Deletes wikilinks from the page text
  • 'colon' - if true, start the wikilink with a leading colon
  • 'wiki' - code of the wiki it points to
  • 'namespace' - namespace for the wikilink
  • 'name' - the page name (without the namespace); mandatory!
  • 'anchor' - the location in the page pointed by the wikilink
  • 'text' - the text the wikilink shows
  • 'newline_after' - if true, add a newline after the wikilink
  • 'limit' - number of times the wikilink must be deleted (default: all)
Worker_EditPage_ReplaceCategories replace_categories.php Replaces categories in the page text
  • 'name' - category name,
  • 'new_sortkey' - a sortkey for the new category (if not given or NULL, the old one will be preserved)
Worker_EditPage_ReplaceFilelinks replace_filelinks.php Replaces filelinks in the page text
  • 'name' - file name,
  • 'with' - a filelink description array:
    • 'namespace' - namespace for the file (default - the localized "File")
    • 'name' - the filename
    • 'params' - the file box parameters ("frame", "left" etc. like)
    • 'caption' - the file caption
  • 'limit' - number of times the filelink must be replaced (default: all)
Worker_EditPage_ReplaceFilelinksCaptions replace_filelinks_captions.php Replaces the captions of filelinks in the page text
  • 'name' - file name,
  • 'namespace' - namespace for the file (default - the localized "File")
  • 'new_caption' - the file new caption
Worker_EditPage_ReplaceFilelinksNames replace_filelinks_names.php Replaces the file names of filelinks in the page text
  • 'old_name' - the file name to be replaced,
  • 'new_name' - the replacement file name,
  • 'old_namespace' - the file namespace to be replaced (if given),
  • 'new_namespace' - the replacement file namespace (if given),
  • 'limit' - number of times the filelink must be replaced (default: all)
Worker_EditPage_ReplaceFilelinksParams replace_filelinks_params.php Replaces some parameters of filelinks in the page text
  • 'name' - the file name whose param is to be replaced,
  • 'namespace' - the file namespace (if given),
  • 'param' - the file wikilink parameter whose value should be replaced
  • 'value' - the new value for the param specified
Worker_EditPage_ReplaceInterwikis replace_interwikis.php Replaces interwikis to the page text
  • 'old_wiki' - code of the wiki to be replaced
  • 'new_wiki' - the replacement wiki code
  • 'title' - the new page title (if specified)
Worker_EditPage_ReplaceRegexes replace_regexes.php Replaces regexes in the page text
  • 'regex' - the regex to be replaced,
  • 'with' - the replacement,
  • 'limit' - number of times the regex must be replaced (default: all)
Worker_EditPage_ReplaceStrings replace_strings.php Replaces strings in the page text
  • 'string' - the string to be replaced,
  • 'with' - the replacement
Worker_EditPage_ReplaceTemplates replace_templates.php Replaces templates in the page text
  • 'name' - the name of the template to be replaced,
  • 'with' - a template array replacement:
    • 'name' - the template name
    • 'params' - an array of template params, names as keys and values as... values :-)
    • 'multiline' - if true, every parameter will be on a separate line
  • 'limit' - number of times the template must be replaced (default: all)
Worker_EditPage_ReplaceTemplatesNames replace_templates_names.php Replaces names of templates in the page text
  • 'old_name' - the name of the template to be replaced,
  • 'new_name' - the replacement name
  • 'limit' - number of times the template name must be replaced (default: all)
Worker_EditPage_ReplaceTemplatesParamnames replace_templates_names.php Replaces names of templates parameters in the page text
  • 'name' - the name of the template to replace paramnames in,
  • 'old_paramname' - the name of the template parameter to be replaced,
  • 'new_paramname' - the replacement parameter name
Worker_EditPage_ReplaceTemplatesParamvalues replace_templates_values.php Replaces values of templates parameters in the page text
  • 'name' - the name of the template to replace paramvalues in,
  • 'paramname' - the name of the template parameter whose value is to be replaced,
  • 'new_value' - the replacement value
Worker_EditPage_ReplaceWikilinks replace_wikilinks.php Replaces wikilinks in the page text
  • Strings or regexparts (please avoid subpatterns if possible, some of them may break the result!)
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
    • 'text' - the text the wikilink shows
  • 'with' - a wikilink string to replace wikilinks is matched by the regex created from the parameters above
  • 'limit' - number of times the wikilink must be replaced (default: all)
Worker_EditPage_ReplaceWikilinksTargets replace_wikilinks_targets.php Replaces wikilinks targets in the page text
  • Strings or regexparts (please avoid subpatterns if possible, some of them may break the result!)
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
    • 'text' - the text the wikilink shows
  • 'with' - a wikilink target string to replace the target in wikilinks is matched by the regex created from the parameters above
  • 'limit' - number of times the wikilink target must be replaced (default: all)
Worker_EditPage_ReplaceWikilinksTexts replace_wikilinks_texts.php Replaces wikilinks texts in the page text
  • Strings or regexparts (please avoid subpatterns if possible, some of them may break the result!)
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
    • 'text' - the text the wikilink shows
  • 'with' - a wikilink text string to replace the text in wikilinks is matched by the regex created from the parameters above
  • 'limit' - number of times the wikilink text must be replaced (default: all)
Worker_EditPage_SetCategoriesSortkeys set_categories_sortkeys.php Sets categories sortkeys in the page text
  • 'name' - category name,
  • 'sortkey' - the new sortkey
Worker_EditPage_SetInterwikisTargets set_interwikis_targets.php Sets interwikis targets in the page text
  • 'wiki' - interwiki to set the new target to,
  • 'target' - the new target (page title)
Worker_EditPage_UnlinkWikilinks unlink_wikilinks.php Unlinks wikilinks in the page text (replaces them with just the texts they show)
  • Strings or regexparts (please avoid subpatterns if possible, some of them may break the result!)
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
    • 'text' - the text the wikilink shows
  • 'limit' - number of times the wikilink must be unlinked (default: all)
Worker_EditPage_WikilinkTexts wikilink_texts.php Include the given text in newly created wikilinks to somewhere
  • 'text' - the text that must be wikilinked
  • Wikilink pieces
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
  • 'limit' - number of times the text must be wikilinked (default: all)
Worker_EditPage_WikilinkRegexes wikilink_regexes.php Include the text that matches the given regex in newly created wikilinks to somewhere
  • 'regex' - the regex whose matching text must be wikilinked
  • Wikilink pieces
    • 'colon' - if true, start the wikilink with a leading colon
    • 'wiki' - code of the wiki it points to
    • 'namespace' - namespace for the wikilink
    • 'name' - the page name (without the namespace); mandatory!
    • 'anchor' - the location in the page pointed by the wikilink
  • 'limit' - number of times the matching text must be wikilinked (default: all)

Page title workers

These objects work on a data element that is or contains a page title - and more specifically, on the title.

All page title workers are situated in the subdirectory title.

Creating

The typical page edit worker class constructor has the following parameters, in this order:

  • $core - the bot Core object
  • $changes - a single change description, or an array of these
  • $autosubmit = true - whether to auto-append a Page Move writer if this is the line last object

Public properties

The typical page edit worker class constructor has the following public properties:

  • $changes
  • $autosubmit = true

For descriptions, see above.

Page title workers list

Class name Defined in file Function Tasks array member format
Worker_MoveTitle move.php Creates a 'to_title' parameter with the changed title, in the 'writer' signal paramgroup. (Thus, a following Writer_Move line object will rename the wiki page to the 'to_title' value.)
  • 'string' - a string that matches all or part of the title, or
  • 'regex' - a regex that matches all or part of the title
  • 'with' - the string that will replace the match.

See also