]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/protect.php
MediaWiki 1.17.1-scripts
[autoinstalls/mediawiki.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                 $this->addArg( 'title', 'Title to protect', true );
32         }
33
34         public function execute() {
35                 global $wgUser;
36
37                 $userName = $this->getOption( 'u', 'Maintenance script' );
38                 $reason = $this->getOption( 'r', '' );
39
40                 $protection = "sysop";
41                 if ( $this->hasOption( 'semiprotect' ) ) {
42                         $protection = "autoconfirmed";
43                 } elseif ( $this->hasOption( 'unprotect' ) ) {
44                         $protection = "";
45                 }
46
47                 $wgUser = User::newFromName( $userName );
48                 $restrictions = array( 'edit' => $protection, 'move' => $protection );
49
50                 $t = Title::newFromText( $this->getArg() );
51                 if ( !$t ) {
52                         $this->error( "Invalid title", true );
53                 }
54
55                 $article = new Article( $t );
56
57                 # un/protect the article
58                 $this->output( "Updating protection status... " );
59                 $success = $article->updateRestrictions( $restrictions, $reason );
60                 if ( $success ) {
61                         $this->output( "done\n" );
62                 } else {
63                         $this->output( "failed\n" );
64                 }
65         }
66 }
67
68 $maintClass = "Protect";
69 require_once( RUN_MAINTENANCE_IF_MAIN );