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
21 * @ingroup Maintenance
24 use MediaWiki\MediaWikiServices
;
26 require_once __DIR__
. '/Maintenance.php';
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 ) );
46 $this->purge( $title );
51 private function purge( $titleText ) {
52 $title = Title
::newFromText( $titleText );
54 if ( $title === null ) {
55 $this->error( 'Invalid page title' );
59 $page = MediaWikiServices
::getInstance()->getWikiPageFactory()->newFromTitle( $title );
61 if ( $page === null ) {
62 $this->error( "Could not instantiate page object" );
66 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
67 $this->error( "Page doesn't exist" );
71 if ( $page->doPurge() ) {
72 $this->output( "Purged {$titleText}\n" );
74 $this->error( "Purge failed for {$titleText}" );
79 $maintClass = PurgePage
::class;
80 require_once RUN_MAINTENANCE_IF_MAIN
;