Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PurgePage
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 purge
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Purges a specific page.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24use MediaWiki\Title\Title;
25
26require_once __DIR__ . '/Maintenance.php';
27
28/**
29 * Maintenance script that purges a list of pages passed through stdin
30 *
31 * @ingroup Maintenance
32 */
33class PurgePage extends Maintenance {
34    public function __construct() {
35        parent::__construct();
36        $this->addDescription( 'Purge page.' );
37        $this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
38    }
39
40    public function execute() {
41        $stdin = $this->getStdin();
42
43        while ( !feof( $stdin ) ) {
44            $title = trim( fgets( $stdin ) );
45            if ( $title != '' ) {
46                $this->purge( $title );
47            }
48        }
49    }
50
51    private function purge( $titleText ) {
52        $title = Title::newFromText( $titleText );
53
54        if ( $title === null ) {
55            $this->error( 'Invalid page title' );
56            return;
57        }
58
59        $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
60
61        if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
62            $this->error( "Page doesn't exist" );
63            return;
64        }
65
66        if ( $page->doPurge() ) {
67            $this->output( "Purged {$titleText}\n" );
68        } else {
69            $this->error( "Purge failed for {$titleText}" );
70        }
71    }
72}
73
74$maintClass = PurgePage::class;
75require_once RUN_MAINTENANCE_IF_MAIN;