r52236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52235‎ | r52236 | r52237 >
Date:12:41, 21 June 2009
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
Big changes to OpenID extension:
* Removed Special:OpenIDFinish, merged in Special:OpenIDLogin
* removed unused methods in SpecialOpenID class
* (bug 17632) Multiple URLs for an user is now supported, requires schema change (patch included in patch-uoi_user-not-unique.sql)
* Added URLs list on Special:Preferences
* (bug 18934) User created by OpenID are now logged in user creation log
* Use XML::* methods rather than raw HTML
* Changed some message from raw HTML to wikitext
* (bug 17660) Users can now choose which options they want to update on login
* Options are only changed if they are present in sreg (they were previously set to either '' or null if not present)
* (bug 17634) Confirmation mails are now sent when the email address changed from OpenID
* Break lines at 80 chars in README file
* updated TODO file
Modified paths:
  • /trunk/extensions/OpenID/OpenID.alias.php (modified) (history)
  • /trunk/extensions/OpenID/OpenID.hooks.php (modified) (history)
  • /trunk/extensions/OpenID/OpenID.i18n.php (modified) (history)
  • /trunk/extensions/OpenID/OpenID.setup.php (modified) (history)
  • /trunk/extensions/OpenID/README (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenID.body.php (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDConvert.body.php (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDFinish.body.php (deleted) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDLogin.body.php (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDServer.body.php (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDXRDS.body.php (modified) (history)
  • /trunk/extensions/OpenID/TODO (modified) (history)
  • /trunk/extensions/OpenID/openid_table.pg.sql (modified) (history)
  • /trunk/extensions/OpenID/openid_table.sql (modified) (history)
  • /trunk/extensions/OpenID/patch-uoi_user-not-unique.sql (added) (history)

Diff [purge]

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 @@
2727
2828 /** English
2929 * @author Evan Prodromou <evan@prodromou.name>
 30+ * @author Sergey Chernyshev
 31+ * @author Alexandre Emsenhuber
3032 */
3133 $messages['en'] = array(
3234 '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+
3336 'openidlogin' => 'Login with OpenID',
34 - 'openidfinish' => 'Finish OpenID login',
3537 'openidserver' => 'OpenID server',
3638 'openidxrds' => 'Yadis file',
3739 'openidconvert' => 'OpenID converter',
 40+
3841 'openiderror' => 'Verification error',
3942 'openiderrortext' => 'An error occured during verification of the OpenID URL.',
4043 'openidconfigerror' => 'OpenID configuration error',
@@ -59,6 +62,7 @@
6063 'openidfullname' => 'Fullname',
6164 'openidemail' => 'E-mail address',
6265 'openidlanguage' => 'Language',
 66+ 'openidtimezone' => 'Time zone',
6367 'openidnotavailable' => 'Your preferred nickname ($1) is already in use by another user.',
6468 'openidnotprovided' => 'Your OpenID server did not provide a nickname (either because it cannot, or because you told it not to).',
6569 'openidchooseinstructions' => 'All users need a nickname;
@@ -92,10 +96,24 @@
9397
9498 There are many [http://openid.net/get/ OpenID providers], and you may already have an OpenID-enabled account on another service.',
9599 '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+
96108 'prefs-openid' => 'OpenID',
97109 'openid-prefstext' => '[http://openid.net/ OpenID] preferences',
98110 '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+
100118 'openidsigninorcreateaccount' => 'Sign-in or Create New Account',
101119 'openid-provider-label-openid' => 'Enter your OpenID URL',
102120 'openid-provider-label-google' => 'Login using your Google account',
@@ -168,7 +186,6 @@
169187 $messages['ar'] = array(
170188 'openid-desc' => 'سجل الدخول للويكي [http://openid.net/ بهوية مفتوحة]، وسجل الدخول لمواقع ويب أخرى تعرف الهوية المفتوحة بحساب مستخدم ويكي',
171189 'openidlogin' => 'تسجيل الدخول بالهوية المفتوحة',
172 - 'openidfinish' => 'إنهاء دخول الهوية المفتوحة',
173190 'openidserver' => 'خادم الهوية المفتوحة',
174191 'openidxrds' => 'ملف ياديس',
175192 'openidconvert' => 'محول الهوية المفتوحة',
@@ -250,7 +267,6 @@
251268 $messages['arz'] = array(
252269 'openid-desc' => 'سجل الدخول للويكى [http://openid.net/ بهوية مفتوحة]، وسجل الدخول لمواقع ويب أخرى تعرف الهوية المفتوحة بحساب مستخدم ويكي',
253270 'openidlogin' => 'تسجيل الدخول بالهوية المفتوحة',
254 - 'openidfinish' => 'إنهاء دخول الهوية المفتوحة',
255271 'openidserver' => 'خادم الهوية المفتوحة',
256272 'openidxrds' => 'ملف ياديس',
257273 'openidconvert' => 'محول الهوية المفتوحة',
@@ -333,7 +349,6 @@
334350 $messages['be-tarask'] = array(
335351 'openid-desc' => 'Уваход ў {{GRAMMAR:вінавальны|{{SITENAME}}}} з дапамогай [http://openid.net/ OpenID], а так сама ў іншыя сайты, якія падтрымліваюць OpenID з вікі-рахунка',
336352 'openidlogin' => 'Уваход у сыстэму з дапамогай OpenID',
337 - 'openidfinish' => 'Скончыць уваход у сыстэму з дапамогай OpenID',
338353 'openidserver' => 'Сэрвэр OpenID',
339354 'openidxrds' => 'Файл Yadis',
340355 'openidconvert' => 'Канвэртар OpenID',
@@ -411,7 +426,6 @@
412427 */
413428 $messages['bg'] = array(
414429 'openidlogin' => 'Влизане с OpenID',
415 - 'openidfinish' => 'Приключване на OpenID влизането',
416430 'openidserver' => 'OpenID сървър',
417431 'openidxrds' => 'Yadis файл',
418432 'openidconvert' => 'Конвертор за OpenID',
@@ -478,7 +492,6 @@
479493 $messages['bs'] = array(
480494 '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',
481495 'openidlogin' => 'Prijava sa OpenID',
482 - 'openidfinish' => 'Završi OpenID prijavu',
483496 'openidserver' => 'OpenID server',
484497 'openidxrds' => 'Yadis datoteka',
485498 'openidconvert' => 'OpenID pretvarač',
@@ -558,7 +571,6 @@
559572 $messages['ca'] = array(
560573 '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',
561574 'openidlogin' => 'Inicia una sessió amb OpenID',
562 - 'openidfinish' => 'Finalitza la sessió amb OpenID',
563575 'openidserver' => 'Servidor OpenID',
564576 'openidxrds' => 'Fitxer Yadis',
565577 'openidconvert' => 'Conversor OpenID',
@@ -586,7 +598,6 @@
587599 $messages['cs'] = array(
588600 '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',
589601 'openidlogin' => 'Přihlášení pomocí OpenID',
590 - 'openidfinish' => 'Dokončit přihlášení pomocí OpenID',
591602 'openidserver' => 'OpenID server',
592603 'openidxrds' => 'Soubor Yadis',
593604 'openidconvert' => 'OpenID konvertor',
@@ -678,7 +689,6 @@
679690 $messages['de'] = array(
680691 '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.',
681692 'openidlogin' => 'Anmelden mit OpenID',
682 - 'openidfinish' => 'OpenID-Anmeldung abschließen',
683693 'openidserver' => 'OpenID-Server',
684694 'openidxrds' => 'Yadis-Datei',
685695 'openidconvert' => 'OpenID-Konverter',
@@ -768,7 +778,6 @@
769779 $messages['dsb'] = array(
770780 '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',
771781 'openidlogin' => 'Pśizjawjenje z OpenID',
772 - 'openidfinish' => 'Pśizjawjenje OpenID dokóńcyś',
773782 'openidserver' => 'Serwer OpenID',
774783 'openidxrds' => 'Yadis-dataja',
775784 'openidconvert' => 'Konwerter OpenID',
@@ -864,7 +873,6 @@
865874 $messages['eo'] = array(
866875 'openid-desc' => 'Ensaluti la vikion kun [http://openid.net/ identigo OpenID], kaj ensaluti aliajn retejon uzantajn OpenID kun vikia uzula konto',
867876 'openidlogin' => 'Ensaluti kun OpenID',
868 - 'openidfinish' => 'Elsaluti kun OpenID',
869877 'openidserver' => 'Servilo OpenID',
870878 'openidxrds' => 'dosiero Yadis',
871879 'openidconvert' => 'OpenID konvertilo',
@@ -933,7 +941,6 @@
934942 $messages['es'] = array(
935943 '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.',
936944 'openidlogin' => 'Conectarse con OpenID',
937 - 'openidfinish' => 'Termina el ingreso OpenID',
938945 'openidserver' => 'servidor OpenID',
939946 'openidxrds' => 'Archivo Yadis',
940947 'openidconvert' => 'Convertidor OpenID',
@@ -1052,7 +1059,6 @@
10531060 $messages['fi'] = array(
10541061 'openid-desc' => 'Kirjaudu wikiin [http://openid.net/ OpenID:llä] ja muille OpenID-tuetuille sivustoille wiki-käyttäjätilillä.',
10551062 'openidlogin' => 'Kirjaudu OpenID:llä',
1056 - 'openidfinish' => 'Lopeta OpenID-kirjautuminen',
10571063 'openidserver' => 'OpenID-palvelin',
10581064 'openidxrds' => 'Yadis-tiedosto',
10591065 'openidconvert' => 'OpenID-muunnin',
@@ -1116,7 +1122,6 @@
11171123 $messages['fr'] = array(
11181124 '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.',
11191125 'openidlogin' => 'Se connecter avec OpenID',
1120 - 'openidfinish' => 'Finir la connection OpenID',
11211126 'openidserver' => 'Serveur OpenID',
11221127 'openidxrds' => 'Fichier Yadis',
11231128 'openidconvert' => 'Convertisseur OpenID',
@@ -1200,7 +1205,6 @@
12011206 $messages['gl'] = array(
12021207 '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',
12031208 'openidlogin' => 'Acceder ao sistema co OpenID',
1204 - 'openidfinish' => 'Saír do sistema OpenID',
12051209 'openidserver' => 'Servidor do OpenID',
12061210 'openidxrds' => 'Ficheiro Yadis',
12071211 'openidconvert' => 'Transformador OpenID',
@@ -1291,7 +1295,6 @@
12921296 $messages['gsw'] = array(
12931297 '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',
12941298 'openidlogin' => 'Aamälde mit OpenID',
1295 - 'openidfinish' => 'OpenID-Aamäldig abschliesse',
12961299 'openidserver' => 'OpenID-Server',
12971300 'openidxrds' => 'Yadis-Datei',
12981301 'openidconvert' => 'OpenID-Konverter',
@@ -1388,7 +1391,6 @@
13891392 $messages['he'] = array(
13901393 'openid-desc' => 'כניסה לחשבון בוויקי באמצעות [http://openid.net/ OpenID], והתחברות לאתרים נוספים הפועלים עם OpenID באמצעות חשבון משתמש בוויקי',
13911394 'openidlogin' => 'כניסה לחשבון עם OpenID',
1392 - 'openidfinish' => 'יציאה מהחשבון עם OpenID',
13931395 'openidserver' => 'שרת OpenID',
13941396 'openidxrds' => 'קובץ Yadis',
13951397 'openidconvert' => 'ממיר OpenID',
@@ -1467,7 +1469,6 @@
14681470 */
14691471 $messages['hi'] = array(
14701472 'openidlogin' => 'OpenID से लॉग इन करें',
1471 - 'openidfinish' => 'OpenID लॉग इन पूरा करें',
14721473 'openidserver' => 'OpenID सर्वर',
14731474 'openidxrds' => 'Yadis फ़ाइल',
14741475 'openidconvert' => 'OpenID कन्वर्टर',
@@ -1531,7 +1532,6 @@
15321533 $messages['hsb'] = array(
15331534 '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',
15341535 'openidlogin' => 'Přizjewjenje z OpenID',
1535 - 'openidfinish' => 'Přizjewjenje OpenID skónčić',
15361536 'openidserver' => 'Serwer OpenID',
15371537 'openidxrds' => 'Yadis-dataja',
15381538 'openidconvert' => 'Konwerter OpenID',
@@ -1607,7 +1607,6 @@
16081608 $messages['hu'] = array(
16091609 'openid-desc' => 'Bejelentkezés [http://openid.net/ OpenID] azonosítóval, és más OpenID-kompatibilis weboldalak használata a wikis azonosítóval',
16101610 'openidlogin' => 'Bejelentkezés OpenID-vel',
1611 - 'openidfinish' => 'OpenID bejelentkezés befejezése',
16121611 'openidserver' => 'OpenID szerver',
16131612 'openidxrds' => 'Yadis fájl',
16141613 'openidconvert' => 'OpenID konverter',
@@ -1680,7 +1679,6 @@
16811680 $messages['ia'] = array(
16821681 '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',
16831682 'openidlogin' => 'Aperir un session con OpenID',
1684 - 'openidfinish' => 'Completar le session OpenID',
16851683 'openidserver' => 'Servitor OpenID',
16861684 'openidxrds' => 'File Yadis',
16871685 'openidconvert' => 'Convertitor de OpenID',
@@ -1760,7 +1758,6 @@
17611759 $messages['id'] = array(
17621760 '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',
17631761 'openidlogin' => 'Masuk log dengan OpenID',
1764 - 'openidfinish' => 'Selesai masuk log dengan OpenID',
17651762 'openidserver' => 'Server OpenID',
17661763 'openidxrds' => 'berkas Yadis',
17671764 'openidconvert' => 'Konverter OpenID',
@@ -1844,7 +1841,6 @@
18451842 $messages['it'] = array(
18461843 'openid-desc' => 'Effettua il login alla wiki con [http://openid.net/ OpenID] e agli altri siti web che utilizzano OpenID con un account wiki',
18471844 'openidlogin' => 'Login con OpenID',
1848 - 'openidfinish' => 'Completa il login OpenID',
18491845 'openidserver' => 'server OpenID',
18501846 'openidxrds' => 'file Yadis',
18511847 'openidconvert' => 'convertitore OpenID',
@@ -1925,7 +1921,6 @@
19261922 $messages['ja'] = array(
19271923 'openid-desc' => '[http://openid.net/ OpenID]によるウィキへのログインを可能にし、ウィキユーザーアカウントを他のOpenID対応サイトにログインすることを可能にする。',
19281924 'openidlogin' => 'OpenIDでログイン',
1929 - 'openidfinish' => 'OpenIDでのログインが完了しました。',
19301925 'openidserver' => 'OpenID サーバー',
19311926 'openidxrds' => 'Yadis ファイル',
19321927 'openidconvert' => 'OpenID コンバーター',
@@ -2078,7 +2073,6 @@
20792074 $messages['ksh'] = array(
20802075 'openid-desc' => 'Hee em Wiki met ener [http://openid.net/ OpenID] enlogge, un angerschwoh mer OpenID kennt met enem Metmaacher-Name fum Wiki enlogge.',
20812076 'openidlogin' => 'Met OpenID enlogge',
2082 - 'openidfinish' => 'Et Enlogge met OpenID afschleeße',
20832077 'openidserver' => 'OpenID Server',
20842078 'openidxrds' => 'Yadis-Dattei',
20852079 'openidconvert' => 'OpenID Ömsetzer',
@@ -2167,7 +2161,6 @@
21682162 $messages['lb'] = array(
21692163 '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.",
21702164 'openidlogin' => 'Umellen mat OpenID',
2171 - 'openidfinish' => "D'Aloggen mat OpenID ofschléissen",
21722165 'openidserver' => 'OpenID-Server',
21732166 'openidxrds' => 'Yadis Fichier',
21742167 'openidconvert' => 'OpenID-Ëmwandler',
@@ -2309,7 +2302,6 @@
23102303 $messages['mr'] = array(
23112304 'openid-desc' => 'विकिवर [http://openid.net/ ओपनID] वापरून प्रवेश करा, तसेच कुठल्याही इतर ओपनID संकेतस्थळावर विकि सदस्य नाम वापरून प्रवेश करा',
23122305 'openidlogin' => 'ओपनID वापरून प्रवेश करा',
2313 - 'openidfinish' => 'ओपनID प्रवेश प्रक्रिया पूर्ण करा',
23142306 'openidserver' => 'ओपनID सर्व्हर',
23152307 'openidxrds' => 'Yadis संचिका',
23162308 'openidconvert' => 'ओपनID कन्व्हर्टर',
@@ -2449,7 +2441,6 @@
24502442 $messages['nl'] = array(
24512443 'openid-desc' => 'Aanmelden bij de wiki met een [http://openid.net/ OpenID] en aanmelden bij andere websites die OpenID ondersteunen met een wikigebruiker',
24522444 'openidlogin' => 'Aanmelden met OpenID',
2453 - 'openidfinish' => 'Aanmelden met OpenID afronden',
24542445 'openidserver' => 'OpenID-server',
24552446 'openidxrds' => 'Yadis-bestand',
24562447 'openidconvert' => 'OpenID-convertor',
@@ -2529,7 +2520,6 @@
25302521 $messages['nn'] = array(
25312522 'openid-desc' => 'Logg inn på wikien med ein [http://openid.net/ OpenID] og logg inn på andre sider som bruker OpenID med kontoen herifrå',
25322523 'openidlogin' => 'Logg inn med OpenID',
2533 - 'openidfinish' => 'Fullfør OpenID-innlogging',
25342524 'openidserver' => 'OpenID-tenar',
25352525 'openidxrds' => 'Yadis-fil',
25362526 'openidconvert' => 'OpenID-konvertering',
@@ -2605,7 +2595,6 @@
26062596 $messages['no'] = array(
26072597 'openid-desc' => 'Logg inn på wikien med en [http://openid.net/ OpenID] og logg inn på andre sider som bruker OpenID med kontoen herfra',
26082598 'openidlogin' => 'Logg inn med OpenID',
2609 - 'openidfinish' => 'Fullfør OpenID-innlogging',
26102599 'openidserver' => 'OpenID-tjener',
26112600 'openidxrds' => 'Yadis-fil',
26122601 'openidconvert' => 'OpenID-konvertering',
@@ -2683,7 +2672,6 @@
26842673 $messages['oc'] = array(
26852674 '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.",
26862675 'openidlogin' => 'Se connectar amb OpenID',
2687 - 'openidfinish' => 'Acabar la connexion OpenID',
26882676 'openidserver' => 'Servidor OpenID',
26892677 'openidxrds' => 'Fichièr Yadis',
26902678 'openidconvert' => 'Convertisseire OpenID',
@@ -2777,7 +2765,6 @@
27782766 $messages['pl'] = array(
27792767 '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',
27802768 'openidlogin' => 'Zaloguj używając OpenID',
2781 - 'openidfinish' => 'Zakończ zalogowanie z użyciem OpenID',
27822769 'openidserver' => 'Serwer OpenID',
27832770 'openidxrds' => 'Plik Yadis',
27842771 'openidconvert' => 'Obsługa OpenID',
@@ -2876,7 +2863,6 @@
28772864 $messages['pt'] = array(
28782865 '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',
28792866 'openidlogin' => 'Autenticação com OpenID',
2880 - 'openidfinish' => 'Terminar autenticação OpenID',
28812867 'openidserver' => 'Servidor OpenID',
28822868 'openidxrds' => 'Ficheiro Yadis',
28832869 'openidconvert' => 'Conversor de OpenID',
@@ -2956,7 +2942,6 @@
29572943 $messages['pt-br'] = array(
29582944 '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',
29592945 'openidlogin' => 'Autenticação com OpenID',
2960 - 'openidfinish' => 'Terminar autenticação OpenID',
29612946 'openidserver' => 'Servidor OpenID',
29622947 'openidxrds' => 'Arquivo Yadis',
29632948 'openidconvert' => 'Conversor de OpenID',
@@ -3074,7 +3059,6 @@
30753060 $messages['ru'] = array(
30763061 'openid-desc' => 'Вход в вики с помощью [http://openid.net/ OpenID], а также вход на другие сайты поддерживающие OpenID с помощью учётной записи в вики',
30773062 'openidlogin' => 'Вход с помощью OpenID',
3078 - 'openidfinish' => 'Завершить вход OpenID',
30793063 'openidserver' => 'Сервер OpenID',
30803064 'openidxrds' => 'Файл Yadis',
30813065 'openidconvert' => 'Преобразователь OpenID',
@@ -3154,7 +3138,6 @@
31553139 $messages['scn'] = array(
31563140 '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",
31573141 'openidlogin' => 'Login cu OpenID',
3158 - 'openidfinish' => 'Cumpleta lu login OpenID',
31593142 'openidserver' => 'server OpenID',
31603143 'openidxrds' => 'file Yadis',
31613144 'openidconvert' => 'cunvirtituri OpenID',
@@ -3236,7 +3219,6 @@
32373220 $messages['sk'] = array(
32383221 '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',
32393222 'openidlogin' => 'Prihlásiť sa pomocou OpenID',
3240 - 'openidfinish' => 'Dokončiť prihlásenie pomocou OpenID',
32413223 'openidserver' => 'OpenID server',
32423224 'openidxrds' => 'Súbor Yadis',
32433225 'openidconvert' => 'OpenID konvertor',
@@ -3311,7 +3293,6 @@
33123294 * @author Михајло Анђелковић
33133295 */
33143296 $messages['sr-ec'] = array(
3315 - 'openidfinish' => 'Заврши OpenID логовање',
33163297 'openidserver' => 'OpenID сервер',
33173298 'openidconvert' => 'OpenID конвертор',
33183299 'openiderror' => 'Грешка приликом верификације',
@@ -3360,7 +3341,6 @@
33613342 $messages['stq'] = array(
33623343 '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.',
33633344 'openidlogin' => 'Anmäldje mäd OpenID',
3364 - 'openidfinish' => 'OpenID-Anmäldenge ousluute',
33653345 'openidserver' => 'OpenID-Server',
33663346 'openidxrds' => 'Yadis-Doatäi',
33673347 'openidconvert' => 'OpenID-Konverter',
@@ -3451,7 +3431,6 @@
34523432 $messages['sv'] = array(
34533433 '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',
34543434 'openidlogin' => 'Logga in med OpenID',
3455 - 'openidfinish' => 'Fullfölj OpenID-inloggning',
34563435 'openidserver' => 'OpenID-server',
34573436 'openidxrds' => 'Yadis-fil',
34583437 'openidconvert' => 'OpenID-konvertering',
@@ -3561,7 +3540,6 @@
35623541 $messages['tg-cyrl'] = array(
35633542 'openid-desc' => 'Ба вики бо [http://openid.net/ OpenID] вуруд кунед, ва ба дигар сомонаҳои OpenID бо ҳисоби корбарии вики вуруд кунед',
35643543 'openidlogin' => 'Бо OpenID вуруд кунед',
3565 - 'openidfinish' => 'Хотима додан вурудшавии OpenID',
35663544 'openidserver' => 'Хидматгузори OpenID',
35673545 'openidxrds' => 'Парвандаи Yadis',
35683546 'openidconvert' => 'Табдилкунандаи OpenID',
@@ -3590,7 +3568,6 @@
35913569 $messages['tl'] = array(
35923570 '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',
35933571 'openidlogin' => 'Lumagda na may OpenID',
3594 - 'openidfinish' => 'Tapusin na ang paglagdang pang-OpenID',
35953572 'openidserver' => 'Serbidor ng OpenID',
35963573 'openidxrds' => 'Talaksang Yadis',
35973574 'openidconvert' => 'Tagapagpalit ng OpenID',
@@ -3663,7 +3640,6 @@
36643641 $messages['tr'] = array(
36653642 '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.',
36663643 'openidlogin' => 'OpenID ile giriş yapın',
3667 - 'openidfinish' => 'OpenID girişini tamamlayın',
36683644 'openidserver' => 'OpenID sunucusu',
36693645 'openidxrds' => 'Yadis dosyası',
36703646 'openidconvert' => 'OpenID çeviricisi',
@@ -3820,7 +3796,6 @@
38213797 $messages['vec'] = array(
38223798 '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",
38233799 'openidlogin' => 'Acesso con OpenID',
3824 - 'openidfinish' => "Conpleta l'acesso OpenID",
38253800 'openidserver' => 'server OpenID',
38263801 'openidxrds' => 'file Yadis',
38273802 'openidconvert' => 'convertidor OpenID',
@@ -3909,7 +3884,6 @@
39103885 $messages['vi'] = array(
39113886 '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',
39123887 'openidlogin' => 'Đăng nhập dùng OpenID',
3913 - 'openidfinish' => 'Đăng nhập dùng OpenID xong',
39143888 'openidserver' => 'Dịch vụ OpenID',
39153889 'openidxrds' => 'Tập tin Yadis',
39163890 'openidconvert' => 'Chuyển đổi ID Mở',
@@ -4010,7 +3984,6 @@
40113985 */
40123986 $messages['zh-hans'] = array(
40133987 'openidlogin' => '使用OpenID登陆',
4014 - 'openidfinish' => '结束OpenID登陆',
40153988 'openidserver' => 'OpenID服务器',
40163989 'openidxrds' => 'Yadis文件',
40173990 'openidconvert' => 'OpenID转换',
Index: trunk/extensions/OpenID/openid_table.sql
@@ -1,7 +1,10 @@
 2+--
 3+-- SQL schema for OpenID extension
 4+--
 5+
26 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*/;
510
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 @@
1313
1414 # Special pages are added at global scope; remove server-related ones
1515 # if client-only flag is set
16 - $addList = array( 'Login', 'Finish', 'Convert' );
 16+ $addList = array( 'Login', 'Convert' );
1717 if ( !$wgOpenIDClientOnly ) {
1818 $addList[] = 'Server';
1919 $addList[] = 'XRDS';
@@ -41,7 +41,7 @@
4242 $user = User::newFromName( $nt->getText() );
4343 if ( $user && $user->getID() != 0 ) {
4444 $openid = SpecialOpenID::getUserUrl( $user );
45 - if ( isset( $openid ) && strlen( $openid ) != 0 ) {
 45+ if ( count( $openid ) && strlen( $openid[0] ) != 0 ) {
4646 global $wgOpenIDShowUrlOnUserPage;
4747
4848 if ( $wgOpenIDShowUrlOnUserPage == 'always' ||
@@ -49,21 +49,20 @@
5050 {
5151 global $wgOpenIDLoginLogoUrl;
5252
53 - $url = SpecialOpenID::OpenIDToUrl( $openid );
54 - $disp = htmlspecialchars( $openid );
 53+ $url = SpecialOpenID::OpenIDToUrl( $openid[0] );
 54+ $disp = htmlspecialchars( $openid[0] );
5555 $wgOut->setSubtitle( "<span class='subpages'>" .
5656 "<img src='$wgOpenIDLoginLogoUrl' alt='OpenID' />" .
5757 "<a href='$url'>$disp</a>" .
5858 "</span>" );
5959 }
60 - } else {
61 - # Add OpenID data iif its allowed
 60+ # Add OpenID data if its allowed
6261 if ( !$wgOpenIDClientOnly ) {
6362 $st = SpecialPage::getTitleFor( 'OpenIDServer' );
6463 $wgOut->addLink( array( 'rel' => 'openid.server',
65 - 'href' => $st->getFullURL() ) );
 64+ 'href' => $st->getFullURL() ) );
6665 $wgOut->addLink( array( 'rel' => 'openid2.provider',
67 - 'href' => $st->getFullURL() ) );
 66+ 'href' => $st->getFullURL() ) );
6867 $rt = SpecialPage::getTitleFor( 'OpenIDXRDS', $user->getName() );
6968 $wgOut->addMeta( 'http:X-XRDS-Location', $rt->getFullURL() );
7069 header( 'X-XRDS-Location: ' . $rt->getFullURL() );
@@ -76,11 +75,10 @@
7776 }
7877
7978 public static function onPersonalUrls( &$personal_urls, &$title ) {
80 - global $wgHideOpenIDLoginLink, $wgUser, $wgLang, $wgOut, $wgOpenIDOnly;
 79+ global $wgHideOpenIDLoginLink, $wgUser, $wgLang, $wgOpenIDOnly;
8180
8281 if ( !$wgHideOpenIDLoginLink && $wgUser->getID() == 0 ) {
8382 wfLoadExtensionMessages( 'OpenID' );
84 - $wgOut->addHeadItem( 'openidloginstyle', self::loginStyle() );
8583 $sk = $wgUser->getSkin();
8684 $returnto = $title->isSpecial( 'Userlogout' ) ?
8785 '' : ( 'returnto=' . $title->getPrefixedURL() );
@@ -104,23 +102,74 @@
105103 return true;
106104 }
107105
 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+
108117 public static function onGetPreferences( $user, &$preferences ) {
 118+ global $wgOpenIDShowUrlOnUserPage, $wgAllowRealName;
 119+
109120 wfLoadExtensionMessages( 'OpenID' );
110 -
111 - $preferences['openid-hide'] =
112 - array(
113 - 'type' => 'toggle',
114 - 'section' => 'openid',
115 - 'label-message' => 'openid-pref-hide',
116 - );
117121
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'] =
119140 array(
120 - 'type' => 'toggle',
 141+ 'type' => 'multiselect',
121142 'section' => 'openid',
122143 'label-message' => 'openid-pref-update-userinfo-on-login',
 144+ 'options' => $update,
 145+ 'prefix' => 'openid-update-on-login-',
123146 );
124147
 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+
125174 return true;
126175 }
127176 public static function onLoadExtensionSchemaUpdates() {
@@ -147,6 +196,7 @@
148197 text-transform: none;
149198 }
150199 </style>
 200+
151201 EOS;
152202 }
153203 }
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
18 + native
Index: trunk/extensions/OpenID/SpecialOpenIDServer.body.php
@@ -51,7 +51,6 @@
5252 }
5353
5454 function execute( $par ) {
55 -
5655 global $wgOut, $wgOpenIDClientOnly;
5756
5857 wfLoadExtensionMessages( 'OpenID' );
@@ -500,7 +499,6 @@
501500 }
502501
503502 function LoginForm( $request, $msg = null ) {
504 -
505503 global $wgOut, $wgUser;
506504
507505 $url = $request->identity;
@@ -514,7 +512,7 @@
515513 $ok = wfMsg( 'ok' );
516514 $cancel = wfMsg( 'cancel' );
517515
518 - if ( isset( $msg ) ) {
 516+ if ( !is_null( $msg ) ) {
519517 $wgOut->addHTML( "<p class='error'>{$msg}</p>" );
520518 }
521519
@@ -744,6 +742,6 @@
745743 }
746744
747745 function serverUrl() {
748 - return $this->fullURL( 'OpenIDServer' );
 746+ return $this->getTitle()->getFullUrl();
749747 }
750748 }
Index: trunk/extensions/OpenID/openid_table.pg.sql
@@ -1,9 +1,9 @@
22
33 -- Schema for the OpenID extension (Postgres version)
44
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*/;
99
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 @@
2626 if ( !defined( 'MEDIAWIKI' ) )
2727 exit( 1 );
2828
29 -require_once( "Auth/OpenID/Consumer.php" );
 29+require_once( "Auth/Yadis/XRI.php" );
3030
3131 class SpecialOpenIDLogin extends SpecialOpenID {
3232
33 - function SpecialOpenIDLogin() {
34 - SpecialPage::SpecialPage( "OpenIDLogin" );
 33+ function __construct() {
 34+ parent::__construct( 'OpenIDLogin' );
3535 }
3636
 37+ /**
 38+ * Entry point
 39+ *
 40+ * @param $par String or null
 41+ */
3742 function execute( $par ) {
38 - global $wgRequest, $wgUser, $wgOut, $wgScriptPath, $wgOpenIDShowProviderIcons;
 43+ global $wgRequest, $wgUser, $wgOut;
3944
4045 wfLoadExtensionMessages( 'OpenID' );
4146
4247 $this->setHeaders();
4348
 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+
4499 $oidScriptPath = $wgScriptPath . '/extensions/OpenID';
45100
46101 $wgOut->addLink( array(
@@ -52,29 +107,6 @@
53108 $wgOut->addScript( '<script type="text/javascript" src="' . $oidScriptPath . '/skin/jquery-1.3.2.min.js"></script>' . "\n" );
54109 $wgOut->addScript( '<script type="text/javascript" src="' . $oidScriptPath . '/skin/openid.js"></script>' . "\n" );
55110
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 -
79111 $formsHTML = '';
80112
81113 $largeButtonsHTML = '<div id="openid_large_providers">';
@@ -92,9 +124,7 @@
93125 $formsHTML .= $provider->getLoginFormHTML();
94126 }
95127 $smallButtonsHTML .= '</div>';
96 - }
97 - else
98 - {
 128+ } else {
99129 $smallButtonsHTML .= '<div id="openid_small_providers_links">';
100130 $smallButtonsHTML .= '<ul class="openid_small_providers_block">';
101131 $small = OpenIDProvider::getSmallProviders();
@@ -116,91 +146,540 @@
117147 $smallButtonsHTML .= '</div>';
118148 }
119149
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' );
130161 }
131162
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'] );
136178 } else {
137 - wfDebug( "OpenID: Handling an URL: $openid\n" );
138 - return $this->toUserNameUrl( $openid );
 179+ $wgOut->addWikiMsg( 'openidnotprovided' );
139180 }
 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+ );
140267 }
141268
142 - function alreadyLoggedIn() {
 269+ function loginSetCookie( $openid ) {
 270+ global $wgRequest, $wgOpenIDCookieExpiration;
 271+ $wgRequest->response()->setcookie( 'OpenID', $openid, time() + $wgOpenIDCookieExpiration );
 272+ }
143273
 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 ) {
144476 global $wgUser, $wgOut;
145477
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' ) );
147490 $wgOut->setRobotPolicy( 'noindex,nofollow' );
148491 $wgOut->setArticleRelated( false );
149 - $wgOut->addWikiText( wfMsg( 'openidalreadyloggedin', $wgUser->getName() ) );
 492+ $wgOut->addWikiMsg( 'openidsuccess', $wgUser->getName(), $openid );
 493+ $wgOut->addHtml( $inject_html );
150494 $wgOut->returnToMain( false, $this->returnTo() );
151495 }
152496
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" );
157512 } 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;
159524 }
160525 }
161526
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 );
165529
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;
170532 }
171533
172 - $dbw->insert( 'user_openid', array( 'uoi_user' => $user->getId(),
173 - 'uoi_openid' => $url ) );
 534+ if ( !$user->checkPassword( $password ) ) {
 535+ return null;
 536+ }
174537
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;
177553 }
178554 }
179555
180 - function updateUserUrl( $user, $url ) {
181 - global $wgSharedDB, $wgDBname;
182 - $dbw =& wfGetDB( DB_MASTER );
183556
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;
188572 }
 573+ }
189574
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+ }
192582
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+ }
195600 }
 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;
196633 }
197634
198 - function saveValues( $response, $sreg ) {
199 - global $wgSessionStarted, $wgUser;
 635+ function toUserNameXri( $xri ) {
 636+ $base = $this->xriBase( $xri );
200637
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 );
203645 }
 646+ }
204647
 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+
205684 $_SESSION['openid_consumer_response'] = $response;
206685 $_SESSION['openid_consumer_sreg'] = $sreg;
207686
Index: trunk/extensions/OpenID/OpenID.alias.php
@@ -13,7 +13,6 @@
1414 */
1515 $aliases['en'] = array(
1616 'OpenIDLogin' => array( 'OpenIDLogin' ),
17 - 'OpenIDFinish' => array( 'OpenIDFinish' ),
1817 'OpenIDConvert' => array( 'OpenIDConvert' ),
1918 'OpenIDServer' => array( 'OpenIDServer' ),
2019 'OpenIDXRDS' => array( 'OpenIDXRDS' ),
@@ -22,7 +21,6 @@
2322 /** Arabic (العربية) */
2423 $aliases['ar'] = array(
2524 'OpenIDLogin' => array( 'دخول_الهوية_المفتوحة' ),
26 - 'OpenIDFinish' => array( 'نهاية_الهوية_المفتوحة' ),
2725 'OpenIDConvert' => array( 'تحويل_الهوية_المفتوحة' ),
2826 'OpenIDServer' => array( 'خادم_الهوية_المفتوحة' ),
2927 'OpenIDXRDS' => array( 'إكسردس_الهوية_المفتوحة' ),
@@ -31,7 +29,6 @@
3230 /** Egyptian Spoken Arabic (مصرى) */
3331 $aliases['arz'] = array(
3432 'OpenIDLogin' => array( 'دخول_الهوية_المفتوحة' ),
35 - 'OpenIDFinish' => array( 'نهاية_الهوية_المفتوحة' ),
3633 'OpenIDConvert' => array( 'تحويل_الهوية_المفتوحة' ),
3734 'OpenIDServer' => array( 'خادم_الهوية_المفتوحة' ),
3835 'OpenIDXRDS' => array( 'إكسردس_الهوية_المفتوحة' ),
@@ -40,7 +37,6 @@
4138 /** Interlingua (Interlingua) */
4239 $aliases['ia'] = array(
4340 'OpenIDLogin' => array( 'Aperir session OpenID' ),
44 - 'OpenIDFinish' => array( 'Completar session OpenID' ),
4541 'OpenIDConvert' => array( 'Converter a OpenID' ),
4642 'OpenIDServer' => array( 'Servitor OpenID' ),
4743 'OpenIDXRDS' => array( 'XRDS OpenID' ),
@@ -49,7 +45,6 @@
5046 /** Japanese (日本語) */
5147 $aliases['ja'] = array(
5248 'OpenIDLogin' => array( 'OpenIDログイン', 'OpenIDログイン' ),
53 - 'OpenIDFinish' => array( 'OpenID完了', 'OpenID完了' ),
5449 'OpenIDConvert' => array( 'OpenID変換', 'OpenID変換' ),
5550 'OpenIDServer' => array( 'OpenIDサーバー', 'OpenIDサーバー' ),
5651 'OpenIDXRDS' => array( 'OpenIDXRDS' ),
@@ -58,14 +53,12 @@
5954 /** Ripoarisch (Ripoarisch) */
6055 $aliases['ksh'] = array(
6156 'OpenIDLogin' => array( 'OpenIDAanmedung' ),
62 - 'OpenIDFinish' => array( 'OpenIDEngk' ),
6357 'OpenIDConvert' => array( 'OpenIDÖmwandele' ),
6458 );
6559
6660 /** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬) */
6761 $aliases['no'] = array(
6862 'OpenIDLogin' => array( 'OpenID-innlogging' ),
69 - 'OpenIDFinish' => array( 'OpenID-fullføring' ),
7063 'OpenIDConvert' => array( 'OpenID-konvertering' ),
7164 'OpenIDServer' => array( 'OpenID-tjener' ),
7265 'OpenIDXRDS' => array( 'OpenID-XRDS' ),
@@ -74,7 +67,6 @@
7568 /** Sanskrit (संस्कृत) */
7669 $aliases['sa'] = array(
7770 'OpenIDLogin' => array( 'उद्घटपरिचयपत्रप्रवेश' ),
78 - 'OpenIDFinish' => array( 'उद्घटपरिचयपत्रसमापयति' ),
7971 'OpenIDConvert' => array( 'उद्घटपरिचयपत्रांतर' ),
8072 'OpenIDServer' => array( 'उद्घटपरिचयपत्रविदादाता' ),
8173 'OpenIDXRDS' => array( 'उद्घटपरिचयपत्रXRDS' ),
@@ -83,7 +75,6 @@
8476 /** Tagalog (Tagalog) */
8577 $aliases['tl'] = array(
8678 'OpenIDLogin' => array( 'Paglagda sa OpenID' ),
87 - 'OpenIDFinish' => array( 'Pagtatapos ng OpenID' ),
8879 'OpenIDConvert' => array( 'Pagpapalit ng OpenID' ),
8980 'OpenIDServer' => array( 'Serbidor ng OpenID' ),
9081 'OpenIDXRDS' => array( 'XRDS ng OpenID' ),
Index: trunk/extensions/OpenID/README
@@ -1,43 +1,39 @@
22 MediaWiki OpenID extension
33
4 -version 0.8.4.1
5 -18 Apr 2009
 4+version 0.9.0
 5+20 June 2009
66
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.
1010
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.
1616
1717 Typical uses:
1818
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.
3229
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.
3633
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.
4238
4339 == License ==
4440
@@ -67,91 +63,81 @@
6864
6965 == Pre-requisites ==
7066
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.
7571
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:
8075
8176 http://www.openidenabled.com/php-openid/
8277
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.
8681
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.
9185
9286 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".
9689
9790 == Installation ==
9891
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.
10496
10597 Run update.php script in in your MediaWiki maintenance folder to create
10698 necessary tables in MediaWiki database.
10799
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).
114105
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:
117108
118 - require_once("$IP/extensions/OpenID/OpenID.setup.php");
 109+ require_once( "$IP/extensions/OpenID/OpenID.setup.php" );
119110
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).
123113
124114 == Upgrade ==
125115
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.
131120
132121 To upgrade, you'll need to do at least the following:
133122
134123 * 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.
153139
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.
156142
157143 == Logging in using OpenID ==
158144
Index: trunk/extensions/OpenID/SpecialOpenID.body.php
@@ -87,70 +87,21 @@
8888 }
8989 }
9090
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 -
12191 # Login, Finish
12292
12393 function getConsumer() {
12494 global $wgOpenIDConsumerStoreType, $wgOpenIDConsumerStorePath;
12595
126 - $store = $this->getOpenIDStore( $wgOpenIDConsumerStoreType,
127 - 'consumer',
128 - array( 'path' => $wgOpenIDConsumerStorePath ) );
 96+ $store = $this->getOpenIDStore(
 97+ $wgOpenIDConsumerStoreType,
 98+ 'consumer',
 99+ array( 'path' => $wgOpenIDConsumerStorePath )
 100+ );
129101
130102 return new Auth_OpenID_Consumer( $store );
131103 }
132104
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 -
153105 function canLogin( $openid_url ) {
154 -
155106 global $wgOpenIDConsumerDenyByDefault, $wgOpenIDConsumerAllow, $wgOpenIDConsumerDeny;
156107
157108 if ( $this->isLocalUrl( $openid_url ) ) {
@@ -194,7 +145,6 @@
195146 }
196147
197148 function isLocalUrl( $url ) {
198 -
199149 global $wgServer, $wgArticlePath;
200150
201151 $pattern = $wgServer . $wgArticlePath;
@@ -204,31 +154,9 @@
205155 return preg_match( '|^' . $pattern . '$|', $url );
206156 }
207157
208 - # Find the user with the given openid, if any
 158+ function login( $openid_url, $finish_page ) {
 159+ global $wgTrustRoot, $wgOut;
209160
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 -
233161 # If it's an interwiki link, expand it
234162
235163 $openid_url = $this->interwikiExpand( $openid_url );
@@ -240,9 +168,7 @@
241169 return;
242170 }
243171
244 - $sk = $wgUser->getSkin();
245 -
246 - if ( isset( $wgTrustRoot ) ) {
 172+ if ( !is_null( $wgTrustRoot ) ) {
247173 $trust_root = $wgTrustRoot;
248174 } else {
249175 global $wgArticlePath, $wgServer;
@@ -250,6 +176,8 @@
251177 $trust_root = $wgServer . $root_article;
252178 }
253179
 180+ wfSuppressWarnings();
 181+
254182 $consumer = $this->getConsumer();
255183
256184 if ( !$consumer ) {
@@ -258,13 +186,8 @@
259187 }
260188
261189 # Make sure the user has a session!
 190+ $this->setupSession();
262191
263 - global $wgSessionStarted;
264 -
265 - if ( !$wgSessionStarted ) {
266 - $wgUser->SetupSession();
267 - }
268 -
269192 $auth_request = $consumer->begin( $openid_url );
270193
271194 // Handle failure status return values.
@@ -277,7 +200,7 @@
278201
279202 $endpoint = $auth_request->endpoint;
280203
281 - if ( isset( $endpoint ) ) {
 204+ if ( !is_null( $endpoint ) ) {
282205 # Check if the URL is allowed
283206
284207 if ( isset( $endpoint->identity_url ) && !$this->canLogin( $endpoint->identity_url ) ) {
@@ -292,17 +215,17 @@
293216 }
294217
295218 $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+ );
301224
302225 if ( $sreg_request ) {
303226 $auth_request->addExtension( $sreg_request );
304227 }
305228
306 - $process_url = $this->scriptUrl( $finish_page );
 229+ $process_url = $finish_page->getFullUrl();
307230
308231 if ( $auth_request->shouldSendRedirect() ) {
309232 $redirect_url = $auth_request->redirectURL( $trust_root,
@@ -322,57 +245,89 @@
323246 // Display an error if the form markup couldn't be generated;
324247 // otherwise, render the HTML.
325248 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 );
327250 } else {
328 - $wgOut->addHTML( "<p>" . wfMsg( "openidautosubmit" ) . "</p>" );
 251+ $wgOut->addWikiMsg( 'openidautosubmit' );
329252 $wgOut->addHTML( $form_html );
330253 $wgOut->addInlineScript( "function submitOpenIDForm() {\n document.getElementById(\"" . $form_id . "\").submit()\n }\nhookEvent(\"load\", submitOpenIDForm);\n" );
331254 }
332255 }
 256+
 257+ wfRestoreWarnings();
333258 }
334259
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();
341265 }
342266 }
343267
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();
347271
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();
352285 }
 286+ return $openid_urls;
 287+ }
353288
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 );
356291
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;
359303 }
360304 }
361305
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 );
365308
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+ );
371317
372 - $dbw->set( 'user_openid', 'uoi_openid', $url,
373 - 'uoi_user = ' . $user->getID() );
 318+ }
374319
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();
378333 }
379334 }
Index: trunk/extensions/OpenID/SpecialOpenIDConvert.body.php
@@ -29,11 +29,10 @@
3030 class SpecialOpenIDConvert extends SpecialOpenID {
3131
3232 function SpecialOpenIDConvert() {
33 - SpecialPage::SpecialPage( "OpenIDConvert" );
 33+ SpecialPage::SpecialPage( 'OpenIDConvert' );
3434 }
3535
3636 function execute( $par ) {
37 -
3837 global $wgRequest, $wgUser, $wgOut;
3938
4039 wfLoadExtensionMessages( 'OpenID' );
@@ -45,37 +44,38 @@
4645 return;
4746 }
4847
 48+ $this->outputHeader();
 49+
4950 switch ( $par ) {
50 - case 'Finish':
 51+ case 'Finish':
5152 $this->finish();
5253 break;
53 - default:
 54+ case 'Delete':
 55+ $this->delete();
 56+ break;
 57+ default:
5458 $openid_url = $wgRequest->getText( 'openid_url' );
5559 if ( isset( $openid_url ) && strlen( $openid_url ) > 0 ) {
5660 $this->convert( $openid_url );
5761 } else {
58 - $this->Form();
 62+ $this->form();
5963 }
6064 }
6165 }
6266
6367 function convert( $openid_url ) {
64 -
6568 global $wgUser, $wgOut;
6669
6770 # Expand Interwiki
68 -
6971 $openid_url = $this->interwikiExpand( $openid_url );
7072
7173 # Is this ID allowed to log in?
72 -
73 - if ( !$this->CanLogin( $openid_url ) ) {
 74+ if ( !$this->canLogin( $openid_url ) ) {
7475 $wgOut->showErrorPage( 'openidpermission', 'openidpermissiontext' );
7576 return;
7677 }
7778
7879 # Is this ID already taken?
79 -
8080 $other = $this->getUser( $openid_url );
8181
8282 if ( isset( $other ) ) {
@@ -88,55 +88,83 @@
8989 }
9090
9191 # 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' ) );
9493 }
9594
9695 function form() {
9796 global $wgOut, $wgUser, $wgOpenIDLoginLogoUrl;
9897
99 - $sk = $wgUser->getSkin();
100 - $url = $this->GetUserUrl( $wgUser );
101 - if ( is_null( $url ) ) {
 98+ $url = self::getUserUrl( $wgUser );
 99+ if ( count( $url ) ) {
102100 $url = '';
103101 }
104102
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+ );
115113 }
116114
 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+
117145 function finish() {
118 -
119146 global $wgUser, $wgOut;
120147
 148+ wfSuppressWarnings();
121149 $consumer = $this->getConsumer();
 150+ $response = $consumer->complete( $this->getTitle( 'Finish' )->getFullUrl() );
 151+ wfRestoreWarnings();
122152
123 - $response = $consumer->complete( $this->scriptUrl( 'OpenIDConvert/Finish' ) );
124 -
125 - if ( !isset( $response ) ) {
 153+ if ( is_null( $response ) ) {
126154 wfDebug( "OpenID: aborting in openid converter because the response was missing\n" );
127155 $wgOut->showErrorPage( 'openiderror', 'openiderrortext' );
128156 return;
129157 }
130158
131159 switch ( $response->status ) {
132 - case Auth_OpenID_CANCEL:
 160+ case Auth_OpenID_CANCEL:
133161 // This means the authentication was cancelled.
134162 $wgOut->showErrorPage( 'openidcancel', 'openidcanceltext' );
135163 break;
136 - case Auth_OpenID_FAILURE:
 164+ case Auth_OpenID_FAILURE:
137165 wfDebug( "OpenID: error in convert: '" . $response->message . "'\n" );
138166 $wgOut->showErrorPage( 'openidfailure', 'openidfailuretext', array( $response->message ) );
139167 break;
140 - case Auth_OpenID_SUCCESS:
 168+ case Auth_OpenID_SUCCESS:
141169 // This means the authentication succeeded.
142170 $openid_url = $response->identity_url;
143171
@@ -160,13 +188,13 @@
161189 return;
162190 }
163191
164 - $this->setUserUrl( $wgUser, $openid_url );
 192+ self::addUserUrl( $wgUser, $openid_url );
165193
166194 $wgOut->setPageTitle( wfMsg( 'openidconvertsuccess' ) );
167195 $wgOut->setRobotPolicy( 'noindex,nofollow' );
168196 $wgOut->setArticleRelated( false );
169 - $wgOut->addWikiText( wfMsg( 'openidconvertsuccesstext', $openid_url ) );
170 - $wgOut->returnToMain( );
 197+ $wgOut->addWikiMsg( 'openidconvertsuccesstext', $openid_url );
 198+ $wgOut->returnToMain();
171199 }
172200 }
173201 }
Index: trunk/extensions/OpenID/SpecialOpenIDXRDS.body.php
@@ -31,7 +31,7 @@
3232 class SpecialOpenIDXRDS extends SpecialOpenID {
3333
3434 function SpecialOpenIDXRDS() {
35 - SpecialPage::SpecialPage( "OpenIDXRDS", '', false );
 35+ SpecialPage::SpecialPage( 'OpenIDXRDS', '', false );
3636 }
3737
3838 # $par is a user name
@@ -51,7 +51,7 @@
5252 }
5353
5454 // 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"?' . '>',
5656 '<xrds:XRDS',
5757 ' xmlns:xrds="xri://\$xrds"',
5858 ' xmlns:openid="http://openid.net/xmlns/1.0"',
@@ -108,6 +108,7 @@
109109
110110 // Print content-type and XRDS XML.
111111 header( "Content-Type: application/xrds+xml" );
 112+
112113 print implode( "\n", $xml_template );
113114 print $service_text;
114115 print implode( "\n", array( "</XRD>", "</xrds:XRDS>" ) );
Index: trunk/extensions/OpenID/OpenID.setup.php
@@ -26,91 +26,118 @@
2727 exit( 1 );
2828 }
2929
30 -define( 'MEDIAWIKI_OPENID_VERSION', '0.8.4.1' );
 30+define( 'MEDIAWIKI_OPENID_VERSION', '0.9.0' );
3131
3232 # CONFIGURATION VARIABLES
3333
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+ */
3638 $wgHideOpenIDLoginLink = false;
3739
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+ */
3944 $wgOpenIDLoginLogoUrl = $wgScriptPath . '/extensions/OpenID/skin/icons/openid-inputicon.png';
4045
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+ */
4450 $wgOpenIDShowUrlOnUserPage = 'user';
4551
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+ */
5056 $wgOpenIDServerForceAllowTrust = array();
5157
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+ */
5461 $wgOpenIDServerStoreType = 'file';
5562
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+ */
5967 $wgOpenIDServerStorePath = "/tmp/$wgDBname/openidserver/";
6068
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+ */
6473 $wgTrustRoot = null;
6574
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+ */
7282 $wgOpenIDConsumerDenyByDefault = false;
7383
74 -# Which partners to allow; regexps here. See above.
75 -
 84+/**
 85+ * Which partners to allow; regexps here. See above.
 86+ */
7687 $wgOpenIDConsumerAllow = array();
7788
78 -# Which partners to deny; regexps here. See above.
79 -
 89+/**
 90+ * Which partners to deny; regexps here. See above.
 91+ */
8092 $wgOpenIDConsumerDeny = array();
8193
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+ */
8497 $wgOpenIDConsumerStoreType = 'file';
8598
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+ */
89103 $wgOpenIDConsumerStorePath = "/tmp/$wgDBname/openidconsumer/";
90104
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+ */
95110 $wgOpenIDCookieExpiration = 365 * 24 * 60 * 60;
96111
97 -# Only allow login with OpenID. Careful -- this means everybody!
98 -
 112+/**
 113+ * Only allow login with OpenID. Careful -- this means everybody!
 114+ */
99115 $wgOpenIDOnly = false;
100116
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+ */
104121 $wgOpenIDClientOnly = false;
105122
106 -# If true, will show provider icons instead of the text
 123+/**
 124+ * If true, will show provider icons instead of the text.
 125+ */
107126 $wgOpenIDShowProviderIcons = false;
108127
 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+
109136 # END CONFIGURATION VARIABLES
110137
111138 $wgExtensionCredits['other'][] = array(
112 - 'path' => __FILE__,
113139 'name' => 'OpenID',
114140 'version' => MEDIAWIKI_OPENID_VERSION,
 141+ 'path' => __FILE__,
115142 'author' => 'Evan Prodromou',
116143 'url' => 'http://www.mediawiki.org/wiki/Extension:OpenID',
117144 '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 @@
141168 $wgAutoloadClasses['SpecialOpenID'] = $dir . 'SpecialOpenID.body.php';
142169
143170 $wgAutoloadClasses['SpecialOpenIDLogin'] = $dir . 'SpecialOpenIDLogin.body.php';
144 -$wgAutoloadClasses['SpecialOpenIDFinish'] = $dir . 'SpecialOpenIDFinish.body.php';
145171 $wgAutoloadClasses['SpecialOpenIDConvert'] = $dir . 'SpecialOpenIDConvert.body.php';
146172 $wgAutoloadClasses['SpecialOpenIDServer'] = $dir . 'SpecialOpenIDServer.body.php';
147173 $wgAutoloadClasses['SpecialOpenIDXRDS'] = $dir . 'SpecialOpenIDXRDS.body.php';
@@ -152,6 +178,7 @@
153179 $wgAutoloadClasses['Auth_OpenID_CheckIDRequest'] = OpenIDGetServerPath();
154180
155181 $wgHooks['PersonalUrls'][] = 'OpenIDHooks::onPersonalUrls';
 182+$wgHooks['BeforePageDisplay'][] = 'OpenIDHooks::onBeforePageDisplay';
156183 $wgHooks['ArticleViewHeader'][] = 'OpenIDHooks::onArticleViewHeader';
157184 $wgHooks['SpecialPage_initList'][] = 'OpenIDHooks::onSpecialPage_initList';
158185 $wgHooks['LoadExtensionSchemaUpdates'][] = 'OpenIDHooks::onLoadExtensionSchemaUpdates';
Index: trunk/extensions/OpenID/TODO
@@ -8,7 +8,7 @@
99 + Function to let skins tell if user is OpenID user
1010 + Function to let skins know user's OpenID URL
1111 + Interwiki login
12 -- drop-down for username prefixes (Yahoo, etc.)
 12++ drop-down for username prefixes (Yahoo, etc.)
1313 + server mode login
1414 + server mode trust form
1515 + server mode share fields form
@@ -24,7 +24,7 @@
2525 + hide openid.server for non-user pages
2626 - optimize trust storage
2727 + change trust data separators from , and | to FS and RS
28 -- User preferences tab for OpenID
 28++ User preferences tab for OpenID
2929 - Manage allow-to-trust settings in User preferences
3030 - Optionally redirect User: page to OpenID URL
3131 - If user logs in with OpenID, add a cookie, and auto-login next time
@@ -54,7 +54,7 @@
5555 - deal with difference between canonical ID and "display ID" with XRIs
5656 + add more explanatory text to the default login instructions (copy Wikitravel text)
5757 - 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
5959 + link to Special:OpenIDConvert if user is already logged in
6060 - support RP discovery
6161 - AJAX login, rather than klutzy JS form

Follow-up revisions

RevisionCommit summaryAuthorDate
r52258PerSergey Chernyshev's comment on r52236 (and fix for that revision): add Spe...ialex21:32, 21 June 2009
r58932Fix total regression in ability to act as OpenID server in r52236....brion00:43, 12 November 2009
r60735* (bug 17654) Automatic creation of the user on OpenID login is now optional...ialex16:00, 6 January 2010

Comments

#Comment by Siebrand (talk | contribs)   18:33, 21 June 2009

The message 'openidautosubmit' references a button with label "Continue". I can however not find a message with this text in OpenID or in MediaWiki core. What is the message used on that button?

#Comment by IAlex (talk | contribs)   19:06, 21 June 2009

This string is hardcoded in php-openid, it is not a MediaWiki message.

#Comment by Siebrand (talk | contribs)   21:18, 21 June 2009

Thanks. Added that to the message documentation and changed it in all the messages on translatewiki. Will be committed on the next export to svn.

#Comment by Sergey Chernyshev (talk | contribs)   20:01, 21 June 2009

Hmm. Looks like this change to Finish broke Short URLs in the process, I'm getting this message now: Verification of the OpenID URL failed. Error message: "return_to does not match return URL. Expected http://www.sharingbuttons.org/Special:OpenIDLogin/Finish, got http://www.sharingbuttons.org/Special:OpenIDLogin/Finish?janrain_nonce=2009-06-21T19%3A37%3A35Zcvmhdl"

When I disable $wgArticlePath = "/$1"; in my LocalSettings.php it works.

#Comment by Nikerabbit (talk | contribs)   20:16, 21 June 2009

Just noting that having short urls directly in the domain root is not a supported configuration.

#Comment by Sergey Chernyshev (talk | contribs)   20:23, 21 June 2009

Can I read about it somewhere?

#Comment by Nikerabbit (talk | contribs)   20:43, 21 June 2009

The manual recommends against it. Imho it should even do it more clearly, because it causes namespace (not in mediawiki sense) conflicts and then the users come asking us for help when they have problems with it.

#Comment by Sergey Chernyshev (talk | contribs)   20:48, 21 June 2009

I don't see it being unsupported and more over, all my instances had no problems with any extensions before. But it's an unrelated issue and can be discussed somewhere else.

#Comment by Sergey Chernyshev (talk | contribs)   20:54, 21 June 2009

I switched to /wiki/* Short URL method (using mod_rewrite).

Problem still persists - the message is as follow:

Verification of the OpenID URL failed. Error message: "return_to does not match return URL.
Expected http://www.sharingbuttons.org/wiki/Special:OpenIDLogin/Finish,
got http://www.sharingbuttons.org/wiki/Special:OpenIDLogin/Finish?janrain_nonce=2009-06-21T20%3A36%3A21ZFoYmDU&openid1_claimed_id=http%3A%2F%2Fwww.sergeychernyshev.com%2F" 
#Comment by Sergey Chernyshev (talk | contribs)   20:59, 21 June 2009

Problem can be traced to removed scriptURL method in old http://svn.wikimedia.org/viewvc/mediawiki/tags/extensions/OpenID/REL_0_8_4_1/SpecialOpenID.body.php?view=markup - handling was terrible and bogus, but it did the job.

It seems that replacing:

$this->scriptUrl( 'OpenIDFinish' )

with

$this->getTitle( 'Finish' )->getFullUrl()

is not doing what's expected by $consumer->complete.

#Comment by IAlex (talk | contribs)   21:32, 21 June 2009

Done in r52258, please see if it fixes the problem.

#Comment by Sergey Chernyshev (talk | contribs)   14:03, 22 June 2009

Hmm. Now there are problems with a trust root:

Verification of the OpenID URL failed. Error message:
"return_to u'http://www.sharingbuttons.org/w/index.php?title=Special:OpenIDLogin/Finish&janrain_nonce=2009-06-22T14%3A00%3A58Zvoabjv'
not under trust_root u'http://www.sharingbuttons.org/wiki/'" 
#Comment by Sergey Chernyshev (talk | contribs)   14:12, 22 June 2009

OK, I should rephrase it - trust root guessing doesn't catch $wgScriptPath = '/w' + $wgArticlePath = "/wiki/$1" setup so one should use $wgTrustRoot = $wgServer; to set actual root.

Setting root manually in LocalSettings.php or using $wgScriptPath = '/w' + $wgArticlePath = "/$1" setup works.

I think it's worth tweaking the trust root guessing a bit, but it works overall! Thanks a lot!

Status & tagging log