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\Title\Title
;
26 // @codeCoverageIgnoreStart
27 require_once __DIR__
. '/Maintenance.php';
28 // @codeCoverageIgnoreEnd
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 ) );
48 $this->purge( $title );
53 private function purge( $titleText ) {
54 $title = Title
::newFromText( $titleText );
56 if ( $title === null ) {
57 $this->error( 'Invalid page title' );
61 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
63 if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
64 $this->error( "Page doesn't exist" );
68 if ( $page->doPurge() ) {
69 $this->output( "Purged {$titleText}\n" );
71 $this->error( "Purge failed for {$titleText}" );
76 // @codeCoverageIgnoreStart
77 $maintClass = PurgePage
::class;
78 require_once RUN_MAINTENANCE_IF_MAIN
;
79 // @codeCoverageIgnoreEnd