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

« back to all changes in this revision

Viewing changes to include/SpecialOpenIDXRDS.body.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-03-25 19:36:16 UTC
  • Revision ID: james.westby@ubuntu.com-20090325193616-wao3b2mgbb0qyv7i
Tags: 1.6
* Updated extensions.
* Added OpenID extension.
* Added README.Debian.
Closes: #516693
* Bumped standards version to 3.8.1
* Bumped compatibility level to 7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
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>
 
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
# Outputs a Yadis (http://yadis.org/) XRDS file, saying that this server
 
29
# supports OpenID and lots of other jazz.
 
30
 
 
31
class SpecialOpenIDXRDS extends SpecialOpenID {
 
32
 
 
33
        function SpecialOpenIDXRDS() {
 
34
                SpecialPage::SpecialPage("OpenIDXRDS", '', false);
 
35
        }
 
36
 
 
37
        # $par is a user name
 
38
 
 
39
        function execute($par) {
 
40
                global $wgOut, $wgOpenIDClientOnly;
 
41
 
 
42
                wfLoadExtensionMessages( 'OpenID' );
 
43
                
 
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.
 
47
                
 
48
                if ($wgOpenIDClientOnly) {
 
49
                        wfHttpError(404, "Not Found", wfMsg('openidclientonlytext'));
 
50
                        return;
 
51
                }
 
52
 
 
53
                // XRDS preamble XML.
 
54
                $xml_template = array('<?xml version="1.0" encoding="UTF-8"?>',
 
55
                                                          '<xrds:XRDS',
 
56
                                                          '  xmlns:xrds="xri://\$xrds"',
 
57
                                                          '  xmlns:openid="http://openid.net/xmlns/1.0"',
 
58
                                                          '  xmlns="xri://$xrd*($v*2.0)">',
 
59
                                                          '<XRD>');
 
60
 
 
61
                # Check to see if the parameter is really a user name
 
62
 
 
63
                if (!$par) {
 
64
                        wfHttpError(404, "Not Found", wfMsg('openidnousername'));
 
65
                }
 
66
 
 
67
                $user = User::newFromName($par);
 
68
 
 
69
                if (!$user || $user->getID() == 0) {
 
70
                        wfHttpError(404, "Not Found", wfMsg('openidbadusername'));
 
71
                }
 
72
 
 
73
                // Generate the user page URL.
 
74
 
 
75
                $user_title = Title::makeTitle(NS_USER, $user->getName());
 
76
                $user_url = $user_title->getFullURL();
 
77
 
 
78
                // Generate the OpenID server endpoint URL.
 
79
                $server_title = Title::makeTitle(NS_SPECIAL, 'OpenIDServer');
 
80
                $server_url = $server_title->getFullURL();
 
81
 
 
82
                // Define array of Yadis services to be included in
 
83
                // the XRDS output.
 
84
                $services = array(
 
85
                                                  array('uri' => $server_url,
 
86
                                                                'priority' => '0',
 
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),
 
91
                                                  );
 
92
 
 
93
                // Generate <Service> elements into $service_text.
 
94
                $service_text = "\n";
 
95
                foreach ($services as $service) {
 
96
                    $types = array();
 
97
                    foreach ($service['types'] as $type_uri) {
 
98
                        $types[] = '    <Type>'.$type_uri.'</Type>';
 
99
                    }
 
100
                    $service_text .= implode("\n",
 
101
                                                                         array('  <Service priority="'.$service['priority'].'">',
 
102
                                                                                   '    <URI>'.$server_url.'</URI>',
 
103
                                                                                   implode("\n", $types),
 
104
                                                                                   '  </Service>'));
 
105
                }
 
106
 
 
107
                $wgOut->disable();
 
108
 
 
109
                // Print content-type and XRDS XML.
 
110
                header("Content-Type", "application/xrds+xml");
 
111
                print implode("\n", $xml_template);
 
112
                print $service_text;
 
113
                print implode("\n", array("</XRD>", "</xrds:XRDS>"));
 
114
        }
 
115
}
 
 
b'\\ No newline at end of file'