r59921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59920‎ | r59921 | r59922 >
Date:01:05, 10 December 2009
Author:simetrical
Status:ok (Comments)
Tags:
Comment:
Add new ExternalAuth mechanism, Hardcoded

This just lets you enter the database by hand in LocalSettings.php, for
testing. Now other people can actually test ExternalAuth without having
a vBulletin license. 23 lines not counting whitespace/comments/closing
braces, and took me ~20 minutes to write.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/extauth/Hardcoded.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -75,6 +75,7 @@
7676 'ExternalStoreHttp' => 'includes/ExternalStoreHttp.php',
7777 'ExternalStore' => 'includes/ExternalStore.php',
7878 'ExternalUser' => 'includes/ExternalUser.php',
 79+ 'ExternalUser_Hardcoded' => 'includes/extauth/Hardcoded.php',
7980 'ExternalUser_vB' => 'includes/extauth/vB.php',
8081 'FatalError' => 'includes/Exception.php',
8182 'FakeTitle' => 'includes/FakeTitle.php',
Index: trunk/phase3/includes/extauth/Hardcoded.php
@@ -0,0 +1,77 @@
 2+<?php
 3+
 4+# Copyright (C) 2009 Aryeh Gregor
 5+#
 6+# This program is free software; you can redistribute it and/or modify
 7+# it under the terms of the GNU General Public License as published by
 8+# the Free Software Foundation; either version 2 of the License, or
 9+# (at your option) any later version.
 10+#
 11+# This program is distributed in the hope that it will be useful,
 12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+# GNU General Public License for more details.
 15+#
 16+# You should have received a copy of the GNU General Public License along
 17+# with this program; if not, write to the Free Software Foundation, Inc.,
 18+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+# http://www.gnu.org/copyleft/gpl.html
 20+
 21+/**
 22+ * This class supports external authentication from a literal array dumped in
 23+ * LocalSettings.php. It's mostly useful for testing. Example configuration:
 24+ *
 25+ * $wgExternalAuthType = 'Hardcoded';
 26+ * $wgExternalAuthConf = array(
 27+ * 'Bob Smith' => array(
 28+ * 'password' => 'literal string',
 29+ * 'emailaddress' => 'bob@example.com',
 30+ * ),
 31+ * );
 32+ *
 33+ * Multiple names may be provided. The keys of the inner arrays can be either
 34+ * 'password', or the name of any preference.
 35+ */
 36+class ExternalUser_Hardcoded extends ExternalUser {
 37+ private $mName;
 38+
 39+ protected function initFromName( $name ) {
 40+ global $wgExternalAuthConf;
 41+
 42+ if ( isset( $wgExternalAuthConf[$name] ) ) {
 43+ $this->mName = $name;
 44+ return true;
 45+ }
 46+ return false;
 47+ }
 48+
 49+ protected function initFromId( $id ) {
 50+ return $this->initFromName( $id );
 51+ }
 52+
 53+ public function getId() {
 54+ return $this->mName;
 55+ }
 56+
 57+ public function getName() {
 58+ return $this->mName;
 59+ }
 60+
 61+ public function authenticate( $password ) {
 62+ global $wgExternalAuthConf;
 63+
 64+ return isset( $wgExternalAuthConf[$this->mName]['password'] )
 65+ && $wgExternalAuthConf[$this->mName]['password'] == $password;
 66+ }
 67+
 68+ public function getPref( $pref ) {
 69+ global $wgExternalAuthConf;
 70+
 71+ if ( isset( $wgExternalAuthConf[$this->mName][$pref] ) ) {
 72+ return $wgExternalAuthConf[$this->mName][$pref];
 73+ }
 74+ return null;
 75+ }
 76+
 77+ # TODO: Implement setPref() via regex on LocalSettings. (Just kidding.)
 78+}
Property changes on: trunk/phase3/includes/extauth/Hardcoded.php
___________________________________________________________________
Name: svn:eol-style
179 + native

Comments

#Comment by Tim Starling (talk | contribs)   04:24, 21 December 2009

Cute.

Status & tagging log