r99347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99346‎ | r99347 | r99348 >
Date:11:46, 9 October 2011
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
Follow-up r99346: updates to EditUser extension to make it compatible, also great code simplifications.
Since this requires MW1.19+ to work, let's use local context instead of global variables.
Modified paths:
  • /trunk/extensions/EditUser/EditUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EditUser/EditUser_body.php
@@ -1,87 +1,86 @@
22 <?php
33 /* Shamelessly copied and modified from /includes/specials/SpecialPreferences.php v1.16.1 */
44 class EditUser extends SpecialPage {
 5+
56 function __construct() {
67 parent::__construct('EditUser', 'edituser');
78 }
 9+
810 function execute( $par ) {
9 - global $wgOut, $wgUser, $wgRequest;
10 -
11 - if( !$wgUser->isAllowed( 'edituser' ) ) {
12 - $wgOut->permissionRequired( 'edituser' );
 11+ $user = $this->getUser();
 12+ $out = $this->getOutput();
 13+
 14+ if( !$user->isAllowed( 'edituser' ) ) {
 15+ $out->permissionRequired( 'edituser' );
1316 return false;
1417 }
1518
16 -
17 -
1819 $this->setHeaders();
19 - $this->target = ( isset( $par ) ) ? $par : $wgRequest->getText( 'username', '' );
 20+
 21+ $request = $this->getRequest();
 22+ $this->target = ( isset( $par ) ) ? $par : $request->getText( 'username', '' );
2023 if( $this->target === '' ) {
21 - $wgOut->addHtml( $this->makeSearchForm() );
 24+ $out->addHtml( $this->makeSearchForm() );
2225 return;
2326 }
2427 $targetuser = User::NewFromName( $this->target );
2528 if( $targetuser->getID() == 0 ) {
26 - $wgOut->addWikiMsg( 'edituser-nouser', htmlspecialchars( $this->target ) );
 29+ $out->addWikiMsg( 'edituser-nouser', htmlspecialchars( $this->target ) );
2730 return;
2831 }
2932 $this->targetuser = $targetuser;
3033 #Allow editing self via this interface
31 - if( $targetuser->isAllowed( 'edituser-exempt' ) && $targetuser->getName() != $wgUser->getName() ) {
32 - $wgOut->addWikiMsg( 'edituser-exempt', $targetuser->getName() );
 34+ if( $targetuser->isAllowed( 'edituser-exempt' ) && $targetuser->getName() != $user->getName() ) {
 35+ $out->addWikiMsg( 'edituser-exempt', $targetuser->getName() );
3336 return;
3437 }
3538
3639 $this->setHeaders();
3740 $this->outputHeader();
38 - $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
 41+ $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
3942
4043 if ( wfReadOnly() ) {
41 - $wgOut->readOnlyPage();
 44+ $out->readOnlyPage();
4245 return;
4346 }
4447
45 - if ( $wgRequest->getCheck( 'reset' ) ) {
 48+ if ( $request->getCheck( 'reset' ) ) {
4649 $this->showResetForm();
4750 return;
4851 }
4952
50 - $wgOut->addModules( 'mediawiki.special.preferences' );
 53+ $out->addModules( 'mediawiki.special.preferences' );
5154
5255 //$this->loadGlobals( $this->target );
53 - $wgOut->addHtml( $this->makeSearchForm() . '<br />' );
 56+ $out->addHtml( $this->makeSearchForm() . '<br />' );
5457 #End EditUser additions
5558
56 - if ( $wgRequest->getCheck( 'success' ) ) {
57 - $wgOut->wrapWikiMsg(
 59+ if ( $request->getCheck( 'success' ) ) {
 60+ $out->wrapWikiMsg(
5861 "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
5962 'savedprefs'
6063 );
6164 }
6265
63 - if ( $wgRequest->getCheck( 'eauth' ) ) {
64 - $wgOut->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
 66+ if ( $request->getCheck( 'eauth' ) ) {
 67+ $out->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
6568 'eauthentsent', $this->target );
6669 }
6770
68 - $htmlForm = self::getFormObject( $targetuser );
69 - $htmlForm->setSubmitCallback( array( $this, 'tryUISubmit' ) );
70 - $htmlForm->setTitle( $this->getTitle() );
 71+ $htmlForm = Preferences::getFormObject( $targetuser, $this->getContext(),
 72+ 'EditUserPreferencesForm', array( 'password' ) );
 73+ $htmlForm->setSubmitCallback( 'Preferences::tryUISubmit' );
7174 $htmlForm->addHiddenField( 'username', $this->target );
72 - $htmlForm->mEditUserUsername = $this->target;
73 -
 75+
7476 $htmlForm->show();
7577 }
7678
7779 function showResetForm() {
78 - global $wgOut;
 80+ $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
7981
80 - $wgOut->addWikiMsg( 'prefs-reset-intro' );
 82+ $htmlForm = new HTMLForm( array(), $this->getContext(), 'prefs-restore' );
8183
82 - $htmlForm = new HTMLForm( array(), 'prefs-restore' );
83 -
8484 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
85 - $htmlForm->setTitle( $this->getTitle() );
8685 $htmlForm->addHiddenField( 'username', $this->target );
8786 $htmlForm->addHiddenField( 'reset' , '1' );
8887 $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) );
@@ -91,87 +90,41 @@
9291 }
9392
9493 function submitReset( $formData ) {
95 - global $wgOut;
9694 $this->targetuser->resetOptions();
9795 $this->targetuser->saveSettings();
9896
9997 $url = $this->getTitle()->getFullURL( array( 'success' => 1, 'username'=>$this->target ) );
10098
101 - $wgOut->redirect( $url );
 99+ $this->getOutput()->redirect( $url );
102100
103101 return true;
104102 }
105 -
106 - function tryUISubmit( $formData ) {
107 - global $wgUser;
108 -
109 - $targetuser = User::NewFromName( $this->target );
110 - if( $targetuser->getID() == 0 ) {
111 - return wfMsg( 'edituser-nouser' ) ;
112 - }
113 -
114 - $realUser = $wgUser;
115 - $wgUser = $targetuser;
116 - $res = Preferences::tryFormSubmit( $formData, 'ui' );
117 - $wgUser = $realUser;
118 -
119 - if ( $res ) {
120 - $urlOptions = array( 'success' => 1);
121103
122 - if ( $res === 'eauth' ) {
123 - $urlOptions['eauth'] = 1;
124 - }
125 -
126 - //$queryString = implode( '&', $urlOptions );
127 - $urlOptions['username'] = $this->target;
128 -
129 - $url = $this->getTitle()->getFullURL( $urlOptions );
130 -
131 - global $wgOut;
132 - $wgOut->redirect( $url );
133 - }
134 -
135 - return true;
136 - }
137 -
138 -
139104 function makeSearchForm() {
 105+ global $wgScript;
 106+
140107 $fields = array();
141108 $fields['edituser-username'] = Html::input( 'username', $this->target );
142109
143 - $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
144 - $form = Html::rawElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ),
145 - Xml::buildForm( $fields, 'edituser-dosearch' ) .
146 - Html::hidden( 'issearch', '1' )
 110+ $thisTitle = $this->getTitle();
 111+ $form = Html::rawElement( 'form', array( 'method' => 'get', 'action' => $wgScript ),
 112+ Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
 113+ Xml::buildForm( $fields, 'edituser-dosearch' )
147114 );
148115 return $form;
149116 }
150 -
151 - static function getFormObject( $user ) {
152 - $formDescriptor = Preferences::getPreferences( $user );
153 - if ( isset( $formDescriptor['password'] ) ) {
154 - unset( $formDescriptor['password'] );
155 - }
156 - $htmlForm = new EditUserPreferencesForm( $formDescriptor, 'prefs' );
157 -
158 - $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
159 - $htmlForm->setSubmitID( 'prefsubmit' );
160 -
161 - return $htmlForm;
162 - }
163117 }
164118
165119 class EditUserPreferencesForm extends PreferencesForm {
166 - var $mEditUserUsername;
167 -
 120+ public function getExtraSuccessRedirectParameters() {
 121+ return array( 'username' => $this->getModifiedUser()->getName() );
 122+ }
 123+
168124 function getButtons() {
169125 $html = HTMLForm::getButtons();
170126
171 - global $wgUser;
 127+ $url = SpecialPage::getTitleFor( 'EditUser' )->getFullURL( array( 'reset' => 1, 'username' => $this->getModifiedUser()->getName() ) );
172128
173 - $sk = $wgUser->getSkin();
174 - $url = SpecialPage::getTitleFor( 'EditUser' )->getFullURL( array( 'reset' => 1, 'username' => $this->mEditUserUsername ) );
175 -
176129 $html .= "\n" . Xml::element('a', array( 'href'=> $url ), wfMsgHtml( 'restoreprefs' ) );
177130
178131 $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99346* Use the context when building the preferences form descriptor...ialex11:43, 9 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   20:53, 9 October 2011

Not introduced here, but this is double escaping:

$html .= "\n" . Xml::element('a', array( 'href'=> $url ), wfMsgHtml( 'restoreprefs' ) );

Status & tagging log