MediaWiki 1.43.1
undelete.php
Go to the documentation of this file.
1<?php
26
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/Maintenance.php';
29// @codeCoverageIgnoreEnd
30
31class 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// @codeCoverageIgnoreStart
72$maintClass = Undelete::class;
73require_once RUN_MAINTENANCE_IF_MAIN;
74// @codeCoverageIgnoreEnd
Represents a title within MediaWiki.
Definition Title.php:78
internal since 1.36
Definition User.php:94
__construct()
Definition undelete.php:32
$maintClass
Definition undelete.php:72