MediaWiki master
purgePage.php
Go to the documentation of this file.
1<?php
12
13// @codeCoverageIgnoreStart
14require_once __DIR__ . '/Maintenance.php';
15// @codeCoverageIgnoreEnd
16
22class PurgePage extends Maintenance {
23 public function __construct() {
24 parent::__construct();
25 $this->addDescription( 'Purge page.' );
26 $this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
27 }
28
29 public function execute() {
30 $stdin = $this->getStdin();
31
32 while ( !feof( $stdin ) ) {
33 $title = trim( fgets( $stdin ) );
34 if ( $title != '' ) {
35 $this->purge( $title );
36 }
37 }
38 }
39
40 private function purge( string $titleText ) {
41 $title = Title::newFromText( $titleText );
42
43 if ( $title === null ) {
44 $this->error( 'Invalid page title' );
45 return;
46 }
47
48 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
49
50 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
51 $this->error( "Page doesn't exist" );
52 return;
53 }
54
55 if ( $page->doPurge() ) {
56 $this->output( "Purged {$titleText}\n" );
57 } else {
58 $this->error( "Purge failed for {$titleText}" );
59 }
60 }
61}
62
63// @codeCoverageIgnoreStart
64$maintClass = PurgePage::class;
65require_once RUN_MAINTENANCE_IF_MAIN;
66// @codeCoverageIgnoreEnd
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
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.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:69
Maintenance script that purges a list of pages passed through stdin.
Definition purgePage.php:22
__construct()
Default constructor.
Definition purgePage.php:23
execute()
Do the actual work.
Definition purgePage.php:29
$maintClass
Definition purgePage.php:64