Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Undelete | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 |
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\StubObject\StubGlobalUser; |
25 | use MediaWiki\Title\Title; |
26 | use MediaWiki\User\User; |
27 | |
28 | require_once __DIR__ . '/Maintenance.php'; |
29 | |
30 | class 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; |
66 | require_once RUN_MAINTENANCE_IF_MAIN; |