Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PurgePage
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 purge
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2/**
3 * Purges a specific page.
4 *
5 * @license GPL-2.0-or-later
6 * @file
7 * @ingroup Maintenance
8 */
9
10use MediaWiki\Maintenance\Maintenance;
11use MediaWiki\Title\Title;
12
13// @codeCoverageIgnoreStart
14require_once __DIR__ . '/Maintenance.php';
15// @codeCoverageIgnoreEnd
16
17/**
18 * Maintenance script that purges a list of pages passed through stdin
19 *
20 * @ingroup Maintenance
21 */
22class 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;
65require_once RUN_MAINTENANCE_IF_MAIN;
66// @codeCoverageIgnoreEnd