2017-06-30 10:23:02 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Purges a specific page.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2020-11-12 20:36:35 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2017-06-30 10:23:02 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2017-06-30 10:23:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maintenance script that purges a list of pages passed through stdin
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
class PurgePage extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addDescription( 'Purge page.' );
|
|
|
|
|
$this->addOption( 'skip-exists-check', 'Skip page existence check', false, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$stdin = $this->getStdin();
|
|
|
|
|
|
|
|
|
|
while ( !feof( $stdin ) ) {
|
|
|
|
|
$title = trim( fgets( $stdin ) );
|
|
|
|
|
if ( $title != '' ) {
|
|
|
|
|
$this->purge( $title );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 09:03:22 +00:00
|
|
|
private function purge( $titleText ) {
|
|
|
|
|
$title = Title::newFromText( $titleText );
|
2017-06-30 10:23:02 +00:00
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2017-06-30 10:23:02 +00:00
|
|
|
$this->error( 'Invalid page title' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2017-06-30 10:23:02 +00:00
|
|
|
|
|
|
|
|
if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) {
|
|
|
|
|
$this->error( "Page doesn't exist" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $page->doPurge() ) {
|
2018-06-04 09:03:22 +00:00
|
|
|
$this->output( "Purged {$titleText}\n" );
|
2017-06-30 10:23:02 +00:00
|
|
|
} else {
|
2018-06-04 09:03:22 +00:00
|
|
|
$this->error( "Purge failed for {$titleText}" );
|
2017-06-30 10:23:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = PurgePage::class;
|
2017-06-30 10:23:02 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|