MediaWiki  master
purgePage.php
Go to the documentation of this file.
1 <?php
25 
26 require_once __DIR__ . '/Maintenance.php';
27 
33 class 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 = MediaWikiServices::getInstance()->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;
75 require_once RUN_MAINTENANCE_IF_MAIN;
PurgePage
Maintenance script that purges a list of pages passed through stdin.
Definition: purgePage.php:33
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:382
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:407
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:195
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
$maintClass
$maintClass
Definition: purgePage.php:74
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
PurgePage\execute
execute()
Do the actual work.
Definition: purgePage.php:40
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:249
$title
$title
Definition: testCompression.php:38
PurgePage\__construct
__construct()
Default constructor.
Definition: purgePage.php:34
PurgePage\purge
purge( $titleText)
Definition: purgePage.php:51
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:286
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:464
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435