MediaWiki
master
purgePage.php
Go to the documentation of this file.
1
<?php
10
use
MediaWiki\Maintenance\Maintenance
;
11
use
MediaWiki\Title\Title
;
12
13
// @codeCoverageIgnoreStart
14
require_once __DIR__ .
'/Maintenance.php'
;
15
// @codeCoverageIgnoreEnd
16
22
class
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;
65
require_once RUN_MAINTENANCE_IF_MAIN;
66
// @codeCoverageIgnoreEnd
MediaWiki\Maintenance\Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:65
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:486
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:266
MediaWiki\Maintenance\Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition
Maintenance.php:300
MediaWiki\Maintenance\Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition
Maintenance.php:513
MediaWiki\Maintenance\Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:680
MediaWiki\Maintenance\Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition
Maintenance.php:458
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:336
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:69
PurgePage
Maintenance script that purges a list of pages passed through stdin.
Definition
purgePage.php:22
PurgePage\__construct
__construct()
Default constructor.
Definition
purgePage.php:23
PurgePage\execute
execute()
Do the actual work.
Definition
purgePage.php:29
$maintClass
$maintClass
Definition
purgePage.php:64
maintenance
purgePage.php
Generated on Sat Feb 14 2026 04:28:58 for MediaWiki by
1.10.0