00001 <?php 00021 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00022 00023 class Protect extends Maintenance { 00024 public function __construct() { 00025 parent::__construct(); 00026 $this->mDescription = "Protect or unprotect an article from the command line."; 00027 $this->addOption( 'unprotect', 'Removes protection' ); 00028 $this->addOption( 'semiprotect', 'Adds semi-protection' ); 00029 $this->addOption( 'u', 'Username to protect with', false, true ); 00030 $this->addOption( 'r', 'Reason for un/protection', false, true ); 00031 } 00032 00033 public function execute() { 00034 global $wgUser, $wgTitle, $wgArticle; 00035 00036 $userName = $this->getOption( 'u', 'Maintenance script' ); 00037 $reason = $this->getOption( 'r', '' ); 00038 00039 $protection = "sysop"; 00040 if ( $this->hasOption('semiprotect') ) { 00041 $protection = "autoconfirmed"; 00042 } elseif ( $this->hasOption('unprotect') ) { 00043 $protection = ""; 00044 } 00045 00046 $wgUser = User::newFromName( $userName ); 00047 $restrictions = array( 'edit' => $protection, 'move' => $protection ); 00048 00049 $wgTitle = Title::newFromText( $this->getArg() ); 00050 if ( !$wgTitle ) { 00051 $this->error( "Invalid title", true ); 00052 } 00053 00054 $wgArticle = new Article( $wgTitle ); 00055 00056 # un/protect the article 00057 $this->output( "Updating protection status... " ); 00058 $success = $wgArticle->updateRestrictions($restrictions, $reason); 00059 if ( $success ) { 00060 $this->output( "done\n" ); 00061 } else { 00062 $this->output( "failed\n" ); 00063 } 00064 } 00065 } 00066 00067 $maintClass = "Protect"; 00068 require_once( DO_MAINTENANCE );