maintenance.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.
  4. 1. Directory structure
  5. 2. How to run a script
  6. 3. How to write your own
  7. 1. DIRECTORY STRUCTURE
  8. The /maintenance directory of a MediaWiki installation contains several
  9. subdirectories, all of which have unique purposes.
  10. 2. HOW TO RUN A SCRIPT
  11. Ridiculously simple, just call 'php someScript.php' that's in the top-
  12. level /maintenance directory.
  13. Example:
  14. php clearCacheStats.php
  15. The following parameters are available to all maintenance scripts
  16. --help : Print a help message
  17. --quiet : Quiet non-error output
  18. --dbuser : The database user to use for the script (if needed)
  19. --dbpass : Same as above (if needed)
  20. --conf : Location of LocalSettings.php, if not default
  21. --wiki : For specifying the wiki ID
  22. --batch-size : If the script supports batch operations, do this many per batch
  23. 3. HOW TO WRITE YOUR OWN
  24. Make a file in the maintenance directory called myScript.php or something.
  25. In it, write the following:
  26. ==BEGIN==
  27. <?php
  28. require_once 'Maintenance.php';
  29. class DemoMaint extends Maintenance {
  30. public function __construct() {
  31. parent::__construct();
  32. }
  33. public function execute() {
  34. }
  35. }
  36. $maintClass = "DemoMaint";
  37. require_once RUN_MAINTENANCE_IF_MAIN;
  38. ==END==
  39. That's it. In the execute() method, you have access to all of the normal
  40. MediaWiki functions, so you can get a DB connection, use the cache, etc.
  41. For full docs on the Maintenance class, see the auto-generated docs at
  42. https://doc.wikimedia.org/mediawiki-core/master/php/html/classMaintenance.html