MediaWiki master
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
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Represents a title within MediaWiki.
Definition Title.php:78
internal since 1.36
Definition User.php:93
__construct()
Default constructor.
Definition undelete.php:32
execute()
Do the actual work.
Definition undelete.php:40
$maintClass
Definition undelete.php:72