r92587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92586‎ | r92587 | r92588 >
Date:21:35, 19 July 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods statically
Modified paths:
  • /trunk/phase3/includes/specials/SpecialEmailuser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialEmailuser.php
@@ -34,14 +34,13 @@
3535 }
3636
3737 protected function getFormFields() {
38 - global $wgUser;
3938 return array(
4039 'From' => array(
4140 'type' => 'info',
4241 'raw' => 1,
43 - 'default' => $this->getSkin()->link(
44 - $wgUser->getUserPage(),
45 - htmlspecialchars( $wgUser->getName() )
 42+ 'default' => Linker::link(
 43+ $this->getUser()->getUserPage(),
 44+ htmlspecialchars( $this->getUser()->getName() )
4645 ),
4746 'label-message' => 'emailfrom',
4847 'id' => 'mw-emailuser-sender',
@@ -49,7 +48,7 @@
5049 'To' => array(
5150 'type' => 'info',
5251 'raw' => 1,
53 - 'default' => $this->getSkin()->link(
 52+ 'default' => Linker::link(
5453 $this->mTargetObj->getUserPage(),
5554 htmlspecialchars( $this->mTargetObj->getName() )
5655 ),
@@ -78,53 +77,47 @@
7978 'CCMe' => array(
8079 'type' => 'check',
8180 'label-message' => 'emailccme',
82 - 'default' => $wgUser->getBoolOption( 'ccmeonemails' ),
 81+ 'default' => $this->getUser()->getBoolOption( 'ccmeonemails' ),
8382 ),
8483 );
8584 }
8685
8786 public function execute( $par ) {
88 - global $wgRequest, $wgOut, $wgUser;
89 -
9087 $this->setHeaders();
9188 $this->outputHeader();
92 - $wgOut->addModuleStyles( 'mediawiki.special' );
 89+ $out = $this->getOutput();
 90+ $out->addModuleStyles( 'mediawiki.special' );
9391 $this->mTarget = is_null( $par )
94 - ? $wgRequest->getVal( 'wpTarget', $wgRequest->getVal( 'target', '' ) )
 92+ ? $this->getRequest()->getVal( 'wpTarget', $this->getRequest()->getVal( 'target', '' ) )
9593 : $par;
9694 // error out if sending user cannot do this
97 - $error = self::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
 95+ $error = self::getPermissionsError( $this->getUser(), $this->getRequest()->getVal( 'wpEditToken' ) );
9896 switch ( $error ) {
9997 case null:
10098 # Wahey!
10199 break;
102100 case 'badaccess':
103 - $wgOut->permissionRequired( 'sendemail' );
104 - return;
 101+ throw new PermissionsError( 'sendemail' );
105102 case 'blockedemailuser':
106 - $wgOut->blockedPage();
107 - return;
 103+ throw new UserBlockedError( $this->getUser()->mBlock );
108104 case 'actionthrottledtext':
109 - $wgOut->rateLimited();
110 - return;
 105+ throw new ThrottledError;
111106 case 'mailnologin':
112107 case 'usermaildisabled':
113 - $wgOut->showErrorPage( $error, "{$error}text" );
114 - return;
 108+ throw new ErrorPageError( $error, "{$error}text" );
115109 default:
116110 # It's a hook error
117111 list( $title, $msg, $params ) = $error;
118 - $wgOut->showErrorPage( $title, $msg, $params );
119 - return;
 112+ throw new ErrorPageError( $title, $msg, $params );
120113 }
121114 // Got a valid target user name? Else ask for one.
122115 $ret = self::getTarget( $this->mTarget );
123116 if( !$ret instanceof User ) {
124117 if( $this->mTarget != '' ) {
125118 $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' );
126 - $wgOut->addHTML( '<p class="error">' . wfMessage( $ret )->parse() . '</p>' );
 119+ $out->addHTML( '<p class="error">' . wfMessage( $ret )->parse() . '</p>' );
127120 }
128 - $wgOut->addHTML( self::userForm( $this->mTarget ) );
 121+ $out->addHTML( self::userForm( $this->mTarget ) );
129122 return false;
130123 }
131124
@@ -142,13 +135,13 @@
143136 return false;
144137 }
145138
146 - $wgOut->setPageTitle( wfMsg( 'emailpage' ) );
 139+ $out->setPageTitle( wfMsg( 'emailpage' ) );
147140 $result = $form->show();
148141
149142 if( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
150 - $wgOut->setPageTitle( wfMsg( 'emailsent' ) );
151 - $wgOut->addWikiMsg( 'emailsenttext' );
152 - $wgOut->returnToMain( false, $this->mTargetObj->getUserPage() );
 143+ $out->setPageTitle( wfMsg( 'emailsent' ) );
 144+ $out->addWikiMsg( 'emailsenttext' );
 145+ $out->returnToMain( false, $this->mTargetObj->getUserPage() );
153146 }
154147 }
155148

Comments

#Comment by Nikerabbit (talk | contribs)   09:13, 20 July 2011

Not introduced here, but wouldn't wrapWikiMsg be better:

+$out->addHTML( '<p class="error">' . wfMessage( $ret )->parse() . '</p>' );

Two spaces after new

+throw new  ErrorPageError( $error, "{$error}text" );

Not introduced here but spelling the message names in full would help grepping them.

Status & tagging log