Update git submodules
[mediawiki.git] / docs / maintenance.txt
blobc363d8666422e101a2263b86f4f664301d59f7f3
1 Prior to version 1.16, maintenance scripts were a hodgepodge of code that
2 had no cohesion or formal method of action. Beginning in 1.16, maintenance
3 scripts have been cleaned up to use a unified class.
5 1. Directory structure
6 2. How to run a script
7 3. How to write your own
9 1. DIRECTORY STRUCTURE
10   The /maintenance directory of a MediaWiki installation contains several
11 subdirectories, all of which have unique purposes.
13 2. HOW TO RUN A SCRIPT
14   Ridiculously simple, just call 'php someScript.php' that's in the top-
15 level /maintenance directory.
17 Example:
18   php clearCacheStats.php
19   
20 The following parameters are available to all maintenance scripts
21 --help   : Print a help message
22 --quiet  : Quiet non-error output
23 --dbuser : The database user to use for the script (if needed)
24 --dbpass : Same as above (if needed)
25 --conf   : Location of LocalSettings.php, if not default
26 --wiki   : For specifying the wiki ID
27 --batch-size : If the script supports batch operations, do this many per batch
29 3. HOW TO WRITE YOUR OWN
30 Make a file in the maintenance directory called myScript.php or something.
31 In it, write the following:
33 ==BEGIN==
35 <?php
37 require_once 'Maintenance.php';
39 class DemoMaint extends Maintenance {
41   public function __construct() {
42     parent::__construct();
43   }
45   public function execute() {
46   }
49 $maintClass = DemoMaint::class;
50 require_once RUN_MAINTENANCE_IF_MAIN;
52 ==END==
54 That's it. In the execute() method, you have access to all of the normal
55 MediaWiki functions, so you can get a DB connection, use the cache, etc.
56 For full docs on the Maintenance class, see the auto-generated docs at
57 https://doc.wikimedia.org/mediawiki-core/master/php/classMaintenance.html