| 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 |
use MediaWiki\User\User; |
| 26 |
|
| 27 |
|
| 28 |
require_once __DIR__ . '/Maintenance.php'; |
| 29 |
|
| 30 |
|
| 31 |
class Undelete extends Maintenance { |
| 32 |
public function __construct() { |
| 33 |
parent::__construct(); |
| 34 |
$this->addDescription( 'Undelete a page' ); |
| 35 |
$this->addOption( 'user', 'The user to perform the undeletion', false, true, 'u' ); |
| 36 |
$this->addOption( 'reason', 'The reason to undelete', false, true, 'r' ); |
| 37 |
$this->addArg( 'pagename', 'Page to undelete' ); |
| 38 |
} |
| 39 |
|
| 40 |
public function execute() { |
| 41 |
$username = $this->getOption( 'user', false ); |
| 42 |
$reason = $this->getOption( 'reason', '' ); |
| 43 |
$pageName = $this->getArg( 0 ); |
| 44 |
|
| 45 |
$title = Title::newFromText( $pageName ); |
| 46 |
if ( !$title ) { |
| 47 |
$this->fatalError( "Invalid title" ); |
| 48 |
} |
| 49 |
if ( $username === false ) { |
| 50 |
$user = User::newSystemUser( 'Command line script', [ 'steal' => true ] ); |
| 51 |
} else { |
| 52 |
$user = User::newFromName( $username ); |
| 53 |
} |
| 54 |
if ( !$user ) { |
| 55 |
$this->fatalError( "Invalid username" ); |
| 56 |
} |
| 57 |
|
| 58 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 59 |
$this->output( "Undeleting " . $title->getPrefixedDBkey() . "...\n" ); |
| 60 |
|
| 61 |
$status = $this->getServiceContainer()->getUndeletePageFactory() |
| 62 |
->newUndeletePage( $page, $user ) |
| 63 |
->undeleteUnsafe( $reason ); |
| 64 |
if ( !$status->isGood() ) { |
| 65 |
$this->fatalError( $status ); |
| 66 |
} |
| 67 |
$this->output( "done\n" ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
$maintClass = Undelete::class; |
| 73 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 74 |
|