[MediaWiki-commits] [Gerrit] Remove globals from special page execution - change (mediawiki...CommunityTwitter)

2013-07-04 Thread FastLizard4 (Code Review)
FastLizard4 has submitted this change and it was merged.

Change subject: Remove globals from special page execution
..


Remove globals from special page execution

Finally, all of the globals in the CommunityTwitter special page are
gone, replaced with variables retrieved from ContextSource. With that
done, we should be able to move on to improving the extension's
functionality instead of improving what's already there.

Change-Id: Id7d2984e66bdf998bdd11249abae5824c8a23591
---
M CommunityTwitter_body.php
1 file changed, 51 insertions(+), 56 deletions(-)

Approvals:
  RAN1: Verified; Looks good to me, approved



diff --git a/CommunityTwitter_body.php b/CommunityTwitter_body.php
index 257cbd5..8c12512 100755
--- a/CommunityTwitter_body.php
+++ b/CommunityTwitter_body.php
@@ -32,33 +32,31 @@
 
 class CommunityTwitter extends SpecialPage {
 
-   function CommunityTwitter() {
-   global $wgUser;
-   global $individualAccs;
+   // Variable to keep track of whether individual accounts are used by 
each user
+   private $individualAccs;
 
-   $individualAccs = true;
+   function __construct() {
+   $this->individualAccs = true;
 
// In case you want to change the name of the special page, you 
have to edit CommunityTwitter_body.php and CommunityTwitter.php
-   SpecialPage::SpecialPage('CommunityTwitter', 'twitter');
-   $this->skin = $wgUser->getSkin();
+   SpecialPage::__construct('CommunityTwitter', 'twitter');
}
 
function execute($query) {
-   global $wgOut;
-   global $wgUser;
-   global $wgScriptPath;
-   global $wgRequest;
-   global $wgDBserver;
-   global $wgDBuser;
-   global $wgDBpassword;
-   global $wgDBname;
+   // Get context variables
+   $output = $this->getOutput();
+   $user = $this->getUser();
+   $request = $this->getRequest();
+   $title = $this->getTitle();
+   $language = $this->getLanguage();
+
+   // Get extension configuration variables
global $ctTableName;
global $ctDefaultAccount;
global $ctDisplayCoordinates;
global $ctLat;
global $ctLong;
global $ctAllowedGroup;
-   global $individualAccs;
 
if (!isset($ctTableName) || !isset($ctDefaultAccount) || 
!isset($ctDisplayCoordinates)) die ("Configure LocalSettings.php first.");
 
@@ -67,7 +65,7 @@
$this->setHeaders();
 
// Grant access to users with twitter right only. All others 
receive error pages.
-   if ( !$this->userCanExecute( $wgUser ) ) {
+   if ( !$this->userCanExecute( $user ) ) {
// User does not have rights or is not logged in
 
$tGroupRights = SpecialPage::getTitleFor( 
'ListGroupRights' );
@@ -77,10 +75,10 @@
array( 'User', 'makeGroupLinkWiki' ),
User::getGroupsWithPermission( 'twitter' )
);
-   $groupsList = $this->getLanguage()->commaList( $groups 
);
+   $groupsList = $language->commaList( $groups );
 
 
-   if ( !$wgUser->isAnon() )
+   if ( !$user->isAnon() )
{
// Logged in, but no rights
 
@@ -102,9 +100,9 @@
 
}
 
-   } else if ( $wgUser->isBlocked() ) {
+   } else if ( $user->isBlocked() ) {
// isBlocked is not checked in userCanExecute, make 
sure blocked users aren't tweeting.
-   throw new UserBlockedError( $wgUser->getBlock() );
+   throw new UserBlockedError( $user->getBlock() );
 
} else {
// Presumably the user is allowed
@@ -121,16 +119,16 @@
// Query for individual account(s)
$sql_individual = sprintf("SELECT app_name, 
consumer_key, consumer_secret, access_token, access_token_secret FROM %s 
NATURAL JOIN %s ".

"JOIN %s ON (user_id=ug_user) WHERE `ug_group` = '%s' AND `active` = 1 
AND (`user_id` = %d OR `user_id` = 0);",
-   
$dbr->tableName("user"), $ctTableName, $dbr->tableName("user_groups"), 
$ctAllowedGroup, $wgUser->getId());
+   
$dbr->tableName("user"), $ctTableName, $dbr->tableName("user_groups"), 
$ctAllowedGroup, 

[MediaWiki-commits] [Gerrit] Remove globals from special page execution - change (mediawiki...CommunityTwitter)

2013-06-25 Thread RAN1 (Code Review)
RAN1 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70452


Change subject: Remove globals from special page execution
..

Remove globals from special page execution

Finally, all of the globals in the CommunityTwitter special page are
gone, replaced with variables retrieved from ContextSource. With that
done, we should be able to move on to improving the extension's
functionality instead of improving what's already there.

Change-Id: Id7d2984e66bdf998bdd11249abae5824c8a23591
---
M CommunityTwitter_body.php
1 file changed, 51 insertions(+), 56 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommunityTwitter 
refs/changes/52/70452/1

diff --git a/CommunityTwitter_body.php b/CommunityTwitter_body.php
index 257cbd5..8c12512 100755
--- a/CommunityTwitter_body.php
+++ b/CommunityTwitter_body.php
@@ -32,33 +32,31 @@
 
 class CommunityTwitter extends SpecialPage {
 
-   function CommunityTwitter() {
-   global $wgUser;
-   global $individualAccs;
+   // Variable to keep track of whether individual accounts are used by 
each user
+   private $individualAccs;
 
-   $individualAccs = true;
+   function __construct() {
+   $this->individualAccs = true;
 
// In case you want to change the name of the special page, you 
have to edit CommunityTwitter_body.php and CommunityTwitter.php
-   SpecialPage::SpecialPage('CommunityTwitter', 'twitter');
-   $this->skin = $wgUser->getSkin();
+   SpecialPage::__construct('CommunityTwitter', 'twitter');
}
 
function execute($query) {
-   global $wgOut;
-   global $wgUser;
-   global $wgScriptPath;
-   global $wgRequest;
-   global $wgDBserver;
-   global $wgDBuser;
-   global $wgDBpassword;
-   global $wgDBname;
+   // Get context variables
+   $output = $this->getOutput();
+   $user = $this->getUser();
+   $request = $this->getRequest();
+   $title = $this->getTitle();
+   $language = $this->getLanguage();
+
+   // Get extension configuration variables
global $ctTableName;
global $ctDefaultAccount;
global $ctDisplayCoordinates;
global $ctLat;
global $ctLong;
global $ctAllowedGroup;
-   global $individualAccs;
 
if (!isset($ctTableName) || !isset($ctDefaultAccount) || 
!isset($ctDisplayCoordinates)) die ("Configure LocalSettings.php first.");
 
@@ -67,7 +65,7 @@
$this->setHeaders();
 
// Grant access to users with twitter right only. All others 
receive error pages.
-   if ( !$this->userCanExecute( $wgUser ) ) {
+   if ( !$this->userCanExecute( $user ) ) {
// User does not have rights or is not logged in
 
$tGroupRights = SpecialPage::getTitleFor( 
'ListGroupRights' );
@@ -77,10 +75,10 @@
array( 'User', 'makeGroupLinkWiki' ),
User::getGroupsWithPermission( 'twitter' )
);
-   $groupsList = $this->getLanguage()->commaList( $groups 
);
+   $groupsList = $language->commaList( $groups );
 
 
-   if ( !$wgUser->isAnon() )
+   if ( !$user->isAnon() )
{
// Logged in, but no rights
 
@@ -102,9 +100,9 @@
 
}
 
-   } else if ( $wgUser->isBlocked() ) {
+   } else if ( $user->isBlocked() ) {
// isBlocked is not checked in userCanExecute, make 
sure blocked users aren't tweeting.
-   throw new UserBlockedError( $wgUser->getBlock() );
+   throw new UserBlockedError( $user->getBlock() );
 
} else {
// Presumably the user is allowed
@@ -121,16 +119,16 @@
// Query for individual account(s)
$sql_individual = sprintf("SELECT app_name, 
consumer_key, consumer_secret, access_token, access_token_secret FROM %s 
NATURAL JOIN %s ".

"JOIN %s ON (user_id=ug_user) WHERE `ug_group` = '%s' AND `active` = 1 
AND (`user_id` = %d OR `user_id` = 0);",
-   
$dbr->tableName("user"), $ctTableName, $dbr->tableName("user_groups"), 
$ctAllowedGroup, $wgUser->getId());
+   
$dbr->tableN