3
* SpecialOpenIDConvert.body.php -- Convert existing account to OpenID account
4
* Copyright 2006,2007 Internet Brands (http://www.internetbrands.com/)
5
* Copyright 2007,2008 Evan Prodromou <evan@prodromou.name>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
* @author Evan Prodromou <evan@prodromou.name>
22
* @addtogroup Extensions
25
if (!defined('MEDIAWIKI')) {
29
class SpecialOpenIDConvert extends SpecialOpenID {
31
function SpecialOpenIDConvert() {
32
SpecialPage::SpecialPage("OpenIDConvert");
35
function execute($par) {
37
global $wgRequest, $wgUser, $wgOut;
39
wfLoadExtensionMessages( 'OpenID' );
43
if ($wgUser->getID() == 0) {
44
$wgOut->showErrorPage('openiderror', 'notloggedin');
53
$openid_url = $wgRequest->getText('openid_url');
54
if (isset($openid_url) && strlen($openid_url) > 0) {
55
$this->convert($openid_url);
62
function convert($openid_url) {
64
global $wgUser, $wgOut;
68
$openid_url = $this->interwikiExpand($openid_url);
70
# Is this ID allowed to log in?
72
if (!$this->CanLogin($openid_url)) {
73
$wgOut->showErrorPage('openidpermission', 'openidpermissiontext');
77
# Is this ID already taken?
79
$other = $this->getUser($openid_url);
82
if ($other->getId() == $wgUser->getID()) {
83
$wgOut->showErrorPage('openiderror', 'openidconvertyourstext');
85
$wgOut->showErrorPage('openiderror', 'openidconvertothertext');
90
# If we're OK to here, let the user go log in
92
$this->Login($openid_url, 'OpenIDConvert/Finish');
96
global $wgOut, $wgUser;
97
$sk = $wgUser->getSkin();
98
$url = $this->GetUserUrl($wgUser);
104
$instructions = wfMsg('openidconvertinstructions');
105
$wgOut->addHTML("<p>{$instructions}</p>" .
106
'<form action="' . $sk->makeSpecialUrl('OpenIDConvert') . '" method="POST">' .
107
'<input type="text" name="openid_url" size="30" ' .
108
' style="background: url(http://www.openid.net/login-bg.gif) ' .
109
' no-repeat; background-color: #fff; background-position: 0 50%; ' .
110
' color: #000; padding-left: 18px;" value="' . $url . '" />' .
111
'<input type="submit" value="' . $ok . '" />' .
117
global $wgUser, $wgOut;
119
$consumer = $this->getConsumer();
121
$response = $consumer->complete($this->scriptUrl('OpenIDConvert/Finish'));
123
if (!isset($response)) {
124
wfDebug("OpenID: aborting in openid converter because the response was missing\n");
125
$wgOut->showErrorPage('openiderror', 'openiderrortext');
129
switch ($response->status) {
130
case Auth_OpenID_CANCEL:
131
// This means the authentication was cancelled.
132
$wgOut->showErrorPage('openidcancel', 'openidcanceltext');
134
case Auth_OpenID_FAILURE:
135
wfDebug("OpenID: error in convert: '" . $response->message . "'\n");
136
$wgOut->showErrorPage('openidfailure', 'openidfailuretext', array($response->message));
138
case Auth_OpenID_SUCCESS:
139
// This means the authentication succeeded.
140
$openid_url = $response->identity_url;
142
if (!isset($openid_url)) {
143
wfDebug("OpenID: aborting in openid converter because the openid_url was missing\n");
144
$wgOut->showErrorPage('openiderror', 'openiderrortext');
148
# We check again for dupes; this may be normalized or
149
# reformatted by the server.
151
$other = $this->getUser($openid_url);
154
if ($other->getId() == $wgUser->getID()) {
155
$wgOut->showErrorPage('openiderror', 'openidconvertyourstext');
157
$wgOut->showErrorPage('openiderror', 'openidconvertothertext');
162
$this->setUserUrl($wgUser, $openid_url);
164
$wgOut->setPageTitle( wfMsg( 'openidconvertsuccess' ) );
165
$wgOut->setRobotPolicy( 'noindex,nofollow' );
166
$wgOut->setArticleRelated( false );
167
$wgOut->addWikiText( wfMsg( 'openidconvertsuccesstext', $openid_url ) );
168
$wgOut->returnToMain( );