Index: trunk/extensions/TwitterLogin/twitter_user.sql |
— | — | @@ -1,6 +0,0 @@ |
2 | | -CREATE TABLE IF NOT EXISTS `twitter_user` ( |
3 | | - `user_id` int(10) unsigned NOT NULL, |
4 | | - `twitter_id` varchar(255) NOT NULL, |
5 | | - PRIMARY KEY (`user_id`), |
6 | | - UNIQUE KEY `twitter_id` (`twitter_id`) |
7 | | -); |
Index: trunk/extensions/TwitterLogin/TwitterLogin.i18n.php |
— | — | @@ -22,3 +22,14 @@ |
23 | 23 | 'twitterlogin-couldnotconnect' => 'Could not connect to Twitter. Refresh the page or try again later.' |
24 | 24 | ); |
25 | 25 | |
| 26 | +/** Message Documentation |
| 27 | + * @author David Raison |
| 28 | + */ |
| 29 | +$messages['qqq'] = array( |
| 30 | + 'twitterlogin' => 'Link of the special page', |
| 31 | + 'twitterlogin-signup' => 'Explains users they can register and sign up to the wiki with their twitter account. Used on specialpage default.', |
| 32 | + 'twiterlogin-tietoaccount' => 'Message displayed on the default specialpage when a logged in user visits it. (NOT in use)', |
| 33 | + 'twitterlogin-desc' => 'Description of the extension, see setup file', |
| 34 | + 'twitterlogin-alreadyloggedin' => 'Message displayed on the default specialpage. tietoaccount replacement.', |
| 35 | + 'twitterlogin-couldnotconnect' => 'Tell the user the connection to twitter oauth server did not work.' |
| 36 | +); |
Index: trunk/extensions/TwitterLogin/schema/twitter_user.patch.user_id.sql |
— | — | @@ -0,0 +1 @@ |
| 2 | +ALTER TABLE `twitter_user` CHANGE `user_id` `tl_user_id` int(10) unsigned; |
Index: trunk/extensions/TwitterLogin/schema/twitter_user.patch.twitter_id.sql |
— | — | @@ -0,0 +1 @@ |
| 2 | +ALTER TABLE `twitter_user` CHANGE `twitter_id` `tl_twitter_id` varchar(255); |
Index: trunk/extensions/TwitterLogin/schema/twitter_user.sql |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +CREATE TABLE IF NOT EXISTS `twitter_user` ( |
| 3 | + `tl_user_id` int(10) unsigned NOT NULL, |
| 4 | + `tl_twitter_id` varchar(255) NOT NULL, |
| 5 | + PRIMARY KEY (`tl_user_id`), |
| 6 | + UNIQUE KEY `tl_twitter_id` (`tl_twitter_id`) |
| 7 | +); |
Index: trunk/extensions/TwitterLogin/TwitterLogin.php |
— | — | @@ -48,8 +48,12 @@ |
49 | 49 | $wgHooks['UserLoadFromSession'][] = array($stl,'efTwitterAuth'); |
50 | 50 | $wgHooks['UserLogoutComplete'][] = array($stl,'efTwitterLogout'); |
51 | 51 | |
52 | | -function efSetupTwitterLoginSchema() { |
| 52 | +function efSetupTwitterLoginSchema( $updater ) { |
53 | 53 | $updater->addExtensionUpdate( array( 'addTable', 'twitter_user', |
54 | | - dirname(__FILE__) . '/twitter_user.sql', true ) ); |
| 54 | + dirname(__FILE__) . '/schema/twitter_user.sql', true ) ); |
| 55 | + $updater->addExtensionUpdate( array( 'modifyField', 'twitter_user','user_id', |
| 56 | + dirname(__FILE__) . '/schema/twitter_user.patch.user_id.sql', true ) ); |
| 57 | + $updater->addExtensionUpdate( array( 'modifyField', 'twitter_user','twitter_id', |
| 58 | + dirname(__FILE__) . '/schema/twitter_user.patch.twitter_id.sql', true ) ); |
55 | 59 | return true; |
56 | 60 | } |
Index: trunk/extensions/TwitterLogin/SpecialTwitterLogin.php |
— | — | @@ -23,7 +23,6 @@ |
24 | 24 | |
25 | 25 | private $_consumerKey; |
26 | 26 | private $_consumerSecret; |
27 | | - private $_oauthCallback; |
28 | 27 | private $_twUserTable = 'twitter_user'; |
29 | 28 | |
30 | 29 | public function __construct(){ |
— | — | @@ -32,20 +31,19 @@ |
33 | 32 | |
34 | 33 | $this->_consumerKey = $wgConsumerKey; |
35 | 34 | $this->_consumerSecret = $wgConsumerSecret; |
36 | | - $this->_oauthCallback = 'https://'.$_SERVER['SERVER_NAME'].$wgScriptPath.'/index.php/Special:TwitterLogin/callback'; |
37 | 35 | } |
38 | 36 | |
39 | 37 | // default method being called by a specialpage |
40 | 38 | public function execute( $parameter ){ |
41 | 39 | switch($parameter){ |
42 | 40 | case 'redirect': |
43 | | - $this->_redirect(); |
| 41 | + $this->_redirect(); |
44 | 42 | break; |
45 | 43 | case 'callback': |
46 | | - $this->_handleCallback(); |
| 44 | + $this->_handleCallback(); |
47 | 45 | break; |
48 | 46 | default: |
49 | | - $this->_default(); |
| 47 | + $this->_default(); |
50 | 48 | break; |
51 | 49 | } |
52 | 50 | |
— | — | @@ -59,7 +57,7 @@ |
60 | 58 | if ( !$wgUser->isLoggedIn() ) { |
61 | 59 | $wgOut->addWikiText( wfMsg( 'twitterlogin-signup') ); |
62 | 60 | |
63 | | - $wgOut->addHTML( '<a href="' . $wgScriptPath . '/index.php/Special:TwitterLogin/redirect">' |
| 61 | + $wgOut->addHTML( '<a href="' . $this->getTitle( 'redirect' )->getFullURL() .'">' |
64 | 62 | .'<img src="' . $wgExtensionAssetsPath . '/TwitterLogin/' . |
65 | 63 | 'images/sign-in-with-twitter-d.png"/></a>' ); |
66 | 64 | } else { |
— | — | @@ -110,10 +108,12 @@ |
111 | 109 | // Creating OAuth object |
112 | 110 | $connection = new TwitterOAuth( $this->_consumerKey, $this->_consumerSecret ); |
113 | 111 | |
| 112 | + // set callback url |
| 113 | + $oauthCallback = $this->getTitle( 'callback' )->getFullURL(); |
| 114 | + |
114 | 115 | // Getting temporary credentials |
115 | | - $request_token = $connection->getRequestToken( $this->_oauthCallback ); |
| 116 | + $request_token = $connection->getRequestToken( $oauthCallback ); |
116 | 117 | |
117 | | - |
118 | 118 | // set returnto url |
119 | 119 | $_SESSION['returnto'] = ( $wgRequest->getText( 'returnto' ) ) ? $wgRequest->getText( 'returnto' ) : ''; |
120 | 120 | |
— | — | @@ -225,7 +225,7 @@ |
226 | 226 | private function _storeInTable( $user, $screen_name ){ |
227 | 227 | $dbw = wfGetDB(DB_MASTER); |
228 | 228 | $dbw->insert( $this->_twUserTable, |
229 | | - array('user_id' => $user->getId(), 'twitter_id' => $screen_name), |
| 229 | + array('tl_user_id' => $user->getId(), 'tl_twitter_id' => $screen_name), |
230 | 230 | __METHOD__, |
231 | 231 | array() |
232 | 232 | ); |
— | — | @@ -234,10 +234,11 @@ |
235 | 235 | // user already exists... was it created from twitter or did it alread exist before? |
236 | 236 | private function _isCreatedFromTwitter( $user ){ |
237 | 237 | $dbr = wfGetDB(DB_SLAVE); |
238 | | - $res = $dbr->select( $this->_twUserTable, 'twitter_id', //'relation' |
239 | | - array( 'user_id' => $user->getId() ), |
| 238 | + $res = $dbr->select( $this->_twUserTable, 'tl_twitter_id', //'tl_relation' |
| 239 | + array( 'tl_user_id' => $user->getId() ), |
240 | 240 | __METHOD__ |
241 | 241 | ); |
| 242 | + |
242 | 243 | if ( $row = $dbr->fetchObject( $res ) ) { |
243 | 244 | $dbr->freeResult( $res ); |
244 | 245 | $user->saveToCache(); |