MediaWiki master
purgePage.php
Go to the documentation of this file.
1<?php
26
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/Maintenance.php';
29// @codeCoverageIgnoreEnd
30
36class PurgePage extends Maintenance {
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Purge page.' );
40 $this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
41 }
42
43 public function execute() {
44 $stdin = $this->getStdin();
45
46 while ( !feof( $stdin ) ) {
47 $title = trim( fgets( $stdin ) );
48 if ( $title != '' ) {
49 $this->purge( $title );
50 }
51 }
52 }
53
54 private function purge( $titleText ) {
55 $title = Title::newFromText( $titleText );
56
57 if ( $title === null ) {
58 $this->error( 'Invalid page title' );
59 return;
60 }
61
62 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
63
64 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
65 $this->error( "Page doesn't exist" );
66 return;
67 }
68
69 if ( $page->doPurge() ) {
70 $this->output( "Purged {$titleText}\n" );
71 } else {
72 $this->error( "Purge failed for {$titleText}" );
73 }
74 }
75}
76
77// @codeCoverageIgnoreStart
78$maintClass = PurgePage::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
80// @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:78
Maintenance script that purges a list of pages passed through stdin.
Definition purgePage.php:36
__construct()
Default constructor.
Definition purgePage.php:37
execute()
Do the actual work.
Definition purgePage.php:43
$maintClass
Definition purgePage.php:78