Merge "Make line breaks in <blockquote> behave like <div> (bug 6200)."
[mediawiki.git] / maintenance / protect.php
blobec03f9349d59f8cced297268d5fd47c1603408d7
1 <?php
2 /**
3 * Protect or unprotect a page.
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.
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.
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
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 /**
27 * Maintenance script that protects or unprotects a page.
29 * @ingroup Maintenance
31 class Protect extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->mDescription = "Protect or unprotect a page from the command line.";
35 $this->addOption( 'unprotect', 'Removes protection' );
36 $this->addOption( 'semiprotect', 'Adds semi-protection' );
37 $this->addOption( 'cascade', 'Add cascading protection' );
38 $this->addOption( 'user', 'Username to protect with', false, true, 'u' );
39 $this->addOption( 'reason', 'Reason for un/protection', false, true, 'r' );
40 $this->addArg( 'title', 'Title to protect', true );
43 public function execute() {
44 $userName = $this->getOption( 'u', 'Maintenance script' );
45 $reason = $this->getOption( 'r', '' );
47 $cascade = $this->hasOption( 'cascade' );
49 $protection = "sysop";
50 if ( $this->hasOption( 'semiprotect' ) ) {
51 $protection = "autoconfirmed";
52 } elseif ( $this->hasOption( 'unprotect' ) ) {
53 $protection = "";
56 $user = User::newFromName( $userName );
57 if ( !$user ) {
58 $this->error( "Invalid username", true );
61 // @todo FIXME: This is reset 7 lines down.
62 $restrictions = array( 'edit' => $protection, 'move' => $protection );
64 $t = Title::newFromText( $this->getArg() );
65 if ( !$t ) {
66 $this->error( "Invalid title", true );
69 $restrictions = array();
70 foreach ( $t->getRestrictionTypes() as $type ) {
71 $restrictions[$type] = $protection;
74 # un/protect the article
75 $this->output( "Updating protection status... " );
77 $page = WikiPage::factory( $t );
78 $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, $reason, $user );
80 if ( $status->isOK() ) {
81 $this->output( "done\n" );
82 } else {
83 $this->output( "failed\n" );
88 $maintClass = "Protect";
89 require_once RUN_MAINTENANCE_IF_MAIN;