Index: trunk/extensions/OpenID/SpecialOpenID.body.php |
— | — | @@ -90,27 +90,29 @@ |
91 | 91 | static function getUserUrl($user) { |
92 | 92 | $openid_url = null; |
93 | 93 | |
94 | | - if (isset($user) && $user->getId() != 0) { |
| 94 | + if ( isset( $user ) && $user->getId() != 0 ) { |
95 | 95 | global $wgSharedDB, $wgDBprefix; |
96 | | - if (isset($wgSharedDB)) { |
| 96 | + if ( isset( $wgSharedDB ) ) { |
97 | 97 | $tableName = "`${wgSharedDB}`.${wgDBprefix}user_openid"; |
98 | 98 | } else { |
99 | 99 | $tableName = 'user_openid'; |
100 | 100 | } |
101 | 101 | |
102 | | - $dbr =& wfGetDB( DB_SLAVE ); |
103 | | - $res = $dbr->select(array($tableName), |
104 | | - array('uoi_openid'), |
105 | | - array('uoi_user' => $user->getId()), |
106 | | - 'OpenIDGetUserUrl'); |
| 102 | + $dbr = wfGetDB( DB_SLAVE ); |
| 103 | + $res = $dbr->select( |
| 104 | + array( $tableName ), |
| 105 | + array( 'uoi_openid' ), |
| 106 | + array( 'uoi_user' => $user->getId() ), |
| 107 | + __METHOD__ |
| 108 | + ); |
107 | 109 | |
108 | 110 | # This should return 0 or 1 result, since user is unique |
109 | 111 | # in the table. |
110 | 112 | |
111 | | - while ($res && $row = $dbr->fetchObject($res)) { |
| 113 | + while ( $row = $res->fetchObject() ) { |
112 | 114 | $openid_url = $row->uoi_openid; |
113 | 115 | } |
114 | | - $dbr->freeResult($res); |
| 116 | + $res->free(); |
115 | 117 | } |
116 | 118 | return $openid_url; |
117 | 119 | } |
Index: trunk/extensions/OpenID/SpecialOpenIDFinish.body.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | SpecialPage::SpecialPage("OpenIDFinish", '', false); |
37 | 37 | } |
38 | 38 | |
39 | | - function execute($par) { |
| 39 | + function execute( $par) { |
40 | 40 | |
41 | 41 | global $wgUser, $wgOut, $wgRequest; |
42 | 42 | |
— | — | @@ -45,58 +45,59 @@ |
46 | 46 | |
47 | 47 | # Shouldn't work if you're already logged in. |
48 | 48 | |
49 | | - if ($wgUser->getID() != 0) { |
| 49 | + if ( $wgUser->getID() != 0 ) { |
50 | 50 | $this->alreadyLoggedIn(); |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $consumer = $this->getConsumer(); |
55 | 55 | |
56 | | - switch ($par) { |
| 56 | + switch ( $par ) { |
57 | 57 | case 'ChooseName': |
58 | | - list($openid, $sreg) = $this->fetchValues(); |
59 | | - if (!isset($openid)) { |
60 | | - wfDebug("OpenID: aborting in ChooseName because identity_url is missing\n"); |
| 58 | + list( $openid, $sreg) = $this->fetchValues(); |
| 59 | + if ( !isset( $openid ) ) { |
| 60 | + wfDebug( "OpenID: aborting in ChooseName because identity_url is missing\n" ); |
61 | 61 | $this->clearValues(); |
62 | 62 | # No messing around, here |
63 | | - $wgOut->showErrorPage('openiderror', 'openiderrortext'); |
| 63 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | | - if ($wgRequest->getCheck('wpCancel')) { |
| 67 | + if ( $wgRequest->getCheck( 'wpCancel' ) ) { |
68 | 68 | $this->clearValues(); |
69 | | - $wgOut->showErrorPage('openidcancel', 'openidcanceltext'); |
| 69 | + $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | | - $choice = $wgRequest->getText('wpNameChoice'); |
74 | | - $nameValue = $wgRequest->getText('wpNameValue'); |
| 73 | + $choice = $wgRequest->getText( 'wpNameChoice' ); |
| 74 | + $nameValue = $wgRequest->getText( 'wpNameValue' ); |
75 | 75 | |
76 | 76 | if ($choice == 'existing') { |
77 | | - $user = $this->attachUser($openid, $sreg, |
78 | | - $wgRequest->getText('wpExistingName'), |
79 | | - $wgRequest->getText('wpExistingPassword')); |
| 77 | + $user = $this->attachUser( $openid, $sreg, |
| 78 | + $wgRequest->getText( 'wpExistingName' ), |
| 79 | + $wgRequest->getText( 'wpExistingPassword' ) |
| 80 | + ); |
80 | 81 | |
81 | | - if (!$user) { |
82 | | - $this->chooseNameForm($openid, $sreg, 'wrongpassword'); |
| 82 | + if ( !$user ) { |
| 83 | + $this->chooseNameForm( $openid, $sreg, 'wrongpassword' ); |
83 | 84 | return; |
84 | 85 | } |
85 | 86 | } else { |
86 | | - $name = $this->getUserName($openid, $sreg, $choice, $nameValue); |
| 87 | + $name = $this->getUserName( $openid, $sreg, $choice, $nameValue); |
87 | 88 | |
88 | | - if (!$name || !$this->userNameOK($name)) { |
89 | | - wfDebug("OpenID: Name not OK: '$name'\n"); |
90 | | - $this->chooseNameForm($openid, $sreg); |
| 89 | + if ( !$name || !$this->userNameOK( $name ) ) { |
| 90 | + wfDebug( "OpenID: Name not OK: '$name'\n" ); |
| 91 | + $this->chooseNameForm( $openid, $sreg ); |
91 | 92 | return; |
92 | 93 | } |
93 | 94 | |
94 | | - $user = $this->createUser($openid, $sreg, $name); |
| 95 | + $user = $this->createUser( $openid, $sreg, $name ); |
95 | 96 | } |
96 | 97 | |
97 | | - if (!isset($user)) { |
98 | | - wfDebug("OpenID: aborting in ChooseName because we could not create user object\n"); |
| 98 | + if ( !isset( $user ) ) { |
| 99 | + wfDebug( "OpenID: aborting in ChooseName because we could not create user object\n" ); |
99 | 100 | $this->clearValues(); |
100 | | - $wgOut->showErrorPage('openiderror', 'openiderrortext'); |
| 101 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
101 | 102 | return; |
102 | 103 | } |
103 | 104 | |
— | — | @@ -104,71 +105,70 @@ |
105 | 106 | |
106 | 107 | $this->clearValues(); |
107 | 108 | |
108 | | - $this->finishLogin($response->identity_url); |
| 109 | + $this->finishLogin( $response->identity_url ); |
109 | 110 | break; |
110 | 111 | |
111 | 112 | default: # No parameter, returning from a server |
112 | 113 | |
113 | | - $response = $consumer->complete($this->scriptUrl('OpenIDFinish')); |
| 114 | + $response = $consumer->complete( $this->scriptUrl( 'OpenIDFinish' ) ); |
114 | 115 | |
115 | | - if (!isset($response)) { |
116 | | - wfDebug("OpenID: aborting in auth because no response was recieved\n"); |
117 | | - $wgOut->showErrorPage('openiderror', 'openiderrortext'); |
| 116 | + if ( !isset( $response ) ) { |
| 117 | + wfDebug( "OpenID: aborting in auth because no response was recieved\n" ); |
| 118 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
118 | 119 | return; |
119 | 120 | } |
120 | 121 | |
121 | | - switch ($response->status) { |
| 122 | + switch ( $response->status ) { |
122 | 123 | case Auth_OpenID_CANCEL: |
123 | 124 | // This means the authentication was cancelled. |
124 | | - $wgOut->showErrorPage('openidcancel', 'openidcanceltext'); |
| 125 | + $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
125 | 126 | break; |
126 | 127 | case Auth_OpenID_FAILURE: |
127 | | - wfDebug("OpenID: error message '" . $response->message . "'\n"); |
128 | | - $wgOut->showErrorPage('openidfailure', 'openidfailuretext', |
129 | | - array(($response->message) ? $response->message : '')); |
| 128 | + wfDebug( "OpenID: error message '" . $response->message . "'\n" ); |
| 129 | + $wgOut->showErrorPage( 'openidfailure', 'openidfailuretext', |
| 130 | + array( ( $response->message ) ? $response->message : '' ) ); |
130 | 131 | break; |
131 | 132 | case Auth_OpenID_SUCCESS: |
132 | 133 | // This means the authentication succeeded. |
133 | 134 | $openid = $response->getDisplayIdentifier(); |
134 | | - $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); |
| 135 | + $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse( $response ); |
135 | 136 | $sreg = $sreg_resp->contents(); |
136 | 137 | |
137 | 138 | if (!isset($openid)) { |
138 | | - wfDebug("OpenID: aborting in auth success because display identifier is missing\n"); |
139 | | - $wgOut->showErrorPage('openiderror', 'openiderrortext'); |
| 139 | + wfDebug( "OpenID: aborting in auth success because display identifier is missing\n" ); |
| 140 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
140 | 141 | return; |
141 | 142 | } |
142 | 143 | |
143 | | - $user = $this->getUser($openid); |
| 144 | + $user = $this->getUser( $openid ); |
144 | 145 | |
145 | | - if (isset($user)) { |
146 | | - $this->updateUser($user, $sreg); # update from server |
| 146 | + if ( isset( $user ) ) { |
| 147 | + $this->updateUser( $user, $sreg ); # update from server |
147 | 148 | } else { |
148 | 149 | # For easy names |
149 | | - $name = $this->createName($openid, $sreg); |
150 | | - if ($name) { |
151 | | - $user = $this->createUser($openid, $sreg, $name); |
| 150 | + $name = $this->createName( $openid, $sreg ); |
| 151 | + if ( $name ) { |
| 152 | + $user = $this->createUser( $openid, $sreg, $name ); |
152 | 153 | } else { |
153 | 154 | # For hard names |
154 | | - $this->saveValues($openid, $sreg); |
155 | | - $this->chooseNameForm($openid, $sreg); |
| 155 | + $this->saveValues( $openid, $sreg ); |
| 156 | + $this->chooseNameForm( $openid, $sreg ); |
156 | 157 | return; |
157 | 158 | } |
158 | 159 | } |
159 | 160 | |
160 | | - if (!isset($user)) { |
161 | | - wfDebug("OpenID: aborting in auth success because we could not create user object\n"); |
162 | | - $wgOut->showErrorPage('openiderror', 'openiderrortext'); |
| 161 | + if ( !isset( $user ) ) { |
| 162 | + wfDebug( "OpenID: aborting in auth success because we could not create user object\n" ); |
| 163 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
163 | 164 | } else { |
164 | 165 | $wgUser = $user; |
165 | | - $this->finishLogin($openid); |
| 166 | + $this->finishLogin( $openid ); |
166 | 167 | } |
167 | 168 | } |
168 | 169 | } |
169 | 170 | } |
170 | 171 | |
171 | | - function finishLogin($openid) { |
172 | | - |
| 172 | + function finishLogin( $openid ) { |
173 | 173 | global $wgUser, $wgOut; |
174 | 174 | |
175 | 175 | $wgUser->SetupSession(); |
— | — | @@ -187,37 +187,37 @@ |
188 | 188 | $wgOut->setArticleRelated( false ); |
189 | 189 | $wgOut->addWikiText( wfMsg( 'openidsuccess', $wgUser->getName(), $openid ) ); |
190 | 190 | $wgOut->addHtml( $inject_html ); |
191 | | - $wgOut->returnToMain(false, $this->returnTo()); |
| 191 | + $wgOut->returnToMain( false, $this->returnTo() ); |
192 | 192 | } |
193 | 193 | |
194 | | - function loginSetCookie($openid) { |
| 194 | + function loginSetCookie( $openid ) { |
195 | 195 | global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix; |
196 | 196 | global $wgOpenIDCookieExpiration; |
197 | 197 | |
198 | 198 | $exp = time() + $wgOpenIDCookieExpiration; |
199 | 199 | |
200 | | - setcookie($wgCookiePrefix.'OpenID', $openid, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure); |
| 200 | + setcookie( $wgCookiePrefix.'OpenID', $openid, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure ); |
201 | 201 | } |
202 | 202 | |
203 | | - function chooseNameForm($openid, $sreg, $messagekey = NULL) { |
| 203 | + function chooseNameForm( $openid, $sreg, $messagekey = NULL ) { |
204 | 204 | |
205 | 205 | global $wgOut, $wgUser, $wgOpenIDOnly; |
206 | 206 | |
207 | 207 | $sk = $wgUser->getSkin(); |
208 | 208 | if ($messagekey) { |
209 | | - $message = wfMsg($messagekey); |
210 | | - } else if (array_key_exists('nickname', $sreg)) { |
211 | | - $message = wfMsg('openidnotavailable', $sreg['nickname']); |
| 209 | + $message = wfMsg( $messagekey ); |
| 210 | + } else if ( array_key_exists( 'nickname', $sreg ) ) { |
| 211 | + $message = wfMsg( 'openidnotavailable', $sreg['nickname'] ); |
212 | 212 | } else { |
213 | | - $message = wfMsg('openidnotprovided'); |
| 213 | + $message = wfMsg( 'openidnotprovided' ); |
214 | 214 | } |
215 | | - $instructions = wfMsg('openidchooseinstructions'); |
216 | | - $wgOut->addHTML("<p>{$message}</p>" . |
217 | | - "<p>{$instructions}</p>" . |
218 | | - '<form action="' . $sk->makeSpecialUrl('OpenIDFinish/ChooseName') . '" method="POST">'); |
| 215 | + $instructions = wfMsg( 'openidchooseinstructions' ); |
| 216 | + $wgOut->addHTML( "<p>{$message}</p>" . |
| 217 | + "<p>{$instructions}</p>" . |
| 218 | + '<form action="' . $sk->makeSpecialUrl( 'OpenIDFinish/ChooseName' ) . '" method="POST">' ); |
219 | 219 | $def = false; |
220 | 220 | |
221 | | - if (!$wgOpenIDOnly) { |
| 221 | + if ( !$wgOpenIDOnly ) { |
222 | 222 | # Let them attach it to an existing user |
223 | 223 | |
224 | 224 | # Grab the UserName in the cookie if it exists |
— | — | @@ -229,67 +229,66 @@ |
230 | 230 | } |
231 | 231 | |
232 | 232 | $wgOut->addHTML("<input type='radio' name='wpNameChoice' id='wpNameChoiceExisting' value='existing' /> " . |
233 | | - "<label for='wpNameChoiceExisting'>" . wfMsg("openidchooseexisting") . "</label> " . |
| 233 | + "<label for='wpNameChoiceExisting'>" . wfMsg( "openidchooseexisting" ) . "</label> " . |
234 | 234 | "<input type='text' name='wpExistingName' id='wpExistingName' size='16' value='{$name}'> " . |
235 | | - "<label for='wpExistingPassword'>" . wfMsg("openidchoosepassword") . "</label> " . |
236 | | - "<input type='password' name='wpExistingPassword' size='8' /><br />"); |
| 235 | + "<label for='wpExistingPassword'>" . wfMsg( "openidchoosepassword" ) . "</label> " . |
| 236 | + "<input type='password' name='wpExistingPassword' size='8' /><br />" ); |
237 | 237 | } |
238 | 238 | |
239 | 239 | # These options won't exist if we can't get them. |
240 | 240 | |
241 | | - if (array_key_exists('fullname', $sreg) && $this->userNameOK($sreg['fullname'])) { |
242 | | - $wgOut->addHTML("<input type='radio' name='wpNameChoice' id='wpNameChoiceFull' value='full' " . |
243 | | - ((!$def) ? "checked = 'checked'" : "") . " />" . |
244 | | - "<label for='wpNameChoiceFull'>" . wfMsg("openidchoosefull", $sreg['fullname']) . "</label><br />"); |
| 241 | + if ( array_key_exists( 'fullname', $sreg ) && $this->userNameOK( $sreg['fullname'] ) ) { |
| 242 | + $wgOut->addHTML( "<input type='radio' name='wpNameChoice' id='wpNameChoiceFull' value='full' " . |
| 243 | + ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
| 244 | + "<label for='wpNameChoiceFull'>" . wfMsg( "openidchoosefull", $sreg['fullname'] ) . "</label><br />" ); |
245 | 245 | $def = true; |
246 | 246 | } |
247 | 247 | |
248 | | - $idname = $this->toUserName($openid); |
| 248 | + $idname = $this->toUserName( $openid ); |
249 | 249 | |
250 | | - if ($idname && $this->userNameOK($idname)) { |
251 | | - $wgOut->addHTML("<input type='radio' name='wpNameChoice' id='wpNameChoiceUrl' value='url' " . |
252 | | - ((!$def) ? "checked = 'checked'" : "") . " />" . |
253 | | - "<label for='wpNameChoiceUrl'>" . wfMsg("openidchooseurl", $idname) . "</label><br />"); |
| 250 | + if ( $idname && $this->userNameOK( $idname ) ) { |
| 251 | + $wgOut->addHTML( "<input type='radio' name='wpNameChoice' id='wpNameChoiceUrl' value='url' " . |
| 252 | + ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
| 253 | + "<label for='wpNameChoiceUrl'>" . wfMsg( "openidchooseurl", $idname ) . "</label><br />" ); |
254 | 254 | $def = true; |
255 | 255 | } |
256 | 256 | |
257 | 257 | # These are always available |
258 | 258 | |
259 | | - $wgOut->addHTML("<input type='radio' name='wpNameChoice' id='wpNameChoiceAuto' value='auto' " . |
260 | | - ((!$def) ? "checked = 'checked'" : "") . " />" . |
261 | | - "<label for='wpNameChoiceAuto'>" . wfMsg("openidchooseauto", $this->automaticName($sreg)) . "</label><br />"); |
| 259 | + $wgOut->addHTML( "<input type='radio' name='wpNameChoice' id='wpNameChoiceAuto' value='auto' " . |
| 260 | + ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
| 261 | + "<label for='wpNameChoiceAuto'>" . wfMsg( "openidchooseauto", $this->automaticName( $sreg ) ) . "</label><br />"); |
262 | 262 | |
263 | 263 | $def = true; |
264 | 264 | |
265 | 265 | $wgOut->addHTML("<input type='radio' name='wpNameChoice' id='wpNameChoiceManual' value='manual' " . |
266 | 266 | " checked='off' />" . |
267 | | - "<label for='wpNameChoiceManual'>" . wfMsg("openidchoosemanual") . "</label> " . |
| 267 | + "<label for='wpNameChoiceManual'>" . wfMsg( "openidchoosemanual" ) . "</label> " . |
268 | 268 | "<input type='text' name='wpNameValue' id='wpNameValue' size='16' /><br />"); |
269 | 269 | |
270 | | - $ok = wfMsg('login'); |
271 | | - $cancel = wfMsg('cancel'); |
| 270 | + $ok = wfMsg( 'login' ); |
| 271 | + $cancel = wfMsg( 'cancel' ); |
272 | 272 | |
273 | | - $wgOut->addHTML("<input type='submit' name='wpOK' value='{$ok}' /> <input type='submit' name='wpCancel' value='{$cancel}' />"); |
274 | | - $wgOut->addHTML("</form>"); |
| 273 | + $wgOut->addHTML( "<input type='submit' name='wpOK' value='{$ok}' /> <input type='submit' name='wpCancel' value='{$cancel}' />" ); |
| 274 | + $wgOut->addHTML( "</form>" ); |
275 | 275 | } |
276 | 276 | |
277 | | - function canLogin($openid_url) { |
278 | | - |
| 277 | + function canLogin( $openid_url ) { |
279 | 278 | global $wgOpenIDConsumerDenyByDefault, $wgOpenIDConsumerAllow, $wgOpenIDConsumerDeny; |
280 | 279 | |
281 | | - if ($this->isLocalUrl($openid_url)) { |
| 280 | + if ( $this->isLocalUrl( $openid_url ) ) { |
282 | 281 | return false; |
283 | 282 | } |
284 | 283 | |
285 | | - if ($wgOpenIDConsumerDenyByDefault) { |
| 284 | + if ( $wgOpenIDConsumerDenyByDefault ) { |
286 | 285 | $canLogin = false; |
287 | | - foreach ($wgOpenIDConsumerAllow as $allow) { |
288 | | - if (preg_match($allow, $openid_url)) { |
289 | | - wfDebug("OpenID: $openid_url matched allow pattern $allow.\n"); |
| 286 | + foreach ( $wgOpenIDConsumerAllow as $allow ) { |
| 287 | + if ( preg_match( $allow, $openid_url ) ) { |
| 288 | + wfDebug( "OpenID: $openid_url matched allow pattern $allow.\n" ); |
290 | 289 | $canLogin = true; |
291 | | - foreach ($wgOpenIDConsumerDeny as $deny) { |
292 | | - if (preg_match($deny, $openid_url)) { |
293 | | - wfDebug("OpenID: $openid_url matched deny pattern $deny.\n"); |
| 290 | + foreach ( $wgOpenIDConsumerDeny as $deny ) { |
| 291 | + if ( preg_match( $deny, $openid_url ) ) { |
| 292 | + wfDebug( "OpenID: $openid_url matched deny pattern $deny.\n" ); |
294 | 293 | $canLogin = false; |
295 | 294 | break; |
296 | 295 | } |
— | — | @@ -299,13 +298,13 @@ |
300 | 299 | } |
301 | 300 | } else { |
302 | 301 | $canLogin = true; |
303 | | - foreach ($wgOpenIDConsumerDeny as $deny) { |
304 | | - if (preg_match($deny, $openid_url)) { |
305 | | - wfDebug("OpenID: $openid_url matched deny pattern $deny.\n"); |
| 302 | + foreach ( $wgOpenIDConsumerDeny as $deny ) { |
| 303 | + if ( preg_match( $deny, $openid_url ) ) { |
| 304 | + wfDebug( "OpenID: $openid_url matched deny pattern $deny.\n" ); |
306 | 305 | $canLogin = false; |
307 | | - foreach ($wgOpenIDConsumerAllow as $allow) { |
308 | | - if (preg_match($allow, $openid_url)) { |
309 | | - wfDebug("OpenID: $openid_url matched allow pattern $allow.\n"); |
| 306 | + foreach ( $wgOpenIDConsumerAllow as $allow ) { |
| 307 | + if ( preg_match( $allow, $openid_url ) ) { |
| 308 | + wfDebug( "OpenID: $openid_url matched allow pattern $allow.\n" ); |
310 | 309 | $canLogin = true; |
311 | 310 | break; |
312 | 311 | } |
— | — | @@ -317,40 +316,43 @@ |
318 | 317 | return $canLogin; |
319 | 318 | } |
320 | 319 | |
321 | | - function isLocalUrl($url) { |
322 | | - |
| 320 | + function isLocalUrl( $url ) { |
323 | 321 | global $wgServer, $wgArticlePath; |
324 | 322 | |
325 | 323 | $pattern = $wgServer . $wgArticlePath; |
326 | | - $pattern = str_replace('$1', '(.*)', $pattern); |
327 | | - $pattern = str_replace('?', '\?', $pattern); |
| 324 | + $pattern = str_replace( '$1', '(.*)', $pattern ); |
| 325 | + $pattern = str_replace( '?', '\?', $pattern ); |
328 | 326 | |
329 | | - return preg_match('|^' . $pattern . '$|', $url); |
| 327 | + return preg_match( '|^' . $pattern . '$|', $url ); |
330 | 328 | } |
331 | 329 | |
332 | 330 | # Find the user with the given openid, if any |
333 | 331 | |
334 | | - function getUser($openid) { |
| 332 | + function getUser( $openid ) { |
335 | 333 | global $wgSharedDB, $wgDBprefix; |
336 | 334 | |
337 | | - if (isset($wgSharedDB)) { |
| 335 | + if ( isset( $wgSharedDB ) ) { |
338 | 336 | $tableName = "`$wgSharedDB`.${wgDBprefix}user_openid"; |
339 | 337 | } else { |
340 | 338 | $tableName = 'user_openid'; |
341 | 339 | } |
342 | 340 | |
343 | | - $dbr =& wfGetDB( DB_SLAVE ); |
344 | | - $id = $dbr->selectField($tableName, 'uoi_user', |
345 | | - array('uoi_openid' => $openid)); |
346 | | - if ($id) { |
347 | | - $name = User::whoIs($id); |
348 | | - return User::newFromName($name); |
| 341 | + $dbr = wfGetDB( DB_SLAVE ); |
| 342 | + $id = $dbr->selectField( |
| 343 | + $tableName, |
| 344 | + 'uoi_user', |
| 345 | + array( 'uoi_openid' => $openid ), |
| 346 | + __METHOD__ |
| 347 | + ); |
| 348 | + if ( $id ) { |
| 349 | + $name = User::whoIs( $id ); |
| 350 | + return User::newFromName( $name ); |
349 | 351 | } else { |
350 | 352 | return NULL; |
351 | 353 | } |
352 | 354 | } |
353 | 355 | |
354 | | - function updateUser($user, $sreg) { |
| 356 | + function updateUser( $user, $sreg ) { |
355 | 357 | global $wgAllowRealName; |
356 | 358 | |
357 | 359 | # FIXME: only update if there's been a change |
— | — | @@ -541,33 +543,35 @@ |
542 | 544 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
543 | 545 | $wgOut->setArticleRelated( false ); |
544 | 546 | $wgOut->addWikiText( wfMsg( 'openidalreadyloggedin', $wgUser->getName() ) ); |
545 | | - $wgOut->returnToMain(false, $this->returnTo() ); |
| 547 | + $wgOut->returnToMain( false, $this->returnTo() ); |
546 | 548 | } |
547 | 549 | |
548 | | - function getUserUrl($user) { |
| 550 | + static function getUserUrl( $user ) { |
549 | 551 | $openid_url = null; |
550 | 552 | |
551 | | - if (isset($user) && $user->getId() != 0) { |
| 553 | + if ( isset( $user ) && $user->getId() != 0 ) { |
552 | 554 | global $wgSharedDB, $wgDBprefix; |
553 | | - if (isset($wgSharedDB)) { |
| 555 | + if ( isset( $wgSharedDB ) ) { |
554 | 556 | $tableName = "`${wgSharedDB}`.${wgDBprefix}user_openid"; |
555 | 557 | } else { |
556 | 558 | $tableName = 'user_openid'; |
557 | 559 | } |
558 | 560 | |
559 | | - $dbr =& wfGetDB( DB_SLAVE ); |
560 | | - $res = $dbr->select(array($tableName), |
561 | | - array('uoi_openid'), |
562 | | - array('uoi_user' => $user->getId()), |
563 | | - 'SpecialOpenIDFinish::getUserUrl'); |
| 561 | + $dbr = wfGetDB( DB_SLAVE ); |
| 562 | + $res = $dbr->select( |
| 563 | + array( $tableName ), |
| 564 | + array( 'uoi_openid' ), |
| 565 | + array( 'uoi_user' => $user->getId() ), |
| 566 | + __METHOD__ |
| 567 | + ); |
564 | 568 | |
565 | 569 | # This should return 0 or 1 result, since user is unique |
566 | 570 | # in the table. |
567 | 571 | |
568 | | - while ($res && $row = $dbr->fetchObject($res)) { |
| 572 | + while ( $row = $res->fetchObject() ) { |
569 | 573 | $openid_url = $row->uoi_openid; |
570 | 574 | } |
571 | | - $dbr->freeResult($res); |
| 575 | + $res->free(); |
572 | 576 | } |
573 | 577 | return $openid_url; |
574 | 578 | } |
— | — | @@ -586,13 +590,13 @@ |
587 | 591 | } |
588 | 592 | |
589 | 593 | function clearValues() { |
590 | | - unset($_SESSION['openid_consumer_identity']); |
591 | | - unset($_SESSION['openid_consumer_sreg']); |
| 594 | + unset( $_SESSION['openid_consumer_identity'] ); |
| 595 | + unset( $_SESSION['openid_consumer_sreg'] ); |
592 | 596 | return true; |
593 | 597 | } |
594 | 598 | |
595 | 599 | function fetchValues() { |
596 | | - return array($_SESSION['openid_consumer_identity'], $_SESSION['openid_consumer_sreg']); |
| 600 | + return array( $_SESSION['openid_consumer_identity'], $_SESSION['openid_consumer_sreg'] ); |
597 | 601 | } |
598 | 602 | |
599 | 603 | function returnTo() { |
— | — | @@ -604,15 +608,15 @@ |
605 | 609 | } |
606 | 610 | |
607 | 611 | function getUserName($openid, $sreg, $choice, $nameValue) { |
608 | | - switch ($choice) { |
| 612 | + switch ( $choice ) { |
609 | 613 | case 'full': |
610 | | - return ((array_key_exists('fullname', $sreg)) ? $sreg['fullname'] : null); |
| 614 | + return ( ( array_key_exists( 'fullname', $sreg ) ) ? $sreg['fullname'] : null ); |
611 | 615 | break; |
612 | 616 | case 'url': |
613 | | - return $this->toUserName($openid); |
| 617 | + return $this->toUserName( $openid ); |
614 | 618 | break; |
615 | 619 | case 'auto': |
616 | | - return $this->automaticName($sreg); |
| 620 | + return $this->automaticName( $sreg ); |
617 | 621 | break; |
618 | 622 | case 'manual': |
619 | 623 | return $nameValue; |
— | — | @@ -621,29 +625,29 @@ |
622 | 626 | } |
623 | 627 | } |
624 | 628 | |
625 | | - function automaticName($sreg) { |
626 | | - if (array_key_exists('nickname', $sreg) && # try auto-generated from nickname |
627 | | - strlen($sreg['nickname']) > 0) { |
628 | | - return $this->firstAvailable($sreg['nickname']); |
| 629 | + function automaticName( $sreg ) { |
| 630 | + if ( array_key_exists( 'nickname', $sreg ) && # try auto-generated from nickname |
| 631 | + strlen( $sreg['nickname']) > 0 ) { |
| 632 | + return $this->firstAvailable( $sreg['nickname'] ); |
629 | 633 | } else { # try auto-generated |
630 | | - return $this->firstAvailable(wfMsg('openidusernameprefix')); |
| 634 | + return $this->firstAvailable( wfMsg( 'openidusernameprefix' ) ); |
631 | 635 | } |
632 | 636 | } |
633 | 637 | |
634 | | - function attachUser($openid, $sreg, $name, $password) { |
| 638 | + function attachUser( $openid, $sreg, $name, $password ) { |
635 | 639 | |
636 | | - $user = User::newFromName($name); |
| 640 | + $user = User::newFromName( $name ); |
637 | 641 | |
638 | | - if (!$user) { |
| 642 | + if ( !$user ) { |
639 | 643 | return NULL; |
640 | 644 | } |
641 | 645 | |
642 | | - if (!$user->checkPassword($password)) { |
| 646 | + if ( !$user->checkPassword( $password ) ) { |
643 | 647 | return NULL; |
644 | 648 | } |
645 | 649 | |
646 | | - $this->setUserUrl($user, $openid); |
647 | | - $this->updateUser($user, $sreg); |
| 650 | + $this->setUserUrl( $user, $openid ); |
| 651 | + $this->updateUser( $user, $sreg ); |
648 | 652 | |
649 | 653 | return $user; |
650 | 654 | } |