r44206 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44205‎ | r44206 | r44207 >
Date:00:05, 4 December 2008
Author:werdna
Status:deferred
Tags:
Comment:
Add LinkOpenID extension, by Michael Holzt, because he asked nicely.
Modified paths:
  • /trunk/extensions/LinkOpenID (added) (history)
  • /trunk/extensions/LinkOpenID/LinkOpenID.i18n.php (added) (history)
  • /trunk/extensions/LinkOpenID/LinkOpenID.php (added) (history)

Diff [purge]

Index: trunk/extensions/LinkOpenID/LinkOpenID.i18n.php
@@ -0,0 +1,42 @@
 2+<?php
 3+/**
 4+ * LinkOpenID.i18n.php - Internationalisation for LinkOpenID
 5+ *
 6+ * @author Michael Holzt <kju@fqdn.org>
 7+ * @copyright 2008 Michael Holzt
 8+ * @license GNU General Public License 2.0
 9+ */
 10+
 11+$messages = array();
 12+
 13+/** English
 14+ * @author Michael Holzt <kju@fqdn.org>
 15+ */
 16+$messages['en'] = array(
 17+ # for Special:Version
 18+ 'linkopenid-desc' => 'Allow users to link their account to an external OpenID',
 19+
 20+ # for Special:Preferences
 21+ 'linkopenid-prefs' => 'OpenID',
 22+ 'linkopenid-prefstext-pre' => 'If you have a OpenID from an external provider you can specify it here. This allows you to use your userpage as a OpenID as well.',
 23+ 'linkopenid-prefstext-openid' => 'Your OpenID:',
 24+ 'linkopenid-prefstext-v1url' => 'Server-URL for OpenID Version 1.1:',
 25+ 'linkopenid-prefstext-v2url' => 'Server-URL for OpenID Version 2:'
 26+);
 27+
 28+/** German
 29+ * @author Michael Holzt <kju@fqdn.org>
 30+ */
 31+
 32+$messages['de'] = array(
 33+ # for Special:Version
 34+ 'linkopenid-desc' => 'Erlaubt Benutzern eine externe OpenID ihrem Account zuzuordnen',
 35+
 36+ # for Special:Preferences
 37+ 'linkopenid-prefs' => 'OpenID',
 38+ 'linkopenid-prefstext-pre' => 'Wenn Sie eine OpenID bei einem externen Anbieter besitzen, können Sie diese hier angeben. Dies ermöglicht Ihnen die alternative Nutzung Ihrer Benutzerseite als OpenID.',
 39+ 'linkopenid-prefstext-openid' => 'Ihre OpenID:',
 40+ 'linkopenid-prefstext-v1url' => 'Server-URL für OpenID Version 1.1:',
 41+ 'linkopenid-prefstext-v2url' => 'Server-URL für OpenID Version 2:'
 42+);
 43+?>
Index: trunk/extensions/LinkOpenID/LinkOpenID.php
@@ -0,0 +1,127 @@
 2+<?php
 3+/**
 4+ * LinkOpenID.php - allow users to link their account to an external OpenID
 5+ *
 6+ * @author Michael Holzt <kju@fqdn.org>
 7+ * @copyright 2008 Michael Holzt
 8+ * @license GNU General Public License 2.0
 9+ */
 10+
 11+if ( !defined('MEDIAWIKI')) {
 12+ echo('This file is an extension for the MediaWiki software and cannot be used standalone.\n');
 13+ die(1);
 14+}
 15+
 16+$wgExtensionCredits['other'][] = array(
 17+ 'name' => 'LinkOpenID',
 18+ 'author' => 'Michael Holzt',
 19+ 'description' => 'allow users to link their account to an external OpenID',
 20+ 'descriptionmsg' => 'linkopenid-desc'
 21+);
 22+
 23+$wgHooks['ArticleViewHeader'][] = 'wfLinkOpenIDViewHeader';
 24+$wgHooks['InitPreferencesForm'][] = 'wfLinkOpenIDInitPrefs';
 25+$wgHooks['RenderPreferencesForm'][] = 'wfLinkOpenIDRenderPrefs';
 26+$wgHooks['SavePreferences'][] = 'wfLinkOpenIDSavePrefs';
 27+$wgHooks['ResetPreferences'][] = 'wfLinkOpenIDResetprefs';
 28+
 29+$dir = dirname(__FILE__) . '/';
 30+$wgExtensionMessagesFiles['LinkOpenID'] = $dir . 'LinkOpenID.i18n.php';
 31+
 32+/* --- */
 33+
 34+function wfLinkOpenIDViewHeader($article)
 35+{
 36+ global $wgOut;
 37+
 38+ /* We only care about the main page of any user */
 39+ $nt = $article->getTitle();
 40+ if ( $nt && $nt->getNamespace() == NS_USER &&
 41+ strpos($nt->getText(), '/') === false ) {
 42+
 43+ $user = User::newFromName($nt->getText());
 44+ if ( $user && $user->getID() != 0) {
 45+
 46+ $openid = $user->getOption('wflinkopenid_openid');
 47+
 48+ if ( $openid != '' ) {
 49+ $v1url = $user->getOption('wflinkopenid_v1url');
 50+ $v2url = $user->getOption('wflinkopenid_v2url');
 51+
 52+ if ( $v1url != '' ) {
 53+ $wgOut->addLink( array('rel' => 'openid.server', 'href' => $v1url) );
 54+ $wgOut->addLink( array('rel' => 'openid.delegate', 'href' => $openid) );
 55+ }
 56+
 57+ if ( $v2url != '' ) {
 58+ $wgOut->addLink( array('rel' => 'openid2.provider', 'href' => $v2url) );
 59+ $wgOut->addLink( array('rel' => 'openid2.local_id', 'href' => $openid) );
 60+ }
 61+ }
 62+ }
 63+ }
 64+
 65+ return TRUE;
 66+}
 67+
 68+/* --- */
 69+
 70+function wfLinkOpenIDInitPrefs($prefs, $request) {
 71+ $prefs->wfLinkOpenID = Array();
 72+ $prefs->wfLinkOpenID['openid'] = $request->getVal('wflinkopenid_openid');
 73+ $prefs->wfLinkOpenID['v1url'] = $request->getVal('wflinkopenid_v1url');
 74+ $prefs->wfLinkOpenID['v2url'] = $request->getVal('wflinkopenid_v2url');
 75+ return TRUE;
 76+}
 77+
 78+/* --- */
 79+
 80+function wfLinkOpenIDRenderPrefs($prefs, $out) {
 81+ wfLoadExtensionMessages( 'LinkOpenID' );
 82+
 83+ $out->addHTML( "<fieldset><legend>" .
 84+ wfMsgHtml( 'linkopenid-prefs' ) .
 85+ "</legend>");
 86+
 87+ $out->addWikiMsg( 'linkopenid-prefstext-pre' );
 88+
 89+ $out->addHTML(
 90+ "<table>" .
 91+
 92+ "<tr><td>" . wfMsgHtml( 'linkopenid-prefstext-openid' ) . "</td><td>" .
 93+ "<input type='text' name='wflinkopenid_openid' size='60' value='" .
 94+ htmlentities($prefs->wfLinkOpenID['openid']) . "'></td></tr>" .
 95+
 96+ "<tr><td>" . wfMsgHtml( 'linkopenid-prefstext-v1url' ) . "</td><td>" .
 97+ "<input type='text' name='wflinkopenid_v1url' size='60' value='" .
 98+ htmlentities($prefs->wfLinkOpenID['v1url']) . "'></td></tr>" .
 99+
 100+ "<tr><td>" . wfMsgHtml( 'linkopenid-prefstext-v2url' ) . "</td><td>" .
 101+ "<input type='text' name='wflinkopenid_v2url' size='60' value='" .
 102+ htmlentities($prefs->wfLinkOpenID['v2url']) . "'></td></tr>" .
 103+ "</table></fieldset>"
 104+ );
 105+
 106+ return TRUE;
 107+}
 108+
 109+/* --- */
 110+
 111+function wfLinkOpenIDSavePrefs($form, $user, &$message) {
 112+ $user->setOption('wflinkopenid_openid', $form->wfLinkOpenID['openid'] );
 113+ $user->setOption('wflinkopenid_v1url', $form->wfLinkOpenID['v1url'] );
 114+ $user->setOption('wflinkopenid_v2url', $form->wfLinkOpenID['v2url'] );
 115+ return TRUE;
 116+}
 117+
 118+/* --- */
 119+
 120+function wfLinkOpenIDResetPrefs($prefs, $user) {
 121+ $prefs->wfLinkOpenID = Array();
 122+ $prefs->wfLinkOpenID['openid'] = $user->getOption('wflinkopenid_openid');
 123+ $prefs->wfLinkOpenID['v1url'] = $user->getOption('wflinkopenid_v1url');
 124+ $prefs->wfLinkOpenID['v2url'] = $user->getOption('wflinkopenid_v2url');
 125+ return TRUE;
 126+}
 127+
 128+?>

Status & tagging log