MediaWiki REL1_40
undelete.php
Go to the documentation of this file.
1<?php
26
27require_once __DIR__ . '/Maintenance.php';
28
29class Undelete extends Maintenance {
30 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Undelete a page' );
33 $this->addOption( 'user', 'The user to perform the undeletion', false, true, 'u' );
34 $this->addOption( 'reason', 'The reason to undelete', false, true, 'r' );
35 $this->addArg( 'pagename', 'Page to undelete' );
36 }
37
38 public function execute() {
39 $username = $this->getOption( 'user', false );
40 $reason = $this->getOption( 'reason', '' );
41 $pageName = $this->getArg( 0 );
42
43 $title = Title::newFromText( $pageName );
44 if ( !$title ) {
45 $this->fatalError( "Invalid title" );
46 }
47 if ( $username === false ) {
48 $user = User::newSystemUser( 'Command line script', [ 'steal' => true ] );
49 } else {
50 $user = User::newFromName( $username );
51 }
52 if ( !$user ) {
53 $this->fatalError( "Invalid username" );
54 }
55 StubGlobalUser::setUser( $user );
56
57 $archive = new PageArchive( $title );
58 $this->output( "Undeleting " . $title->getPrefixedDBkey() . '...' );
59 $archive->undeleteAsUser( [], $user, $reason );
60 $this->output( "done\n" );
61 }
62}
63
64$maintClass = Undelete::class;
65require_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:82
Used to show archived pages and eventually restore them.
__construct()
Default constructor.
Definition undelete.php:30
execute()
Do the actual work.
Definition undelete.php:38
static newFromName( $name, $validate='valid')
Definition User.php:592
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
Definition User.php:793
$maintClass
Definition undelete.php:64