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