Merge "Update to Shellbox 4.1.0"
[mediawiki.git] / maintenance / purgePage.php
blobf592517ec5568d319138d3047b548e538dce3e9c
1 <?php
2 /**
3 * Purges a specific page.
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.
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.
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
20 * @file
21 * @ingroup Maintenance
24 use MediaWiki\Title\Title;
26 // @codeCoverageIgnoreStart
27 require_once __DIR__ . '/Maintenance.php';
28 // @codeCoverageIgnoreEnd
30 /**
31 * Maintenance script that purges a list of pages passed through stdin
33 * @ingroup Maintenance
35 class PurgePage extends Maintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Purge page.' );
39 $this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
42 public function execute() {
43 $stdin = $this->getStdin();
45 while ( !feof( $stdin ) ) {
46 $title = trim( fgets( $stdin ) );
47 if ( $title != '' ) {
48 $this->purge( $title );
53 private function purge( $titleText ) {
54 $title = Title::newFromText( $titleText );
56 if ( $title === null ) {
57 $this->error( 'Invalid page title' );
58 return;
61 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
63 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
64 $this->error( "Page doesn't exist" );
65 return;
68 if ( $page->doPurge() ) {
69 $this->output( "Purged {$titleText}\n" );
70 } else {
71 $this->error( "Purge failed for {$titleText}" );
76 // @codeCoverageIgnoreStart
77 $maintClass = PurgePage::class;
78 require_once RUN_MAINTENANCE_IF_MAIN;
79 // @codeCoverageIgnoreEnd