Debian Codegraph @

maintenance/undelete.php

raw symbols SCIP
1 <?php
2 /**
3 * Undelete a page by fetching it from the archive table
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 use MediaWiki\Title\Title;
25 use MediaWiki\User\User;
26
27 // @codeCoverageIgnoreStart
28 require_once __DIR__ . '/Maintenance.php';
29 // @codeCoverageIgnoreEnd
30
31 class 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;
73 require_once RUN_MAINTENANCE_IF_MAIN;
74 // @codeCoverageIgnoreEnd