Index: trunk/extensions/OpenID/SpecialOpenID.body.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | class SpecialOpenID extends SpecialPage { |
34 | 34 | |
35 | 35 | function getOpenIDStore( $storeType, $prefix, $options ) { |
36 | | - global $wgOut; |
| 36 | + global $wgOut, $wgMemc, $wgDBtype; |
37 | 37 | |
38 | 38 | # FIXME: support other kinds of store |
39 | 39 | # XXX: used to support memc, now use memcached from php-openid |
— | — | @@ -49,6 +49,30 @@ |
50 | 50 | } |
51 | 51 | return new Auth_OpenID_FileStore( $options['path'] ); |
52 | 52 | |
| 53 | + case 'db': |
| 54 | + if ( $wgDBtype == 'sqlite' ) { |
| 55 | + $db = new MediaWikiOpenIDDatabaseConnection( wfGetDB( DB_MASTER ) ); |
| 56 | + require_once( 'Auth/OpenID/SQLiteStore.php' ); |
| 57 | + return new Auth_OpenID_SQLiteStore( $db ); |
| 58 | + } else { |
| 59 | + $lb = wfGetLBFactory()->newMainLB(); |
| 60 | + $db = new MediaWikiOpenIDDatabaseConnection( $lb->getConnection( DB_MASTER ) ); |
| 61 | + switch( $wgDBtype ) { |
| 62 | + case 'mysql': |
| 63 | + require_once( 'Auth/OpenID/MySQLStore.php' ); |
| 64 | + return new Auth_OpenID_MySQLStore( $db ); |
| 65 | + case 'postgres': |
| 66 | + require_once( 'Auth/OpenID/PostgreSQLStore.php' ); |
| 67 | + return new Auth_OpenID_PostgreSQLStore( $db ); |
| 68 | + default: |
| 69 | + $wgOut->showErrorPage( 'openidconfigerror', 'openidconfigerrortext' ); |
| 70 | + return NULL; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + case 'memcached': |
| 75 | + return new MediaWikiOpenIDMemcachedStore( $wgMemc ); |
| 76 | + |
53 | 77 | default: |
54 | 78 | $wgOut->showErrorPage( 'openidconfigerror', 'openidconfigerrortext' ); |
55 | 79 | } |
Index: trunk/extensions/OpenID/OpenID.setup.php |
— | — | @@ -55,7 +55,8 @@ |
56 | 56 | $wgOpenIDServerForceAllowTrust = array(); |
57 | 57 | |
58 | 58 | /** |
59 | | - * Where to store transitory data. Only supported type is 'file'. |
| 59 | + * Where to store transitory data. |
| 60 | + * Supported types are 'file', 'memcached', 'db'. |
60 | 61 | */ |
61 | 62 | $wgOpenIDServerStoreType = 'file'; |
62 | 63 | |
— | — | @@ -91,7 +92,8 @@ |
92 | 93 | $wgOpenIDConsumerDeny = array(); |
93 | 94 | |
94 | 95 | /** |
95 | | - * Where to store transitory data. Only supported type is 'file'. |
| 96 | + * Where to store transitory data. |
| 97 | + * Supported types are 'file', 'memcached', 'db'. |
96 | 98 | */ |
97 | 99 | $wgOpenIDConsumerStoreType = 'file'; |
98 | 100 | |
— | — | @@ -177,6 +179,9 @@ |
178 | 180 | # Gets stored in the session, needs to be reified before our setup |
179 | 181 | $wgAutoloadClasses['Auth_OpenID_CheckIDRequest'] = OpenIDGetServerPath(); |
180 | 182 | |
| 183 | +$wgAutoloadClasses['MediaWikiOpenIDDatabaseConnection'] = $dir . 'DatabaseConnection.php'; |
| 184 | +$wgAutoloadClasses['MediaWikiOpenIDMemcachedStore'] = $dir . 'MemcachedStore.php'; |
| 185 | + |
181 | 186 | $wgHooks['PersonalUrls'][] = 'OpenIDHooks::onPersonalUrls'; |
182 | 187 | $wgHooks['BeforePageDisplay'][] = 'OpenIDHooks::onBeforePageDisplay'; |
183 | 188 | $wgHooks['ArticleViewHeader'][] = 'OpenIDHooks::onArticleViewHeader'; |
Index: trunk/extensions/OpenID/TODO |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | + Add a Storage class for $wgMemc |
3 | | -+ Prevent running OpenIDLogin, OpenIDFinish when you're already logged in |
| 3 | ++ Prevent running OpenIDLogin when you're already logged in |
4 | 4 | + Add a server mode |
5 | 5 | + Prevent serving OpenID accounts |
6 | 6 | + Prevent trusting the same server |
— | — | @@ -36,8 +36,8 @@ |
37 | 37 | like http://getopenid.com/evanprodromou or |
38 | 38 | http://profile.typekey.com/EvanProdromou/ |
39 | 39 | + Allow specifying a FileStore |
40 | | -- Allow specifying a MySQLStore |
41 | | -- Allow specifying a memcached store |
| 40 | ++ Allow specifying a MySQLStore |
| 41 | ++ Allow specifying a memcached store |
42 | 42 | + Fall back to FileStore if Memc is bogus |
43 | 43 | + Unit test for MemcStore |
44 | 44 | + for just-a-hostname OpenIDs, if the first element is not |
Index: trunk/extensions/OpenID/MemcachedStore.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once( 'Auth/OpenID/MemcachedStore.php' ); |
| 5 | + |
| 6 | +class MediaWikiOpenIDMemcachedStore extends Auth_OpenID_MemcachedStore { |
| 7 | + |
| 8 | + function __construct( $connection ) { |
| 9 | + $this->connection = $connection; |
| 10 | + } |
| 11 | + |
| 12 | + function storeAssociation( $server_url, $association ) { |
| 13 | + $associationKey = $this->associationKey( $server_url, |
| 14 | + $association->handle ); |
| 15 | + $serverKey = $this->associationServerKey( $server_url ); |
| 16 | + |
| 17 | + $serverAssociations = $this->connection->get( $serverKey ); |
| 18 | + |
| 19 | + if ( !$serverAssociations ) { |
| 20 | + $serverAssociations = array(); |
| 21 | + } |
| 22 | + |
| 23 | + $serverAssociations[$association->issued] = $associationKey; |
| 24 | + |
| 25 | + $this->connection->set( $serverKey, $serverAssociations ); |
| 26 | + |
| 27 | + $this->connection->set( $associationKey, $association, |
| 28 | + $association->issued + $association->lifetime ); |
| 29 | + } |
| 30 | + |
| 31 | + function getAssociation( $server_url, $handle = null ) { |
| 32 | + if ( $handle !== null ) { |
| 33 | + $association = $this->connection->get( |
| 34 | + $this->associationKey( $server_url, $handle ) ); |
| 35 | + return $association ? $association : null; |
| 36 | + } |
| 37 | + |
| 38 | + $serverKey = $this->associationServerKey( $server_url ); |
| 39 | + |
| 40 | + $serverAssociations = $this->connection->get( $serverKey ); |
| 41 | + if ( !$serverAssociations ) { |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + $keys = array_keys( $serverAssociations ); |
| 46 | + sort( $keys ); |
| 47 | + $lastKey = $serverAssociations[array_pop( $keys )]; |
| 48 | + |
| 49 | + $association = $this->connection->get( $lastKey ); |
| 50 | + return $association ? $association : null; |
| 51 | + } |
| 52 | + |
| 53 | + function removeAssociation( $server_url, $handle ) { |
| 54 | + $serverKey = $this->associationServerKey( $server_url ); |
| 55 | + $associationKey = $this->associationKey( $server_url, |
| 56 | + $handle ); |
| 57 | + |
| 58 | + $serverAssociations = $this->connection->get( $serverKey ); |
| 59 | + if ( !$serverAssociations ) { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + $serverAssociations = array_flip( $serverAssociations ); |
| 64 | + if ( !array_key_exists( $associationKey, $serverAssociations ) ) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | + unset( $serverAssociations[$associationKey] ); |
| 69 | + $serverAssociations = array_flip( $serverAssociations ); |
| 70 | + |
| 71 | + $this->connection->set( $serverKey, $serverAssociations ); |
| 72 | + |
| 73 | + return $this->connection->delete( $associationKey ); |
| 74 | + } |
| 75 | + |
| 76 | + function useNonce( $server_url, $timestamp, $salt ) { |
| 77 | + global $Auth_OpenID_SKEW; |
| 78 | + |
| 79 | + if ( abs( $timestamp - time() ) > $Auth_OpenID_SKEW ) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + return $this->connection->add( |
| 84 | + 'openid_nonce_' . sha1( $server_url ) . '_' . sha1( $salt ), |
| 85 | + 1, $Auth_OpenID_SKEW ); |
| 86 | + } |
| 87 | + |
| 88 | +} |
Property changes on: trunk/extensions/OpenID/MemcachedStore.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 89 | + native |
Index: trunk/extensions/OpenID/DatabaseConnection.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once( 'Auth/OpenID/DatabaseConnection.php' ); |
| 5 | +require_once( 'PEAR.php' ); |
| 6 | + |
| 7 | +class MediaWikiOpenIDDatabaseConnection extends Auth_OpenID_DatabaseConnection { |
| 8 | + |
| 9 | + function __construct( $db ) { |
| 10 | + $this->db = $db; |
| 11 | + } |
| 12 | + |
| 13 | + function autoCommit( $mode ) { |
| 14 | + $old = $this->db->getFlag( DBO_TRX ); |
| 15 | + if ( $mode ) { |
| 16 | + $this->db->setFlag( DBO_TRX ); |
| 17 | + } else { |
| 18 | + $this->db->clearFlag( DBO_TRX ); |
| 19 | + } |
| 20 | + return $old; |
| 21 | + } |
| 22 | + |
| 23 | + function query( $sql, $params = array() ) { |
| 24 | + try { |
| 25 | + $res = $this->db->safeQuery( $sql, $params ); |
| 26 | + } catch( DBQueryError $e ) { |
| 27 | + $ret = PEAR::raiseError( $e->getMessage(), 1, PEAR_ERROR_RETURN ); |
| 28 | + } |
| 29 | + return $res; |
| 30 | + } |
| 31 | + |
| 32 | + function begin() { |
| 33 | + $this->db->commit(); |
| 34 | + } |
| 35 | + |
| 36 | + function commit() { |
| 37 | + $this->db->commit(); |
| 38 | + } |
| 39 | + |
| 40 | + function rollback() { |
| 41 | + $this->db->rollback(); |
| 42 | + } |
| 43 | + |
| 44 | + function getOne( $sql, $params = array() ) { |
| 45 | + $res = $this->query( $sql, $params ); |
| 46 | + |
| 47 | + if ( !$res instanceof ResultWrapper ) |
| 48 | + return $res; |
| 49 | + if ( !$res->numRows() ) |
| 50 | + return false; |
| 51 | + |
| 52 | + $row = $res->fetchRow(); |
| 53 | + if ( $row !== false ) { |
| 54 | + $res->free(); |
| 55 | + return reset( $row ); |
| 56 | + } else { |
| 57 | + return false; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + function getRow( $sql, $params = array() ) { |
| 62 | + $res = $this->query( $sql, $params ); |
| 63 | + |
| 64 | + if ( !$res instanceof ResultWrapper ) |
| 65 | + return $res; |
| 66 | + if ( !$res->numRows() ) |
| 67 | + return false; |
| 68 | + |
| 69 | + $row = $res->fetchRow(); |
| 70 | + $res->free(); |
| 71 | + return $row; |
| 72 | + } |
| 73 | + |
| 74 | + function getAll( $sql, $params = array() ) { |
| 75 | + $res = $this->query( $sql, $params ); |
| 76 | + |
| 77 | + if ( !$res instanceof ResultWrapper ) |
| 78 | + return $res; |
| 79 | + if ( !$res->numRows() ) |
| 80 | + return false; |
| 81 | + |
| 82 | + $ret = array(); |
| 83 | + foreach( $res as $row ) { |
| 84 | + $ret[] = (array)$row; |
| 85 | + } |
| 86 | + return $ret; |
| 87 | + } |
| 88 | +} |
Property changes on: trunk/extensions/OpenID/DatabaseConnection.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 89 | + native |