Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Undelete | |
100.00% |
26 / 26 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Undelete a page by fetching it from the archive table |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Maintenance |
| 8 | */ |
| 9 | |
| 10 | use MediaWiki\Maintenance\Maintenance; |
| 11 | use MediaWiki\Title\Title; |
| 12 | use MediaWiki\User\User; |
| 13 | |
| 14 | // @codeCoverageIgnoreStart |
| 15 | require_once __DIR__ . '/Maintenance.php'; |
| 16 | // @codeCoverageIgnoreEnd |
| 17 | |
| 18 | class Undelete extends Maintenance { |
| 19 | public function __construct() { |
| 20 | parent::__construct(); |
| 21 | $this->addDescription( 'Undelete a page' ); |
| 22 | $this->addOption( 'user', 'The user to perform the undeletion', false, true, 'u' ); |
| 23 | $this->addOption( 'reason', 'The reason to undelete', false, true, 'r' ); |
| 24 | $this->addArg( 'pagename', 'Page to undelete' ); |
| 25 | } |
| 26 | |
| 27 | public function execute() { |
| 28 | $username = $this->getOption( 'user', false ); |
| 29 | $reason = $this->getOption( 'reason', '' ); |
| 30 | $pageName = $this->getArg( 0 ); |
| 31 | |
| 32 | $title = Title::newFromText( $pageName ); |
| 33 | if ( !$title ) { |
| 34 | $this->fatalError( "Invalid title" ); |
| 35 | } |
| 36 | if ( $username === false ) { |
| 37 | $user = User::newSystemUser( 'Command line script', [ 'steal' => true ] ); |
| 38 | } else { |
| 39 | $user = User::newFromName( $username ); |
| 40 | } |
| 41 | if ( !$user ) { |
| 42 | $this->fatalError( "Invalid username" ); |
| 43 | } |
| 44 | |
| 45 | $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 46 | $this->output( "Undeleting " . $title->getPrefixedDBkey() . "...\n" ); |
| 47 | |
| 48 | $this->beginTransactionRound( __METHOD__ ); |
| 49 | $status = $this->getServiceContainer()->getUndeletePageFactory() |
| 50 | ->newUndeletePage( $page, $user ) |
| 51 | ->undeleteUnsafe( $reason ); |
| 52 | $this->commitTransactionRound( __METHOD__ ); |
| 53 | |
| 54 | if ( !$status->isGood() ) { |
| 55 | $this->fatalError( $status ); |
| 56 | } |
| 57 | $this->output( "done\n" ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // @codeCoverageIgnoreStart |
| 62 | $maintClass = Undelete::class; |
| 63 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 64 | // @codeCoverageIgnoreEnd |