MediaWiki REL1_41
purgePage.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/Maintenance.php';
27
33class PurgePage extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Purge page.' );
37 $this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
38 }
39
40 public function execute() {
41 $stdin = $this->getStdin();
42
43 while ( !feof( $stdin ) ) {
44 $title = trim( fgets( $stdin ) );
45 if ( $title != '' ) {
46 $this->purge( $title );
47 }
48 }
49 }
50
51 private function purge( $titleText ) {
52 $title = Title::newFromText( $titleText );
53
54 if ( $title === null ) {
55 $this->error( 'Invalid page title' );
56 return;
57 }
58
59 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
60
61 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
62 $this->error( "Page doesn't exist" );
63 return;
64 }
65
66 if ( $page->doPurge() ) {
67 $this->output( "Purged {$titleText}\n" );
68 } else {
69 $this->error( "Purge failed for {$titleText}" );
70 }
71 }
72}
73
74$maintClass = PurgePage::class;
75require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Represents a title within MediaWiki.
Definition Title.php:76
Maintenance script that purges a list of pages passed through stdin.
Definition purgePage.php:33
__construct()
Default constructor.
Definition purgePage.php:34
execute()
Do the actual work.
Definition purgePage.php:40
$maintClass
Definition purgePage.php:74