MediaWiki master
undelete.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
30class Undelete extends Maintenance {
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( 'Undelete a page' );
34 $this->addOption( 'user', 'The user to perform the undeletion', false, true, 'u' );
35 $this->addOption( 'reason', 'The reason to undelete', false, true, 'r' );
36 $this->addArg( 'pagename', 'Page to undelete' );
37 }
38
39 public function execute() {
40 $username = $this->getOption( 'user', false );
41 $reason = $this->getOption( 'reason', '' );
42 $pageName = $this->getArg( 0 );
43
44 $title = Title::newFromText( $pageName );
45 if ( !$title ) {
46 $this->fatalError( "Invalid title" );
47 }
48 if ( $username === false ) {
49 $user = User::newSystemUser( 'Command line script', [ 'steal' => true ] );
50 } else {
51 $user = User::newFromName( $username );
52 }
53 if ( !$user ) {
54 $this->fatalError( "Invalid username" );
55 }
56 StubGlobalUser::setUser( $user );
57
58 $archive = new PageArchive( $title );
59 $this->output( "Undeleting " . $title->getPrefixedDBkey() . '...' );
60 $archive->undeleteAsUser( [], $user, $reason );
61 $this->output( "done\n" );
62 }
63}
64
65$maintClass = Undelete::class;
66require_once RUN_MAINTENANCE_IF_MAIN;
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.
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.
Stub object for the global user ($wgUser) that makes it possible to change the relevant underlying ob...
Represents a title within MediaWiki.
Definition Title.php:78
internal since 1.36
Definition User.php:93
Used to show archived pages and eventually restore them.
__construct()
Default constructor.
Definition undelete.php:31
execute()
Do the actual work.
Definition undelete.php:39
$maintClass
Definition undelete.php:65