class Protect extends Maintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Protect or unprotect a page from the command line.";
+ $this->addDescription( 'Protect or unprotect a page from the command line.' );
$this->addOption( 'unprotect', 'Removes protection' );
$this->addOption( 'semiprotect', 'Adds semi-protection' );
$this->addOption( 'cascade', 'Add cascading protection' );
}
public function execute() {
- $userName = $this->getOption( 'u', 'Maintenance script' );
+ $userName = $this->getOption( 'u', false );
$reason = $this->getOption( 'r', '' );
$cascade = $this->hasOption( 'cascade' );
$protection = "";
}
- $user = User::newFromName( $userName );
+ if ( $userName === false ) {
+ $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
+ } else {
+ $user = User::newFromName( $userName );
+ }
if ( !$user ) {
$this->error( "Invalid username", true );
}
// @todo FIXME: This is reset 7 lines down.
- $restrictions = array( 'edit' => $protection, 'move' => $protection );
+ $restrictions = [ 'edit' => $protection, 'move' => $protection ];
$t = Title::newFromText( $this->getArg() );
if ( !$t ) {
$this->error( "Invalid title", true );
}
- $restrictions = array();
+ $restrictions = [];
foreach ( $t->getRestrictionTypes() as $type ) {
$restrictions[$type] = $protection;
}
$this->output( "Updating protection status... " );
$page = WikiPage::factory( $t );
- $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, $reason, $user );
+ $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, $reason, $user );
if ( $status->isOK() ) {
$this->output( "done\n" );