X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=blobdiff_plain;f=maintenance%2Fprotect.php;h=31b2101c685bb405b5c48e0de47571ff8903d689;hb=82d6f1d89fb4521ea2355832aff4b4e0f9ba27fa;hp=ec03f9349d59f8cced297268d5fd47c1603408d7;hpb=5cfec935722d8f4015dc24cda1de8bfc7f330537;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/protect.php b/maintenance/protect.php index ec03f9349d..31b2101c68 100644 --- a/maintenance/protect.php +++ b/maintenance/protect.php @@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php'; 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' ); @@ -41,7 +41,7 @@ class Protect extends Maintenance { } public function execute() { - $userName = $this->getOption( 'u', 'Maintenance script' ); + $userName = $this->getOption( 'u', false ); $reason = $this->getOption( 'r', '' ); $cascade = $this->hasOption( 'cascade' ); @@ -53,20 +53,24 @@ class Protect extends Maintenance { $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; } @@ -75,7 +79,7 @@ class Protect extends Maintenance { $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" );