Updating composer/semver (1.5.1 => 1.5.2)
[mediawiki.git] / maintenance / purgePage.php
bloba793174fa5037fbcb403aedc8afd491969d52df0
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\MediaWikiServices;
26 require_once __DIR__ . '/Maintenance.php';
28 /**
29 * Maintenance script that purges a list of pages passed through stdin
31 * @ingroup Maintenance
33 class 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 );
40 public function execute() {
41 $stdin = $this->getStdin();
43 while ( !feof( $stdin ) ) {
44 $title = trim( fgets( $stdin ) );
45 if ( $title != '' ) {
46 $this->purge( $title );
51 private function purge( $titleText ) {
52 $title = Title::newFromText( $titleText );
54 if ( $title === null ) {
55 $this->error( 'Invalid page title' );
56 return;
59 $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
61 if ( $page === null ) {
62 $this->error( "Could not instantiate page object" );
63 return;
66 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
67 $this->error( "Page doesn't exist" );
68 return;
71 if ( $page->doPurge() ) {
72 $this->output( "Purged {$titleText}\n" );
73 } else {
74 $this->error( "Purge failed for {$titleText}" );
79 $maintClass = PurgePage::class;
80 require_once RUN_MAINTENANCE_IF_MAIN;