Assembly line writers

From Apibot
Jump to: navigation, search

There is little good in processing wiki data - or any other - to eventually lose it. The processed data has to be written somewhere - back to the wiki, or in files, or in databases... The assembly line objects that do write the data are called writers.

If a writer object receives a signal that contains a paramgroup named 'writer', the values of the writer object will be set from the parameters in this paramgroup with equivalent names.

All writers files are situated in subdirectories of the directory line/writers.

Writers list

Wiki writers

These write changed data back to the wiki, or change the wiki data in some way determined by the assembly line.

All are situated in the directory line/writers/wiki. Some of them have also Web-based backends in addition to the MediaWiki API-based functionality.

If the signal received contains a paramgroup named 'writer', the values of the receiving writer object will be set from the parameters in it with the same names.

Class name Defined in file What it does Properties
Writer_Wiki_Block block.php Blocks an user
  • $reason - a text that explans, as a comment, the blocking
  • $expiry - an expiry for the block (see the MediaWiki docs for details)
  • $anononly - if true, only anonymous users from the user's IP will be blocked
  • $nocreate - if true, block account's creation from the user's IP
  • $autoblock - if true, will automatically blocks the user's last IP, and any other they will try to log in from
  • $noemail - if true, will prevent the user from sending email through Special:Emailuser.

Also, the username is supplied by the signal data_user() function.

Writer_Wiki_Createaccount
(v0.40.6+)
createaccount.php Creates a new user account
  • $name - the user account name.
  • $password - the password for the user. (Will be ignored if $mailpassword is set to true.)
  • $domain - a domain for the authentication of the user
  • $email - an email address for the user account
  • $realname - the real name of the user whose account is being created
  • $mailpassword - if true, will cause a random password to be generated and sent to the email address specified above. (In this case, the $password setting will be ignored.)
  • $reason - a text that will show in the MediaWiki logs
  • $language - the default language for the new user
Writer_Wiki_DeletePageid delete_pageid.php Deletes a page by pageid
  • $reason - a text that explans, as a comment, the deletion
  • $watch - if true, add the page name to the bot account's watchlist
  • $oldimage - the name of an old image file to delete (as provided by imageinfo's archivename property)

Also, the page pageid is supplied by the signal data_pageid() function.

Writer_Wiki_DeleteTitle delete_title.php Deletes a page by title
  • $reason - a text that explans, as a comment, the deletion
  • $watch - if true, add the page name to the bot account's watchlist
  • $oldimage - the name of an old image file to delete (as provided by imageinfo's archivename property)

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Edit edit.php Edits (submits) a potentially changed page
  • $summary - a description of the changes
  • $section - section No. to edit (0 - top, "new" - new section, leave unset for the entire page)
  • $sectiontitle - title to use while creating new section. (From MW 1.19 on, if this is omitted, the comment will be used.)
  • $is_bot - if true, will mark this edit as bot-made
  • $is_minor - if true, will mark this edit as minor
  • $watch - if true, add the page name to the bot account's watchlist
  • $recreate - if true, If set, suppress errors about the page having been deleted in the meantime and will create it anew
  • $createonly - if true, will not act and return an error if the page already exists
  • $nocreate - if true, will edit only already existing pages (will not create a page)

Also, the page is supplied by the signal data_element() function.

Writer_Wiki_Emailuser emailuser.php Sends an email to the user supplied
  • $subject - a subject line for the message
  • $text - the message body
  • $ccme - if true, will send also a copy to the sender' email

Also, the username is supplied by the signal data_user() function.

Writer_Wiki_ImportInterwiki import_interwiki.php Imports a page from an interwiki-described another wiki
  • $summary - a description of the import
  • $iwcode - code of the interwiki to import from
  • $fullhistory - import the page with the full history
  • $into_namespace - import the page into this namespace
  • $templates - if true, import also the templates transcluded in this page

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_ImportXML import_xml.php Imports page(s) from a XML file
  • $summary - a description of the import
Writer_Wiki_MovePageid move_pageid.php Moves the page with this pageid under a given title
  • $reason - a text that explans, as a comment, the move
  • $to_title - the new title for this page
  • $noredirect - if true, will not leave a redirect under the original page title
  • $movetalk - if true, move also the talk page (if present) with the main one
  • $movesubpages - if true, move also any subpages with the main one
  • $watch - if true, add the page name to the bot account's watchlist

Also, the page pageid is supplied by the signal data_pageid() function.

Writer_Wiki_MoveTitle move_title.php Moves the page with this title under a given title
  • $reason - a text that explans, as a comment, the move
  • $to_title - the new title for this page
  • $noredirect - if true, will not leave a redirect under the original page title
  • $movetalk - if true, move also the talk page (if present) with the main one
  • $movesubpages - if true, move also any subpages with the main one
  • $watch - if true, add the page name to the bot account's watchlist

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Patrol patrol.php Marks a recentchange as patrolled The recentchange ID is supplied by the signal data_rcid() function.
Writer_Wiki_Protect protect.php Marks a page as protected
  • $reason - a text that explans, as a comment, the move
  • $protections - an array with actions as keys and the appropriate minimal access levels (eg. "sysop") to allow for them as values
  • $expiry - an expiry for the protection (see the MediaWiki docs for details)
  • $cascade - if true, protect (with the same protections) also the templates transcluded in this page

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Purge purge.php Purge the page cache The page title is supplied by the signal data_title() function.
Writer_Wiki_Rollback rollback.php Rolls back the last changes to this page, if made by the user given
  • $summary - a description of the rollback
  • $user - username whose changes to rollback
  • $markbot - if true, mark the rollback as made by a bot

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Semiprotect semiprotect.php Marks a page as semi-protected
  • $reason - a text that explans, as a comment, the move
  • $protections - an array with actions as keys and the appropriate minimal access levels (eg. "sysop") to allow for them as values (in this case, 'delete' and 'restore' are "sysop" and all others are "autoconfirmed")
  • $expiry - an expiry for the protection (see the MediaWiki docs for details)
  • $cascade - if true, protect (with the same protections) also the templates transcluded in this page

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Unblock unblock.php Unblocks an user
  • $reason - a text that explans, as a comment, the unblocking
  • $block_id - the id for the block you want to undo, if not the last (can be obtained through the API / bot query for blocks list)

Also, the username is supplied by the signal data_user() function.

Writer_Wiki_Undelete undelete.php Undeletes page revisions (and possibly the entire page);
  • $reason - a text that explans, as a comment, the undeleting
  • $timestamps - timestamps for the revisions that must be undeleted

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Undo undo.php Undoes (removes) a number of page revisions
  • $summary - a description of the changes
  • $undo_revid - revision ID to undo
  • $to_revid - undo back to this revision (but not including it)
  • $is_bot - if true, will mark this undo as bot-made
  • $is_minor - if true, will mark this undo as minor
  • $watch - if true, add the page name to the bot account's watchlist

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Unprotect unprotect.php Marks a page as unprotected
  • $reason - a text that explans, as a comment, the move
  • $protections - an array with actions as keys and the appropriate minimal access levels (eg. "sysop") to allow for them as values (in this case, 'delete' and 'restore' are "sysop", 'edit' is "*" and 'move' and 'rollback' are "autoconfirmed")
  • $expiry - an expiry for the un-protection (see the MediaWiki docs for details)
  • $cascade - if true, unprotect also the templates transcluded in this page

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Unwatch unwatch.php Removes the page from the bot account's watchlist The page title is supplied by the signal data_title() function.
Writer_Wiki_UploadFile upload_file.php Uploads a file to the wiki
  • $comment - a comment for the upload
  • $file_body - the body of the file, in binary form
  • $file - a local filename to read the file from (if $file_body is not set)
  • $text - the text for the future file page (if not set, $comment will be used)
  • $watch - if true, add the page name to the bot account's watchlist
  • $ignorewarnings - if true, ignore the warnings that might be raised by the wiki

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_UploadURL upload_url.php Uploads a file to the wiki by URL
  • $comment - a comment for the upload
  • $url - an URL to take the file from
  • $text - the text for the future file page (if not set, $comment will be used)
  • $watch - if true, add the page name to the bot account's watchlist
  • $ignorewarnings - if true, ignore the warnings that might be raised by the wiki
  • $async - if true, set the asynchronous mode for this file upload

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_UploadURLAsync upload_url.php Uploads a file to the wiki by URL, in asynchronous mode
  • $comment - a comment for the upload
  • $url - an URL to take the file from
  • $text - the text for the future file page (if not set, $comment will be used)
  • $watch - if true, add the page name to the bot account's watchlist
  • $ignorewarnings - if true, ignore the warnings that might be raised by the wiki

Also, the page title is supplied by the signal data_title() function.

Writer_Wiki_Userrights userrights.php Change user rights.
  • $reason - a reason for changing the rights
  • $add_groups - an array with the groups to add
  • $remove_groups - an array with the groups to remove

The username is supplied by the signal data_user() function.

Writer_Wiki_Watch watch.php Adds the page from the bot account's watchlist The page title is supplied by the signal data_title() function.

File writers

These write changed data to local files.

All are situated in the directory line/writers/file.

Class name Defined in file What it writes Properties
Writer_File_CSV csv.php A .CSV file, each data element a line in it, the fields are the selected values in the object, taken as array. Dataobjects are auto-converted to arrays.
  • $filename - a name for the file that must be written
  • $mode - a mode to open the file in (default - "a+")
  • $delimiter - the CSV field delimiter to use (default - a comma)
  • $enclosure - an enclosing sign to put around strings (default - a double quote)
  • $fields - an array with the names of the keys in the data array that must be written in the file as fields, in the order they must be written
Writer_File_Plain plain.php A plain text file, each data element a line in it. Good only for data elements that are strings.
  • $filename - a name for the file that must be written
  • $mode - a mode to open the file in (default - "a+")

DB writers (v0.40.5+)

These write the data into a database. All are situated in the directory line/writers/db.

All support the following properties:

  • $db_params - an array with database parameters:
    • 'host' - the host to connect to (default - localhost)
    • 'port' - the DB port to use (default - the DB default, eg. 3306 for MySQL)
    • 'name' - the database name (required)
    • 'user' - the database user name (required)
    • 'pass' - the database user password (required)
    • 'charset' - the character set to use (default - UTF-8)
  • $write_mode - one of three constants who determine how data will be written:
    • DB_WM_INSERT - data will be inserted
    • DB_WM_UPDATE - present data will be updated, but no new will be inserted
    • DB_WM_INSUPD (default) - present data will be updated, new will be inserted
Class name Defined in file What it writes Additional properties
Writer_MySQL_Table mysql_table.php The data as records in a MySQL table.
  • $table - the name of the table
  • $fields - array with the names of the fields to write (must match data array keys, or the $fields key must match data array key and its value must match the field name to write into)
  • $match_fields - array with the fields whose values must match the data elements in order for data to be considered as present (also permitting for data_key => table_field)
  • $order_by - ORDER BY value for the SELECT that will check for existing data
  • $limit - LIMIT value for the SELECT that will check for existing data

Debug writers

These are designed to help debug assembly line problems. They write the data to the standard output.

All are situated in the directory line/writers/debug.

Class name Defined in file Method of writing Properties
Writer_Echo echo.php Just echoes the data element. Obviously good only with data elements that is strings $print_default - if true, prints the default data element
Writer_Null null.php Outputs nothing.
Writer_PrintR print_r.php Prints the info using the print_r PHP function
  • $print_default - if true, prints the default data element
  • $print_data - if true, prints all data elements
  • $print_signal_params - if true, prints all signal parameters
  • $print_log - if true, prints the signal log
Writer_VarDump var_dump.php Prints the info using the var_dump PHP function
  • $print_default - if true, prints the default data element
  • $print_data - if true, prints all data elements
  • $print_signal_params - if true, prints all signal parameters
  • $print_log - if true, prints the signal log