Manual:Writing maintenance scripts/pt-br

This is a step-by-step tutorial on writing a maintenance script based on the  class (see ) which was introduced in MediaWiki 1.16 to make it easier to write command-line MediaWiki maintenance scripts.

Exemplo de script
We'll walk through a helloWorld.php maintenance script that simply prints “Hello, World”. This program contains the minimum amount of code needed to run as well as the expected copyright header (for alternative headers, see copyright headers):

O programa simplesmente imprimirá “Hello, World!” porém já possui um parâmetro --help (e outras opções de linha de comando). Saída de exemplo:

 $ php helloWorld.php Hello, World! $ php helloWorld.php --help

Usage: php helloWorld.php [--conf|--dbpass|--dbuser|--globals|--help|--quiet|--wiki] conf : Location of LocalSettings.php, if not default dbpass : The password to use for this script dbuser : The DB user to use for this script globals : Output globals at the end of processing for debugging help : Display this help message quiet : Whether to supress non-error output wiki : For specifying the wiki ID

Uma visão geral:


 * We include Maintenance.php. This defines the   which has method to parse arguments, read the console, get the database, etc.  It is best to use the full path to Maintenance.php.


 * Nós substituímos a classe Maintenance e, em seguida, em


 * dizemos para a classe Maintenance executar o script usando a classe HelloWorld, somente se for executado a partir da linha de comando.

Internally,  loads another file  which autoloads MediaWiki classes and configuration, and then


 * The execute function that we've defined is executed, and our script does its work.

Análise de opções e argumentos
Cumprimentar o mundo está tudo bem, mas nós queremos ser capazes de cumprimentar as pessoas, também.

To add a command-line option, add a constructor to  that calls  's   and update the   method to use the new option. 's parameters are, so:

Desta vez, quando executado, a saída do script helloWorld.php muda, dependendo do argumento fornecido:

 $ php helloWorld.php Hello, World! $ php helloWorld.php --name=Mark Hello, Mark! $ php helloWorld.php --help Usage: php helloWorld.php [--conf|--dbpass|--dbuser|--globals|--help|--name|--quiet|--wiki] …   name : Who to say Hello to