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