Index: trunk/extensions/OpenID/SpecialOpenIDFinish.body.php |
— | — | @@ -1,676 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * SpecialOpenIDFinish.body.php -- Finish logging into an OpenID site |
5 | | - * Copyright 2006,2007 Internet Brands (http://www.internetbrands.com/) |
6 | | - * Copyright 2007,2008 Evan Prodromou <evan@prodromou.name> |
7 | | - * |
8 | | - * This program is free software; you can redistribute it and/or modify |
9 | | - * it under the terms of the GNU General Public License as published by |
10 | | - * the Free Software Foundation; either version 2 of the License, or |
11 | | - * (at your option) any later version. |
12 | | - * |
13 | | - * This program is distributed in the hope that it will be useful, |
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | - * GNU General Public License for more details. |
17 | | - * |
18 | | - * You should have received a copy of the GNU General Public License |
19 | | - * along with this program; if not, write to the Free Software |
20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | | - * |
22 | | - * @author Evan Prodromou <evan@prodromou.name> |
23 | | - * @addtogroup Extensions |
24 | | - */ |
25 | | - |
26 | | -if ( !defined( 'MEDIAWIKI' ) ) |
27 | | - exit( 1 ); |
28 | | - |
29 | | -require_once( "Auth/OpenID/Consumer.php" ); |
30 | | -require_once( "Auth/OpenID/SReg.php" ); |
31 | | -require_once( "Auth/Yadis/XRI.php" ); |
32 | | - |
33 | | -class SpecialOpenIDFinish extends SpecialOpenID { |
34 | | - function SpecialOpenIDFinish() { |
35 | | - SpecialPage::SpecialPage( "OpenIDFinish", '', false ); |
36 | | - } |
37 | | - |
38 | | - function execute( $par ) { |
39 | | - |
40 | | - global $wgUser, $wgOut, $wgRequest; |
41 | | - |
42 | | - wfLoadExtensionMessages( 'OpenID' ); |
43 | | - |
44 | | - $this->setHeaders(); |
45 | | - |
46 | | - # Shouldn't work if you're already logged in. |
47 | | - |
48 | | - if ( $wgUser->getID() != 0 ) { |
49 | | - $this->alreadyLoggedIn(); |
50 | | - return; |
51 | | - } |
52 | | - |
53 | | - $consumer = $this->getConsumer(); |
54 | | - |
55 | | - switch ( $par ) { |
56 | | - case 'ChooseName': |
57 | | - list( $openid, $sreg ) = $this->fetchValues(); |
58 | | - if ( !isset( $openid ) ) { |
59 | | - wfDebug( "OpenID: aborting in ChooseName because identity_url is missing\n" ); |
60 | | - $this->clearValues(); |
61 | | - # No messing around, here |
62 | | - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
63 | | - return; |
64 | | - } |
65 | | - |
66 | | - if ( $wgRequest->getCheck( 'wpCancel' ) ) { |
67 | | - $this->clearValues(); |
68 | | - $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
69 | | - return; |
70 | | - } |
71 | | - |
72 | | - $choice = $wgRequest->getText( 'wpNameChoice' ); |
73 | | - $nameValue = $wgRequest->getText( 'wpNameValue' ); |
74 | | - |
75 | | - if ( $choice == 'existing' ) { |
76 | | - $user = $this->attachUser( $openid, $sreg, |
77 | | - $wgRequest->getText( 'wpExistingName' ), |
78 | | - $wgRequest->getText( 'wpExistingPassword' ) |
79 | | - ); |
80 | | - |
81 | | - if ( !$user ) { |
82 | | - $this->chooseNameForm( $openid, $sreg, 'wrongpassword' ); |
83 | | - return; |
84 | | - } |
85 | | - |
86 | | - if ( $wgRequest->getText( 'wpUpdateUserInfo' ) ) |
87 | | - { |
88 | | - $this->updateUser( $user, $sreg ); |
89 | | - } |
90 | | - } else { |
91 | | - $name = $this->getUserName( $openid, $sreg, $choice, $nameValue ); |
92 | | - |
93 | | - if ( !$name || !$this->userNameOK( $name ) ) { |
94 | | - wfDebug( "OpenID: Name not OK: '$name'\n" ); |
95 | | - $this->chooseNameForm( $openid, $sreg ); |
96 | | - return; |
97 | | - } |
98 | | - |
99 | | - $user = $this->createUser( $openid, $sreg, $name ); |
100 | | - } |
101 | | - |
102 | | - if ( !isset( $user ) ) { |
103 | | - wfDebug( "OpenID: aborting in ChooseName because we could not create user object\n" ); |
104 | | - $this->clearValues(); |
105 | | - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
106 | | - return; |
107 | | - } |
108 | | - |
109 | | - $wgUser = $user; |
110 | | - |
111 | | - $this->clearValues(); |
112 | | - |
113 | | - $this->finishLogin( $response->identity_url ); |
114 | | - break; |
115 | | - |
116 | | - default: # No parameter, returning from a server |
117 | | - |
118 | | - $response = $consumer->complete( $this->scriptUrl( 'OpenIDFinish' ) ); |
119 | | - |
120 | | - if ( !isset( $response ) ) { |
121 | | - wfDebug( "OpenID: aborting in auth because no response was recieved\n" ); |
122 | | - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
123 | | - return; |
124 | | - } |
125 | | - |
126 | | - switch ( $response->status ) { |
127 | | - case Auth_OpenID_CANCEL: |
128 | | - // This means the authentication was cancelled. |
129 | | - $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
130 | | - break; |
131 | | - case Auth_OpenID_FAILURE: |
132 | | - wfDebug( "OpenID: error message '" . $response->message . "'\n" ); |
133 | | - $wgOut->showErrorPage( 'openidfailure', 'openidfailuretext', |
134 | | - array( ( $response->message ) ? $response->message : '' ) ); |
135 | | - break; |
136 | | - case Auth_OpenID_SUCCESS: |
137 | | - // This means the authentication succeeded. |
138 | | - $openid = $response->getDisplayIdentifier(); |
139 | | - $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse( $response ); |
140 | | - $sreg = $sreg_resp->contents(); |
141 | | - |
142 | | - if ( !isset( $openid ) ) { |
143 | | - wfDebug( "OpenID: aborting in auth success because display identifier is missing\n" ); |
144 | | - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
145 | | - return; |
146 | | - } |
147 | | - |
148 | | - $user = $this->getUser( $openid ); |
149 | | - |
150 | | - if ( isset( $user ) ) |
151 | | - { |
152 | | - if ( $user->getOption( 'openid-update-userinfo-on-login' ) ) |
153 | | - { |
154 | | - $this->updateUser( $user, $sreg ); # update from server |
155 | | - } |
156 | | - } else { |
157 | | - # For easy names |
158 | | - $name = $this->createName( $openid, $sreg ); |
159 | | - if ( $name ) { |
160 | | - $user = $this->createUser( $openid, $sreg, $name ); |
161 | | - } else { |
162 | | - # For hard names |
163 | | - $this->saveValues( $openid, $sreg ); |
164 | | - $this->chooseNameForm( $openid, $sreg ); |
165 | | - return; |
166 | | - } |
167 | | - } |
168 | | - |
169 | | - if ( !isset( $user ) ) { |
170 | | - wfDebug( "OpenID: aborting in auth success because we could not create user object\n" ); |
171 | | - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
172 | | - } else { |
173 | | - $wgUser = $user; |
174 | | - $this->finishLogin( $openid ); |
175 | | - } |
176 | | - } |
177 | | - } |
178 | | - } |
179 | | - |
180 | | - function finishLogin( $openid ) { |
181 | | - global $wgUser, $wgOut; |
182 | | - |
183 | | - $wgUser->SetupSession(); |
184 | | - $wgUser->SetCookies(); |
185 | | - |
186 | | - # Run any hooks; ignore results |
187 | | - $inject_html = ''; |
188 | | - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$inject_html ) ); |
189 | | - |
190 | | - # Set a cookie for later check-immediate use |
191 | | - |
192 | | - $this->loginSetCookie( $openid ); |
193 | | - |
194 | | - $wgOut->setPageTitle( wfMsg( 'openidsuccess' ) ); |
195 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
196 | | - $wgOut->setArticleRelated( false ); |
197 | | - $wgOut->addWikiText( wfMsg( 'openidsuccess', $wgUser->getName(), $openid ) ); |
198 | | - $wgOut->addHtml( $inject_html ); |
199 | | - $wgOut->returnToMain( false, $this->returnTo() ); |
200 | | - } |
201 | | - |
202 | | - function loginSetCookie( $openid ) { |
203 | | - global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix; |
204 | | - global $wgOpenIDCookieExpiration; |
205 | | - |
206 | | - $exp = time() + $wgOpenIDCookieExpiration; |
207 | | - |
208 | | - setcookie( $wgCookiePrefix . 'OpenID', $openid, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure ); |
209 | | - } |
210 | | - |
211 | | - function chooseNameForm( $openid, $sreg, $messagekey = NULL ) { |
212 | | - |
213 | | - global $wgOut, $wgUser, $wgOpenIDOnly; |
214 | | - |
215 | | - $sk = $wgUser->getSkin(); |
216 | | - if ( $messagekey ) { |
217 | | - $message = wfMsg( $messagekey ); |
218 | | - } else if ( array_key_exists( 'nickname', $sreg ) ) { |
219 | | - $message = wfMsg( 'openidnotavailable', $sreg['nickname'] ); |
220 | | - } else { |
221 | | - $message = wfMsg( 'openidnotprovided' ); |
222 | | - } |
223 | | - $instructions = wfMsg( 'openidchooseinstructions' ); |
224 | | - $wgOut->addHTML( "<p>{$message}</p>" . |
225 | | - "<p>{$instructions}</p>" . |
226 | | - '<form action="' . $sk->makeSpecialUrl( 'OpenIDFinish/ChooseName' ) . '" method="POST">' ); |
227 | | - $def = false; |
228 | | - |
229 | | - if ( !$wgOpenIDOnly ) { |
230 | | - # Let them attach it to an existing user |
231 | | - |
232 | | - # Grab the UserName in the cookie if it exists |
233 | | - |
234 | | - global $wgCookiePrefix; |
235 | | - $name = ''; |
236 | | - if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) { |
237 | | - $name = trim( $_COOKIE["{$wgCookiePrefix}UserName"] ); |
238 | | - } |
239 | | - |
240 | | - # show OpenID Attributes |
241 | | - $oidAttributesToAccept = array( 'fullname', 'nickname', 'email', 'language' ); |
242 | | - $oidAttributes = array(); |
243 | | - |
244 | | - foreach ( $oidAttributesToAccept as $oidAttr ) |
245 | | - { |
246 | | - if ( $oidAttr == 'fullname' && !$wgAllowRealName ) |
247 | | - { |
248 | | - next; |
249 | | - } |
250 | | - |
251 | | - if ( array_key_exists( $oidAttr, $sreg ) ) { |
252 | | - $oidAttributes[] = '<div>' . wfMsg( "openid$oidAttr" ) . ': <i>' . $sreg[$oidAttr] . '</i></div>'; |
253 | | - } |
254 | | - } |
255 | | - |
256 | | - $oidAttributesUpdate = ''; |
257 | | - if ( count( $oidAttributes ) > 0 ) |
258 | | - { |
259 | | - $oidAttributesUpdate = '<div style="margin-left: 25px">' . |
260 | | - '<input type="checkbox" name="wpUpdateUserInfo" id="wpUpdateUserInfo">' . |
261 | | - '<label for="wpUpdateUserInfo">' . wfMsg( "openidupdateuserinfo" ) . |
262 | | - '<div style="margin-left: 25px">' . implode( '', $oidAttributes ) . '</div>' . |
263 | | - '</label></div>'; |
264 | | - } |
265 | | - |
266 | | - $wgOut->addHTML( "<div><input type='radio' name='wpNameChoice' id='wpNameChoiceExisting' value='existing' />" . |
267 | | - "<label for='wpNameChoiceExisting'>" . wfMsg( "openidchooseexisting" ) . "</label> " . |
268 | | - "<input type='text' name='wpExistingName' id='wpExistingName' size='16' value='{$name}'> " . |
269 | | - "<label for='wpExistingPassword'>" . wfMsg( "openidchoosepassword" ) . "</label> " . |
270 | | - "<input type='password' name='wpExistingPassword' size='8' /> " . |
271 | | - $oidAttributesUpdate . "</div>\n" ); |
272 | | - } |
273 | | - |
274 | | - # These options won't exist if we can't get them. |
275 | | - |
276 | | - if ( array_key_exists( 'fullname', $sreg ) && $this->userNameOK( $sreg['fullname'] ) ) { |
277 | | - $wgOut->addHTML( "<div><input type='radio' name='wpNameChoice' id='wpNameChoiceFull' value='full' " . |
278 | | - ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
279 | | - "<label for='wpNameChoiceFull'>" . wfMsg( "openidchoosefull", $sreg['fullname'] ) . "</label></div>\n" ); |
280 | | - $def = true; |
281 | | - } |
282 | | - |
283 | | - $idname = $this->toUserName( $openid ); |
284 | | - |
285 | | - if ( $idname && $this->userNameOK( $idname ) ) { |
286 | | - $wgOut->addHTML( "<div><input type='radio' name='wpNameChoice' id='wpNameChoiceUrl' value='url' " . |
287 | | - ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
288 | | - "<label for='wpNameChoiceUrl'>" . wfMsg( "openidchooseurl", $idname ) . "</label></div>\n" ); |
289 | | - $def = true; |
290 | | - } |
291 | | - |
292 | | - # These are always available |
293 | | - |
294 | | - $wgOut->addHTML( "<div><input type='radio' name='wpNameChoice' id='wpNameChoiceAuto' value='auto' " . |
295 | | - ( ( !$def ) ? "checked = 'checked'" : "" ) . " />" . |
296 | | - "<label for='wpNameChoiceAuto'>" . wfMsg( "openidchooseauto", $this->automaticName( $sreg ) ) . "</label></div>\n" ); |
297 | | - |
298 | | - $def = true; |
299 | | - |
300 | | - $wgOut->addHTML( "<div><input type='radio' name='wpNameChoice' id='wpNameChoiceManual' value='manual' " . |
301 | | - " checked='off' />" . |
302 | | - "<label for='wpNameChoiceManual'>" . wfMsg( "openidchoosemanual" ) . "</label> " . |
303 | | - "<input type='text' name='wpNameValue' id='wpNameValue' size='16' /></div>\n" ); |
304 | | - |
305 | | - $ok = wfMsg( 'login' ); |
306 | | - $cancel = wfMsg( 'cancel' ); |
307 | | - |
308 | | - $wgOut->addHTML( "<input type='submit' name='wpOK' value='{$ok}' /> <input type='submit' name='wpCancel' value='{$cancel}' />" ); |
309 | | - $wgOut->addHTML( "</form>" ); |
310 | | - } |
311 | | - |
312 | | - function canLogin( $openid_url ) { |
313 | | - global $wgOpenIDConsumerDenyByDefault, $wgOpenIDConsumerAllow, $wgOpenIDConsumerDeny; |
314 | | - |
315 | | - if ( $this->isLocalUrl( $openid_url ) ) { |
316 | | - return false; |
317 | | - } |
318 | | - |
319 | | - if ( $wgOpenIDConsumerDenyByDefault ) { |
320 | | - $canLogin = false; |
321 | | - foreach ( $wgOpenIDConsumerAllow as $allow ) { |
322 | | - if ( preg_match( $allow, $openid_url ) ) { |
323 | | - wfDebug( "OpenID: $openid_url matched allow pattern $allow.\n" ); |
324 | | - $canLogin = true; |
325 | | - foreach ( $wgOpenIDConsumerDeny as $deny ) { |
326 | | - if ( preg_match( $deny, $openid_url ) ) { |
327 | | - wfDebug( "OpenID: $openid_url matched deny pattern $deny.\n" ); |
328 | | - $canLogin = false; |
329 | | - break; |
330 | | - } |
331 | | - } |
332 | | - break; |
333 | | - } |
334 | | - } |
335 | | - } else { |
336 | | - $canLogin = true; |
337 | | - foreach ( $wgOpenIDConsumerDeny as $deny ) { |
338 | | - if ( preg_match( $deny, $openid_url ) ) { |
339 | | - wfDebug( "OpenID: $openid_url matched deny pattern $deny.\n" ); |
340 | | - $canLogin = false; |
341 | | - foreach ( $wgOpenIDConsumerAllow as $allow ) { |
342 | | - if ( preg_match( $allow, $openid_url ) ) { |
343 | | - wfDebug( "OpenID: $openid_url matched allow pattern $allow.\n" ); |
344 | | - $canLogin = true; |
345 | | - break; |
346 | | - } |
347 | | - } |
348 | | - break; |
349 | | - } |
350 | | - } |
351 | | - } |
352 | | - return $canLogin; |
353 | | - } |
354 | | - |
355 | | - function isLocalUrl( $url ) { |
356 | | - global $wgServer, $wgArticlePath; |
357 | | - |
358 | | - $pattern = $wgServer . $wgArticlePath; |
359 | | - $pattern = str_replace( '$1', '(.*)', $pattern ); |
360 | | - $pattern = str_replace( '?', '\?', $pattern ); |
361 | | - |
362 | | - return preg_match( '|^' . $pattern . '$|', $url ); |
363 | | - } |
364 | | - |
365 | | - # Find the user with the given openid, if any |
366 | | - |
367 | | - function getUser( $openid ) { |
368 | | - global $wgSharedDB, $wgDBprefix; |
369 | | - |
370 | | - if ( isset( $wgSharedDB ) ) { |
371 | | - $tableName = "`$wgSharedDB`.${wgDBprefix}user_openid"; |
372 | | - } else { |
373 | | - $tableName = 'user_openid'; |
374 | | - } |
375 | | - |
376 | | - $dbr = wfGetDB( DB_SLAVE ); |
377 | | - $id = $dbr->selectField( |
378 | | - $tableName, |
379 | | - 'uoi_user', |
380 | | - array( 'uoi_openid' => $openid ), |
381 | | - __METHOD__ |
382 | | - ); |
383 | | - if ( $id ) { |
384 | | - return User::newFromID( $id ); |
385 | | - } else { |
386 | | - return NULL; |
387 | | - } |
388 | | - } |
389 | | - |
390 | | - function updateUser( $user, $sreg ) { |
391 | | - global $wgAllowRealName; |
392 | | - |
393 | | - # FIXME: only update if there's been a change |
394 | | - $user->setOption( 'nickname', array_key_exists( 'nickname', $sreg ) |
395 | | - ? $sreg['nickname'] : '' ); |
396 | | - |
397 | | - $user->setEmail( array_key_exists( 'email', $sreg ) ? $sreg['email'] : '' ); |
398 | | - |
399 | | - $user->setRealName( ( array_key_exists( 'fullname', $sreg ) && $wgAllowRealName ) |
400 | | - ? $sreg['fullname'] : '' ); |
401 | | - |
402 | | - if ( array_key_exists( 'language', $sreg ) ) { |
403 | | - # FIXME: check and make sure the language exists |
404 | | - $user->setOption( 'language', $sreg['language'] ); |
405 | | - } else { |
406 | | - $user->setOption( 'language', NULL ); |
407 | | - } |
408 | | - |
409 | | - if ( array_key_exists( 'timezone', $sreg ) ) { |
410 | | - # FIXME: do something with it. |
411 | | - # $offset = OpenIDTimezoneToTzoffset($sreg['timezone']); |
412 | | - # $user->setOption('timecorrection', $offset); |
413 | | - } else { |
414 | | - # $user->setOption('timecorrection', NULL); |
415 | | - } |
416 | | - |
417 | | - $user->saveSettings(); |
418 | | - } |
419 | | - |
420 | | - function createUser( $openid, $sreg, $name ) { |
421 | | - |
422 | | - global $wgAuth, $wgAllowRealName; |
423 | | - |
424 | | - $user = User::newFromName( $name ); |
425 | | - |
426 | | - if ( !$user ) { |
427 | | - wfDebug( "OpenID: Error adding new user.\n" ); |
428 | | - return NULL; |
429 | | - } |
430 | | - |
431 | | - $user->addToDatabase(); |
432 | | - |
433 | | - if ( !$user->getId() ) { |
434 | | - wfDebug( "OpenID: Error adding new user.\n" ); |
435 | | - } else { |
436 | | - |
437 | | - $this->insertUserUrl( $user, $openid ); |
438 | | - |
439 | | - if ( array_key_exists( 'nickname', $sreg ) ) { |
440 | | - $user->setOption( 'nickname', $sreg['nickname'] ); |
441 | | - } |
442 | | - if ( array_key_exists( 'email', $sreg ) ) { |
443 | | - $user->setEmail( $sreg['email'] ); |
444 | | - } |
445 | | - if ( $wgAllowRealName && array_key_exists( 'fullname', $sreg ) ) { |
446 | | - $user->setRealName( $sreg['fullname'] ); |
447 | | - } |
448 | | - if ( array_key_exists( 'language', $sreg ) ) { |
449 | | - # FIXME: check and make sure the language exists |
450 | | - $user->setOption( 'language', $sreg['language'] ); |
451 | | - } |
452 | | - if ( array_key_exists( 'timezone', $sreg ) ) { |
453 | | - # FIXME: do something with it. |
454 | | - # $offset = OpenIDTimezoneToTzoffset($sreg['timezone']); |
455 | | - # $user->setOption('timecorrection', $offset); |
456 | | - } |
457 | | - $user->saveSettings(); |
458 | | - return $user; |
459 | | - } |
460 | | - } |
461 | | - |
462 | | - function createName( $openid, $sreg ) { |
463 | | - |
464 | | - if ( array_key_exists( 'nickname', $sreg ) && # try nickname |
465 | | - $this->userNameOK( $sreg['nickname'] ) ) |
466 | | - { |
467 | | - return $sreg['nickname']; |
468 | | - } |
469 | | - } |
470 | | - |
471 | | - function toUserName( $openid ) { |
472 | | - if ( Auth_Yadis_identifierScheme( $openid ) == 'XRI' ) { |
473 | | - return $this->toUserNameXri( $openid ); |
474 | | - } else { |
475 | | - return $this->toUserNameUrl( $openid ); |
476 | | - } |
477 | | - } |
478 | | - |
479 | | - # We try to use an OpenID URL as a legal MediaWiki user name in this order |
480 | | - # 1. Plain hostname, like http://evanp.myopenid.com/ |
481 | | - # 2. One element in path, like http://profile.typekey.com/EvanProdromou/ |
482 | | - # or http://getopenid.com/evanprodromou |
483 | | - |
484 | | - function toUserNameUrl( $openid ) { |
485 | | - static $bad = array( 'query', 'user', 'password', 'port', 'fragment' ); |
486 | | - |
487 | | - $parts = parse_url( $openid ); |
488 | | - |
489 | | - # If any of these parts exist, this won't work |
490 | | - |
491 | | - foreach ( $bad as $badpart ) { |
492 | | - if ( array_key_exists( $badpart, $parts ) ) { |
493 | | - return NULL; |
494 | | - } |
495 | | - } |
496 | | - |
497 | | - # We just have host and/or path |
498 | | - |
499 | | - # If it's just a host... |
500 | | - if ( array_key_exists( 'host', $parts ) && |
501 | | - ( !array_key_exists( 'path', $parts ) || strcmp( $parts['path'], '/' ) == 0 ) ) |
502 | | - { |
503 | | - $hostparts = explode( '.', $parts['host'] ); |
504 | | - |
505 | | - # Try to catch common idiom of nickname.service.tld |
506 | | - |
507 | | - if ( ( count( $hostparts ) > 2 ) && |
508 | | - ( strlen( $hostparts[count( $hostparts ) - 2] ) > 3 ) && # try to skip .co.uk, .com.au |
509 | | - ( strcmp( $hostparts[0], 'www' ) != 0 ) ) |
510 | | - { |
511 | | - return $hostparts[0]; |
512 | | - } else { |
513 | | - # Do the whole hostname |
514 | | - return $parts['host']; |
515 | | - } |
516 | | - } else { |
517 | | - if ( array_key_exists( 'path', $parts ) ) { |
518 | | - # Strip starting, ending slashes |
519 | | - $path = preg_replace( '@/$@', '', $parts['path'] ); |
520 | | - $path = preg_replace( '@^/@', '', $path ); |
521 | | - if ( strpos( $path, '/' ) === false ) { |
522 | | - return $path; |
523 | | - } |
524 | | - } |
525 | | - } |
526 | | - |
527 | | - return NULL; |
528 | | - } |
529 | | - |
530 | | - function toUserNameXri( $xri ) { |
531 | | - $base = $this->xriBase( $xri ); |
532 | | - |
533 | | - if ( !$base ) { |
534 | | - return NULL; |
535 | | - } else { |
536 | | - # =evan.prodromou |
537 | | - # or @gratis*evan.prodromou |
538 | | - $parts = explode( '*', substr( $base, 1 ) ); |
539 | | - return array_pop( $parts ); |
540 | | - } |
541 | | - } |
542 | | - |
543 | | - # Is this name OK to use as a user name? |
544 | | - |
545 | | - function userNameOK( $name ) { |
546 | | - global $wgReservedUsernames; |
547 | | - return ( 0 == User::idFromName( $name ) && |
548 | | - !in_array( $name, $wgReservedUsernames ) ); |
549 | | - } |
550 | | - |
551 | | - # Get an auto-incremented name |
552 | | - |
553 | | - function firstAvailable( $prefix ) { |
554 | | - for ( $i = 2; ; $i++ ) { # FIXME: this is the DUMB WAY to do this |
555 | | - $name = "$prefix$i"; |
556 | | - if ( $this->userNameOK( $name ) ) { |
557 | | - return $name; |
558 | | - } |
559 | | - } |
560 | | - } |
561 | | - |
562 | | - function alreadyLoggedIn() { |
563 | | - |
564 | | - global $wgUser, $wgOut; |
565 | | - |
566 | | - $wgOut->setPageTitle( wfMsg( 'openiderror' ) ); |
567 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
568 | | - $wgOut->setArticleRelated( false ); |
569 | | - $wgOut->addWikiText( wfMsg( 'openidalreadyloggedin', $wgUser->getName() ) ); |
570 | | - $wgOut->returnToMain( false, $this->returnTo() ); |
571 | | - } |
572 | | - |
573 | | - static function getUserUrl( $user ) { |
574 | | - $openid_url = null; |
575 | | - |
576 | | - if ( isset( $user ) && $user->getId() != 0 ) { |
577 | | - global $wgSharedDB, $wgDBprefix; |
578 | | - if ( isset( $wgSharedDB ) ) { |
579 | | - $tableName = "`${wgSharedDB}`.${wgDBprefix}user_openid"; |
580 | | - } else { |
581 | | - $tableName = 'user_openid'; |
582 | | - } |
583 | | - |
584 | | - $dbr = wfGetDB( DB_SLAVE ); |
585 | | - $res = $dbr->select( |
586 | | - array( $tableName ), |
587 | | - array( 'uoi_openid' ), |
588 | | - array( 'uoi_user' => $user->getId() ), |
589 | | - __METHOD__ |
590 | | - ); |
591 | | - |
592 | | - # This should return 0 or 1 result, since user is unique |
593 | | - # in the table. |
594 | | - |
595 | | - while ( $row = $res->fetchObject() ) { |
596 | | - $openid_url = $row->uoi_openid; |
597 | | - } |
598 | | - $res->free(); |
599 | | - } |
600 | | - return $openid_url; |
601 | | - } |
602 | | - |
603 | | - function saveValues( $openid, $sreg ) { |
604 | | - global $wgSessionStarted, $wgUser; |
605 | | - |
606 | | - if ( !$wgSessionStarted ) { |
607 | | - $wgUser->SetupSession(); |
608 | | - } |
609 | | - |
610 | | - $_SESSION['openid_consumer_identity'] = $openid; |
611 | | - $_SESSION['openid_consumer_sreg'] = $sreg; |
612 | | - |
613 | | - return true; |
614 | | - } |
615 | | - |
616 | | - function clearValues() { |
617 | | - unset( $_SESSION['openid_consumer_identity'] ); |
618 | | - unset( $_SESSION['openid_consumer_sreg'] ); |
619 | | - return true; |
620 | | - } |
621 | | - |
622 | | - function fetchValues() { |
623 | | - return array( $_SESSION['openid_consumer_identity'], $_SESSION['openid_consumer_sreg'] ); |
624 | | - } |
625 | | - |
626 | | - function returnTo() { |
627 | | - return $_SESSION['openid_consumer_returnto']; |
628 | | - } |
629 | | - |
630 | | - function setReturnTo( $returnto ) { |
631 | | - $_SESSION['openid_consumer_returnto'] = $returnto; |
632 | | - } |
633 | | - |
634 | | - function getUserName( $openid, $sreg, $choice, $nameValue ) { |
635 | | - switch ( $choice ) { |
636 | | - case 'full': |
637 | | - return ( ( array_key_exists( 'fullname', $sreg ) ) ? $sreg['fullname'] : null ); |
638 | | - break; |
639 | | - case 'url': |
640 | | - return $this->toUserName( $openid ); |
641 | | - break; |
642 | | - case 'auto': |
643 | | - return $this->automaticName( $sreg ); |
644 | | - break; |
645 | | - case 'manual': |
646 | | - return $nameValue; |
647 | | - default: |
648 | | - return null; |
649 | | - } |
650 | | - } |
651 | | - |
652 | | - function automaticName( $sreg ) { |
653 | | - if ( array_key_exists( 'nickname', $sreg ) && # try auto-generated from nickname |
654 | | - strlen( $sreg['nickname'] ) > 0 ) { |
655 | | - return $this->firstAvailable( $sreg['nickname'] ); |
656 | | - } else { # try auto-generated |
657 | | - return $this->firstAvailable( wfMsg( 'openidusernameprefix' ) ); |
658 | | - } |
659 | | - } |
660 | | - |
661 | | - function attachUser( $openid, $sreg, $name, $password ) { |
662 | | - |
663 | | - $user = User::newFromName( $name ); |
664 | | - |
665 | | - if ( !$user ) { |
666 | | - return NULL; |
667 | | - } |
668 | | - |
669 | | - if ( !$user->checkPassword( $password ) ) { |
670 | | - return NULL; |
671 | | - } |
672 | | - |
673 | | - $this->setUserUrl( $user, $openid ); |
674 | | - |
675 | | - return $user; |
676 | | - } |
677 | | -} |
Index: trunk/extensions/OpenID/OpenID.i18n.php |
— | — | @@ -26,14 +26,17 @@ |
27 | 27 | |
28 | 28 | /** English |
29 | 29 | * @author Evan Prodromou <evan@prodromou.name> |
| 30 | + * @author Sergey Chernyshev |
| 31 | + * @author Alexandre Emsenhuber |
30 | 32 | */ |
31 | 33 | $messages['en'] = array( |
32 | 34 | 'openid-desc' => 'Login to the wiki with an [http://openid.net/ OpenID], and login to other OpenID-aware web sites with a wiki user account', |
| 35 | + |
33 | 36 | 'openidlogin' => 'Login with OpenID', |
34 | | - 'openidfinish' => 'Finish OpenID login', |
35 | 37 | 'openidserver' => 'OpenID server', |
36 | 38 | 'openidxrds' => 'Yadis file', |
37 | 39 | 'openidconvert' => 'OpenID converter', |
| 40 | + |
38 | 41 | 'openiderror' => 'Verification error', |
39 | 42 | 'openiderrortext' => 'An error occured during verification of the OpenID URL.', |
40 | 43 | 'openidconfigerror' => 'OpenID configuration error', |
— | — | @@ -59,6 +62,7 @@ |
60 | 63 | 'openidfullname' => 'Fullname', |
61 | 64 | 'openidemail' => 'E-mail address', |
62 | 65 | 'openidlanguage' => 'Language', |
| 66 | + 'openidtimezone' => 'Time zone', |
63 | 67 | 'openidnotavailable' => 'Your preferred nickname ($1) is already in use by another user.', |
64 | 68 | 'openidnotprovided' => 'Your OpenID server did not provide a nickname (either because it cannot, or because you told it not to).', |
65 | 69 | 'openidchooseinstructions' => 'All users need a nickname; |
— | — | @@ -92,10 +96,24 @@ |
93 | 97 | |
94 | 98 | There are many [http://openid.net/get/ OpenID providers], and you may already have an OpenID-enabled account on another service.', |
95 | 99 | 'openidupdateuserinfo' => 'Update my personal information', |
| 100 | + |
| 101 | + 'openiddelete' => 'Delete OpenID', |
| 102 | + 'openiddelete-text' => 'By clicking the "Confirm" button, you will remove then OpenID $1 from your account. |
| 103 | +You will not be able anymore to login anymore with this OpenID.', |
| 104 | + 'openiddelete-button' => 'Confirm', |
| 105 | + 'openiddelete-sucess' => 'The OpenID has been successfully removed from your account.', |
| 106 | + 'openiddelete-error' => 'An error occured while removing the OpenID from your account.', |
| 107 | + |
96 | 108 | 'prefs-openid' => 'OpenID', |
97 | 109 | 'openid-prefstext' => '[http://openid.net/ OpenID] preferences', |
98 | 110 | 'openid-pref-hide' => 'Hide your OpenID URL on your user page, if you log in with OpenID.', |
99 | | - 'openid-pref-update-userinfo-on-login' => 'Update my information from OpenID persona every time I login', |
| 111 | + 'openid-pref-update-userinfo-on-login' => 'Update the following information from OpenID persona every time I login:', |
| 112 | + 'openid-urls-desc' => 'OpenIDs associated with your account:', |
| 113 | + 'openid-urls-url' => 'URL', |
| 114 | + 'openid-urls-action' => 'Action', |
| 115 | + 'openid-urls-delete' => 'Delete', |
| 116 | + 'openid-add-url' => 'Add a new OpenID', |
| 117 | + |
100 | 118 | 'openidsigninorcreateaccount' => 'Sign-in or Create New Account', |
101 | 119 | 'openid-provider-label-openid' => 'Enter your OpenID URL', |
102 | 120 | 'openid-provider-label-google' => 'Login using your Google account', |
— | — | @@ -168,7 +186,6 @@ |
169 | 187 | $messages['ar'] = array( |
170 | 188 | 'openid-desc' => 'سجل الدخول للويكي [http://openid.net/ بهوية مفتوحة]، وسجل الدخول لمواقع ويب أخرى تعرف الهوية المفتوحة بحساب مستخدم ويكي', |
171 | 189 | 'openidlogin' => 'تسجيل الدخول بالهوية المفتوحة', |
172 | | - 'openidfinish' => 'إنهاء دخول الهوية المفتوحة', |
173 | 190 | 'openidserver' => 'خادم الهوية المفتوحة', |
174 | 191 | 'openidxrds' => 'ملف ياديس', |
175 | 192 | 'openidconvert' => 'محول الهوية المفتوحة', |
— | — | @@ -250,7 +267,6 @@ |
251 | 268 | $messages['arz'] = array( |
252 | 269 | 'openid-desc' => 'سجل الدخول للويكى [http://openid.net/ بهوية مفتوحة]، وسجل الدخول لمواقع ويب أخرى تعرف الهوية المفتوحة بحساب مستخدم ويكي', |
253 | 270 | 'openidlogin' => 'تسجيل الدخول بالهوية المفتوحة', |
254 | | - 'openidfinish' => 'إنهاء دخول الهوية المفتوحة', |
255 | 271 | 'openidserver' => 'خادم الهوية المفتوحة', |
256 | 272 | 'openidxrds' => 'ملف ياديس', |
257 | 273 | 'openidconvert' => 'محول الهوية المفتوحة', |
— | — | @@ -333,7 +349,6 @@ |
334 | 350 | $messages['be-tarask'] = array( |
335 | 351 | 'openid-desc' => 'Уваход ў {{GRAMMAR:вінавальны|{{SITENAME}}}} з дапамогай [http://openid.net/ OpenID], а так сама ў іншыя сайты, якія падтрымліваюць OpenID з вікі-рахунка', |
336 | 352 | 'openidlogin' => 'Уваход у сыстэму з дапамогай OpenID', |
337 | | - 'openidfinish' => 'Скончыць уваход у сыстэму з дапамогай OpenID', |
338 | 353 | 'openidserver' => 'Сэрвэр OpenID', |
339 | 354 | 'openidxrds' => 'Файл Yadis', |
340 | 355 | 'openidconvert' => 'Канвэртар OpenID', |
— | — | @@ -411,7 +426,6 @@ |
412 | 427 | */ |
413 | 428 | $messages['bg'] = array( |
414 | 429 | 'openidlogin' => 'Влизане с OpenID', |
415 | | - 'openidfinish' => 'Приключване на OpenID влизането', |
416 | 430 | 'openidserver' => 'OpenID сървър', |
417 | 431 | 'openidxrds' => 'Yadis файл', |
418 | 432 | 'openidconvert' => 'Конвертор за OpenID', |
— | — | @@ -478,7 +492,6 @@ |
479 | 493 | $messages['bs'] = array( |
480 | 494 | 'openid-desc' => 'Prijava na wiki sa [http://openid.net/ OpenID] i prijava na druge stranice koje podržavaju OpenID sa wiki korisničkim računom', |
481 | 495 | 'openidlogin' => 'Prijava sa OpenID', |
482 | | - 'openidfinish' => 'Završi OpenID prijavu', |
483 | 496 | 'openidserver' => 'OpenID server', |
484 | 497 | 'openidxrds' => 'Yadis datoteka', |
485 | 498 | 'openidconvert' => 'OpenID pretvarač', |
— | — | @@ -558,7 +571,6 @@ |
559 | 572 | $messages['ca'] = array( |
560 | 573 | 'openid-desc' => 'Inicieu una sessió al wiki amb un [http://openid.net/ OpenID], i inicieu una sessió a qualsevol lloc web compatible amb OpenID amb el vostre compte wiki', |
561 | 574 | 'openidlogin' => 'Inicia una sessió amb OpenID', |
562 | | - 'openidfinish' => 'Finalitza la sessió amb OpenID', |
563 | 575 | 'openidserver' => 'Servidor OpenID', |
564 | 576 | 'openidxrds' => 'Fitxer Yadis', |
565 | 577 | 'openidconvert' => 'Conversor OpenID', |
— | — | @@ -586,7 +598,6 @@ |
587 | 599 | $messages['cs'] = array( |
588 | 600 | 'openid-desc' => 'Přihlašování se na wiki pomocí [http://openid.net/ OpenID] a přihlašování se na jiné stránky podporující OpenID pomocí uživatelského účtu z wiki', |
589 | 601 | 'openidlogin' => 'Přihlášení pomocí OpenID', |
590 | | - 'openidfinish' => 'Dokončit přihlášení pomocí OpenID', |
591 | 602 | 'openidserver' => 'OpenID server', |
592 | 603 | 'openidxrds' => 'Soubor Yadis', |
593 | 604 | 'openidconvert' => 'OpenID konvertor', |
— | — | @@ -678,7 +689,6 @@ |
679 | 690 | $messages['de'] = array( |
680 | 691 | 'openid-desc' => 'Anmeldung an dieses Wiki mit einer [http://openid.net/ OpenID] und anmelden an anderen Websites, die OpenID unterstützen, mit einem Wiki-Benutzerkonto.', |
681 | 692 | 'openidlogin' => 'Anmelden mit OpenID', |
682 | | - 'openidfinish' => 'OpenID-Anmeldung abschließen', |
683 | 693 | 'openidserver' => 'OpenID-Server', |
684 | 694 | 'openidxrds' => 'Yadis-Datei', |
685 | 695 | 'openidconvert' => 'OpenID-Konverter', |
— | — | @@ -768,7 +778,6 @@ |
769 | 779 | $messages['dsb'] = array( |
770 | 780 | 'openid-desc' => 'Pśizjawjenje pla wikija z [http://openid.net/ OpenID] a pśizjawjenje pla drugich websedłow, kótarež pódpěraju OpenID z wikijowym wužywarskim kontom', |
771 | 781 | 'openidlogin' => 'Pśizjawjenje z OpenID', |
772 | | - 'openidfinish' => 'Pśizjawjenje OpenID dokóńcyś', |
773 | 782 | 'openidserver' => 'Serwer OpenID', |
774 | 783 | 'openidxrds' => 'Yadis-dataja', |
775 | 784 | 'openidconvert' => 'Konwerter OpenID', |
— | — | @@ -864,7 +873,6 @@ |
865 | 874 | $messages['eo'] = array( |
866 | 875 | 'openid-desc' => 'Ensaluti la vikion kun [http://openid.net/ identigo OpenID], kaj ensaluti aliajn retejon uzantajn OpenID kun vikia uzula konto', |
867 | 876 | 'openidlogin' => 'Ensaluti kun OpenID', |
868 | | - 'openidfinish' => 'Elsaluti kun OpenID', |
869 | 877 | 'openidserver' => 'Servilo OpenID', |
870 | 878 | 'openidxrds' => 'dosiero Yadis', |
871 | 879 | 'openidconvert' => 'OpenID konvertilo', |
— | — | @@ -933,7 +941,6 @@ |
934 | 942 | $messages['es'] = array( |
935 | 943 | 'openid-desc' => 'Ingresa a la wiki con un [http://openid.net OpenID] e ingresa a los otros sitios que aceptan OpenID con una cuenta de usuario wiki.', |
936 | 944 | 'openidlogin' => 'Conectarse con OpenID', |
937 | | - 'openidfinish' => 'Termina el ingreso OpenID', |
938 | 945 | 'openidserver' => 'servidor OpenID', |
939 | 946 | 'openidxrds' => 'Archivo Yadis', |
940 | 947 | 'openidconvert' => 'Convertidor OpenID', |
— | — | @@ -1052,7 +1059,6 @@ |
1053 | 1060 | $messages['fi'] = array( |
1054 | 1061 | 'openid-desc' => 'Kirjaudu wikiin [http://openid.net/ OpenID:llä] ja muille OpenID-tuetuille sivustoille wiki-käyttäjätilillä.', |
1055 | 1062 | 'openidlogin' => 'Kirjaudu OpenID:llä', |
1056 | | - 'openidfinish' => 'Lopeta OpenID-kirjautuminen', |
1057 | 1063 | 'openidserver' => 'OpenID-palvelin', |
1058 | 1064 | 'openidxrds' => 'Yadis-tiedosto', |
1059 | 1065 | 'openidconvert' => 'OpenID-muunnin', |
— | — | @@ -1116,7 +1122,6 @@ |
1117 | 1123 | $messages['fr'] = array( |
1118 | 1124 | 'openid-desc' => 'Se connecter au wiki avec [http://openid.net/ OpenID] et se connecter à d’autres sites internet OpenID avec un compte utilisateur du wiki.', |
1119 | 1125 | 'openidlogin' => 'Se connecter avec OpenID', |
1120 | | - 'openidfinish' => 'Finir la connection OpenID', |
1121 | 1126 | 'openidserver' => 'Serveur OpenID', |
1122 | 1127 | 'openidxrds' => 'Fichier Yadis', |
1123 | 1128 | 'openidconvert' => 'Convertisseur OpenID', |
— | — | @@ -1200,7 +1205,6 @@ |
1201 | 1206 | $messages['gl'] = array( |
1202 | 1207 | 'openid-desc' => 'Acceder ao sistema do wiki cun [http://openid.net/ OpenID] e acceder a outras páxinas web OpenID cunha conta de usuario dun wiki', |
1203 | 1208 | 'openidlogin' => 'Acceder ao sistema co OpenID', |
1204 | | - 'openidfinish' => 'Saír do sistema OpenID', |
1205 | 1209 | 'openidserver' => 'Servidor do OpenID', |
1206 | 1210 | 'openidxrds' => 'Ficheiro Yadis', |
1207 | 1211 | 'openidconvert' => 'Transformador OpenID', |
— | — | @@ -1291,7 +1295,6 @@ |
1292 | 1296 | $messages['gsw'] = array( |
1293 | 1297 | 'openid-desc' => 'Mit eme Wiki-Benutzerkonto in däm Wiki mit ere [http://openid.net/ OpenID] aamälde un bi andere Netzsyte aamälde, wu OpenID unterstitze', |
1294 | 1298 | 'openidlogin' => 'Aamälde mit OpenID', |
1295 | | - 'openidfinish' => 'OpenID-Aamäldig abschliesse', |
1296 | 1299 | 'openidserver' => 'OpenID-Server', |
1297 | 1300 | 'openidxrds' => 'Yadis-Datei', |
1298 | 1301 | 'openidconvert' => 'OpenID-Konverter', |
— | — | @@ -1388,7 +1391,6 @@ |
1389 | 1392 | $messages['he'] = array( |
1390 | 1393 | 'openid-desc' => 'כניסה לחשבון בוויקי באמצעות [http://openid.net/ OpenID], והתחברות לאתרים נוספים הפועלים עם OpenID באמצעות חשבון משתמש בוויקי', |
1391 | 1394 | 'openidlogin' => 'כניסה לחשבון עם OpenID', |
1392 | | - 'openidfinish' => 'יציאה מהחשבון עם OpenID', |
1393 | 1395 | 'openidserver' => 'שרת OpenID', |
1394 | 1396 | 'openidxrds' => 'קובץ Yadis', |
1395 | 1397 | 'openidconvert' => 'ממיר OpenID', |
— | — | @@ -1467,7 +1469,6 @@ |
1468 | 1470 | */ |
1469 | 1471 | $messages['hi'] = array( |
1470 | 1472 | 'openidlogin' => 'OpenID से लॉग इन करें', |
1471 | | - 'openidfinish' => 'OpenID लॉग इन पूरा करें', |
1472 | 1473 | 'openidserver' => 'OpenID सर्वर', |
1473 | 1474 | 'openidxrds' => 'Yadis फ़ाइल', |
1474 | 1475 | 'openidconvert' => 'OpenID कन्वर्टर', |
— | — | @@ -1531,7 +1532,6 @@ |
1532 | 1533 | $messages['hsb'] = array( |
1533 | 1534 | 'openid-desc' => 'Přizjewjenje pola wikija z [http://openid.net/ OpenID], a přizjewjenje pola druhich websydłow, kotrež OpenID podpěruja, z wikijowym wužiwarskim kontom', |
1534 | 1535 | 'openidlogin' => 'Přizjewjenje z OpenID', |
1535 | | - 'openidfinish' => 'Přizjewjenje OpenID skónčić', |
1536 | 1536 | 'openidserver' => 'Serwer OpenID', |
1537 | 1537 | 'openidxrds' => 'Yadis-dataja', |
1538 | 1538 | 'openidconvert' => 'Konwerter OpenID', |
— | — | @@ -1607,7 +1607,6 @@ |
1608 | 1608 | $messages['hu'] = array( |
1609 | 1609 | 'openid-desc' => 'Bejelentkezés [http://openid.net/ OpenID] azonosítóval, és más OpenID-kompatibilis weboldalak használata a wikis azonosítóval', |
1610 | 1610 | 'openidlogin' => 'Bejelentkezés OpenID-vel', |
1611 | | - 'openidfinish' => 'OpenID bejelentkezés befejezése', |
1612 | 1611 | 'openidserver' => 'OpenID szerver', |
1613 | 1612 | 'openidxrds' => 'Yadis fájl', |
1614 | 1613 | 'openidconvert' => 'OpenID konverter', |
— | — | @@ -1680,7 +1679,6 @@ |
1681 | 1680 | $messages['ia'] = array( |
1682 | 1681 | 'openid-desc' => 'Aperir un session in le wiki con [http://openid.net/ OpenID], e aperir un session in altere sitos web usante OpenID con un conto de usator del wiki', |
1683 | 1682 | 'openidlogin' => 'Aperir un session con OpenID', |
1684 | | - 'openidfinish' => 'Completar le session OpenID', |
1685 | 1683 | 'openidserver' => 'Servitor OpenID', |
1686 | 1684 | 'openidxrds' => 'File Yadis', |
1687 | 1685 | 'openidconvert' => 'Convertitor de OpenID', |
— | — | @@ -1760,7 +1758,6 @@ |
1761 | 1759 | $messages['id'] = array( |
1762 | 1760 | 'openid-desc' => 'Masuk log ke wiki dengan sebuah [http://openid.net/ OpenID], dan masuk log ke situs web lain yang berbasis OpenID dengan sebuah akun pengguna wiki', |
1763 | 1761 | 'openidlogin' => 'Masuk log dengan OpenID', |
1764 | | - 'openidfinish' => 'Selesai masuk log dengan OpenID', |
1765 | 1762 | 'openidserver' => 'Server OpenID', |
1766 | 1763 | 'openidxrds' => 'berkas Yadis', |
1767 | 1764 | 'openidconvert' => 'Konverter OpenID', |
— | — | @@ -1844,7 +1841,6 @@ |
1845 | 1842 | $messages['it'] = array( |
1846 | 1843 | 'openid-desc' => 'Effettua il login alla wiki con [http://openid.net/ OpenID] e agli altri siti web che utilizzano OpenID con un account wiki', |
1847 | 1844 | 'openidlogin' => 'Login con OpenID', |
1848 | | - 'openidfinish' => 'Completa il login OpenID', |
1849 | 1845 | 'openidserver' => 'server OpenID', |
1850 | 1846 | 'openidxrds' => 'file Yadis', |
1851 | 1847 | 'openidconvert' => 'convertitore OpenID', |
— | — | @@ -1925,7 +1921,6 @@ |
1926 | 1922 | $messages['ja'] = array( |
1927 | 1923 | 'openid-desc' => '[http://openid.net/ OpenID]によるウィキへのログインを可能にし、ウィキユーザーアカウントを他のOpenID対応サイトにログインすることを可能にする。', |
1928 | 1924 | 'openidlogin' => 'OpenIDでログイン', |
1929 | | - 'openidfinish' => 'OpenIDでのログインが完了しました。', |
1930 | 1925 | 'openidserver' => 'OpenID サーバー', |
1931 | 1926 | 'openidxrds' => 'Yadis ファイル', |
1932 | 1927 | 'openidconvert' => 'OpenID コンバーター', |
— | — | @@ -2078,7 +2073,6 @@ |
2079 | 2074 | $messages['ksh'] = array( |
2080 | 2075 | 'openid-desc' => 'Hee em Wiki met ener [http://openid.net/ OpenID] enlogge, un angerschwoh mer OpenID kennt met enem Metmaacher-Name fum Wiki enlogge.', |
2081 | 2076 | 'openidlogin' => 'Met OpenID enlogge', |
2082 | | - 'openidfinish' => 'Et Enlogge met OpenID afschleeße', |
2083 | 2077 | 'openidserver' => 'OpenID Server', |
2084 | 2078 | 'openidxrds' => 'Yadis-Dattei', |
2085 | 2079 | 'openidconvert' => 'OpenID Ömsetzer', |
— | — | @@ -2167,7 +2161,6 @@ |
2168 | 2162 | $messages['lb'] = array( |
2169 | 2163 | 'openid-desc' => "Sech an d'Wiki matt enger [http://openid.net/ OpenID] aloggen, a sech op aneren Internetsiten, déi OpenID ënerstetzen, matt engem Wiki-Benotzerkont aloggen.", |
2170 | 2164 | 'openidlogin' => 'Umellen mat OpenID', |
2171 | | - 'openidfinish' => "D'Aloggen mat OpenID ofschléissen", |
2172 | 2165 | 'openidserver' => 'OpenID-Server', |
2173 | 2166 | 'openidxrds' => 'Yadis Fichier', |
2174 | 2167 | 'openidconvert' => 'OpenID-Ëmwandler', |
— | — | @@ -2309,7 +2302,6 @@ |
2310 | 2303 | $messages['mr'] = array( |
2311 | 2304 | 'openid-desc' => 'विकिवर [http://openid.net/ ओपनID] वापरून प्रवेश करा, तसेच कुठल्याही इतर ओपनID संकेतस्थळावर विकि सदस्य नाम वापरून प्रवेश करा', |
2312 | 2305 | 'openidlogin' => 'ओपनID वापरून प्रवेश करा', |
2313 | | - 'openidfinish' => 'ओपनID प्रवेश प्रक्रिया पूर्ण करा', |
2314 | 2306 | 'openidserver' => 'ओपनID सर्व्हर', |
2315 | 2307 | 'openidxrds' => 'Yadis संचिका', |
2316 | 2308 | 'openidconvert' => 'ओपनID कन्व्हर्टर', |
— | — | @@ -2449,7 +2441,6 @@ |
2450 | 2442 | $messages['nl'] = array( |
2451 | 2443 | 'openid-desc' => 'Aanmelden bij de wiki met een [http://openid.net/ OpenID] en aanmelden bij andere websites die OpenID ondersteunen met een wikigebruiker', |
2452 | 2444 | 'openidlogin' => 'Aanmelden met OpenID', |
2453 | | - 'openidfinish' => 'Aanmelden met OpenID afronden', |
2454 | 2445 | 'openidserver' => 'OpenID-server', |
2455 | 2446 | 'openidxrds' => 'Yadis-bestand', |
2456 | 2447 | 'openidconvert' => 'OpenID-convertor', |
— | — | @@ -2529,7 +2520,6 @@ |
2530 | 2521 | $messages['nn'] = array( |
2531 | 2522 | 'openid-desc' => 'Logg inn på wikien med ein [http://openid.net/ OpenID] og logg inn på andre sider som bruker OpenID med kontoen herifrå', |
2532 | 2523 | 'openidlogin' => 'Logg inn med OpenID', |
2533 | | - 'openidfinish' => 'Fullfør OpenID-innlogging', |
2534 | 2524 | 'openidserver' => 'OpenID-tenar', |
2535 | 2525 | 'openidxrds' => 'Yadis-fil', |
2536 | 2526 | 'openidconvert' => 'OpenID-konvertering', |
— | — | @@ -2605,7 +2595,6 @@ |
2606 | 2596 | $messages['no'] = array( |
2607 | 2597 | 'openid-desc' => 'Logg inn på wikien med en [http://openid.net/ OpenID] og logg inn på andre sider som bruker OpenID med kontoen herfra', |
2608 | 2598 | 'openidlogin' => 'Logg inn med OpenID', |
2609 | | - 'openidfinish' => 'Fullfør OpenID-innlogging', |
2610 | 2599 | 'openidserver' => 'OpenID-tjener', |
2611 | 2600 | 'openidxrds' => 'Yadis-fil', |
2612 | 2601 | 'openidconvert' => 'OpenID-konvertering', |
— | — | @@ -2683,7 +2672,6 @@ |
2684 | 2673 | $messages['oc'] = array( |
2685 | 2674 | 'openid-desc' => "Se connecta al wiki amb [http://openid.net/ OpenID] e se connecta a d'autres sits internet OpenID amb un wiki utilizant un compte d'utilizaire.", |
2686 | 2675 | 'openidlogin' => 'Se connectar amb OpenID', |
2687 | | - 'openidfinish' => 'Acabar la connexion OpenID', |
2688 | 2676 | 'openidserver' => 'Servidor OpenID', |
2689 | 2677 | 'openidxrds' => 'Fichièr Yadis', |
2690 | 2678 | 'openidconvert' => 'Convertisseire OpenID', |
— | — | @@ -2777,7 +2765,6 @@ |
2778 | 2766 | $messages['pl'] = array( |
2779 | 2767 | 'openid-desc' => 'Logowanie się do wiki z użyciem [http://openid.net/ OpenID], oraz logowanie się do innych witryn używających OpenID z użyciem konta użytkownika z wiki', |
2780 | 2768 | 'openidlogin' => 'Zaloguj używając OpenID', |
2781 | | - 'openidfinish' => 'Zakończ zalogowanie z użyciem OpenID', |
2782 | 2769 | 'openidserver' => 'Serwer OpenID', |
2783 | 2770 | 'openidxrds' => 'Plik Yadis', |
2784 | 2771 | 'openidconvert' => 'Obsługa OpenID', |
— | — | @@ -2876,7 +2863,6 @@ |
2877 | 2864 | $messages['pt'] = array( |
2878 | 2865 | 'openid-desc' => 'Autentique-se no wiki com um [http://openid.net/ OpenID], e autentique-se noutros sítios que usem OpenID com uma conta de utilizador wiki', |
2879 | 2866 | 'openidlogin' => 'Autenticação com OpenID', |
2880 | | - 'openidfinish' => 'Terminar autenticação OpenID', |
2881 | 2867 | 'openidserver' => 'Servidor OpenID', |
2882 | 2868 | 'openidxrds' => 'Ficheiro Yadis', |
2883 | 2869 | 'openidconvert' => 'Conversor de OpenID', |
— | — | @@ -2956,7 +2942,6 @@ |
2957 | 2943 | $messages['pt-br'] = array( |
2958 | 2944 | 'openid-desc' => 'Autentique-se no wiki com um [http://openid.net/ OpenID], e autentique-se em outros sítios que usem OpenID com uma conta de utilizador wiki', |
2959 | 2945 | 'openidlogin' => 'Autenticação com OpenID', |
2960 | | - 'openidfinish' => 'Terminar autenticação OpenID', |
2961 | 2946 | 'openidserver' => 'Servidor OpenID', |
2962 | 2947 | 'openidxrds' => 'Arquivo Yadis', |
2963 | 2948 | 'openidconvert' => 'Conversor de OpenID', |
— | — | @@ -3074,7 +3059,6 @@ |
3075 | 3060 | $messages['ru'] = array( |
3076 | 3061 | 'openid-desc' => 'Вход в вики с помощью [http://openid.net/ OpenID], а также вход на другие сайты поддерживающие OpenID с помощью учётной записи в вики', |
3077 | 3062 | 'openidlogin' => 'Вход с помощью OpenID', |
3078 | | - 'openidfinish' => 'Завершить вход OpenID', |
3079 | 3063 | 'openidserver' => 'Сервер OpenID', |
3080 | 3064 | 'openidxrds' => 'Файл Yadis', |
3081 | 3065 | 'openidconvert' => 'Преобразователь OpenID', |
— | — | @@ -3154,7 +3138,6 @@ |
3155 | 3139 | $messages['scn'] = array( |
3156 | 3140 | 'openid-desc' => "Fai lu login a la wiki cu [http://openid.net/ OpenID] r a l'àutri siti web ca non ùsanu OpenID cu n'account wiki", |
3157 | 3141 | 'openidlogin' => 'Login cu OpenID', |
3158 | | - 'openidfinish' => 'Cumpleta lu login OpenID', |
3159 | 3142 | 'openidserver' => 'server OpenID', |
3160 | 3143 | 'openidxrds' => 'file Yadis', |
3161 | 3144 | 'openidconvert' => 'cunvirtituri OpenID', |
— | — | @@ -3236,7 +3219,6 @@ |
3237 | 3220 | $messages['sk'] = array( |
3238 | 3221 | 'openid-desc' => 'Prihlásenie sa na wiki pomocou [http://openid.net/ OpenID] a prihlásenie na iné stránky podporujúce OpenID pomocou používateľského účtu wiki', |
3239 | 3222 | 'openidlogin' => 'Prihlásiť sa pomocou OpenID', |
3240 | | - 'openidfinish' => 'Dokončiť prihlásenie pomocou OpenID', |
3241 | 3223 | 'openidserver' => 'OpenID server', |
3242 | 3224 | 'openidxrds' => 'Súbor Yadis', |
3243 | 3225 | 'openidconvert' => 'OpenID konvertor', |
— | — | @@ -3311,7 +3293,6 @@ |
3312 | 3294 | * @author Михајло Анђелковић |
3313 | 3295 | */ |
3314 | 3296 | $messages['sr-ec'] = array( |
3315 | | - 'openidfinish' => 'Заврши OpenID логовање', |
3316 | 3297 | 'openidserver' => 'OpenID сервер', |
3317 | 3298 | 'openidconvert' => 'OpenID конвертор', |
3318 | 3299 | 'openiderror' => 'Грешка приликом верификације', |
— | — | @@ -3360,7 +3341,6 @@ |
3361 | 3342 | $messages['stq'] = array( |
3362 | 3343 | 'openid-desc' => 'Anmeldenge an dit Wiki mäd ne [http://openid.net/ OpenID] un anmäldje an uur Websites, do der OpenID unnerstutsje, mäd een Wiki-Benutserkonto.', |
3363 | 3344 | 'openidlogin' => 'Anmäldje mäd OpenID', |
3364 | | - 'openidfinish' => 'OpenID-Anmäldenge ousluute', |
3365 | 3345 | 'openidserver' => 'OpenID-Server', |
3366 | 3346 | 'openidxrds' => 'Yadis-Doatäi', |
3367 | 3347 | 'openidconvert' => 'OpenID-Konverter', |
— | — | @@ -3451,7 +3431,6 @@ |
3452 | 3432 | $messages['sv'] = array( |
3453 | 3433 | 'openid-desc' => 'Logga in på wikin med en [http://openid.net/ OpenID] och logga in på andra sidor som använder OpenID med konton härifrån', |
3454 | 3434 | 'openidlogin' => 'Logga in med OpenID', |
3455 | | - 'openidfinish' => 'Fullfölj OpenID-inloggning', |
3456 | 3435 | 'openidserver' => 'OpenID-server', |
3457 | 3436 | 'openidxrds' => 'Yadis-fil', |
3458 | 3437 | 'openidconvert' => 'OpenID-konvertering', |
— | — | @@ -3561,7 +3540,6 @@ |
3562 | 3541 | $messages['tg-cyrl'] = array( |
3563 | 3542 | 'openid-desc' => 'Ба вики бо [http://openid.net/ OpenID] вуруд кунед, ва ба дигар сомонаҳои OpenID бо ҳисоби корбарии вики вуруд кунед', |
3564 | 3543 | 'openidlogin' => 'Бо OpenID вуруд кунед', |
3565 | | - 'openidfinish' => 'Хотима додан вурудшавии OpenID', |
3566 | 3544 | 'openidserver' => 'Хидматгузори OpenID', |
3567 | 3545 | 'openidxrds' => 'Парвандаи Yadis', |
3568 | 3546 | 'openidconvert' => 'Табдилкунандаи OpenID', |
— | — | @@ -3590,7 +3568,6 @@ |
3591 | 3569 | $messages['tl'] = array( |
3592 | 3570 | 'openid-desc' => 'Lumagda sa wiki na may [http://openid.net/ OpenID], at lumagda sa iba pang mga websayt na nakakaalam sa/nakababatid ng OpenID na may kuwenta/akawnt na pang-wiki', |
3593 | 3571 | 'openidlogin' => 'Lumagda na may OpenID', |
3594 | | - 'openidfinish' => 'Tapusin na ang paglagdang pang-OpenID', |
3595 | 3572 | 'openidserver' => 'Serbidor ng OpenID', |
3596 | 3573 | 'openidxrds' => 'Talaksang Yadis', |
3597 | 3574 | 'openidconvert' => 'Tagapagpalit ng OpenID', |
— | — | @@ -3663,7 +3640,6 @@ |
3664 | 3641 | $messages['tr'] = array( |
3665 | 3642 | 'openid-desc' => 'Vikiye bir [http://openid.net/ OpenID] ile giriş yapın, ve diğer OpenID kullanan web sitelerine bir viki kullanıcı hesabıyla giriş yapın.', |
3666 | 3643 | 'openidlogin' => 'OpenID ile giriş yapın', |
3667 | | - 'openidfinish' => 'OpenID girişini tamamlayın', |
3668 | 3644 | 'openidserver' => 'OpenID sunucusu', |
3669 | 3645 | 'openidxrds' => 'Yadis dosyası', |
3670 | 3646 | 'openidconvert' => 'OpenID çeviricisi', |
— | — | @@ -3820,7 +3796,6 @@ |
3821 | 3797 | $messages['vec'] = array( |
3822 | 3798 | 'openid-desc' => "Entra con [http://openid.net/ OpenID] in te la wiki, e entra in tei altri siti web che dòpara OpenID co' na utensa wiki", |
3823 | 3799 | 'openidlogin' => 'Acesso con OpenID', |
3824 | | - 'openidfinish' => "Conpleta l'acesso OpenID", |
3825 | 3800 | 'openidserver' => 'server OpenID', |
3826 | 3801 | 'openidxrds' => 'file Yadis', |
3827 | 3802 | 'openidconvert' => 'convertidor OpenID', |
— | — | @@ -3909,7 +3884,6 @@ |
3910 | 3885 | $messages['vi'] = array( |
3911 | 3886 | 'openid-desc' => 'Đăng nhập vào wiki dùng [http://openid.net/ OpenID] và đăng nhập vào các website nhận OpenID dùng tài khoản wiki', |
3912 | 3887 | 'openidlogin' => 'Đăng nhập dùng OpenID', |
3913 | | - 'openidfinish' => 'Đăng nhập dùng OpenID xong', |
3914 | 3888 | 'openidserver' => 'Dịch vụ OpenID', |
3915 | 3889 | 'openidxrds' => 'Tập tin Yadis', |
3916 | 3890 | 'openidconvert' => 'Chuyển đổi ID Mở', |
— | — | @@ -4010,7 +3984,6 @@ |
4011 | 3985 | */ |
4012 | 3986 | $messages['zh-hans'] = array( |
4013 | 3987 | 'openidlogin' => '使用OpenID登陆', |
4014 | | - 'openidfinish' => '结束OpenID登陆', |
4015 | 3988 | 'openidserver' => 'OpenID服务器', |
4016 | 3989 | 'openidxrds' => 'Yadis文件', |
4017 | 3990 | 'openidconvert' => 'OpenID转换', |
Index: trunk/extensions/OpenID/openid_table.sql |
— | — | @@ -1,7 +1,10 @@ |
| 2 | +-- |
| 3 | +-- SQL schema for OpenID extension |
| 4 | +-- |
| 5 | + |
2 | 6 | CREATE TABLE /*$wgDBprefix*/user_openid ( |
3 | | - uoi_openid varchar(255) NOT NULL, |
4 | | - uoi_user int(5) unsigned NOT NULL, |
| 7 | + uoi_openid varchar(255) NOT NULL PRIMARY KEY, |
| 8 | + uoi_user int(5) unsigned NOT NULL |
| 9 | +) /*$wgDBTableOptions*/; |
5 | 10 | |
6 | | - PRIMARY KEY uoi_openid (uoi_openid), |
7 | | - UNIQUE INDEX uoi_user (uoi_user) |
8 | | -) TYPE=InnoDB; |
| 11 | +CREATE INDEX user_openid_user ON user_openid(uoi_user); |
\ No newline at end of file |
Index: trunk/extensions/OpenID/OpenID.hooks.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | |
14 | 14 | # Special pages are added at global scope; remove server-related ones |
15 | 15 | # if client-only flag is set |
16 | | - $addList = array( 'Login', 'Finish', 'Convert' ); |
| 16 | + $addList = array( 'Login', 'Convert' ); |
17 | 17 | if ( !$wgOpenIDClientOnly ) { |
18 | 18 | $addList[] = 'Server'; |
19 | 19 | $addList[] = 'XRDS'; |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | $user = User::newFromName( $nt->getText() ); |
43 | 43 | if ( $user && $user->getID() != 0 ) { |
44 | 44 | $openid = SpecialOpenID::getUserUrl( $user ); |
45 | | - if ( isset( $openid ) && strlen( $openid ) != 0 ) { |
| 45 | + if ( count( $openid ) && strlen( $openid[0] ) != 0 ) { |
46 | 46 | global $wgOpenIDShowUrlOnUserPage; |
47 | 47 | |
48 | 48 | if ( $wgOpenIDShowUrlOnUserPage == 'always' || |
— | — | @@ -49,21 +49,20 @@ |
50 | 50 | { |
51 | 51 | global $wgOpenIDLoginLogoUrl; |
52 | 52 | |
53 | | - $url = SpecialOpenID::OpenIDToUrl( $openid ); |
54 | | - $disp = htmlspecialchars( $openid ); |
| 53 | + $url = SpecialOpenID::OpenIDToUrl( $openid[0] ); |
| 54 | + $disp = htmlspecialchars( $openid[0] ); |
55 | 55 | $wgOut->setSubtitle( "<span class='subpages'>" . |
56 | 56 | "<img src='$wgOpenIDLoginLogoUrl' alt='OpenID' />" . |
57 | 57 | "<a href='$url'>$disp</a>" . |
58 | 58 | "</span>" ); |
59 | 59 | } |
60 | | - } else { |
61 | | - # Add OpenID data iif its allowed |
| 60 | + # Add OpenID data if its allowed |
62 | 61 | if ( !$wgOpenIDClientOnly ) { |
63 | 62 | $st = SpecialPage::getTitleFor( 'OpenIDServer' ); |
64 | 63 | $wgOut->addLink( array( 'rel' => 'openid.server', |
65 | | - 'href' => $st->getFullURL() ) ); |
| 64 | + 'href' => $st->getFullURL() ) ); |
66 | 65 | $wgOut->addLink( array( 'rel' => 'openid2.provider', |
67 | | - 'href' => $st->getFullURL() ) ); |
| 66 | + 'href' => $st->getFullURL() ) ); |
68 | 67 | $rt = SpecialPage::getTitleFor( 'OpenIDXRDS', $user->getName() ); |
69 | 68 | $wgOut->addMeta( 'http:X-XRDS-Location', $rt->getFullURL() ); |
70 | 69 | header( 'X-XRDS-Location: ' . $rt->getFullURL() ); |
— | — | @@ -76,11 +75,10 @@ |
77 | 76 | } |
78 | 77 | |
79 | 78 | public static function onPersonalUrls( &$personal_urls, &$title ) { |
80 | | - global $wgHideOpenIDLoginLink, $wgUser, $wgLang, $wgOut, $wgOpenIDOnly; |
| 79 | + global $wgHideOpenIDLoginLink, $wgUser, $wgLang, $wgOpenIDOnly; |
81 | 80 | |
82 | 81 | if ( !$wgHideOpenIDLoginLink && $wgUser->getID() == 0 ) { |
83 | 82 | wfLoadExtensionMessages( 'OpenID' ); |
84 | | - $wgOut->addHeadItem( 'openidloginstyle', self::loginStyle() ); |
85 | 83 | $sk = $wgUser->getSkin(); |
86 | 84 | $returnto = $title->isSpecial( 'Userlogout' ) ? |
87 | 85 | '' : ( 'returnto=' . $title->getPrefixedURL() ); |
— | — | @@ -104,23 +102,74 @@ |
105 | 103 | return true; |
106 | 104 | } |
107 | 105 | |
| 106 | + public static function onBeforePageDisplay( $out, &$sk ) { |
| 107 | + global $wgHideOpenIDLoginLink, $wgUser; |
| 108 | + |
| 109 | + # We need to do this *before* PersonalUrls is called |
| 110 | + if ( !$wgHideOpenIDLoginLink && $wgUser->getID() == 0 ) { |
| 111 | + $out->addHeadItem( 'openidloginstyle', self::loginStyle() ); |
| 112 | + } |
| 113 | + |
| 114 | + return true; |
| 115 | + } |
| 116 | + |
108 | 117 | public static function onGetPreferences( $user, &$preferences ) { |
| 118 | + global $wgOpenIDShowUrlOnUserPage, $wgAllowRealName; |
| 119 | + |
109 | 120 | wfLoadExtensionMessages( 'OpenID' ); |
110 | | - |
111 | | - $preferences['openid-hide'] = |
112 | | - array( |
113 | | - 'type' => 'toggle', |
114 | | - 'section' => 'openid', |
115 | | - 'label-message' => 'openid-pref-hide', |
116 | | - ); |
117 | 121 | |
118 | | - $preferences['openid-update-userinfo-on-login'] = |
| 122 | + if ( $wgOpenIDShowUrlOnUserPage == 'user' ) { |
| 123 | + $preferences['openid-hide'] = |
| 124 | + array( |
| 125 | + 'type' => 'toggle', |
| 126 | + 'section' => 'openid', |
| 127 | + 'label-message' => 'openid-pref-hide', |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + $update = array(); |
| 132 | + $update[wfMsg( 'openidnickname' )] = 'nickname'; |
| 133 | + $update[wfMsg( 'openidemail' )] = 'email'; |
| 134 | + if ( $wgAllowRealName ) |
| 135 | + $update[wfMsg( 'openidfullname' )] = 'fullname'; |
| 136 | + $update[wfMsg( 'openidlanguage' )] = 'language'; |
| 137 | + $update[wfMsg( 'openidtimezone' )] = 'timezone'; |
| 138 | + |
| 139 | + $preferences['openid-update-on-login'] = |
119 | 140 | array( |
120 | | - 'type' => 'toggle', |
| 141 | + 'type' => 'multiselect', |
121 | 142 | 'section' => 'openid', |
122 | 143 | 'label-message' => 'openid-pref-update-userinfo-on-login', |
| 144 | + 'options' => $update, |
| 145 | + 'prefix' => 'openid-update-on-login-', |
123 | 146 | ); |
124 | 147 | |
| 148 | + $urls = SpecialOpenID::getUserUrl( $user ); |
| 149 | + $delTitle = SpecialPage::getTitleFor( 'OpenIDConvert', 'Delete' ); |
| 150 | + $sk = $user->getSkin(); |
| 151 | + $rows = ''; |
| 152 | + foreach( $urls as $url ) { |
| 153 | + $rows .= Xml::tags( 'tr', array(), |
| 154 | + Xml::tags( 'td', array(), Xml::element( 'a', array( 'href' => $url ), $url ) ) . |
| 155 | + Xml::tags( 'td', array(), $sk->link( $delTitle, wfMsg( 'openid-urls-delete' ), array(), array( 'url' => $url ) ) ) |
| 156 | + ) . "\n"; |
| 157 | + } |
| 158 | + $info = Xml::tags( 'table', array( 'class' => 'wikitable' ), |
| 159 | + Xml::tags( 'tr', array(), Xml::element( 'th', array(), wfMsg( 'openid-urls-url' ) ) . Xml::element( 'th', array(), wfMsg( 'openid-urls-action' ) ) ) . "\n" . |
| 160 | + $rows |
| 161 | + ); |
| 162 | + $info .= $user->getSkin()->link( SpecialPage::getTitleFor( 'OpenIDConvert' ), wfMsgHtml( 'openid-add-url' ) ); |
| 163 | + |
| 164 | + $preferences['openid-urls'] = |
| 165 | + array( |
| 166 | + 'type' => 'info', |
| 167 | + 'label-message' => 'openid-urls-desc', |
| 168 | + 'default' => $info, |
| 169 | + 'raw' => true, |
| 170 | + 'section' => 'openid', |
| 171 | + ); |
| 172 | + |
| 173 | + |
125 | 174 | return true; |
126 | 175 | } |
127 | 176 | public static function onLoadExtensionSchemaUpdates() { |
— | — | @@ -147,6 +196,7 @@ |
148 | 197 | text-transform: none; |
149 | 198 | } |
150 | 199 | </style> |
| 200 | + |
151 | 201 | EOS; |
152 | 202 | } |
153 | 203 | } |
Index: trunk/extensions/OpenID/patch-uoi_user-not-unique.sql |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +-- |
| 3 | +-- SQL schema update for OpenID extension to make the uoi_user field not unique |
| 4 | +-- |
| 5 | + |
| 6 | +ALTER TABLE user_openid DROP INDEX uoi_user; |
| 7 | +CREATE INDEX user_openid_user ON user_openid(uoi_user); |
\ No newline at end of file |
Property changes on: trunk/extensions/OpenID/patch-uoi_user-not-unique.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 8 | + native |
Index: trunk/extensions/OpenID/SpecialOpenIDServer.body.php |
— | — | @@ -51,7 +51,6 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | function execute( $par ) { |
55 | | - |
56 | 55 | global $wgOut, $wgOpenIDClientOnly; |
57 | 56 | |
58 | 57 | wfLoadExtensionMessages( 'OpenID' ); |
— | — | @@ -500,7 +499,6 @@ |
501 | 500 | } |
502 | 501 | |
503 | 502 | function LoginForm( $request, $msg = null ) { |
504 | | - |
505 | 503 | global $wgOut, $wgUser; |
506 | 504 | |
507 | 505 | $url = $request->identity; |
— | — | @@ -514,7 +512,7 @@ |
515 | 513 | $ok = wfMsg( 'ok' ); |
516 | 514 | $cancel = wfMsg( 'cancel' ); |
517 | 515 | |
518 | | - if ( isset( $msg ) ) { |
| 516 | + if ( !is_null( $msg ) ) { |
519 | 517 | $wgOut->addHTML( "<p class='error'>{$msg}</p>" ); |
520 | 518 | } |
521 | 519 | |
— | — | @@ -744,6 +742,6 @@ |
745 | 743 | } |
746 | 744 | |
747 | 745 | function serverUrl() { |
748 | | - return $this->fullURL( 'OpenIDServer' ); |
| 746 | + return $this->getTitle()->getFullUrl(); |
749 | 747 | } |
750 | 748 | } |
Index: trunk/extensions/OpenID/openid_table.pg.sql |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | |
3 | 3 | -- Schema for the OpenID extension (Postgres version) |
4 | 4 | |
5 | | -CREATE TABLE user_openid ( |
6 | | - uoi_openid VARCHAR(255) PRIMARY KEY NOT NULL, |
7 | | - uoi_user INTEGER NOT NULL |
8 | | -); |
| 5 | +CREATE TABLE /*$wgDBprefix*/user_openid ( |
| 6 | + uoi_openid VARCHAR(255) NOT NULL PRIMARY KEY, |
| 7 | + uoi_user INTEGER NOT NULL REFERENCES mwuser(user_id) |
| 8 | +) /*$wgDBTableOptions*/; |
9 | 9 | |
10 | | -CREATE UNIQUE INDEX user_openid_unique ON user_openid(uoi_user); |
| 10 | +CREATE INDEX user_openid_user ON user_openid(uoi_user); |
\ No newline at end of file |
Index: trunk/extensions/OpenID/SpecialOpenIDLogin.body.php |
— | — | @@ -25,21 +25,76 @@ |
26 | 26 | if ( !defined( 'MEDIAWIKI' ) ) |
27 | 27 | exit( 1 ); |
28 | 28 | |
29 | | -require_once( "Auth/OpenID/Consumer.php" ); |
| 29 | +require_once( "Auth/Yadis/XRI.php" ); |
30 | 30 | |
31 | 31 | class SpecialOpenIDLogin extends SpecialOpenID { |
32 | 32 | |
33 | | - function SpecialOpenIDLogin() { |
34 | | - SpecialPage::SpecialPage( "OpenIDLogin" ); |
| 33 | + function __construct() { |
| 34 | + parent::__construct( 'OpenIDLogin' ); |
35 | 35 | } |
36 | 36 | |
| 37 | + /** |
| 38 | + * Entry point |
| 39 | + * |
| 40 | + * @param $par String or null |
| 41 | + */ |
37 | 42 | function execute( $par ) { |
38 | | - global $wgRequest, $wgUser, $wgOut, $wgScriptPath, $wgOpenIDShowProviderIcons; |
| 43 | + global $wgRequest, $wgUser, $wgOut; |
39 | 44 | |
40 | 45 | wfLoadExtensionMessages( 'OpenID' ); |
41 | 46 | |
42 | 47 | $this->setHeaders(); |
43 | 48 | |
| 49 | + if ( $wgUser->getID() != 0 ) { |
| 50 | + $this->alreadyLoggedIn(); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + $this->outputHeader(); |
| 55 | + |
| 56 | + switch ( $par ) { |
| 57 | + case 'ChooseName': |
| 58 | + $this->chooseName(); |
| 59 | + break; |
| 60 | + |
| 61 | + case 'Finish': # Returning from a server |
| 62 | + $this->finish(); |
| 63 | + break; |
| 64 | + |
| 65 | + default: # Main entry point |
| 66 | + if ( $wgRequest->getText( 'returnto' ) ) { |
| 67 | + $this->setReturnTo( $wgRequest->getText( 'returnto' ) ); |
| 68 | + } |
| 69 | + |
| 70 | + $openid_url = $wgRequest->getText( 'openid_url' ); |
| 71 | + |
| 72 | + if ( !is_null( $openid_url ) && strlen( $openid_url ) > 0 ) { |
| 73 | + $this->login( $openid_url, $this->getTitle( 'Finish' ) ); |
| 74 | + } else { |
| 75 | + $this->loginForm(); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Displays an error message saying that the user is already logged-in |
| 82 | + */ |
| 83 | + function alreadyLoggedIn() { |
| 84 | + global $wgUser, $wgOut; |
| 85 | + |
| 86 | + $wgOut->setPageTitle( wfMsg( 'openiderror' ) ); |
| 87 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 88 | + $wgOut->setArticleRelated( false ); |
| 89 | + $wgOut->addWikiMsg( 'openidalreadyloggedin', $wgUser->getName() ); |
| 90 | + $wgOut->returnToMain( false, $this->returnTo() ); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Displays the main login form |
| 95 | + */ |
| 96 | + function loginForm() { |
| 97 | + global $wgOut, $wgScriptPath, $wgOpenIDShowProviderIcons; |
| 98 | + |
44 | 99 | $oidScriptPath = $wgScriptPath . '/extensions/OpenID'; |
45 | 100 | |
46 | 101 | $wgOut->addLink( array( |
— | — | @@ -52,29 +107,6 @@ |
53 | 108 | $wgOut->addScript( '<script type="text/javascript" src="' . $oidScriptPath . '/skin/jquery-1.3.2.min.js"></script>' . "\n" ); |
54 | 109 | $wgOut->addScript( '<script type="text/javascript" src="' . $oidScriptPath . '/skin/openid.js"></script>' . "\n" ); |
55 | 110 | |
56 | | - if ( $wgUser->getID() != 0 ) { |
57 | | - $this->alreadyLoggedIn(); |
58 | | - return; |
59 | | - } |
60 | | - |
61 | | - if ( $wgRequest->getText( 'returnto' ) ) { |
62 | | - $this->setReturnTo( $wgRequest->getText( 'returnto' ) ); |
63 | | - } |
64 | | - |
65 | | - $openid_url = $wgRequest->getText( 'openid_url' ); |
66 | | - |
67 | | - if ( isset( $openid_url ) && strlen( $openid_url ) > 0 ) { |
68 | | - $this->login( $openid_url ); |
69 | | - } else { |
70 | | - $this->loginForm(); |
71 | | - } |
72 | | - } |
73 | | - |
74 | | - function loginForm() { |
75 | | - global $wgOut, $wgUser, $wgOpenIDLoginLogoUrl, $wgOpenIDShowProviderIcons; |
76 | | - $sk = $wgUser->getSkin(); |
77 | | - $instructions = wfMsgExt( 'openidlogininstructions', array( 'parse' ) ); |
78 | | - |
79 | 111 | $formsHTML = ''; |
80 | 112 | |
81 | 113 | $largeButtonsHTML = '<div id="openid_large_providers">'; |
— | — | @@ -92,9 +124,7 @@ |
93 | 125 | $formsHTML .= $provider->getLoginFormHTML(); |
94 | 126 | } |
95 | 127 | $smallButtonsHTML .= '</div>'; |
96 | | - } |
97 | | - else |
98 | | - { |
| 128 | + } else { |
99 | 129 | $smallButtonsHTML .= '<div id="openid_small_providers_links">'; |
100 | 130 | $smallButtonsHTML .= '<ul class="openid_small_providers_block">'; |
101 | 131 | $small = OpenIDProvider::getSmallProviders(); |
— | — | @@ -116,91 +146,540 @@ |
117 | 147 | $smallButtonsHTML .= '</div>'; |
118 | 148 | } |
119 | 149 | |
120 | | - $wgOut->addHTML( '<form id="openid_form" action="' . $sk->makeSpecialUrl( 'OpenIDLogin' ) . '" method="POST" onsubmit="openid.update()">' . |
121 | | - '<fieldset><legend>' . wfMsg( 'openidsigninorcreateaccount' ) . '</legend>' . |
122 | | - $largeButtonsHTML . |
123 | | - '<div id="openid_input_area">' . |
124 | | - $formsHTML . |
125 | | - '</div>' . |
126 | | - $smallButtonsHTML . |
127 | | - '</fieldset></form>' . |
128 | | - $instructions |
129 | | - ); |
| 150 | + $wgOut->addHTML( |
| 151 | + Xml::openElement( 'form', array( 'id' => 'openid_form', 'action' => $this->getTitle()->getLocalUrl(), 'method' => 'post', 'onsubmit' => 'openid.update()' ) ) . |
| 152 | + Xml::fieldset( wfMsg( 'openidsigninorcreateaccount' ) ) . |
| 153 | + $largeButtonsHTML . |
| 154 | + '<div id="openid_input_area">' . |
| 155 | + $formsHTML . |
| 156 | + '</div>' . |
| 157 | + $smallButtonsHTML . |
| 158 | + Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) |
| 159 | + ); |
| 160 | + $wgOut->addWikiMsg( 'openidlogininstructions' ); |
130 | 161 | } |
131 | 162 | |
132 | | - function toUserName( $openid ) { |
133 | | - if ( Services_Yadis_identifierScheme( $openid ) == 'XRI' ) { |
134 | | - wfDebug( "OpenID: Handling an XRI: $openid\n" ); |
135 | | - return $this->toUserNameXri( $openid ); |
| 163 | + /** |
| 164 | + * Displays a form to let the user choose an account to attach with the |
| 165 | + * given OpenID |
| 166 | + * |
| 167 | + * @param $openid String: OpenID url |
| 168 | + * @param $sreg Array: options get from OpenID |
| 169 | + * @param $messagekey String or null: message name to display at the top |
| 170 | + */ |
| 171 | + function chooseNameForm( $openid, $sreg, $messagekey = NULL ) { |
| 172 | + global $wgOut, $wgOpenIDOnly, $wgAllowRealName; |
| 173 | + |
| 174 | + if ( $messagekey ) { |
| 175 | + $wgOut->addWikiMsg( $messagekey ); |
| 176 | + } else if ( array_key_exists( 'nickname', $sreg ) ) { |
| 177 | + $wgOut->addWikiMsg( 'openidnotavailable', $sreg['nickname'] ); |
136 | 178 | } else { |
137 | | - wfDebug( "OpenID: Handling an URL: $openid\n" ); |
138 | | - return $this->toUserNameUrl( $openid ); |
| 179 | + $wgOut->addWikiMsg( 'openidnotprovided' ); |
139 | 180 | } |
| 181 | + $wgOut->addWikiMsg( 'openidchooseinstructions' ); |
| 182 | + |
| 183 | + $wgOut->addHTML( |
| 184 | + Xml::openElement( 'form', |
| 185 | + array( 'action' => $this->getTitle( 'ChooseName' )->getLocalUrl(), 'method' => 'POST' ) ) . "\n" |
| 186 | + ); |
| 187 | + $def = false; |
| 188 | + |
| 189 | + if ( !$wgOpenIDOnly ) { |
| 190 | + # Let them attach it to an existing user |
| 191 | + |
| 192 | + # Grab the UserName in the cookie if it exists |
| 193 | + |
| 194 | + global $wgCookiePrefix; |
| 195 | + $name = ''; |
| 196 | + if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) { |
| 197 | + $name = trim( $_COOKIE["{$wgCookiePrefix}UserName"] ); |
| 198 | + } |
| 199 | + |
| 200 | + # show OpenID Attributes |
| 201 | + $oidAttributesToAccept = array( 'fullname', 'nickname', 'email', 'language' ); |
| 202 | + $oidAttributes = array(); |
| 203 | + |
| 204 | + foreach ( $oidAttributesToAccept as $oidAttr ) { |
| 205 | + if ( $oidAttr == 'fullname' && !$wgAllowRealName ) { |
| 206 | + continue; |
| 207 | + } |
| 208 | + |
| 209 | + if ( array_key_exists( $oidAttr, $sreg ) ) { |
| 210 | + $oidAttributes[] = Xml::tags( 'div', array(), wfMsgHtml( "openid$oidAttr" ) . ': ' . Xml::tags( 'i', array(), $sreg[$oidAttr] ) ); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + $oidAttributesUpdate = ''; |
| 215 | + if ( count( $oidAttributes ) > 0 ) { |
| 216 | + $oidAttributesUpdate = Xml::openElement( 'div', array( 'style' => 'margin-left: 25px' ) ) . "\n" . |
| 217 | + Xml::check( 'wpUpdateUserInfo', false, array( 'id' => 'wpUpdateUserInfo' ) ) . "\n" . |
| 218 | + Xml::openElement( 'label', array( 'for' => 'wpUpdateUserInfo' ) ) . |
| 219 | + wfMsgHtml( 'openidupdateuserinfo' ) . |
| 220 | + Xml::tags( 'div', array( 'style' => 'margin-left: 25px' ), implode( "\n", $oidAttributes ) ) . |
| 221 | + Xml::closeElement( 'label' ) . Xml::closeElement( 'div' ); |
| 222 | + } |
| 223 | + |
| 224 | + $wgOut->addHTML( |
| 225 | + Xml::openElement( 'div' ) . |
| 226 | + Xml::radioLabel( wfMsg( 'openidchooseexisting' ), 'wpNameChoice', 'existing', 'wpNameChoiceExisting' ) . "\n" . |
| 227 | + Xml::input( 'wpExistingName', 16, $name, array( 'id' => 'wpExistingName' ) ) . "\n" . |
| 228 | + wfMsgHtml( 'openidchoosepassword' ) . "\n" . |
| 229 | + Xml::password( 'wpExistingPassword' ) . "\n" . |
| 230 | + $oidAttributesUpdate . "\n" . |
| 231 | + Xml::closeElement( 'div' ) |
| 232 | + ); |
| 233 | + } |
| 234 | + |
| 235 | + # These options won't exist if we can't get them. |
| 236 | + if ( array_key_exists( 'fullname', $sreg ) && $this->userNameOK( $sreg['fullname'] ) ) { |
| 237 | + $wgOut->addHTML( |
| 238 | + Xml::openElement( 'div' ) . |
| 239 | + Xml::radioLabel( wfMsg( 'openidchoosefull', $sreg['fullname'] ), 'wpNameChoice', 'full', 'wpNameChoiceFull', !$def ) . |
| 240 | + Xml::closeElement( 'div' ) |
| 241 | + ); |
| 242 | + $def = true; |
| 243 | + } |
| 244 | + |
| 245 | + $idname = $this->toUserName( $openid ); |
| 246 | + if ( $idname && $this->userNameOK( $idname ) ) { |
| 247 | + $wgOut->addHTML( |
| 248 | + Xml::openElement( 'div' ) . |
| 249 | + Xml::radioLabel( wfMsg( 'openidchooseurl', $idname ), 'wpNameChoice', 'url', 'wpNameChoiceUrl', !$def ) . |
| 250 | + Xml::closeElement( 'div' ) |
| 251 | + ); |
| 252 | + $def = true; |
| 253 | + } |
| 254 | + |
| 255 | + # These are always available |
| 256 | + $wgOut->addHTML( |
| 257 | + Xml::openElement( 'div' ) . "\n" . |
| 258 | + Xml::radioLabel( wfMsg( 'openidchooseauto', $this->automaticName( $sreg ) ), 'wpNameChoice', 'auto', 'wpNameChoiceAuto', !$def ) . "\n" . |
| 259 | + Xml::closeElement( 'div' ) . "\n" . |
| 260 | + Xml::openElement( 'div' ) . "\n" . |
| 261 | + Xml::radioLabel( wfMsg( 'openidchoosemanual' ), 'wpNameChoice', 'manual', 'wpNameChoiceManual' ) . "\n" . |
| 262 | + Xml::input( 'wpNameValue', 16, false, array( 'id' => 'wpNameValue' ) ) . "\n" . |
| 263 | + Xml::closeElement( 'div' ) . "\n" . |
| 264 | + Xml::submitButton( wfMsg( 'login' ), array( 'name' => 'wpOK' ) ) . Xml::submitButton( wfMsg( 'cancel' ), array( 'name' => 'wpCancel' ) ) . "\n" . |
| 265 | + Xml::closeElement( 'form' ) |
| 266 | + ); |
140 | 267 | } |
141 | 268 | |
142 | | - function alreadyLoggedIn() { |
| 269 | + function loginSetCookie( $openid ) { |
| 270 | + global $wgRequest, $wgOpenIDCookieExpiration; |
| 271 | + $wgRequest->response()->setcookie( 'OpenID', $openid, time() + $wgOpenIDCookieExpiration ); |
| 272 | + } |
143 | 273 | |
| 274 | + /** |
| 275 | + * Handle "Choose name" form submission |
| 276 | + */ |
| 277 | + function chooseName() { |
| 278 | + global $wgRequest, $wgUser, $wgOut; |
| 279 | + |
| 280 | + list( $openid, $sreg ) = $this->fetchValues(); |
| 281 | + if ( is_null( $openid ) ) { |
| 282 | + wfDebug( "OpenID: aborting in ChooseName because identity_url is missing\n" ); |
| 283 | + $this->clearValues(); |
| 284 | + # No messing around, here |
| 285 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
| 286 | + return; |
| 287 | + } |
| 288 | + |
| 289 | + if ( $wgRequest->getCheck( 'wpCancel' ) ) { |
| 290 | + $this->clearValues(); |
| 291 | + $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
| 292 | + return; |
| 293 | + } |
| 294 | + |
| 295 | + $choice = $wgRequest->getText( 'wpNameChoice' ); |
| 296 | + $nameValue = $wgRequest->getText( 'wpNameValue' ); |
| 297 | + |
| 298 | + if ( $choice == 'existing' ) { |
| 299 | + $user = $this->attachUser( $openid, $sreg, |
| 300 | + $wgRequest->getText( 'wpExistingName' ), |
| 301 | + $wgRequest->getText( 'wpExistingPassword' ) |
| 302 | + ); |
| 303 | + |
| 304 | + if ( !$user ) { |
| 305 | + $this->chooseNameForm( $openid, $sreg, 'wrongpassword' ); |
| 306 | + return; |
| 307 | + } |
| 308 | + |
| 309 | + if ( $wgRequest->getText( 'wpUpdateUserInfo' ) ) { |
| 310 | + $this->updateUser( $user, $sreg ); |
| 311 | + } |
| 312 | + } else { |
| 313 | + $name = $this->getUserName( $openid, $sreg, $choice, $nameValue ); |
| 314 | + |
| 315 | + if ( !$name || !$this->userNameOK( $name ) ) { |
| 316 | + wfDebug( "OpenID: Name not OK: '$name'\n" ); |
| 317 | + $this->chooseNameForm( $openid, $sreg ); |
| 318 | + return; |
| 319 | + } |
| 320 | + |
| 321 | + $user = $this->createUser( $openid, $sreg, $name ); |
| 322 | + } |
| 323 | + |
| 324 | + if ( is_null( $user ) ) { |
| 325 | + wfDebug( "OpenID: aborting in ChooseName because we could not create user object\n" ); |
| 326 | + $this->clearValues(); |
| 327 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
| 328 | + return; |
| 329 | + } |
| 330 | + |
| 331 | + $wgUser = $user; |
| 332 | + |
| 333 | + $this->clearValues(); |
| 334 | + |
| 335 | + $this->displaySuccessLogin( $openid ); |
| 336 | + } |
| 337 | + |
| 338 | + /** |
| 339 | + * Called when returning from the authentication server |
| 340 | + * Find the user with the given openid, if any or displays the "Choose name" |
| 341 | + * form |
| 342 | + */ |
| 343 | + function finish() { |
| 344 | + global $wgOut, $wgUser; |
| 345 | + |
| 346 | + wfSuppressWarnings(); |
| 347 | + $consumer = $this->getConsumer(); |
| 348 | + $response = $consumer->complete( $this->getTitle( 'Finish' )->getFullUrl() ); |
| 349 | + wfRestoreWarnings(); |
| 350 | + |
| 351 | + if ( is_null( $response ) ) { |
| 352 | + wfDebug( "OpenID: aborting in auth because no response was recieved\n" ); |
| 353 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
| 354 | + return; |
| 355 | + } |
| 356 | + |
| 357 | + switch ( $response->status ) { |
| 358 | + case Auth_OpenID_CANCEL: |
| 359 | + // This means the authentication was cancelled. |
| 360 | + $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
| 361 | + break; |
| 362 | + case Auth_OpenID_FAILURE: |
| 363 | + wfDebug( "OpenID: error message '" . $response->message . "'\n" ); |
| 364 | + $wgOut->showErrorPage( 'openidfailure', 'openidfailuretext', |
| 365 | + array( ( $response->message ) ? $response->message : '' ) ); |
| 366 | + break; |
| 367 | + case Auth_OpenID_SUCCESS: |
| 368 | + // This means the authentication succeeded. |
| 369 | + wfSuppressWarnings(); |
| 370 | + $openid = $response->getDisplayIdentifier(); |
| 371 | + $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse( $response ); |
| 372 | + $sreg = $sreg_resp->contents(); |
| 373 | + wfRestoreWarnings(); |
| 374 | + |
| 375 | + if ( is_null( $openid ) ) { |
| 376 | + wfDebug( "OpenID: aborting in auth success because display identifier is missing\n" ); |
| 377 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
| 378 | + return; |
| 379 | + } |
| 380 | + |
| 381 | + $user = self::getUser( $openid ); |
| 382 | + |
| 383 | + if ( $user instanceof User ) { |
| 384 | + $this->updateUser( $user, $sreg ); # update from server |
| 385 | + } else { |
| 386 | + # For easy names |
| 387 | + $name = $this->createName( $openid, $sreg ); |
| 388 | + if ( $name ) { |
| 389 | + $user = $this->createUser( $openid, $sreg, $name ); |
| 390 | + } else { |
| 391 | + # For hard names |
| 392 | + $this->saveValues( $openid, $sreg ); |
| 393 | + $this->chooseNameForm( $openid, $sreg ); |
| 394 | + return; |
| 395 | + } |
| 396 | + } |
| 397 | + |
| 398 | + if ( !$user instanceof User ) { |
| 399 | + wfDebug( "OpenID: aborting in auth success because we could not create user object\n" ); |
| 400 | + $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
| 401 | + } else { |
| 402 | + $wgUser = $user; |
| 403 | + $this->displaySuccessLogin( $openid ); |
| 404 | + } |
| 405 | + } |
| 406 | + } |
| 407 | + |
| 408 | + /** |
| 409 | + * Update some user's settings with value get from OpenID |
| 410 | + * |
| 411 | + * @param $user User object |
| 412 | + * @param $sreg Array of options get from OpenID |
| 413 | + */ |
| 414 | + function updateUser( $user, $sreg ) { |
| 415 | + global $wgAllowRealName, $wgEmailAuthentication; |
| 416 | + |
| 417 | + // Back compat with old option |
| 418 | + $updateAll = $user->getOption( 'openid-update-userinfo-on-login' ); |
| 419 | + |
| 420 | + // Nick name |
| 421 | + if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-nickname' ) ) { |
| 422 | + // FIXME: only update if there's been a change |
| 423 | + if ( array_key_exists( 'nickname', $sreg ) ) |
| 424 | + $user->setOption( 'nickname', $sreg['nickname'] ); |
| 425 | + } |
| 426 | + |
| 427 | + // E-mail |
| 428 | + if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-email' ) ) { |
| 429 | + if ( array_key_exists( 'email', $sreg ) ) { |
| 430 | + $email = $sreg['email']; |
| 431 | + // If email changed, then email a confirmation mail |
| 432 | + if ( $email != $user->getEmail() ) { |
| 433 | + $user->setEmail( $email ); |
| 434 | + $user->invalidateEmail(); |
| 435 | + if ( $wgEmailAuthentication && $email != '' ) { |
| 436 | + $result = $user->sendConfirmationMail(); |
| 437 | + if( WikiError::isError( $result ) ) { |
| 438 | + $wgOut->addWikiMsg( 'mailerror', $result->getMessage() ); |
| 439 | + } |
| 440 | + } |
| 441 | + } |
| 442 | + } |
| 443 | + } |
| 444 | + |
| 445 | + // Full name |
| 446 | + if ( $wgAllowRealName && ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-fullname' ) ) ) { |
| 447 | + if ( array_key_exists( 'fullname', $sreg ) ) |
| 448 | + $user->setRealName( $sreg['fullname'] ); |
| 449 | + } |
| 450 | + |
| 451 | + // Language |
| 452 | + if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-language' ) ) { |
| 453 | + if ( array_key_exists( 'language', $sreg ) ) { |
| 454 | + # FIXME: check and make sure the language exists |
| 455 | + $user->setOption( 'language', $sreg['language'] ); |
| 456 | + } |
| 457 | + } |
| 458 | + |
| 459 | + if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-timezone' ) ) { |
| 460 | + if ( array_key_exists( 'timezone', $sreg ) ) { |
| 461 | + # FIXME: do something with it. |
| 462 | + # $offset = OpenIDTimezoneToTzoffset($sreg['timezone']); |
| 463 | + # $user->setOption('timecorrection', $offset); |
| 464 | + } |
| 465 | + } |
| 466 | + |
| 467 | + $user->saveSettings(); |
| 468 | + } |
| 469 | + |
| 470 | + /** |
| 471 | + * Display the final "Successful login" |
| 472 | + * |
| 473 | + * @param $openid String: OpenID url |
| 474 | + */ |
| 475 | + function displaySuccessLogin( $openid ) { |
144 | 476 | global $wgUser, $wgOut; |
145 | 477 | |
146 | | - $wgOut->setPageTitle( wfMsg( 'openiderror' ) ); |
| 478 | + $this->setupSession(); |
| 479 | + $wgUser->SetCookies(); |
| 480 | + |
| 481 | + # Run any hooks; ignore results |
| 482 | + $inject_html = ''; |
| 483 | + wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$inject_html ) ); |
| 484 | + |
| 485 | + # Set a cookie for later check-immediate use |
| 486 | + |
| 487 | + $this->loginSetCookie( $openid ); |
| 488 | + |
| 489 | + $wgOut->setPageTitle( wfMsg( 'openidsuccess' ) ); |
147 | 490 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
148 | 491 | $wgOut->setArticleRelated( false ); |
149 | | - $wgOut->addWikiText( wfMsg( 'openidalreadyloggedin', $wgUser->getName() ) ); |
| 492 | + $wgOut->addWikiMsg( 'openidsuccess', $wgUser->getName(), $openid ); |
| 493 | + $wgOut->addHtml( $inject_html ); |
150 | 494 | $wgOut->returnToMain( false, $this->returnTo() ); |
151 | 495 | } |
152 | 496 | |
153 | | - function setUserUrl( $user, $url ) { |
154 | | - $other = $this->getUserUrl( $user ); |
155 | | - if ( isset( $other ) ) { |
156 | | - $this->updateUserUrl( $user, $url ); |
| 497 | + function createUser( $openid, $sreg, $name ) { |
| 498 | + global $wgAuth; |
| 499 | + |
| 500 | + $user = User::newFromName( $name ); |
| 501 | + |
| 502 | + if ( !$user ) { |
| 503 | + wfDebug( "OpenID: Error adding new user.\n" ); |
| 504 | + return NULL; |
| 505 | + } |
| 506 | + |
| 507 | + $user->addToDatabase(); |
| 508 | + $user->addNewUserLogEntry(); |
| 509 | + |
| 510 | + if ( !$user->getId() ) { |
| 511 | + wfDebug( "OpenID: Error adding new user.\n" ); |
157 | 512 | } else { |
158 | | - $this->insertUserUrl( $user, $url ); |
| 513 | + $wgAuth->initUser( $user ); |
| 514 | + $wgAuth->updateUser( $user ); |
| 515 | + |
| 516 | + # Update site stats |
| 517 | + $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
| 518 | + $ssUpdate->doUpdate(); |
| 519 | + |
| 520 | + $this->insertUserUrl( $user, $openid ); |
| 521 | + $this->updateUser( $user, $sreg ); |
| 522 | + $user->saveSettings(); |
| 523 | + return $user; |
159 | 524 | } |
160 | 525 | } |
161 | 526 | |
162 | | - function insertUserUrl( $user, $url ) { |
163 | | - global $wgSharedDB, $wgDBname; |
164 | | - $dbw =& wfGetDB( DB_MASTER ); |
| 527 | + function attachUser( $openid, $sreg, $name, $password ) { |
| 528 | + $user = User::newFromName( $name ); |
165 | 529 | |
166 | | - if ( isset( $wgSharedDB ) ) { |
167 | | - # It would be nicer to get the existing dbname |
168 | | - # and save it, but it's not possible |
169 | | - $dbw->selectDB( $wgSharedDB ); |
| 530 | + if ( !$user ) { |
| 531 | + return null; |
170 | 532 | } |
171 | 533 | |
172 | | - $dbw->insert( 'user_openid', array( 'uoi_user' => $user->getId(), |
173 | | - 'uoi_openid' => $url ) ); |
| 534 | + if ( !$user->checkPassword( $password ) ) { |
| 535 | + return null; |
| 536 | + } |
174 | 537 | |
175 | | - if ( isset( $wgSharedDB ) ) { |
176 | | - $dbw->selectDB( $wgDBname ); |
| 538 | + self::addUserUrl( $user, $openid ); |
| 539 | + |
| 540 | + return $user; |
| 541 | + } |
| 542 | + |
| 543 | + # Methods to get the user name |
| 544 | + # ---------------------------- |
| 545 | + |
| 546 | + function createName( $openid, $sreg ) { |
| 547 | + # try nickname |
| 548 | + if ( array_key_exists( 'nickname', $sreg ) && |
| 549 | + $this->userNameOK( $sreg['nickname'] ) ) { |
| 550 | + return $sreg['nickname']; |
| 551 | + } else { |
| 552 | + return null; |
177 | 553 | } |
178 | 554 | } |
179 | 555 | |
180 | | - function updateUserUrl( $user, $url ) { |
181 | | - global $wgSharedDB, $wgDBname; |
182 | | - $dbw =& wfGetDB( DB_MASTER ); |
183 | 556 | |
184 | | - if ( isset( $wgSharedDB ) ) { |
185 | | - # It would be nicer to get the existing dbname |
186 | | - # and save it, but it's not possible |
187 | | - $dbw->selectDB( $wgSharedDB ); |
| 557 | + function getUserName( $openid, $sreg, $choice, $nameValue ) { |
| 558 | + switch ( $choice ) { |
| 559 | + case 'full': |
| 560 | + return ( ( array_key_exists( 'fullname', $sreg ) ) ? $sreg['fullname'] : null ); |
| 561 | + break; |
| 562 | + case 'url': |
| 563 | + return $this->toUserName( $openid ); |
| 564 | + break; |
| 565 | + case 'auto': |
| 566 | + return $this->automaticName( $sreg ); |
| 567 | + break; |
| 568 | + case 'manual': |
| 569 | + return $nameValue; |
| 570 | + default: |
| 571 | + return null; |
188 | 572 | } |
| 573 | + } |
189 | 574 | |
190 | | - $dbw->set( 'user_openid', 'uoi_openid', $url, |
191 | | - 'uoi_user = ' . $user->getID() ); |
| 575 | + function toUserName( $openid ) { |
| 576 | + if ( Auth_Yadis_identifierScheme( $openid ) == 'XRI' ) { |
| 577 | + return $this->toUserNameXri( $openid ); |
| 578 | + } else { |
| 579 | + return $this->toUserNameUrl( $openid ); |
| 580 | + } |
| 581 | + } |
192 | 582 | |
193 | | - if ( isset( $wgSharedDB ) ) { |
194 | | - $dbw->selectDB( $wgDBname ); |
| 583 | + /** |
| 584 | + * We try to use an OpenID URL as a legal MediaWiki user name in this order |
| 585 | + * 1. Plain hostname, like http://evanp.myopenid.com/ |
| 586 | + * 2. One element in path, like http://profile.typekey.com/EvanProdromou/ |
| 587 | + * or http://getopenid.com/evanprodromou |
| 588 | + */ |
| 589 | + function toUserNameUrl( $openid ) { |
| 590 | + static $bad = array( 'query', 'user', 'password', 'port', 'fragment' ); |
| 591 | + |
| 592 | + $parts = parse_url( $openid ); |
| 593 | + |
| 594 | + # If any of these parts exist, this won't work |
| 595 | + |
| 596 | + foreach ( $bad as $badpart ) { |
| 597 | + if ( array_key_exists( $badpart, $parts ) ) { |
| 598 | + return NULL; |
| 599 | + } |
195 | 600 | } |
| 601 | + |
| 602 | + # We just have host and/or path |
| 603 | + |
| 604 | + # If it's just a host... |
| 605 | + if ( array_key_exists( 'host', $parts ) && |
| 606 | + ( !array_key_exists( 'path', $parts ) || strcmp( $parts['path'], '/' ) == 0 ) ) |
| 607 | + { |
| 608 | + $hostparts = explode( '.', $parts['host'] ); |
| 609 | + |
| 610 | + # Try to catch common idiom of nickname.service.tld |
| 611 | + |
| 612 | + if ( ( count( $hostparts ) > 2 ) && |
| 613 | + ( strlen( $hostparts[count( $hostparts ) - 2] ) > 3 ) && # try to skip .co.uk, .com.au |
| 614 | + ( strcmp( $hostparts[0], 'www' ) != 0 ) ) |
| 615 | + { |
| 616 | + return $hostparts[0]; |
| 617 | + } else { |
| 618 | + # Do the whole hostname |
| 619 | + return $parts['host']; |
| 620 | + } |
| 621 | + } else { |
| 622 | + if ( array_key_exists( 'path', $parts ) ) { |
| 623 | + # Strip starting, ending slashes |
| 624 | + $path = preg_replace( '@/$@', '', $parts['path'] ); |
| 625 | + $path = preg_replace( '@^/@', '', $path ); |
| 626 | + if ( strpos( $path, '/' ) === false ) { |
| 627 | + return $path; |
| 628 | + } |
| 629 | + } |
| 630 | + } |
| 631 | + |
| 632 | + return null; |
196 | 633 | } |
197 | 634 | |
198 | | - function saveValues( $response, $sreg ) { |
199 | | - global $wgSessionStarted, $wgUser; |
| 635 | + function toUserNameXri( $xri ) { |
| 636 | + $base = $this->xriBase( $xri ); |
200 | 637 | |
201 | | - if ( !$wgSessionStarted ) { |
202 | | - $wgUser->SetupSession(); |
| 638 | + if ( !$base ) { |
| 639 | + return null; |
| 640 | + } else { |
| 641 | + # =evan.prodromou |
| 642 | + # or @gratis*evan.prodromou |
| 643 | + $parts = explode( '*', substr( $base, 1 ) ); |
| 644 | + return array_pop( $parts ); |
203 | 645 | } |
| 646 | + } |
204 | 647 | |
| 648 | + function automaticName( $sreg ) { |
| 649 | + if ( array_key_exists( 'nickname', $sreg ) && # try auto-generated from nickname |
| 650 | + strlen( $sreg['nickname'] ) > 0 ) { |
| 651 | + return $this->firstAvailable( $sreg['nickname'] ); |
| 652 | + } else { # try auto-generated |
| 653 | + return $this->firstAvailable( wfMsg( 'openidusernameprefix' ) ); |
| 654 | + } |
| 655 | + } |
| 656 | + |
| 657 | + /** |
| 658 | + * Get an auto-incremented name |
| 659 | + */ |
| 660 | + function firstAvailable( $prefix ) { |
| 661 | + for ( $i = 2; ; $i++ ) { # FIXME: this is the DUMB WAY to do this |
| 662 | + $name = "$prefix$i"; |
| 663 | + if ( $this->userNameOK( $name ) ) { |
| 664 | + return $name; |
| 665 | + } |
| 666 | + } |
| 667 | + } |
| 668 | + |
| 669 | + /** |
| 670 | + * Is this name OK to use as a user name? |
| 671 | + */ |
| 672 | + function userNameOK( $name ) { |
| 673 | + global $wgReservedUsernames; |
| 674 | + return ( 0 == User::idFromName( $name ) && |
| 675 | + !in_array( $name, $wgReservedUsernames ) ); |
| 676 | + } |
| 677 | + |
| 678 | + # Session stuff |
| 679 | + # ------------- |
| 680 | + |
| 681 | + function saveValues( $response, $sreg ) { |
| 682 | + $this->setupSession(); |
| 683 | + |
205 | 684 | $_SESSION['openid_consumer_response'] = $response; |
206 | 685 | $_SESSION['openid_consumer_sreg'] = $sreg; |
207 | 686 | |
Index: trunk/extensions/OpenID/OpenID.alias.php |
— | — | @@ -13,7 +13,6 @@ |
14 | 14 | */ |
15 | 15 | $aliases['en'] = array( |
16 | 16 | 'OpenIDLogin' => array( 'OpenIDLogin' ), |
17 | | - 'OpenIDFinish' => array( 'OpenIDFinish' ), |
18 | 17 | 'OpenIDConvert' => array( 'OpenIDConvert' ), |
19 | 18 | 'OpenIDServer' => array( 'OpenIDServer' ), |
20 | 19 | 'OpenIDXRDS' => array( 'OpenIDXRDS' ), |
— | — | @@ -22,7 +21,6 @@ |
23 | 22 | /** Arabic (العربية) */ |
24 | 23 | $aliases['ar'] = array( |
25 | 24 | 'OpenIDLogin' => array( 'دخول_الهوية_المفتوحة' ), |
26 | | - 'OpenIDFinish' => array( 'نهاية_الهوية_المفتوحة' ), |
27 | 25 | 'OpenIDConvert' => array( 'تحويل_الهوية_المفتوحة' ), |
28 | 26 | 'OpenIDServer' => array( 'خادم_الهوية_المفتوحة' ), |
29 | 27 | 'OpenIDXRDS' => array( 'إكسردس_الهوية_المفتوحة' ), |
— | — | @@ -31,7 +29,6 @@ |
32 | 30 | /** Egyptian Spoken Arabic (مصرى) */ |
33 | 31 | $aliases['arz'] = array( |
34 | 32 | 'OpenIDLogin' => array( 'دخول_الهوية_المفتوحة' ), |
35 | | - 'OpenIDFinish' => array( 'نهاية_الهوية_المفتوحة' ), |
36 | 33 | 'OpenIDConvert' => array( 'تحويل_الهوية_المفتوحة' ), |
37 | 34 | 'OpenIDServer' => array( 'خادم_الهوية_المفتوحة' ), |
38 | 35 | 'OpenIDXRDS' => array( 'إكسردس_الهوية_المفتوحة' ), |
— | — | @@ -40,7 +37,6 @@ |
41 | 38 | /** Interlingua (Interlingua) */ |
42 | 39 | $aliases['ia'] = array( |
43 | 40 | 'OpenIDLogin' => array( 'Aperir session OpenID' ), |
44 | | - 'OpenIDFinish' => array( 'Completar session OpenID' ), |
45 | 41 | 'OpenIDConvert' => array( 'Converter a OpenID' ), |
46 | 42 | 'OpenIDServer' => array( 'Servitor OpenID' ), |
47 | 43 | 'OpenIDXRDS' => array( 'XRDS OpenID' ), |
— | — | @@ -49,7 +45,6 @@ |
50 | 46 | /** Japanese (日本語) */ |
51 | 47 | $aliases['ja'] = array( |
52 | 48 | 'OpenIDLogin' => array( 'OpenIDログイン', 'OpenIDログイン' ), |
53 | | - 'OpenIDFinish' => array( 'OpenID完了', 'OpenID完了' ), |
54 | 49 | 'OpenIDConvert' => array( 'OpenID変換', 'OpenID変換' ), |
55 | 50 | 'OpenIDServer' => array( 'OpenIDサーバー', 'OpenIDサーバー' ), |
56 | 51 | 'OpenIDXRDS' => array( 'OpenIDXRDS' ), |
— | — | @@ -58,14 +53,12 @@ |
59 | 54 | /** Ripoarisch (Ripoarisch) */ |
60 | 55 | $aliases['ksh'] = array( |
61 | 56 | 'OpenIDLogin' => array( 'OpenIDAanmedung' ), |
62 | | - 'OpenIDFinish' => array( 'OpenIDEngk' ), |
63 | 57 | 'OpenIDConvert' => array( 'OpenIDÖmwandele' ), |
64 | 58 | ); |
65 | 59 | |
66 | 60 | /** Norwegian (bokmål) (Norsk (bokmål)) */ |
67 | 61 | $aliases['no'] = array( |
68 | 62 | 'OpenIDLogin' => array( 'OpenID-innlogging' ), |
69 | | - 'OpenIDFinish' => array( 'OpenID-fullføring' ), |
70 | 63 | 'OpenIDConvert' => array( 'OpenID-konvertering' ), |
71 | 64 | 'OpenIDServer' => array( 'OpenID-tjener' ), |
72 | 65 | 'OpenIDXRDS' => array( 'OpenID-XRDS' ), |
— | — | @@ -74,7 +67,6 @@ |
75 | 68 | /** Sanskrit (संस्कृत) */ |
76 | 69 | $aliases['sa'] = array( |
77 | 70 | 'OpenIDLogin' => array( 'उद्घटपरिचयपत्रप्रवेश' ), |
78 | | - 'OpenIDFinish' => array( 'उद्घटपरिचयपत्रसमापयति' ), |
79 | 71 | 'OpenIDConvert' => array( 'उद्घटपरिचयपत्रांतर' ), |
80 | 72 | 'OpenIDServer' => array( 'उद्घटपरिचयपत्रविदादाता' ), |
81 | 73 | 'OpenIDXRDS' => array( 'उद्घटपरिचयपत्रXRDS' ), |
— | — | @@ -83,7 +75,6 @@ |
84 | 76 | /** Tagalog (Tagalog) */ |
85 | 77 | $aliases['tl'] = array( |
86 | 78 | 'OpenIDLogin' => array( 'Paglagda sa OpenID' ), |
87 | | - 'OpenIDFinish' => array( 'Pagtatapos ng OpenID' ), |
88 | 79 | 'OpenIDConvert' => array( 'Pagpapalit ng OpenID' ), |
89 | 80 | 'OpenIDServer' => array( 'Serbidor ng OpenID' ), |
90 | 81 | 'OpenIDXRDS' => array( 'XRDS ng OpenID' ), |
Index: trunk/extensions/OpenID/README |
— | — | @@ -1,43 +1,39 @@ |
2 | 2 | MediaWiki OpenID extension |
3 | 3 | |
4 | | -version 0.8.4.1 |
5 | | -18 Apr 2009 |
| 4 | +version 0.9.0 |
| 5 | +20 June 2009 |
6 | 6 | |
7 | | -This is the README file for the OpenID extension for MediaWiki |
8 | | -software. The extension is only useful if you've got a MediaWiki |
9 | | -installation; it can only be installed by the administrator of the site. |
| 7 | +This is the README file for the OpenID extension for MediaWiki software. The |
| 8 | +extension is only useful if you've got a MediaWiki installation; it can only be |
| 9 | +installed by the administrator of the site. |
10 | 10 | |
11 | | -The extension lets users log in with an OpenID |
12 | | -(http://www.openid.net/) instead of a username and password. An OpenID |
13 | | -is a special URL that people can use to log in to a Web site. The |
14 | | -extension also lets users who have an account on the wiki log in to |
15 | | -other OpenID-aware Web sites with their wiki user page as their OpenID. |
| 11 | +The extension lets users log in with an OpenID (http://www.openid.net/) instead |
| 12 | +of a username and password. An OpenID is a special URL that people can use to |
| 13 | +log in to a Web site. The extension also lets users who have an account on the |
| 14 | +wiki log in to other OpenID-aware Web sites with their wiki user page as their |
| 15 | +OpenID. |
16 | 16 | |
17 | 17 | Typical uses: |
18 | 18 | |
19 | | -* Single-signon between multiple affiliated wikis and other sites. We |
20 | | - have almost 20 wikis that work together for Wikitravel, and users |
21 | | - can login to different Wikitravel wikis with their home wiki |
22 | | - account. |
23 | | -* Single-signon across the Internet. Many, many sites now support |
24 | | - OpenID, including "big names" like Yahoo!, Google, and AOL. Allowing |
25 | | - users to login with OpenID means one less step for them to |
26 | | - contribute to your wiki. |
27 | | -* Distributed reputation. Logging into a new wiki with the same |
28 | | - username as you have on another wiki doesn't prove that they're the |
29 | | - same person. Logging in with your OpenID from the old wiki does. |
30 | | - Using OpenID can help build a distributed reputation across the |
31 | | - wiki world. |
| 19 | +* Single-signon between multiple affiliated wikis and other sites. We have |
| 20 | + almost 20 wikis that work together for Wikitravel, and users can login to |
| 21 | + different Wikitravel wikis with their home wiki account. |
| 22 | +* Single-signon across the Internet. Many, many sites now support OpenID, |
| 23 | + including "big names" like Yahoo!, Google, and AOL. Allowing users to login |
| 24 | + with OpenID means one less step for them to contribute to your wiki. |
| 25 | +* Distributed reputation. Logging into a new wiki with the same username as you |
| 26 | + have on another wiki doesn't prove that they're the same person. Logging in |
| 27 | + with your OpenID from the old wiki does. Using OpenID can help build a |
| 28 | + distributed reputation across the wiki world. |
32 | 29 | |
33 | | -The software supports OpenID 2.0 and '''requires''' the |
34 | | -openidenabled.com 2.x libraries. Users of previous versions should see |
35 | | -[[#Upgrade]] for more information. |
| 30 | +The software supports OpenID 2.0 and '''requires''' the openidenabled.com 2.x |
| 31 | +libraries. Users of previous versions should see [[#Upgrade]] for more |
| 32 | +information. |
36 | 33 | |
37 | | -This extension has been in use for years on several large wikis |
38 | | -without known security problems. However, no software is completely |
39 | | -bug-free or secure, and there's no guarantee that this software will |
40 | | -work as advertised. See [[#Bugs]] section below for info on how to |
41 | | -report problems. |
| 34 | +This extension has been in use for years on several large wikis without known |
| 35 | +security problems. However, no software is completely bug-free or secure, and |
| 36 | +there's no guarantee that this software will work as advertised. See [[#Bugs]] |
| 37 | +section below for info on how to report problems. |
42 | 38 | |
43 | 39 | == License == |
44 | 40 | |
— | — | @@ -67,91 +63,81 @@ |
68 | 64 | |
69 | 65 | == Pre-requisites == |
70 | 66 | |
71 | | -This software has been tested in production with MediaWiki 1.11.x. It |
72 | | -may or may not work with earlier or later versions, but I'm interested |
73 | | -in making later versions work, and I'd be happy to make minor changes |
74 | | -to make older, unsupported versions work too. |
| 67 | +This software has been tested in production with MediaWiki 1.11.x. It may or |
| 68 | +may not work with earlier or later versions, but I'm interested in making later |
| 69 | +versions work, and I'd be happy to make minor changes to make older, unsupported |
| 70 | +versions work too. |
75 | 71 | |
76 | | -The software depends on the OpenIDEnabled.com PHP library for OpenID, |
77 | | -which in turn depends on the OpenIDEnabled.com PHP library for YADIS. |
78 | | -At the time of this writing, info on installing these libraries was |
79 | | -available here: |
| 72 | +The software depends on the OpenIDEnabled.com PHP library for OpenID, which in |
| 73 | +turn depends on the OpenIDEnabled.com PHP library for YADIS. At the time of this |
| 74 | +writing, info on installing these libraries was available here: |
80 | 75 | |
81 | 76 | http://www.openidenabled.com/php-openid/ |
82 | 77 | |
83 | | -The last version tested with is 2.0.1; '''versions below 2.0 will not |
84 | | -work'''. If you must use version 1.x of the openidenabled.com library, |
85 | | -you can use the unsupported version 0.7.0 or below of this extension. |
| 78 | +The last version tested with is 2.0.1; '''versions below 2.0 will not work'''. |
| 79 | +If you must use version 1.x of the openidenabled.com library, you can use the |
| 80 | +unsupported version 0.7.0 or below of this extension. |
86 | 81 | |
87 | | -There are also some required PHP extensions; see the OpenIDEnabled |
88 | | -documentation for details. This software has been tested with the gmp |
89 | | -and curl PHP extensions installed, and it's recommended that you |
90 | | -install them, too. |
| 82 | +There are also some required PHP extensions; see the OpenIDEnabled documentation |
| 83 | +for details. This software has been tested with the gmp and curl PHP extensions |
| 84 | +installed, and it's recommended that you install them, too. |
91 | 85 | |
92 | 86 | Note that some versions of MediaWiki overwrite the PHP library path in |
93 | | -LocalSettings.php. You may need to add the path to your PHP library |
94 | | -directory to the $path variable, like "/usr/share/php" or |
95 | | -"/usr/local/share/php". |
| 87 | +LocalSettings.php. You may need to add the path to your PHP library directory |
| 88 | +to the $path variable, like "/usr/share/php" or "/usr/local/share/php". |
96 | 89 | |
97 | 90 | == Installation == |
98 | 91 | |
99 | | -To install, copy all the files in the archive you downloaded to the |
100 | | -OpenID subdirectory of the extensions subdirectory of your MediaWiki |
101 | | -installation. Note that the software depends on having its code all in |
102 | | -the "OpenID" sub-directory; naming it "OpenID-Test" or "newextension1" |
103 | | -or whatever won't work. |
| 92 | +To install, copy all the files in the archive you downloaded to the OpenID |
| 93 | +subdirectory of the extensions subdirectory of your MediaWiki installation. Note |
| 94 | +that the software depends on having its code all in the "OpenID" sub-directory; |
| 95 | +naming it "OpenID-Test" or "newextension1" or whatever won't work. |
104 | 96 | |
105 | 97 | Run update.php script in in your MediaWiki maintenance folder to create |
106 | 98 | necessary tables in MediaWiki database. |
107 | 99 | |
108 | | -Version 0.3 and below of this extension used a different database |
109 | | -structure that was pretty inefficient. If you installed this extension |
110 | | -before, you should copy the optionToTable.php script to your MediaWiki |
111 | | -"maintenance" directory and run it from the command line. This will |
112 | | -copy the OpenID mappings from the user table to the new table (but it |
113 | | -doesn't erase the old data... just in case). |
| 100 | +Version 0.3 and below of this extension used a different database structure |
| 101 | +that was pretty inefficient. If you installed this extension before, you should |
| 102 | +copy the optionToTable.php script to your MediaWiki "maintenance" directory and |
| 103 | +run it from the command line. This will copy the OpenID mappings from the user |
| 104 | +table to the new table (but it doesn't erase the old data... just in case). |
114 | 105 | |
115 | | -In your MediaWiki LocalSettings.php, add the following line some place |
116 | | -towards the bottom of the file: |
| 106 | +In your MediaWiki LocalSettings.php, add the following line some place towards |
| 107 | +the bottom of the file: |
117 | 108 | |
118 | | - require_once("$IP/extensions/OpenID/OpenID.setup.php"); |
| 109 | + require_once( "$IP/extensions/OpenID/OpenID.setup.php" ); |
119 | 110 | |
120 | | -Theoretically it should work out of the box, but you'll almost |
121 | | -definitely want to set the trust root and access controls (see |
122 | | -Configuration below). |
| 111 | +Theoretically it should work out of the box, but you'll almost definitely want |
| 112 | +to set the trust root and access controls (see Configuration below). |
123 | 113 | |
124 | 114 | == Upgrade == |
125 | 115 | |
126 | | -'''This is an incompatible upgrade to the previous version of the |
127 | | -MediaWiki OpenID library.''' In particular, the interfaces of the |
128 | | -openidenabled.com libraries have changed from 1.x to 2.x, and no |
129 | | -effort has been made to retain backwards compatibility with the 1.x |
130 | | -versions of the library. |
| 116 | +'''This is an incompatible upgrade to the previous version of the MediaWiki |
| 117 | +OpenID library.''' In particular, the interfaces of the openidenabled.com |
| 118 | +libraries have changed from 1.x to 2.x, and no effort has been made to retain |
| 119 | +backwards compatibility with the 1.x versions of the library. |
131 | 120 | |
132 | 121 | To upgrade, you'll need to do at least the following: |
133 | 122 | |
134 | 123 | * Install the 2.x version of the openidenabled.com PHP OpenID library. |
135 | | -* Check that your consumer and server stores are correct. I got tired |
136 | | - of maintaining the MemcStore that nobody seemed to want, so if you |
137 | | - used that, you need to use the filestore now. See below for how to |
138 | | - configure it. |
139 | | -* Change your require_once line in LocalSettings.php to use the |
140 | | - .setup.php file. |
141 | | -* 'openidlogininstructions' is now wikitext, not HTML. If you've |
142 | | - customized it, you may need to re-customize it. Also, it's now |
143 | | - shown '''below''' the login box, so if you say ''the box below'', |
144 | | - you may want to change that to ''the box above''. |
145 | | -* The extension has been converted to use a clumsy and perverse |
146 | | - OOP-like structure, with one class per special page. Most function |
147 | | - names have been changed to methods of these classes. If you used |
148 | | - them, look around for their replacements. |
149 | | -* The extension has been converted to use the autoloading features |
150 | | - of MediaWiki, which means that you need to require() the files |
151 | | - directly if you really want to use their code. Or you might get |
152 | | - lucky and have autoloading work for you. |
| 124 | +* Check that your consumer and server stores are correct. I got tired of |
| 125 | + maintaining the MemcStore that nobody seemed to want, so if you used that, you |
| 126 | + need to use the filestore now. See below for how to configure it. |
| 127 | +* Change your require_once line in LocalSettings.php to use the .setup.php file. |
| 128 | +* 'openidlogininstructions' is now wikitext, not HTML. If you've customized it, |
| 129 | + you may need to re-customize it. Also, it's now shown '''below''' the login |
| 130 | + box, so if you say ''the box below'', you may want to change that to ''the box |
| 131 | + above''. |
| 132 | +* The extension has been converted to use a clumsy and perverse OOP-like |
| 133 | + structure, with one class per special page. Most function names have been |
| 134 | + changed to methods of these classes. If you used them, look around for their |
| 135 | + replacements. |
| 136 | +* The extension has been converted to use the autoloading features of MediaWiki, |
| 137 | + which means that you need to require() the files directly if you really want |
| 138 | + to use their code. Or you might get lucky and have autoloading work for you. |
153 | 139 | |
154 | | -If you find other incompatibilities that I haven't mentioned here, |
155 | | -please let me know. |
| 140 | +If you find other incompatibilities that I haven't mentioned here, please let |
| 141 | +me know. |
156 | 142 | |
157 | 143 | == Logging in using OpenID == |
158 | 144 | |
Index: trunk/extensions/OpenID/SpecialOpenID.body.php |
— | — | @@ -87,70 +87,21 @@ |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | | - static function getUserUrl( $user ) { |
92 | | - $openid_url = null; |
93 | | - |
94 | | - if ( isset( $user ) && $user->getId() != 0 ) { |
95 | | - global $wgSharedDB, $wgDBprefix; |
96 | | - if ( isset( $wgSharedDB ) ) { |
97 | | - $tableName = "`${wgSharedDB}`.${wgDBprefix}user_openid"; |
98 | | - } else { |
99 | | - $tableName = 'user_openid'; |
100 | | - } |
101 | | - |
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 | | - ); |
109 | | - |
110 | | - # This should return 0 or 1 result, since user is unique |
111 | | - # in the table. |
112 | | - |
113 | | - while ( $row = $res->fetchObject() ) { |
114 | | - $openid_url = $row->uoi_openid; |
115 | | - } |
116 | | - $res->free(); |
117 | | - } |
118 | | - return $openid_url; |
119 | | - } |
120 | | - |
121 | 91 | # Login, Finish |
122 | 92 | |
123 | 93 | function getConsumer() { |
124 | 94 | global $wgOpenIDConsumerStoreType, $wgOpenIDConsumerStorePath; |
125 | 95 | |
126 | | - $store = $this->getOpenIDStore( $wgOpenIDConsumerStoreType, |
127 | | - 'consumer', |
128 | | - array( 'path' => $wgOpenIDConsumerStorePath ) ); |
| 96 | + $store = $this->getOpenIDStore( |
| 97 | + $wgOpenIDConsumerStoreType, |
| 98 | + 'consumer', |
| 99 | + array( 'path' => $wgOpenIDConsumerStorePath ) |
| 100 | + ); |
129 | 101 | |
130 | 102 | return new Auth_OpenID_Consumer( $store ); |
131 | 103 | } |
132 | 104 | |
133 | | - function fullUrl( $title ) { |
134 | | - $nt = Title::makeTitleSafe( NS_SPECIAL, $title ); |
135 | | - if ( isset( $nt ) ) { |
136 | | - return $nt->getFullURL(); |
137 | | - } else { |
138 | | - return NULL; |
139 | | - } |
140 | | - } |
141 | | - |
142 | | - function scriptUrl( $title ) { |
143 | | - global $wgServer, $wgScript; |
144 | | - $nt = Title::makeTitleSafe( NS_SPECIAL, $title ); |
145 | | - if ( isset( $nt ) ) { |
146 | | - $dbkey = wfUrlencode( $nt->getPrefixedDBkey() ); |
147 | | - return "{$wgServer}{$wgScript}?title={$dbkey}"; |
148 | | - } else { |
149 | | - return $url; |
150 | | - } |
151 | | - } |
152 | | - |
153 | 105 | function canLogin( $openid_url ) { |
154 | | - |
155 | 106 | global $wgOpenIDConsumerDenyByDefault, $wgOpenIDConsumerAllow, $wgOpenIDConsumerDeny; |
156 | 107 | |
157 | 108 | if ( $this->isLocalUrl( $openid_url ) ) { |
— | — | @@ -194,7 +145,6 @@ |
195 | 146 | } |
196 | 147 | |
197 | 148 | function isLocalUrl( $url ) { |
198 | | - |
199 | 149 | global $wgServer, $wgArticlePath; |
200 | 150 | |
201 | 151 | $pattern = $wgServer . $wgArticlePath; |
— | — | @@ -204,31 +154,9 @@ |
205 | 155 | return preg_match( '|^' . $pattern . '$|', $url ); |
206 | 156 | } |
207 | 157 | |
208 | | - # Find the user with the given openid, if any |
| 158 | + function login( $openid_url, $finish_page ) { |
| 159 | + global $wgTrustRoot, $wgOut; |
209 | 160 | |
210 | | - function getUser( $openid ) { |
211 | | - global $wgSharedDB, $wgDBprefix; |
212 | | - |
213 | | - if ( isset( $wgSharedDB ) ) { |
214 | | - $tableName = "`$wgSharedDB`.${wgDBprefix}user_openid"; |
215 | | - } else { |
216 | | - $tableName = 'user_openid'; |
217 | | - } |
218 | | - |
219 | | - $dbr =& wfGetDB( DB_SLAVE ); |
220 | | - $id = $dbr->selectField( $tableName, 'uoi_user', |
221 | | - array( 'uoi_openid' => $openid ) ); |
222 | | - if ( $id ) { |
223 | | - $name = User::whoIs( $id ); |
224 | | - return User::newFromName( $name ); |
225 | | - } else { |
226 | | - return NULL; |
227 | | - } |
228 | | - } |
229 | | - function login( $openid_url, $finish_page = 'OpenIDFinish' ) { |
230 | | - |
231 | | - global $wgUser, $wgTrustRoot, $wgOut; |
232 | | - |
233 | 161 | # If it's an interwiki link, expand it |
234 | 162 | |
235 | 163 | $openid_url = $this->interwikiExpand( $openid_url ); |
— | — | @@ -240,9 +168,7 @@ |
241 | 169 | return; |
242 | 170 | } |
243 | 171 | |
244 | | - $sk = $wgUser->getSkin(); |
245 | | - |
246 | | - if ( isset( $wgTrustRoot ) ) { |
| 172 | + if ( !is_null( $wgTrustRoot ) ) { |
247 | 173 | $trust_root = $wgTrustRoot; |
248 | 174 | } else { |
249 | 175 | global $wgArticlePath, $wgServer; |
— | — | @@ -250,6 +176,8 @@ |
251 | 177 | $trust_root = $wgServer . $root_article; |
252 | 178 | } |
253 | 179 | |
| 180 | + wfSuppressWarnings(); |
| 181 | + |
254 | 182 | $consumer = $this->getConsumer(); |
255 | 183 | |
256 | 184 | if ( !$consumer ) { |
— | — | @@ -258,13 +186,8 @@ |
259 | 187 | } |
260 | 188 | |
261 | 189 | # Make sure the user has a session! |
| 190 | + $this->setupSession(); |
262 | 191 | |
263 | | - global $wgSessionStarted; |
264 | | - |
265 | | - if ( !$wgSessionStarted ) { |
266 | | - $wgUser->SetupSession(); |
267 | | - } |
268 | | - |
269 | 192 | $auth_request = $consumer->begin( $openid_url ); |
270 | 193 | |
271 | 194 | // Handle failure status return values. |
— | — | @@ -277,7 +200,7 @@ |
278 | 201 | |
279 | 202 | $endpoint = $auth_request->endpoint; |
280 | 203 | |
281 | | - if ( isset( $endpoint ) ) { |
| 204 | + if ( !is_null( $endpoint ) ) { |
282 | 205 | # Check if the URL is allowed |
283 | 206 | |
284 | 207 | if ( isset( $endpoint->identity_url ) && !$this->canLogin( $endpoint->identity_url ) ) { |
— | — | @@ -292,17 +215,17 @@ |
293 | 216 | } |
294 | 217 | |
295 | 218 | $sreg_request = Auth_OpenID_SRegRequest::build( |
296 | | - // Required |
297 | | - array(), |
298 | | - // Optional |
299 | | - array( 'nickname', 'email', |
300 | | - 'fullname', 'language', 'timezone' ) ); |
| 219 | + // Required |
| 220 | + array(), |
| 221 | + // Optional |
| 222 | + array( 'nickname', 'email', 'fullname', 'language', 'timezone' ) |
| 223 | + ); |
301 | 224 | |
302 | 225 | if ( $sreg_request ) { |
303 | 226 | $auth_request->addExtension( $sreg_request ); |
304 | 227 | } |
305 | 228 | |
306 | | - $process_url = $this->scriptUrl( $finish_page ); |
| 229 | + $process_url = $finish_page->getFullUrl(); |
307 | 230 | |
308 | 231 | if ( $auth_request->shouldSendRedirect() ) { |
309 | 232 | $redirect_url = $auth_request->redirectURL( $trust_root, |
— | — | @@ -322,57 +245,89 @@ |
323 | 246 | // Display an error if the form markup couldn't be generated; |
324 | 247 | // otherwise, render the HTML. |
325 | 248 | if ( Auth_OpenID::isFailure( $form_html ) ) { |
326 | | - displayError( "Could not redirect to server: " . $form_html->message ); |
| 249 | + displayError( 'Could not redirect to server: ' . $form_html->message ); |
327 | 250 | } else { |
328 | | - $wgOut->addHTML( "<p>" . wfMsg( "openidautosubmit" ) . "</p>" ); |
| 251 | + $wgOut->addWikiMsg( 'openidautosubmit' ); |
329 | 252 | $wgOut->addHTML( $form_html ); |
330 | 253 | $wgOut->addInlineScript( "function submitOpenIDForm() {\n document.getElementById(\"" . $form_id . "\").submit()\n }\nhookEvent(\"load\", submitOpenIDForm);\n" ); |
331 | 254 | } |
332 | 255 | } |
| 256 | + |
| 257 | + wfRestoreWarnings(); |
333 | 258 | } |
334 | 259 | |
335 | | - function setUserUrl( $user, $url ) { |
336 | | - $other = $this->getUserUrl( $user ); |
337 | | - if ( isset( $other ) ) { |
338 | | - $this->updateUserUrl( $user, $url ); |
339 | | - } else { |
340 | | - $this->insertUserUrl( $user, $url ); |
| 260 | + protected function setupSession() { |
| 261 | + global $wgSessionStarted; |
| 262 | + |
| 263 | + if ( !$wgSessionStarted ) { |
| 264 | + wfSetupSession(); |
341 | 265 | } |
342 | 266 | } |
343 | 267 | |
344 | | - function insertUserUrl( $user, $url ) { |
345 | | - global $wgSharedDB, $wgDBname; |
346 | | - $dbw =& wfGetDB( DB_MASTER ); |
| 268 | + # Find the user with the given openid, if any |
| 269 | + public static function getUserUrl( $user ) { |
| 270 | + $openid_urls = array(); |
347 | 271 | |
348 | | - if ( isset( $wgSharedDB ) ) { |
349 | | - # It would be nicer to get the existing dbname |
350 | | - # and save it, but it's not possible |
351 | | - $dbw->selectDB( $wgSharedDB ); |
| 272 | + if ( $user instanceof User && $user->getId() != 0 ) { |
| 273 | + $dbr = wfGetDB( DB_SLAVE ); |
| 274 | + $res = $dbr->select( |
| 275 | + array( 'user_openid' ), |
| 276 | + array( 'uoi_openid' ), |
| 277 | + array( 'uoi_user' => $user->getId() ), |
| 278 | + __METHOD__ |
| 279 | + ); |
| 280 | + |
| 281 | + foreach( $res as $row ) { |
| 282 | + $openid_urls[] = $row->uoi_openid; |
| 283 | + } |
| 284 | + $res->free(); |
352 | 285 | } |
| 286 | + return $openid_urls; |
| 287 | + } |
353 | 288 | |
354 | | - $dbw->insert( 'user_openid', array( 'uoi_user' => $user->getId(), |
355 | | - 'uoi_openid' => $url ) ); |
| 289 | + public static function getUser( $openid ) { |
| 290 | + $dbr = wfGetDB( DB_SLAVE ); |
356 | 291 | |
357 | | - if ( isset( $wgSharedDB ) ) { |
358 | | - $dbw->selectDB( $wgDBname ); |
| 292 | + $id = $dbr->selectField( |
| 293 | + 'user_openid', |
| 294 | + 'uoi_user', |
| 295 | + array( 'uoi_openid' => $openid ), |
| 296 | + __METHOD__ |
| 297 | + ); |
| 298 | + |
| 299 | + if ( $id ) { |
| 300 | + return User::newFromId( $id ); |
| 301 | + } else { |
| 302 | + return null; |
359 | 303 | } |
360 | 304 | } |
361 | 305 | |
362 | | - function updateUserUrl( $user, $url ) { |
363 | | - global $wgSharedDB, $wgDBname; |
364 | | - $dbw =& wfGetDB( DB_MASTER ); |
| 306 | + public static function addUserUrl( $user, $url ) { |
| 307 | + $dbw = wfGetDB( DB_MASTER ); |
365 | 308 | |
366 | | - if ( isset( $wgSharedDB ) ) { |
367 | | - # It would be nicer to get the existing dbname |
368 | | - # and save it, but it's not possible |
369 | | - $dbw->selectDB( $wgSharedDB ); |
370 | | - } |
| 309 | + $dbw->insert( |
| 310 | + 'user_openid', |
| 311 | + array( |
| 312 | + 'uoi_user' => $user->getId(), |
| 313 | + 'uoi_openid' => $url |
| 314 | + ), |
| 315 | + __METHOD__ |
| 316 | + ); |
371 | 317 | |
372 | | - $dbw->set( 'user_openid', 'uoi_openid', $url, |
373 | | - 'uoi_user = ' . $user->getID() ); |
| 318 | + } |
374 | 319 | |
375 | | - if ( isset( $wgSharedDB ) ) { |
376 | | - $dbw->selectDB( $wgDBname ); |
377 | | - } |
| 320 | + public static function removeUserUrl( $user, $url ) { |
| 321 | + $dbw = wfGetDB( DB_MASTER ); |
| 322 | + |
| 323 | + $dbw->delete( |
| 324 | + 'user_openid', |
| 325 | + array( |
| 326 | + 'uoi_user' => $user->getId(), |
| 327 | + 'uoi_openid' => $url |
| 328 | + ), |
| 329 | + __METHOD__ |
| 330 | + ); |
| 331 | + |
| 332 | + return (bool)$dbw->affectedRows(); |
378 | 333 | } |
379 | 334 | } |
Index: trunk/extensions/OpenID/SpecialOpenIDConvert.body.php |
— | — | @@ -29,11 +29,10 @@ |
30 | 30 | class SpecialOpenIDConvert extends SpecialOpenID { |
31 | 31 | |
32 | 32 | function SpecialOpenIDConvert() { |
33 | | - SpecialPage::SpecialPage( "OpenIDConvert" ); |
| 33 | + SpecialPage::SpecialPage( 'OpenIDConvert' ); |
34 | 34 | } |
35 | 35 | |
36 | 36 | function execute( $par ) { |
37 | | - |
38 | 37 | global $wgRequest, $wgUser, $wgOut; |
39 | 38 | |
40 | 39 | wfLoadExtensionMessages( 'OpenID' ); |
— | — | @@ -45,37 +44,38 @@ |
46 | 45 | return; |
47 | 46 | } |
48 | 47 | |
| 48 | + $this->outputHeader(); |
| 49 | + |
49 | 50 | switch ( $par ) { |
50 | | - case 'Finish': |
| 51 | + case 'Finish': |
51 | 52 | $this->finish(); |
52 | 53 | break; |
53 | | - default: |
| 54 | + case 'Delete': |
| 55 | + $this->delete(); |
| 56 | + break; |
| 57 | + default: |
54 | 58 | $openid_url = $wgRequest->getText( 'openid_url' ); |
55 | 59 | if ( isset( $openid_url ) && strlen( $openid_url ) > 0 ) { |
56 | 60 | $this->convert( $openid_url ); |
57 | 61 | } else { |
58 | | - $this->Form(); |
| 62 | + $this->form(); |
59 | 63 | } |
60 | 64 | } |
61 | 65 | } |
62 | 66 | |
63 | 67 | function convert( $openid_url ) { |
64 | | - |
65 | 68 | global $wgUser, $wgOut; |
66 | 69 | |
67 | 70 | # Expand Interwiki |
68 | | - |
69 | 71 | $openid_url = $this->interwikiExpand( $openid_url ); |
70 | 72 | |
71 | 73 | # Is this ID allowed to log in? |
72 | | - |
73 | | - if ( !$this->CanLogin( $openid_url ) ) { |
| 74 | + if ( !$this->canLogin( $openid_url ) ) { |
74 | 75 | $wgOut->showErrorPage( 'openidpermission', 'openidpermissiontext' ); |
75 | 76 | return; |
76 | 77 | } |
77 | 78 | |
78 | 79 | # Is this ID already taken? |
79 | | - |
80 | 80 | $other = $this->getUser( $openid_url ); |
81 | 81 | |
82 | 82 | if ( isset( $other ) ) { |
— | — | @@ -88,55 +88,83 @@ |
89 | 89 | } |
90 | 90 | |
91 | 91 | # If we're OK to here, let the user go log in |
92 | | - |
93 | | - $this->Login( $openid_url, 'OpenIDConvert/Finish' ); |
| 92 | + $this->login( $openid_url, SpecialPage::getTitleFor( 'OpenIDConvert', 'Finish' ) ); |
94 | 93 | } |
95 | 94 | |
96 | 95 | function form() { |
97 | 96 | global $wgOut, $wgUser, $wgOpenIDLoginLogoUrl; |
98 | 97 | |
99 | | - $sk = $wgUser->getSkin(); |
100 | | - $url = $this->GetUserUrl( $wgUser ); |
101 | | - if ( is_null( $url ) ) { |
| 98 | + $url = self::getUserUrl( $wgUser ); |
| 99 | + if ( count( $url ) ) { |
102 | 100 | $url = ''; |
103 | 101 | } |
104 | 102 | |
105 | | - $ok = wfMsg( 'ok' ); |
106 | | - $instructions = wfMsg( 'openidconvertinstructions' ); |
107 | | - $wgOut->addHTML( "<p>{$instructions}</p>" . |
108 | | - '<form action="' . $sk->makeSpecialUrl( 'OpenIDConvert' ) . '" method="POST">' . |
109 | | - '<input type="text" name="openid_url" size="30" ' . |
110 | | - ' style="background: url(' . $wgOpenIDLoginLogoUrl . ') ' . |
111 | | - ' no-repeat; background-color: #fff; background-position: 0 50%; ' . |
112 | | - ' color: #000; padding-left: 18px;" value="' . $url . '" />' . |
113 | | - '<input type="submit" value="' . $ok . '" />' . |
114 | | - '</form>' ); |
| 103 | + $wgOut->addWikiMsg( 'openidconvertinstructions' ); |
| 104 | + $wgOut->addHTML( |
| 105 | + Xml::openElement( 'form', array( 'action' => $this->getTitle()->getLocalUrl(), 'method' => 'post' ) ) . |
| 106 | + '<input type="text" name="openid_url" size="30" ' . |
| 107 | + ' style="background: url(' . $wgOpenIDLoginLogoUrl . ') ' . |
| 108 | + ' no-repeat; background-color: #fff; background-position: 0 50%; ' . |
| 109 | + ' color: #000; padding-left: 18px;" value="" />' . |
| 110 | + Xml::submitButton( wfMsg( 'ok' ) ) . |
| 111 | + Xml::closeElement( 'form' ) |
| 112 | + ); |
115 | 113 | } |
116 | 114 | |
| 115 | + function delete() { |
| 116 | + global $wgUser, $wgOut, $wgRequest; |
| 117 | + |
| 118 | + $openid = $wgRequest->getVal( 'url' ); |
| 119 | + $user = self::getUser( $openid ); |
| 120 | + |
| 121 | + if ( $user->getId() == 0 || $user->getId() != $wgUser->getId() ) { |
| 122 | + $wgOut->showErrorPage( 'openiderror', 'openidconvertothertext' ); |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + $wgOut->setPageTitle( wfMsg( 'openiddelete' ) ); |
| 127 | + |
| 128 | + if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $openid ) ) { |
| 129 | + $ret = self::removeUserUrl( $wgUser, $openid ); |
| 130 | + $wgOut->addWikiMsg( $ret ? 'openiddelete-sucess' : 'openiddelete-error' ); |
| 131 | + return; |
| 132 | + } |
| 133 | + |
| 134 | + $wgOut->addWikiMsg( 'openiddelete-text', $openid ); |
| 135 | + |
| 136 | + $wgOut->addHtml( |
| 137 | + Xml::openElement( 'form', array( 'action' => $this->getTitle( 'Delete' )->getLocalUrl(), 'method' => 'post' ) ) . |
| 138 | + Xml::submitButton( wfMsg( 'openiddelete-button' ) ) . "\n" . |
| 139 | + Xml::hidden( 'url', $openid ) . "\n" . |
| 140 | + Xml::hidden( 'wpEditToken', $wgUser->editToken( $openid ) ) . "\n" . |
| 141 | + Xml::closeElement( 'form' ) |
| 142 | + ); |
| 143 | + } |
| 144 | + |
117 | 145 | function finish() { |
118 | | - |
119 | 146 | global $wgUser, $wgOut; |
120 | 147 | |
| 148 | + wfSuppressWarnings(); |
121 | 149 | $consumer = $this->getConsumer(); |
| 150 | + $response = $consumer->complete( $this->getTitle( 'Finish' )->getFullUrl() ); |
| 151 | + wfRestoreWarnings(); |
122 | 152 | |
123 | | - $response = $consumer->complete( $this->scriptUrl( 'OpenIDConvert/Finish' ) ); |
124 | | - |
125 | | - if ( !isset( $response ) ) { |
| 153 | + if ( is_null( $response ) ) { |
126 | 154 | wfDebug( "OpenID: aborting in openid converter because the response was missing\n" ); |
127 | 155 | $wgOut->showErrorPage( 'openiderror', 'openiderrortext' ); |
128 | 156 | return; |
129 | 157 | } |
130 | 158 | |
131 | 159 | switch ( $response->status ) { |
132 | | - case Auth_OpenID_CANCEL: |
| 160 | + case Auth_OpenID_CANCEL: |
133 | 161 | // This means the authentication was cancelled. |
134 | 162 | $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' ); |
135 | 163 | break; |
136 | | - case Auth_OpenID_FAILURE: |
| 164 | + case Auth_OpenID_FAILURE: |
137 | 165 | wfDebug( "OpenID: error in convert: '" . $response->message . "'\n" ); |
138 | 166 | $wgOut->showErrorPage( 'openidfailure', 'openidfailuretext', array( $response->message ) ); |
139 | 167 | break; |
140 | | - case Auth_OpenID_SUCCESS: |
| 168 | + case Auth_OpenID_SUCCESS: |
141 | 169 | // This means the authentication succeeded. |
142 | 170 | $openid_url = $response->identity_url; |
143 | 171 | |
— | — | @@ -160,13 +188,13 @@ |
161 | 189 | return; |
162 | 190 | } |
163 | 191 | |
164 | | - $this->setUserUrl( $wgUser, $openid_url ); |
| 192 | + self::addUserUrl( $wgUser, $openid_url ); |
165 | 193 | |
166 | 194 | $wgOut->setPageTitle( wfMsg( 'openidconvertsuccess' ) ); |
167 | 195 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
168 | 196 | $wgOut->setArticleRelated( false ); |
169 | | - $wgOut->addWikiText( wfMsg( 'openidconvertsuccesstext', $openid_url ) ); |
170 | | - $wgOut->returnToMain( ); |
| 197 | + $wgOut->addWikiMsg( 'openidconvertsuccesstext', $openid_url ); |
| 198 | + $wgOut->returnToMain(); |
171 | 199 | } |
172 | 200 | } |
173 | 201 | } |
Index: trunk/extensions/OpenID/SpecialOpenIDXRDS.body.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | class SpecialOpenIDXRDS extends SpecialOpenID { |
33 | 33 | |
34 | 34 | function SpecialOpenIDXRDS() { |
35 | | - SpecialPage::SpecialPage( "OpenIDXRDS", '', false ); |
| 35 | + SpecialPage::SpecialPage( 'OpenIDXRDS', '', false ); |
36 | 36 | } |
37 | 37 | |
38 | 38 | # $par is a user name |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | // XRDS preamble XML. |
55 | | - $xml_template = array( '<?xml version="1.0" encoding="UTF-8"?>', |
| 55 | + $xml_template = array( '<?xml version="1.0" encoding="UTF-8"?' . '>', |
56 | 56 | '<xrds:XRDS', |
57 | 57 | ' xmlns:xrds="xri://\$xrds"', |
58 | 58 | ' xmlns:openid="http://openid.net/xmlns/1.0"', |
— | — | @@ -108,6 +108,7 @@ |
109 | 109 | |
110 | 110 | // Print content-type and XRDS XML. |
111 | 111 | header( "Content-Type: application/xrds+xml" ); |
| 112 | + |
112 | 113 | print implode( "\n", $xml_template ); |
113 | 114 | print $service_text; |
114 | 115 | print implode( "\n", array( "</XRD>", "</xrds:XRDS>" ) ); |
Index: trunk/extensions/OpenID/OpenID.setup.php |
— | — | @@ -26,91 +26,118 @@ |
27 | 27 | exit( 1 ); |
28 | 28 | } |
29 | 29 | |
30 | | -define( 'MEDIAWIKI_OPENID_VERSION', '0.8.4.1' ); |
| 30 | +define( 'MEDIAWIKI_OPENID_VERSION', '0.9.0' ); |
31 | 31 | |
32 | 32 | # CONFIGURATION VARIABLES |
33 | 33 | |
34 | | -# Whether to hide the "Login with OpenID link" link; set to true if you already have this link in your skin. |
35 | | - |
| 34 | +/** |
| 35 | + * Whether to hide the "Login with OpenID link" link; set to true if you already |
| 36 | + * have this link in your skin. |
| 37 | + */ |
36 | 38 | $wgHideOpenIDLoginLink = false; |
37 | 39 | |
38 | | -# Location of the OpenID login logo. You can copy this to your server if you want. |
| 40 | +/** |
| 41 | + * Location of the OpenID login logo. You can copy this to your server if you |
| 42 | + * want. |
| 43 | + */ |
39 | 44 | $wgOpenIDLoginLogoUrl = $wgScriptPath . '/extensions/OpenID/skin/icons/openid-inputicon.png'; |
40 | 45 | |
41 | | -# Whether to show the OpenID identity URL on a user's home page. Possible values are 'always', 'never', or 'user' |
42 | | -# 'user' lets the user decide. |
43 | | - |
| 46 | +/** |
| 47 | + * Whether to show the OpenID identity URL on a user's home page. Possible |
| 48 | + * values are 'always', 'never', or 'user'. 'user' lets the user decide. |
| 49 | + */ |
44 | 50 | $wgOpenIDShowUrlOnUserPage = 'user'; |
45 | 51 | |
46 | | -# These are trust roots that we don't bother asking users |
47 | | -# whether the trust root is allowed to trust; typically |
48 | | -# for closely-linked partner sites. |
49 | | - |
| 52 | +/** |
| 53 | + * These are trust roots that we don't bother asking users whether the trust |
| 54 | + * root is allowed to trust; typically for closely-linked partner sites. |
| 55 | + */ |
50 | 56 | $wgOpenIDServerForceAllowTrust = array(); |
51 | 57 | |
52 | | -# Where to store transitory data. Only supported type is 'file'. |
53 | | - |
| 58 | +/** |
| 59 | + * Where to store transitory data. Only supported type is 'file'. |
| 60 | + */ |
54 | 61 | $wgOpenIDServerStoreType = 'file'; |
55 | 62 | |
56 | | -# If the store type is set to 'file', this is is the name of a |
57 | | -# directory to store the data in. |
58 | | - |
| 63 | +/** |
| 64 | + * If the store type is set to 'file', this is is the name of a directory to |
| 65 | + * store the data in. |
| 66 | + */ |
59 | 67 | $wgOpenIDServerStorePath = "/tmp/$wgDBname/openidserver/"; |
60 | 68 | |
61 | | -# Defines the trust root for this server |
62 | | -# If null, we make a guess |
63 | | - |
| 69 | +/** |
| 70 | + * Defines the trust root for this server |
| 71 | + * If null, we make a guess |
| 72 | + */ |
64 | 73 | $wgTrustRoot = null; |
65 | 74 | |
66 | | -# When using deny and allow arrays, defines how the security works. |
67 | | -# If true, works like "Order Allow,Deny" in Apache; deny by default, |
68 | | -# allow items that match allow that don't match deny to pass. |
69 | | -# If false, works like "Order Deny,Allow" in Apache; allow by default, |
70 | | -# deny items in deny that aren't in allow. |
71 | | - |
| 75 | +/** |
| 76 | + * When using deny and allow arrays, defines how the security works. |
| 77 | + * If true, works like "Order Allow,Deny" in Apache; deny by default, |
| 78 | + * allow items that match allow that don't match deny to pass. |
| 79 | + * If false, works like "Order Deny,Allow" in Apache; allow by default, |
| 80 | + * deny items in deny that aren't in allow. |
| 81 | + */ |
72 | 82 | $wgOpenIDConsumerDenyByDefault = false; |
73 | 83 | |
74 | | -# Which partners to allow; regexps here. See above. |
75 | | - |
| 84 | +/** |
| 85 | + * Which partners to allow; regexps here. See above. |
| 86 | + */ |
76 | 87 | $wgOpenIDConsumerAllow = array(); |
77 | 88 | |
78 | | -# Which partners to deny; regexps here. See above. |
79 | | - |
| 89 | +/** |
| 90 | + * Which partners to deny; regexps here. See above. |
| 91 | + */ |
80 | 92 | $wgOpenIDConsumerDeny = array(); |
81 | 93 | |
82 | | -# Where to store transitory data. Only supported type is 'file'. |
83 | | - |
| 94 | +/** |
| 95 | + * Where to store transitory data. Only supported type is 'file'. |
| 96 | + */ |
84 | 97 | $wgOpenIDConsumerStoreType = 'file'; |
85 | 98 | |
86 | | -# If the store type is set to 'file', this is is the name of a |
87 | | -# directory to store the data in. |
88 | | - |
| 99 | +/** |
| 100 | + * If the store type is set to 'file', this is is the name of a |
| 101 | + * directory to store the data in. |
| 102 | + */ |
89 | 103 | $wgOpenIDConsumerStorePath = "/tmp/$wgDBname/openidconsumer/"; |
90 | 104 | |
91 | | -# Expiration time for the OpenID cookie. Lets the user re-authenticate |
92 | | -# automatically if their session is expired. Only really useful if |
93 | | -# it's much greater than $wgCookieExpiration. Default: about one year. |
94 | | - |
| 105 | +/** |
| 106 | + * Expiration time for the OpenID cookie. Lets the user re-authenticate |
| 107 | + * automatically if their session is expired. Only really useful if |
| 108 | + * it's much greater than $wgCookieExpiration. Default: about one year. |
| 109 | + */ |
95 | 110 | $wgOpenIDCookieExpiration = 365 * 24 * 60 * 60; |
96 | 111 | |
97 | | -# Only allow login with OpenID. Careful -- this means everybody! |
98 | | - |
| 112 | +/** |
| 113 | + * Only allow login with OpenID. Careful -- this means everybody! |
| 114 | + */ |
99 | 115 | $wgOpenIDOnly = false; |
100 | 116 | |
101 | | -# If true, user accounts on this wiki *cannot* be used as |
102 | | -# OpenIDs on other sites. |
103 | | - |
| 117 | +/** |
| 118 | + * If true, user accounts on this wiki *cannot* be used as OpenIDs on other |
| 119 | + * sites. |
| 120 | + */ |
104 | 121 | $wgOpenIDClientOnly = false; |
105 | 122 | |
106 | | -# If true, will show provider icons instead of the text |
| 123 | +/** |
| 124 | + * If true, will show provider icons instead of the text. |
| 125 | + */ |
107 | 126 | $wgOpenIDShowProviderIcons = false; |
108 | 127 | |
| 128 | +# New options |
| 129 | +$wgDefaultUserOptions['openid-hide'] = 0; |
| 130 | +$wgDefaultUserOptions['openid-update-on-login-nickname'] = false; |
| 131 | +$wgDefaultUserOptions['openid-update-on-login-email'] = false; |
| 132 | +$wgDefaultUserOptions['openid-update-on-login-fullname'] = false; |
| 133 | +$wgDefaultUserOptions['openid-update-on-login-language'] = false; |
| 134 | +$wgDefaultUserOptions['openid-update-on-login-timezone'] = false; |
| 135 | + |
109 | 136 | # END CONFIGURATION VARIABLES |
110 | 137 | |
111 | 138 | $wgExtensionCredits['other'][] = array( |
112 | | - 'path' => __FILE__, |
113 | 139 | 'name' => 'OpenID', |
114 | 140 | 'version' => MEDIAWIKI_OPENID_VERSION, |
| 141 | + 'path' => __FILE__, |
115 | 142 | 'author' => 'Evan Prodromou', |
116 | 143 | 'url' => 'http://www.mediawiki.org/wiki/Extension:OpenID', |
117 | 144 | 'description' => 'Lets users login to the wiki with an [http://openid.net/ OpenID] and login to other OpenID-aware Web sites with their wiki user account', |
— | — | @@ -140,7 +167,6 @@ |
141 | 168 | $wgAutoloadClasses['SpecialOpenID'] = $dir . 'SpecialOpenID.body.php'; |
142 | 169 | |
143 | 170 | $wgAutoloadClasses['SpecialOpenIDLogin'] = $dir . 'SpecialOpenIDLogin.body.php'; |
144 | | -$wgAutoloadClasses['SpecialOpenIDFinish'] = $dir . 'SpecialOpenIDFinish.body.php'; |
145 | 171 | $wgAutoloadClasses['SpecialOpenIDConvert'] = $dir . 'SpecialOpenIDConvert.body.php'; |
146 | 172 | $wgAutoloadClasses['SpecialOpenIDServer'] = $dir . 'SpecialOpenIDServer.body.php'; |
147 | 173 | $wgAutoloadClasses['SpecialOpenIDXRDS'] = $dir . 'SpecialOpenIDXRDS.body.php'; |
— | — | @@ -152,6 +178,7 @@ |
153 | 179 | $wgAutoloadClasses['Auth_OpenID_CheckIDRequest'] = OpenIDGetServerPath(); |
154 | 180 | |
155 | 181 | $wgHooks['PersonalUrls'][] = 'OpenIDHooks::onPersonalUrls'; |
| 182 | +$wgHooks['BeforePageDisplay'][] = 'OpenIDHooks::onBeforePageDisplay'; |
156 | 183 | $wgHooks['ArticleViewHeader'][] = 'OpenIDHooks::onArticleViewHeader'; |
157 | 184 | $wgHooks['SpecialPage_initList'][] = 'OpenIDHooks::onSpecialPage_initList'; |
158 | 185 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'OpenIDHooks::onLoadExtensionSchemaUpdates'; |
Index: trunk/extensions/OpenID/TODO |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | + Function to let skins tell if user is OpenID user |
10 | 10 | + Function to let skins know user's OpenID URL |
11 | 11 | + Interwiki login |
12 | | -- drop-down for username prefixes (Yahoo, etc.) |
| 12 | ++ drop-down for username prefixes (Yahoo, etc.) |
13 | 13 | + server mode login |
14 | 14 | + server mode trust form |
15 | 15 | + server mode share fields form |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | + hide openid.server for non-user pages |
26 | 26 | - optimize trust storage |
27 | 27 | + change trust data separators from , and | to FS and RS |
28 | | -- User preferences tab for OpenID |
| 28 | ++ User preferences tab for OpenID |
29 | 29 | - Manage allow-to-trust settings in User preferences |
30 | 30 | - Optionally redirect User: page to OpenID URL |
31 | 31 | - If user logs in with OpenID, add a cookie, and auto-login next time |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | - deal with difference between canonical ID and "display ID" with XRIs |
56 | 56 | + add more explanatory text to the default login instructions (copy Wikitravel text) |
57 | 57 | - add a public-domain Help:OpenID.wiki |
58 | | -- add more than one OpenID to a user account |
| 58 | ++ add more than one OpenID to a user account |
59 | 59 | + link to Special:OpenIDConvert if user is already logged in |
60 | 60 | - support RP discovery |
61 | 61 | - AJAX login, rather than klutzy JS form |