3
* SpecialOpenIDXRDS.body.php -- Server side of OpenID site
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'))
28
# Outputs a Yadis (http://yadis.org/) XRDS file, saying that this server
29
# supports OpenID and lots of other jazz.
31
class SpecialOpenIDXRDS extends SpecialOpenID {
33
function SpecialOpenIDXRDS() {
34
SpecialPage::SpecialPage("OpenIDXRDS", '', false);
39
function execute($par) {
40
global $wgOut, $wgOpenIDClientOnly;
42
wfLoadExtensionMessages( 'OpenID' );
44
# No server functionality if this site is only a client
45
# Note: special page is un-registered if this flag is set,
46
# so it'd be unusual to get here.
48
if ($wgOpenIDClientOnly) {
49
wfHttpError(404, "Not Found", wfMsg('openidclientonlytext'));
54
$xml_template = array('<?xml version="1.0" encoding="UTF-8"?>',
56
' xmlns:xrds="xri://\$xrds"',
57
' xmlns:openid="http://openid.net/xmlns/1.0"',
58
' xmlns="xri://$xrd*($v*2.0)">',
61
# Check to see if the parameter is really a user name
64
wfHttpError(404, "Not Found", wfMsg('openidnousername'));
67
$user = User::newFromName($par);
69
if (!$user || $user->getID() == 0) {
70
wfHttpError(404, "Not Found", wfMsg('openidbadusername'));
73
// Generate the user page URL.
75
$user_title = Title::makeTitle(NS_USER, $user->getName());
76
$user_url = $user_title->getFullURL();
78
// Generate the OpenID server endpoint URL.
79
$server_title = Title::makeTitle(NS_SPECIAL, 'OpenIDServer');
80
$server_url = $server_title->getFullURL();
82
// Define array of Yadis services to be included in
85
array('uri' => $server_url,
87
'types' => array('http://openid.net/signon/1.0',
88
'http://openid.net/sreg/1.0',
89
'http://specs.openid.net/auth/2.0/signon'),
90
'delegate' => $user_url),
93
// Generate <Service> elements into $service_text.
95
foreach ($services as $service) {
97
foreach ($service['types'] as $type_uri) {
98
$types[] = ' <Type>'.$type_uri.'</Type>';
100
$service_text .= implode("\n",
101
array(' <Service priority="'.$service['priority'].'">',
102
' <URI>'.$server_url.'</URI>',
103
implode("\n", $types),
109
// Print content-type and XRDS XML.
110
header("Content-Type", "application/xrds+xml");
111
print implode("\n", $xml_template);
113
print implode("\n", array("</XRD>", "</xrds:XRDS>"));
b'\\ No newline at end of file'