FastLizard4 has submitted this change and it was merged.

Change subject: Divide access-error into sub-messages, add block check
......................................................................


Divide access-error into sub-messages, add block check

The communitytwitter-access-error message is problematic. First of all, it 
includes links encoded in
plain HTML, which is not good since it mixes raw code with messages. It also 
makes the messages harder
to translate. This is reflected in how only half of the 18 languages that 
CommunityTwitter has
translations for actually have the communitytwitter-access-error message 
translated. The mixing of
HTML code with messages also obscures the need to translate the titles of each 
link. This translation
is absent in about half of the 9 languages where a translation for the message 
has been submitted.
With a full translation rate of 25%, the communitytwitter-access-error message 
has to be split up so
HTML does not obfuscate translation.

In patchset #3, the error page has been split into two different pages, one 
with a nologin error
(communitytwitter-nologin), and a second with an access error 
(communitytwitter-access-error). Links
have been converted to the appropriate wikitext. In patchset 1, the titles were 
given their own messages,
but this was dropped in patchset 3 for translation convenience.

In patchset #5, the 'twitter' right restriction is now passed to SpecialPage's 
constructor and the
userCanExecute() method is now used to determine whether an access/login error 
has not occurred.

In patchset #6, proper user rights error handling was introduced using the 
communitytwitter-nologin and
communitytwitter-access-error messages, accompanying additional text in these 
messages that elaborated
on group rights. User block checking was also added. This removed the need for 
the communitytwitter-
unknown-error message to bring up the possibility of a user block; blocked 
users no longer have access
to the special page. Patchset #7 introduces message plural checks on the groups 
allowed to tweet.

Change-Id: I4fc3f17879b30bd5bc36b64e317ec56c9ab24ec2
---
M CommunityTwitter.i18n.php
M CommunityTwitter_body.php
2 files changed, 47 insertions(+), 11 deletions(-)

Approvals:
  FastLizard4: Verified; Looks good to me, approved
  RAN1: Verified; Looks good to me, but someone else must approve
  Raimond Spekking: Looks good to me, but someone else must approve



diff --git a/CommunityTwitter.i18n.php b/CommunityTwitter.i18n.php
index a841ead..dc4f265 100755
--- a/CommunityTwitter.i18n.php
+++ b/CommunityTwitter.i18n.php
@@ -43,7 +43,7 @@
        'communitytwitter-desc' => 'Provides a special page, where authorized 
users are able to twitter via a community account without the need of giving 
away login credentials',
        'communitytwitter-no-db-connection' => 'No database connection 
possible.',
        'communitytwitter-no-db' => 'Database does not exist.',
-       'communitytwitter-unknown-error' => 'Either you were blocked/your 
account is not set up or an unknown error occurred.
+       'communitytwitter-unknown-error' => 'Your account is not set up or an 
unknown error occurred.
 
 In case you think you should have access, please contact an administrator',
        'communitytwitter-connection-failure' => 'Connection to Twitter could 
not be established.',
@@ -62,9 +62,8 @@
        'communitytwitter-no-last-tweets' => 'No tweets available',
        'communitytwitter-description-template' => 'CommunityTwitter 
description',
        'communitytwitter-advice-template' => 'CommunityTwitter advice',
-       'communitytwitter-access-error' => "You have to be <span 
class=\"plainlinks\"><a href=\"/wiki/Special:UserLogin\" class=\"external 
text\" title=\"log in\" rel=\"nofollow\">logged in</a></span> and \n".
-                                                                               
                                "<span class=\"plainlinks\"><a 
href=\"/wiki/Special:ListGroupRights\" class=\"external text\" title=\"See 
group rights\" \n".
-                                                                               
                                "rel=\"nofollow\">allowed</a></span> to access 
this page.",
+       'communitytwitter-nologin' => 'You must <span class="plainlinks">[$1 
log in]</span>, and be [[$2|allowed]], to use Community Twitter. Note that use 
of Community Twitter is limited to users in {{PLURAL:$4|the group|one of the 
following groups}}: $3.',
+       'communitytwitter-access-error' => 'You do not have the necessary 
permissions to use Community Twitter. Use of Community Twitter is limited to 
users in {{PLURAL:$2|the group|one of the following groups}}: $1. See the 
[[$3|list of group rights]] or contact your MediaWiki administrator for more 
information.',
        'communitytwitter-userlinks-name' => 'Twitter',
        'right-twitter' => 'Use Twitter special page',
 );
diff --git a/CommunityTwitter_body.php b/CommunityTwitter_body.php
index fbdb310..6a20363 100755
--- a/CommunityTwitter_body.php
+++ b/CommunityTwitter_body.php
@@ -39,7 +39,7 @@
                $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");
+               SpecialPage::SpecialPage('CommunityTwitter', 'twitter');
                $this->skin = $wgUser->getSkin();
        }
 
@@ -66,8 +66,48 @@
 
                $this->setHeaders();
 
-               // Grant access to defined group only
-               if ($wgUser->getId() != 0 && in_array($ctAllowedGroup, 
$wgUser->getEffectiveGroups())) {
+               // Grant access to users with twitter right only. All others 
receive error pages.
+               if ( !$this->userCanExecute( $wgUser ) ) {
+                       // User does not have rights or is not logged in
+
+                       $tGroupRights = SpecialPage::getTitleFor( 
'ListGroupRights' );
+                       $rightsLink = $tGroupRights->getPrefixedText();
+
+                       $groups = array_map(
+                               array( 'User', 'makeGroupLinkWiki' ),
+                               User::getGroupsWithPermission( 'twitter' )
+                       );
+                       $groupsList = $this->getLanguage()->commaList( $groups 
);
+
+
+                       if ( !$wgUser->isAnon() )
+                       {
+                               // Logged in, but no rights
+
+                               $accessErrorMsg = $this->msg( 
'communitytwitter-access-error', $groupsList, count( $groups ), $rightsLink );
+
+                               throw new ErrorPageError( $this->msg( 
'permissionserrors' ), $accessErrorMsg );
+                               return;
+
+                       } else {
+                               // Not logged in
+
+                               $tLogin = SpecialPage::getTitleFor( 'UserLogin' 
);
+                               $ctPrefixedText = 
$this->getTitle()->getPrefixedText();
+                               $loginLink = $tLogin->getFullURL( array( 
'returnto' => $ctPrefixedText ) );
+                               $nologinMsg = $this->msg( 
'communitytwitter-nologin', $loginLink, $rightsLink, $groupsList, count( 
$groups ) );
+
+                               throw new UserNotLoggedIn( $nologinMsg );
+                               return;
+
+                       }
+
+               } else if ( $wgUser->isBlocked() ) {
+                       // isBlocked is not checked in userCanExecute, make 
sure blocked users aren't tweeting.
+                       throw new UserBlockedError( $wgUser->getBlock() );
+
+               } else {
+                       // Presumably the user is allowed
 
                        require_once("includes/twitteroauth.php");
 
@@ -137,7 +177,7 @@
                                                        foreach($connections as 
$name => $connection) {
                                                                
$wgOut->addWikiText("<strong 
class=\"ct-success\">".wfMsg("communitytwitter-update-success")." 
([http://twitter.com/".$name."/status/".$responseIds[$name]."; 
".wfMsg("communitytwitter-check-tweet")."]).</strong>\n");
                                                        }
-                                               
+
                                                        // Get the new status 
only to display updated "last tweets" section
                                                        $newStatus = 
$connections[$ctDefaultAccount]->get("statuses/show", array("id" => 
$responseIds[$ctDefaultAccount], "include_rts" => "true"));
                                                        
array_unshift($twitterStatuses, $newStatus);
@@ -234,9 +274,6 @@
                        } else {
                                $wgOut->addHTML("<strong 
class=\"ct-error\">".wfMsg("communitytwitter-unknown-error-request")."</strong>\n");
                        }
-               } else {
-                       // Not logged in or no adequate group status
-                       
$wgOut->addHTML(wfMsg("communitytwitter-access-error")."\n");
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/69275
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4fc3f17879b30bd5bc36b64e317ec56c9ab24ec2
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/CommunityTwitter
Gerrit-Branch: master
Gerrit-Owner: RAN1 <r...@fastlizard4.org>
Gerrit-Reviewer: Basti2342 <ba...@randomprojects.de>
Gerrit-Reviewer: FastLizard4 <fastlizard4-git-comm...@fastlizard4.org>
Gerrit-Reviewer: RAN1 <r...@fastlizard4.org>
Gerrit-Reviewer: Raimond Spekking <raimond.spekk...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to