Add tests for parser tag hooks.
[lhc/web/wiklou.git] / maintenance / protect.php
1 <?php
2 /**
3 * Protect or unprotect an article.
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 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class Protect extends Maintenance {
26 public function __construct() {
27 parent::__construct();
28 $this->mDescription = "Protect or unprotect an article from the command line.";
29 $this->addOption( 'unprotect', 'Removes protection' );
30 $this->addOption( 'semiprotect', 'Adds semi-protection' );
31 $this->addOption( 'u', 'Username to protect with', false, true );
32 $this->addOption( 'r', 'Reason for un/protection', false, true );
33 $this->addArg( 'title', 'Title to protect', true );
34 }
35
36 public function execute() {
37 global $wgUser;
38
39 $userName = $this->getOption( 'u', 'Maintenance script' );
40 $reason = $this->getOption( 'r', '' );
41
42 $protection = "sysop";
43 if ( $this->hasOption( 'semiprotect' ) ) {
44 $protection = "autoconfirmed";
45 } elseif ( $this->hasOption( 'unprotect' ) ) {
46 $protection = "";
47 }
48
49 $wgUser = User::newFromName( $userName );
50 $restrictions = array( 'edit' => $protection, 'move' => $protection );
51
52 $t = Title::newFromText( $this->getArg() );
53 if ( !$t ) {
54 $this->error( "Invalid title", true );
55 }
56
57 $article = new Article( $t );
58
59 # un/protect the article
60 $this->output( "Updating protection status... " );
61 $success = $article->updateRestrictions( $restrictions, $reason );
62 if ( $success ) {
63 $this->output( "done\n" );
64 } else {
65 $this->output( "failed\n" );
66 }
67 }
68 }
69
70 $maintClass = "Protect";
71 require_once( DO_MAINTENANCE );