MediaWiki
master
purgePage.php
Go to the documentation of this file.
1
<?php
24
use
MediaWiki\Maintenance\Maintenance
;
25
use
MediaWiki\Title\Title
;
26
27
// @codeCoverageIgnoreStart
28
require_once __DIR__ .
'/Maintenance.php'
;
29
// @codeCoverageIgnoreEnd
30
36
class
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;
79
require_once RUN_MAINTENANCE_IF_MAIN;
80
// @codeCoverageIgnoreEnd
MediaWiki\Maintenance\Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:78
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:493
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:273
MediaWiki\Maintenance\Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition
Maintenance.php:307
MediaWiki\Maintenance\Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition
Maintenance.php:524
MediaWiki\Maintenance\Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:691
MediaWiki\Maintenance\Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition
Maintenance.php:465
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:343
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:78
PurgePage
Maintenance script that purges a list of pages passed through stdin.
Definition
purgePage.php:36
PurgePage\__construct
__construct()
Default constructor.
Definition
purgePage.php:37
PurgePage\execute
execute()
Do the actual work.
Definition
purgePage.php:43
$maintClass
$maintClass
Definition
purgePage.php:78
maintenance
purgePage.php
Generated on Mon Dec 30 2024 13:27:24 for MediaWiki by
1.10.0