Index: trunk/extensions/EditUser/EditUser_body.php |
— | — | @@ -1,87 +1,86 @@ |
2 | 2 | <?php |
3 | 3 | /* Shamelessly copied and modified from /includes/specials/SpecialPreferences.php v1.16.1 */ |
4 | 4 | class EditUser extends SpecialPage { |
| 5 | + |
5 | 6 | function __construct() { |
6 | 7 | parent::__construct('EditUser', 'edituser'); |
7 | 8 | } |
| 9 | + |
8 | 10 | 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' ); |
13 | 16 | return false; |
14 | 17 | } |
15 | 18 | |
16 | | - |
17 | | - |
18 | 19 | $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', '' ); |
20 | 23 | if( $this->target === '' ) { |
21 | | - $wgOut->addHtml( $this->makeSearchForm() ); |
| 24 | + $out->addHtml( $this->makeSearchForm() ); |
22 | 25 | return; |
23 | 26 | } |
24 | 27 | $targetuser = User::NewFromName( $this->target ); |
25 | 28 | if( $targetuser->getID() == 0 ) { |
26 | | - $wgOut->addWikiMsg( 'edituser-nouser', htmlspecialchars( $this->target ) ); |
| 29 | + $out->addWikiMsg( 'edituser-nouser', htmlspecialchars( $this->target ) ); |
27 | 30 | return; |
28 | 31 | } |
29 | 32 | $this->targetuser = $targetuser; |
30 | 33 | #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() ); |
33 | 36 | return; |
34 | 37 | } |
35 | 38 | |
36 | 39 | $this->setHeaders(); |
37 | 40 | $this->outputHeader(); |
38 | | - $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. |
| 41 | + $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. |
39 | 42 | |
40 | 43 | if ( wfReadOnly() ) { |
41 | | - $wgOut->readOnlyPage(); |
| 44 | + $out->readOnlyPage(); |
42 | 45 | return; |
43 | 46 | } |
44 | 47 | |
45 | | - if ( $wgRequest->getCheck( 'reset' ) ) { |
| 48 | + if ( $request->getCheck( 'reset' ) ) { |
46 | 49 | $this->showResetForm(); |
47 | 50 | return; |
48 | 51 | } |
49 | 52 | |
50 | | - $wgOut->addModules( 'mediawiki.special.preferences' ); |
| 53 | + $out->addModules( 'mediawiki.special.preferences' ); |
51 | 54 | |
52 | 55 | //$this->loadGlobals( $this->target ); |
53 | | - $wgOut->addHtml( $this->makeSearchForm() . '<br />' ); |
| 56 | + $out->addHtml( $this->makeSearchForm() . '<br />' ); |
54 | 57 | #End EditUser additions |
55 | 58 | |
56 | | - if ( $wgRequest->getCheck( 'success' ) ) { |
57 | | - $wgOut->wrapWikiMsg( |
| 59 | + if ( $request->getCheck( 'success' ) ) { |
| 60 | + $out->wrapWikiMsg( |
58 | 61 | "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>", |
59 | 62 | 'savedprefs' |
60 | 63 | ); |
61 | 64 | } |
62 | 65 | |
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>", |
65 | 68 | 'eauthentsent', $this->target ); |
66 | 69 | } |
67 | 70 | |
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' ); |
71 | 74 | $htmlForm->addHiddenField( 'username', $this->target ); |
72 | | - $htmlForm->mEditUserUsername = $this->target; |
73 | | - |
| 75 | + |
74 | 76 | $htmlForm->show(); |
75 | 77 | } |
76 | 78 | |
77 | 79 | function showResetForm() { |
78 | | - global $wgOut; |
| 80 | + $this->getOutput()->addWikiMsg( 'prefs-reset-intro' ); |
79 | 81 | |
80 | | - $wgOut->addWikiMsg( 'prefs-reset-intro' ); |
| 82 | + $htmlForm = new HTMLForm( array(), $this->getContext(), 'prefs-restore' ); |
81 | 83 | |
82 | | - $htmlForm = new HTMLForm( array(), 'prefs-restore' ); |
83 | | - |
84 | 84 | $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) ); |
85 | | - $htmlForm->setTitle( $this->getTitle() ); |
86 | 85 | $htmlForm->addHiddenField( 'username', $this->target ); |
87 | 86 | $htmlForm->addHiddenField( 'reset' , '1' ); |
88 | 87 | $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) ); |
— | — | @@ -91,87 +90,41 @@ |
92 | 91 | } |
93 | 92 | |
94 | 93 | function submitReset( $formData ) { |
95 | | - global $wgOut; |
96 | 94 | $this->targetuser->resetOptions(); |
97 | 95 | $this->targetuser->saveSettings(); |
98 | 96 | |
99 | 97 | $url = $this->getTitle()->getFullURL( array( 'success' => 1, 'username'=>$this->target ) ); |
100 | 98 | |
101 | | - $wgOut->redirect( $url ); |
| 99 | + $this->getOutput()->redirect( $url ); |
102 | 100 | |
103 | 101 | return true; |
104 | 102 | } |
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); |
121 | 103 | |
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 | | - |
139 | 104 | function makeSearchForm() { |
| 105 | + global $wgScript; |
| 106 | + |
140 | 107 | $fields = array(); |
141 | 108 | $fields['edituser-username'] = Html::input( 'username', $this->target ); |
142 | 109 | |
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' ) |
147 | 114 | ); |
148 | 115 | return $form; |
149 | 116 | } |
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 | | - } |
163 | 117 | } |
164 | 118 | |
165 | 119 | class EditUserPreferencesForm extends PreferencesForm { |
166 | | - var $mEditUserUsername; |
167 | | - |
| 120 | + public function getExtraSuccessRedirectParameters() { |
| 121 | + return array( 'username' => $this->getModifiedUser()->getName() ); |
| 122 | + } |
| 123 | + |
168 | 124 | function getButtons() { |
169 | 125 | $html = HTMLForm::getButtons(); |
170 | 126 | |
171 | | - global $wgUser; |
| 127 | + $url = SpecialPage::getTitleFor( 'EditUser' )->getFullURL( array( 'reset' => 1, 'username' => $this->getModifiedUser()->getName() ) ); |
172 | 128 | |
173 | | - $sk = $wgUser->getSkin(); |
174 | | - $url = SpecialPage::getTitleFor( 'EditUser' )->getFullURL( array( 'reset' => 1, 'username' => $this->mEditUserUsername ) ); |
175 | | - |
176 | 129 | $html .= "\n" . Xml::element('a', array( 'href'=> $url ), wfMsgHtml( 'restoreprefs' ) ); |
177 | 130 | |
178 | 131 | $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html ); |