Manual:Writing maintenance scripts/ja

Version 1.16 of MediaWiki introduced the maintenance class to make it easier to write command-line MediaWiki maintenance scripts.

''これは、ステップバイステップのチュートリアルとして書かれている. ''

スクリプトの例
To describe writing these maintenance scripts, we'll walk through an helloWorld.php, a 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):

The program will just print out “Hello, World!” but already has a --help (and other command line options). Sample output:

 $ 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 概要:


 * 行 12
 * Of course, if we're going to write a maintenance script, we have to include Maintenance.php. This takes care of setting up Autoloading and the like.  It is best to use the full path to Maintenance.php.


 * 行 14
 * We override Maintenance class and then, in


 * 行 20、21
 * tell the Maintenance class to run the script using the HelloWorld class, only if being executed from the command line.


 * 行 15
 * The execute function that we've provided is executed.

オプションと引数の解析
世界挨拶すると、すべてが順調と良いですが、私たちも、個人を迎えることができるようにしたい.

To add an option, add a constructor with a call addOption and update the execute</tt> method to use the new option. addOption's parameters are $name, $description, $required = false, $withArg = false, $shortName = false:

This time, when executed, the output of the helloWorld.php</tt> script changes depending on the argument provided:

<pre style="overflow:auto;"> $ 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