MediaWiki
REL1_20
|
00001 <?php 00024 require_once( __DIR__ . '/Maintenance.php' ); 00025 00031 class Protect extends Maintenance { 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->mDescription = "Protect or unprotect a page from the command line."; 00035 $this->addOption( 'unprotect', 'Removes protection' ); 00036 $this->addOption( 'semiprotect', 'Adds semi-protection' ); 00037 $this->addOption( 'cascade', 'Add cascading protection' ); 00038 $this->addOption( 'user', 'Username to protect with', false, true, 'u' ); 00039 $this->addOption( 'reason', 'Reason for un/protection', false, true, 'r' ); 00040 $this->addArg( 'title', 'Title to protect', true ); 00041 } 00042 00043 public function execute() { 00044 $userName = $this->getOption( 'u', 'Maintenance script' ); 00045 $reason = $this->getOption( 'r', '' ); 00046 00047 $cascade = $this->hasOption( 'cascade' ); 00048 00049 $protection = "sysop"; 00050 if ( $this->hasOption( 'semiprotect' ) ) { 00051 $protection = "autoconfirmed"; 00052 } elseif ( $this->hasOption( 'unprotect' ) ) { 00053 $protection = ""; 00054 } 00055 00056 $user = User::newFromName( $userName ); 00057 if ( !$user ) { 00058 $this->error( "Invalid username", true ); 00059 } 00060 00061 $restrictions = array( 'edit' => $protection, 'move' => $protection ); 00062 00063 $t = Title::newFromText( $this->getArg() ); 00064 if ( !$t ) { 00065 $this->error( "Invalid title", true ); 00066 } 00067 00068 $restrictions = array(); 00069 foreach( $t->getRestrictionTypes() as $type ) { 00070 $restrictions[$type] = $protection; 00071 } 00072 00073 # un/protect the article 00074 $this->output( "Updating protection status... " ); 00075 00076 $page = WikiPage::factory( $t ); 00077 $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, $reason, $user ); 00078 00079 if ( $status->isOK() ) { 00080 $this->output( "done\n" ); 00081 } else { 00082 $this->output( "failed\n" ); 00083 } 00084 } 00085 } 00086 00087 $maintClass = "Protect"; 00088 require_once( RUN_MAINTENANCE_IF_MAIN );