Dataobject class

From Apibot
Jump to: navigation, search

Apibot fetches most wiki data elements as arrays, but can auto-convert them to objects belonging to descendants of the class Dataobject. This allows supplying them some convenient methods.

Dataobject<code>

This is the root for all wiki data object classes in Apibot.

Creating

Creating an object of this class requires two parameters:

  • <code>$core - an object of the Core class.
  • $data - the wiki data element

Public functions

  • $data() - returns the wiki data element, in its original form

List elements classes

These match the wiki elements returned by API Query lists.

Currently none of them has functionality different than that of the generic Dataobject class.

Image

Usercontrib

Recentchange

User

Block

Logevent

ProtectedTitle

PageWithExtlink

PageFromWatchlist

PageFromList

Page properties classes

These match the page properties returned by some API Queries.

Currently none of them has functionality different than that of the generic Dataobject class.

Page_Revision

Page_Category

Page_Imageinfo

Page_Langlink

Page_Link

Page_Template

Page_Image

Page_Extlink

Page_Duplicatefile

Page_Globalusage

Page

This class is used for wiki page objects, mostly intended to be edited. Has a lot of suitable methods.

Creating

Creating an object of this class requires two parameters:

  • $core - an object of the Core class
  • $title - the page title (will also accept a page array, fetched from the wiki)

If $title is only a page title string, will accept also a third parameter, if given - the page text.

Public properties

  • $text_sections - an array that will keep the page text sections, if the text is splitted into them.

Public methods

Info

  • is_redirect() - true if the page text indicates that it is a redirect, false if it does not.
  • redirects_to() - the title of the page this one redirects to, or NULL if the page text indicates that it is not a redirect.
  • is_main() - true if the page title indicates that it is a main (non-talk) namespace page, false if it does not.
  • is_talk() - true if the page title indicates that it is a talk namespace page, false if it does not.
  • is_special() - true if the page title indicates that it is a special namespace page, false if it does not.
  • talk_page_title() - the title of the talk page that belongs to this non-talk page
  • main_page_title() - the title of the main page that this talk page belongs to

Editing the page text

These functions edit (or return results from) the page text. They will not return or change properties that do not depend on it. For example, they will not detect or change categories that are part not of this page text, but of a template transcluded in it.

General
  • regex_exists ( $regex ) - the count of the matches found for this regex, false if error occurred
  • string_exists ( $string ) - true if this string exists in the page text, false if it does not
  • replace_regex ( $regex, $with, $limit = -1 ) - replaces in the text this regex with this string this number of times (-1 - unlimited)
  • replace_string ( $string, $with ) - replaces in the text the first parameter, as string, with the second
  • append ( $text ) - adds this text after the end of the current page text
  • prepend ( $text ) - prefaces this text before the end of the current page text
  • insert ( $text, $regexpart_before = NULL, $regexpart_after = NULL, $limit = -1 ) - inserts this text in the current page text, after a string that matches the regex part $regexpart_before (if not NULL), and before a string that matches the regex part $regexpart_after (if not NULL), $limit number of times (-1 - unlimited)
  • delete ( $regex, $limit = -1 ) - deleted in the text this regex this number of times (-1 - unlimited)
Wikilinks
  • wikilinks_strings ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL ) - all wikilinks strings that match the set of the supplied params for the different wikilink parts ($colon is boolean, all other params are regex parts)
  • wikilinks ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL ) - all wikilinks that match the set of the supplied params (see above), as arrays of wikilink parts
  • wikilink_exists ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL ) - true if a wikilink that matches the set of the supplied params exists, false if it does not
  • replace_wikilink ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $with = NULL, $limit = -1 ) - replace a wikilink that matches the set of the supplied params with $with, $limit number of times (-1 - unlimited)
  • unlink_wikilink ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $limit = -1 ) - unlink (turn into an ordinary text) a wikilink that matches the set of the supplied params, $limit number of times (-1 - unlimited)
  • wikilink_text_by_regex ( $regex, $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $limit = 1 ) - turn the text matched by $regex into a wikilink with the set of the supplied params, $limit number of times (-1 - unlimited)
  • wikilink_text ( $text, $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $limit = 1 ) - turn $text into a wikilink with the set of the supplied params, $limit number of times (-1 - unlimited)
  • replace_wikilink_target ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $new_target = NULL, $limit = 1 ) - replace the target of the wikilink with the set of the supplied params with $new_target, $limit number of times (-1 - unlimited)
  • replace_wikilink_text ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $new_text = NULL, $limit = 1 ) - replace the text of the wikilink with the set of the supplied params with $new_text, $limit number of times (-1 - unlimited)
  • add_wikilink ( $wikilink, $regexpart_before = NULL, $regexpart_after = NULL, $limit = -1 ) - inserts this wikilink (passed as string or array) in the current page text, after a string that matches the regex part $regexpart_before (if not NULL), and before a string that matches the regex part $regexpart_after (if not NULL), $limit number of times (-1 - unlimited)
  • delete_wikilink ( $colon = NULL, $wiki = NULL, $namespace = NULL, $name = NULL, $anchor = NULL, $text = NULL, $limit = -1 ) - delete a wikilink that matches the set of the supplied params, $limit number of times (-1 - unlimited)
Categories
  • categories_strings ( $name = NULL, $sortkey = NULL, $namespace = NULL, $newline_after = NULL ) - all categories strings that match the set of the supplied params for the different category title parts ($newline_after is boolean, all other params are regex parts)
  • categories ( $name = NULL, $sortkey = NULL, $namespace = NULL, $newline_after = NULL ) - all categories that match the set of the supplied params (see above), as arrays of category title parts
  • categories_names ( $name = NULL, $sortkey = NULL, $namespace = NULL ) - the names of all categories that match the set of the supplied params (see above)
  • categories_titles ( $name = NULL, $sortkey = NULL, $namespace = NULL ) - the titles of all categories that match the set of the supplied params (see above)
  • category_exists ( $name = NULL, $sortkey = NULL, $namespace = NULL ) - true if a category that matches the set of the supplied params exists, false if it does not
  • add_category_string ( $string ) - add this category (as string) to the text
  • add_category ( $name, $sortkey = NULL, $namespace = NULL, $newline_after = NULL ) - add this category to the text (as separate parts, or as an array with category parts or full string supplied as the first argument)
  • add_categories ( $categories ) - add this array of categories (strings or arrays with category parts) to the text
  • delete_categories ( $name = NULL ) - delete the categories matching this string or regexpart, or array of category parts (who can be regex parts)
  • extract_categories_strings ( $name = NULL ) - returns the categories strings matching this string or regexpart, or array of category parts (who can be regex parts)
  • extract_categories ( $name = NULL ) - returns the categories (as arrays of parts) matching this string or regexpart, or array of category parts (who can be regex parts)
  • replace_category ( $old_name, $new_name, $new_sortkey = NULL ) - replace a category that matches the old name (or regexpart, or array of category parts or regexparts) with $with, $limit number of times (-1 - unlimited)
  • category_sortkey ( $name ) - return the sortkey of the category with this name (or category parts or regexparts) array
  • set_category_sortkey ( $name, $new_sortkey ) - return the sortkey of the category with this name (or category parts or regexparts) array
  • delete_category_sortkey ( $name ) - remove the sortkey of the category with this name (or category parts or regexparts) array
Interwikis
  • interwikis_strings ( $name = '*', $namespace = NULL, $name = NULL, $newline_after = NULL ) - all interwikis strings that match the set of the supplied params for the different interwiki parts ($newline_after is boolean, all other params are regex parts)
  • interwikis ( $name = '*', $namespace = NULL, $name = NULL, $newline_after = NULL ) - all interwikis that match the set of the supplied params (see above), as arrays of interwiki parts
  • interwiki_exists ( $name = '*', $namespace = NULL, $name = NULL, $newline_after = NULL ) - true if an interwiki that matches the set of the supplied params exists, false if it does not
  • interwiki_target ( $wiki ) - the target (page title) of this interwiki (NULL if it does not exist)
  • add_interwiki_string ( $string ) - add this interwiki (as string) to the text
  • add_interwiki ( $name = '*', $namespace = NULL, $name = NULL, $newline_after = NULL ) - add this interwiki to the text (as separate parts, or as an array with interwiki parts or full string supplied as the first argument)
  • add_interwiki ( $interwikis ) - add this array of interwikis (strings or arrays with interwiki parts) to the text
  • delete_interwikis ( $name = "*" ) - delete the interwikis matching this string or regexpart, or array of interwiki parts (who can be regex parts)
  • extract_interwikis_strings ( $wiki = "*" ) - returns the interwikis strings matching this string or regexpart, or array of interwiki parts (who can be regex parts)
  • extract_interwikis ( $wiki = "*" ) - returns the interwikis (as arrays of parts) matching this string or regexpart, or array of interwiki parts (who can be regex parts)
  • replace_interwiki ( $old_wiki, $new_wiki, $new_title ) - replace an interwiki that matches the old name (or regexpart, or array of interwiki parts or regexparts) with $with, $limit number of times (-1 - unlimited)
  • set_interwiki_target ( $wiki, $new_target ) - return the sortkey of the interwiki with this name (or interwiki parts or regexparts) array
Filelinks
  • filelinks_strings ( $name = NULL, $namespace = NULL ) - all filelinks strings that match the set of the supplied params for the different filelink parts (who can be regex parts)
  • filelinks ( $name = NULL, $namespace = NULL ) - all filelinks that match the set of the supplied params (see above), as arrays of filelink parts
  • filelink_exists ( $name = NULL, $namespace = NULL ) - true if a filelink that matches the set of the supplied params exists, false if it does not
  • replace_filelink ( $name, $with, $limit = -1 ) - replace a filelink that matches the old name (or regexpart, or array of filelink parts or regexparts) with $with, $limit number of times (-1 - unlimited)
  • replace_filelink_name ( $old_name, $new_name, $old_namespace = NULL, $new_namespace = NULL, $limit = -1 ) - replace the name of a filelink that matches the old name (or regexpart, or array of filelink parts or regexparts) with $with, $limit number of times (-1 - unlimited)
  • replace_filelink_param ( $name, $param, $new_value, $namespace = NULL ) - replace the value of a param of the filelink that matches the old name (or regexpart, or array of filelink parts or regexparts) with $new_value
  • replace_filelink_caption ( $name, $new_caption, $namespace = NULL ) - replace the caption of the filelink that matches this name (or regexpart, or array of filelink parts or regexparts) with $new_caption
  • add_filelink ( $filelink, $regexpart_before = NULL, $regexpart_after = NULL, $limit = -1 ) - insert this filelink after a match for $regexpart_before who is followed by a match for $regexpart_after, $limit number of times (-1 - unlimited)
  • delete_filelink ( $name, $namespace = NULL, $limit = -1 ) - delete a filelink that matches this name (or regexpart, or array of filelink parts or regexparts) and namespace, $limit number of times (-1 - unlimited)
Templates
  • templates_strings ( $name = NULL ) - the strings of all templates that match this name (who can be regex part)
  • templates ( $name = NULL ) - all templates that match this name (see above), as template structure arrays
  • template_exists ( $name = NULL, $namespace = NULL, $wiki = NULL ) - true if a template that matches the set of the supplied params exists, false if it does not
  • replace_template ( $name, $new_template, $limit = -1 ) - replace a template with this name (or regexpart) with $new_template, $limit number of times (-1 - unlimited)
  • replace_template_name ( $old_name, $new_name, $limit = -1 ) - replace the name of a template with this name (or regexpart) with $new_name, $limit number of times (-1 - unlimited)
  • replace_template_paramname ( $name, $paramname, $new_name ) - replace in template with this name the paramname (or regexpart) with $new_name
  • replace_template_paramvalue ( $name, $paramname, $new_value ) - replace in template with this name the value of this paramname (or regexpart) with $new_value
  • add_template ( $template, $regexpart_before = NULL, $regexpart_after = NULL, $limit = -1 ) - insert this template after a match for $regexpart_before and before a match for $regexpart_after, $limit number of times (-1 - unlimited)
  • delete_template ( $name, $limit = -1 ) - delete a template that matches this name (or regexpart), $limit number of times (-1 - unlimited)
Sections
  • text_to_sections ( $text ) - parse this text to wiki page sections structure and return it
  • sections_to_text ( $sections ) - parse this wiki page sections structure into text and return it
  • to_sections() - parse the page text into wiki page sections structure and assign it to the $text_sections property (and unset the page text)
  • from_sections() - read a wiki page sections structure from the $text_sections property and rebuild the page text from it (and unset the $text_sections property)
  • section_no_by_header ( $header ) - return the number of the section with this header, false if a section with this header was not found, or NULL if the page text was not parsed into sections
  • section_by_header ( $header ) - return the array structure of the section with this header, false if a section with this header was not found, or NULL if the page text was not parsed into sections
  • section_with_subs ( $section_no ) - return an array containing the section with this number and all of its subsections, false if a section with this number was not found, or NULL if the page text was not parsed into sections
  • section_with_subs_by_header ( $header ) - return an array containing the section with this header and all of its subsections, false if a section with this header was not found, or NULL if the page text was not parsed into sections
  • modify_section_level ( $no, $by, $with_subs = true ) - changes the section level of the section with this number, by $by (positive or negative), and of all its subsections if $with_subs is true
  • modify_section_level_by_header ( $header, $by, $with_subs = true ) - changes the section level of the section with this header, by $by (positive or negative), and of all its subsections if $with_subs is true
  • set_section_level ( $no, $level, $with_subs = true ) - sets the section level of the section with this number, to $level, and of all its subsections if $with_subs is true
  • set_section_level_by_header ( $header, $level, $with_subs = true ) - sets the section level of the section with this header, to $level, and of all its subsections if $with_subs is true
  • insert_sections ( $sections, $no ) - insert these sections after the section with this number
  • insert_section ( $section, $no ) - insert this section after the section with this number
  • insert_sections_after_section_with_header ( $sections, $header ) - insert these sections after the section with this header
  • insert_section_after_section_with_header ( $section, $header ) - insert this section after the section with this header
  • delete_section ( $no, $with_subs = true ) - delete the section with this number
  • delete_section_by_header ( $header, $with_subs = true ) - delete the section with this header
  • move_section ( $current_no, $after_no, $with_subs = true ) - move the section with this number after the section with $after_no
  • move_section_by_header ( $header, $after_no, $with_subs = true ) - move the section with this header after the section with $after_no
  • move_section_after_section_with_header ( $header, $after_header, $with_subs = true ) - move the section with this header after the section with $after_header
Lists
  • add_list ( $list_array, $ordered_list = false, $regexpart_before = NULL, $regexpart_after = NULL ) - insert this list after a match for $regexpart_before and before a match for $regexpart_after
Misc
  • neat() - tries to make the page text a bit neater