r77769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77768‎ | r77769 | r77770 >
Date:05:19, 5 December 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
No need for globals, works fine without. Also add missing (and required) title arg
Modified paths:
  • /trunk/phase3/maintenance/protect.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/protect.php
@@ -28,10 +28,11 @@
2929 $this->addOption( 'semiprotect', 'Adds semi-protection' );
3030 $this->addOption( 'u', 'Username to protect with', false, true );
3131 $this->addOption( 'r', 'Reason for un/protection', false, true );
 32+ $this->addArg( 'title', 'Title to protect', true );
3233 }
3334
3435 public function execute() {
35 - global $wgUser, $wgTitle, $wgArticle;
 36+ global $wgUser;
3637
3738 $userName = $this->getOption( 'u', 'Maintenance script' );
3839 $reason = $this->getOption( 'r', '' );
@@ -46,16 +47,16 @@
4748 $wgUser = User::newFromName( $userName );
4849 $restrictions = array( 'edit' => $protection, 'move' => $protection );
4950
50 - $wgTitle = Title::newFromText( $this->getArg() );
51 - if ( !$wgTitle ) {
 51+ $t = Title::newFromText( $this->getArg() );
 52+ if ( !$t ) {
5253 $this->error( "Invalid title", true );
5354 }
5455
55 - $wgArticle = new Article( $wgTitle );
 56+ $article = new Article( $t );
5657
5758 # un/protect the article
5859 $this->output( "Updating protection status... " );
59 - $success = $wgArticle->updateRestrictions( $restrictions, $reason );
 60+ $success = $article->updateRestrictions( $restrictions, $reason );
6061 if ( $success ) {
6162 $this->output( "done\n" );
6263 } else {

Comments

#Comment by The Evil IP address (talk | contribs)   12:28, 5 December 2010

Same can probably be done for global $wgUser, too:

$wgUser = User::newFromName( $userName );
#Comment by 😂 (talk | contribs)   19:41, 5 December 2010

No it can't. Article::updateRestrictions() calls Title::userCan().

Status & tagging log