~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to dist/mediawiki-extensions-openid/usr/share/mediawiki-extensions/openid/SpecialOpenIDConvert.body.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
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>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 *
 
21
 * @author Evan Prodromou <evan@prodromou.name>
 
22
 * @addtogroup Extensions
 
23
 */
 
24
 
 
25
if (!defined('MEDIAWIKI')) {
 
26
        exit( 1 );
 
27
}
 
28
 
 
29
class SpecialOpenIDConvert extends SpecialOpenID {
 
30
 
 
31
        function SpecialOpenIDConvert() {
 
32
                SpecialPage::SpecialPage("OpenIDConvert");
 
33
        }
 
34
 
 
35
        function execute($par) {
 
36
 
 
37
                global $wgRequest, $wgUser, $wgOut;
 
38
 
 
39
                wfLoadExtensionMessages( 'OpenID' );
 
40
 
 
41
                $this->setHeaders();
 
42
 
 
43
                if ($wgUser->getID() == 0) {
 
44
                        $wgOut->showErrorPage('openiderror', 'notloggedin');
 
45
                        return;
 
46
                }
 
47
 
 
48
                switch ($par) {
 
49
                 case 'Finish':
 
50
                        $this->finish();
 
51
                        break;
 
52
                 default:
 
53
                        $openid_url = $wgRequest->getText('openid_url');
 
54
                        if (isset($openid_url) && strlen($openid_url) > 0) {
 
55
                                $this->convert($openid_url);
 
56
                        } else {
 
57
                                $this->Form();
 
58
                        }
 
59
                }
 
60
        }
 
61
 
 
62
        function convert($openid_url) {
 
63
 
 
64
                global $wgUser, $wgOut;
 
65
 
 
66
                # Expand Interwiki
 
67
 
 
68
                $openid_url = $this->interwikiExpand($openid_url);
 
69
 
 
70
                # Is this ID allowed to log in?
 
71
 
 
72
                if (!$this->CanLogin($openid_url)) {
 
73
                        $wgOut->showErrorPage('openidpermission', 'openidpermissiontext');
 
74
                        return;
 
75
                }
 
76
 
 
77
                # Is this ID already taken?
 
78
 
 
79
                $other = $this->getUser($openid_url);
 
80
 
 
81
                if (isset($other)) {
 
82
                        if ($other->getId() == $wgUser->getID()) {
 
83
                                $wgOut->showErrorPage('openiderror', 'openidconvertyourstext');
 
84
                        } else {
 
85
                                $wgOut->showErrorPage('openiderror', 'openidconvertothertext');
 
86
                        }
 
87
                        return;
 
88
                }
 
89
 
 
90
                # If we're OK to here, let the user go log in
 
91
 
 
92
                $this->Login($openid_url, 'OpenIDConvert/Finish');
 
93
        }
 
94
 
 
95
        function form() {
 
96
                global $wgOut, $wgUser;
 
97
                $sk = $wgUser->getSkin();
 
98
                $url = $this->GetUserUrl($wgUser);
 
99
                if (is_null($url)) {
 
100
                        $url = '';
 
101
                }
 
102
 
 
103
                $ok = wfMsg('ok');
 
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 . '" />' .
 
112
                                                '</form>');
 
113
        }
 
114
 
 
115
        function finish() {
 
116
 
 
117
                global $wgUser, $wgOut;
 
118
 
 
119
                $consumer = $this->getConsumer();
 
120
 
 
121
                $response = $consumer->complete($this->scriptUrl('OpenIDConvert/Finish'));
 
122
 
 
123
                if (!isset($response)) {
 
124
                        wfDebug("OpenID: aborting in openid converter because the response was missing\n");
 
125
                        $wgOut->showErrorPage('openiderror', 'openiderrortext');
 
126
                        return;
 
127
                }
 
128
 
 
129
                switch ($response->status) {
 
130
                 case Auth_OpenID_CANCEL:
 
131
                        // This means the authentication was cancelled.
 
132
                        $wgOut->showErrorPage('openidcancel', 'openidcanceltext');
 
133
                        break;
 
134
                 case Auth_OpenID_FAILURE:
 
135
                        wfDebug("OpenID: error in convert: '" . $response->message . "'\n");
 
136
                        $wgOut->showErrorPage('openidfailure', 'openidfailuretext', array($response->message));
 
137
                        break;
 
138
                 case Auth_OpenID_SUCCESS:
 
139
                        // This means the authentication succeeded.
 
140
                        $openid_url = $response->identity_url;
 
141
 
 
142
                        if (!isset($openid_url)) {
 
143
                                wfDebug("OpenID: aborting in openid converter because the openid_url was missing\n");
 
144
                                $wgOut->showErrorPage('openiderror', 'openiderrortext');
 
145
                                return;
 
146
                        }
 
147
 
 
148
                        # We check again for dupes; this may be normalized or
 
149
                        # reformatted by the server.
 
150
 
 
151
                        $other = $this->getUser($openid_url);
 
152
 
 
153
                        if (isset($other)) {
 
154
                                if ($other->getId() == $wgUser->getID()) {
 
155
                                        $wgOut->showErrorPage('openiderror', 'openidconvertyourstext');
 
156
                                } else {
 
157
                                        $wgOut->showErrorPage('openiderror', 'openidconvertothertext');
 
158
                                }
 
159
                                return;
 
160
                        }
 
161
 
 
162
                        $this->setUserUrl($wgUser, $openid_url);
 
163
 
 
164
                        $wgOut->setPageTitle( wfMsg( 'openidconvertsuccess' ) );
 
165
                        $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
166
                        $wgOut->setArticleRelated( false );
 
167
                        $wgOut->addWikiText( wfMsg( 'openidconvertsuccesstext', $openid_url ) );
 
168
                        $wgOut->returnToMain( );
 
169
                }
 
170
        }
 
171
}