ajaxwatch.js: coding style tweaks
[lhc/web/wiklou.git] / maintenance / protect.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @ingroup Maintenance
19 */
20
21 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
22
23 class Protect extends Maintenance {
24 public function __construct() {
25 parent::__construct();
26 $this->mDescription = "Protect or unprotect an article from the command line.";
27 $this->addOption( 'unprotect', 'Removes protection' );
28 $this->addOption( 'semiprotect', 'Adds semi-protection' );
29 $this->addOption( 'u', 'Username to protect with', false, true );
30 $this->addOption( 'r', 'Reason for un/protection', false, true );
31 }
32
33 public function execute() {
34 global $wgUser, $wgTitle, $wgArticle;
35
36 $userName = $this->getOption( 'u', 'Maintenance script' );
37 $reason = $this->getOption( 'r', '' );
38
39 $protection = "sysop";
40 if ( $this->hasOption( 'semiprotect' ) ) {
41 $protection = "autoconfirmed";
42 } elseif ( $this->hasOption( 'unprotect' ) ) {
43 $protection = "";
44 }
45
46 $wgUser = User::newFromName( $userName );
47 $restrictions = array( 'edit' => $protection, 'move' => $protection );
48
49 $wgTitle = Title::newFromText( $this->getArg() );
50 if ( !$wgTitle ) {
51 $this->error( "Invalid title", true );
52 }
53
54 $wgArticle = new Article( $wgTitle );
55
56 # un/protect the article
57 $this->output( "Updating protection status... " );
58 $success = $wgArticle->updateRestrictions( $restrictions, $reason );
59 if ( $success ) {
60 $this->output( "done\n" );
61 } else {
62 $this->output( "failed\n" );
63 }
64 }
65 }
66
67 $maintClass = "Protect";
68 require_once( DO_MAINTENANCE );