X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fprotect.php;h=ff13bd6e694aa5ae731824975e49855e08c34a85;hb=6c31ca8b46b7dd27b7f1037e3bb337fa0ede4695;hp=c3043967d43aaadccb819ff67618a2bc35a6f658;hpb=792c38f4242fc8c90454ee6297e9614b5eeeb7c9;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/protect.php b/maintenance/protect.php index c3043967d4..ff13bd6e69 100644 --- a/maintenance/protect.php +++ b/maintenance/protect.php @@ -1,6 +1,6 @@ mDescription = "Protect or unprotect an article from the command line."; + $this->mDescription = "Protect or unprotect a page from the command line."; $this->addOption( 'unprotect', 'Removes protection' ); $this->addOption( 'semiprotect', 'Adds semi-protection' ); - $this->addOption( 'u', 'Username to protect with', false, true ); - $this->addOption( 'r', 'Reason for un/protection', false, true ); + $this->addOption( 'cascade', 'Add cascading protection' ); + $this->addOption( 'user', 'Username to protect with', false, true, 'u' ); + $this->addOption( 'reason', 'Reason for un/protection', false, true, 'r' ); $this->addArg( 'title', 'Title to protect', true ); } public function execute() { - global $wgUser; - $userName = $this->getOption( 'u', 'Maintenance script' ); $reason = $this->getOption( 'r', '' ); + $cascade = $this->hasOption( 'cascade' ); + $protection = "sysop"; if ( $this->hasOption( 'semiprotect' ) ) { $protection = "autoconfirmed"; @@ -46,11 +53,12 @@ class Protect extends Maintenance { $protection = ""; } - $wgUser = User::newFromName( $userName ); - if ( !$wgUser ) { + $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 ); $t = Title::newFromText( $this->getArg() ); @@ -58,12 +66,18 @@ class Protect extends Maintenance { $this->error( "Invalid title", true ); } - $article = new Article( $t ); + $restrictions = array(); + foreach( $t->getRestrictionTypes() as $type ) { + $restrictions[$type] = $protection; + } # un/protect the article $this->output( "Updating protection status... " ); - $success = $article->updateRestrictions( $restrictions, $reason ); - if ( $success ) { + + $page = WikiPage::factory( $t ); + $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, $reason, $user ); + + if ( $status->isOK() ) { $this->output( "done\n" ); } else { $this->output( "failed\n" );