| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use MediaWiki\Title\Title; |
| 25 |
|
| 26 |
|
| 27 |
require_once __DIR__ . '/Maintenance.php'; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 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 ); |
| 40 |
} |
| 41 |
|
| 42 |
public function execute() { |
| 43 |
$stdin = $this->getStdin(); |
| 44 |
|
| 45 |
while ( !feof( $stdin ) ) { |
| 46 |
$title = trim( fgets( $stdin ) ); |
| 47 |
if ( $title != '' ) { |
| 48 |
$this->purge( $title ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private function purge( $titleText ) { |
| 54 |
$title = Title::newFromText( $titleText ); |
| 55 |
|
| 56 |
if ( $title === null ) { |
| 57 |
$this->error( 'Invalid page title' ); |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 62 |
|
| 63 |
if ( !$this->getOption( 'skip-exists-check' ) && !$page->exists() ) { |
| 64 |
$this->error( "Page doesn't exist" ); |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
if ( $page->doPurge() ) { |
| 69 |
$this->output( "Purged {$titleText}\n" ); |
| 70 |
} else { |
| 71 |
$this->error( "Purge failed for {$titleText}" ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
$maintClass = PurgePage::class; |
| 78 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 79 |
|