r58430 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58429‎ | r58430 | r58431 >
Date:18:19, 2 November 2009
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Usability tweaks to SecurePoll from feedback on enwiki:
* Entry page:
** Add an introductory text
** Only show action links that are valid for the user and election status (don't show vote link if election is closed, don't show translate link if user is not admin, etc)
** Style table rows based on whether the election is open or closed.
* On List page:
** Don't show inaccessible "details" link to non-admins
** Link usernames if the user is local, pass through a system message to allow wikis to add extra links etc
* Disable user JS on voting page, as is done for Special:UserLogin, Special:ResetPass, and other sensitive form submissions.
Modified paths:
  • /trunk/extensions/SecurePoll/SecurePoll.i18n.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/main/Base.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/pages/EntryPage.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/pages/ListPage.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/pages/VotePage.php (modified) (history)
  • /trunk/extensions/SecurePoll/resources/SecurePoll.css (modified) (history)

Diff [purge]

Index: trunk/extensions/SecurePoll/SecurePoll.i18n.php
@@ -100,6 +100,8 @@
101101 'securepoll-strike-error' => 'Error performing strike/unstrike: $1',
102102 'securepoll-strike-token-mismatch' => 'Session data lost',
103103 'securepoll-details-link' => 'Details',
 104+ 'securepoll-votername-local' => '[[User:$1|$1]]',
 105+ 'securepoll-votername-remote' => '$1',
104106
105107 # Details page
106108 # Mostly for admins
@@ -133,6 +135,7 @@
134136 'securepoll-submit-select-lang' => 'Translate',
135137
136138 # Entry page
 139+ 'securepoll-entry-text' => 'Below is the list of polls.',
137140 'securepoll-header-title' => 'Name',
138141 'securepoll-header-start-date' => 'Start date',
139142 'securepoll-header-end-date' => 'End date',
Index: trunk/extensions/SecurePoll/includes/pages/VotePage.php
@@ -67,6 +67,10 @@
6868 $this->showJumpForm();
6969 return;
7070 }
 71+
 72+ // This is when it starts getting all serious; disable JS
 73+ // that might be used to sniff cookies or log voting data.
 74+ $wgOut->disallowUserJs();
7175
7276 // Show welcome
7377 if ( $this->voter->isRemote() ) {
Index: trunk/extensions/SecurePoll/includes/pages/EntryPage.php
@@ -11,6 +11,7 @@
1212 function execute( $params ) {
1313 global $wgOut;
1414 $pager = new SecurePoll_ElectionPager( $this );
 15+ $wgOut->addWikiMsg( 'securepoll-entry-text' );
1516 $wgOut->addHTML(
1617 $pager->getBody() .
1718 $pager->getNavigationBar()
@@ -29,13 +30,6 @@
3031 * Pager for an election list. See TablePager documentation.
3132 */
3233 class SecurePoll_ElectionPager extends TablePager {
33 - var $subpages = array(
34 - 'vote',
35 - 'translate',
36 - 'list',
37 - 'dump',
38 - 'tally'
39 - );
4034 var $fields = array(
4135 'el_title',
4236 'el_start_date',
@@ -63,6 +57,18 @@
6458 'el_title', 'el_start_date', 'el_end_date'
6559 ) );
6660 }
 61+
 62+ /**
 63+ * Add classes based on whether the poll is open or closed
 64+ * @param $row database object
 65+ * @return String
 66+ * @see TablePager::getRowClass()
 67+ */
 68+ function getRowClass( $row ){
 69+ return $row->el_end_date > wfTimestampNow( TS_DB )
 70+ ? 'securepoll-election-open'
 71+ : 'securepoll-election-closed';
 72+ }
6773
6874 function formatValue( $name, $value ) {
6975 global $wgLang;
@@ -76,20 +82,47 @@
7783 return htmlspecialchars( $value );
7884 }
7985 }
 86+
 87+ function formatRow( $row ){
 88+ global $wgUser;
 89+ $id = $row->el_entity;
 90+ $this->election = $this->entryPage->context->getElection( $id );
 91+ if( !$this->election ) {
 92+ $this->isAdmin = false;
 93+ } else {
 94+ $this->isAdmin = $this->election->isAdmin( $wgUser );
 95+ }
 96+ return parent::formatRow( $row );
 97+ }
8098
8199 function getLinks() {
82100 global $wgUser;
83101 $id = $this->mCurrentRow->el_entity;
 102+
 103+ $links = array(
 104+ # visible to non-admins
 105+ # visible after election is closed
 106+ 'vote' => array( true, false ),
 107+ 'translate' => array( false, false ),
 108+ 'list' => array( true, true ),
 109+ 'dump' => array( false, true ),
 110+ 'tally' => array( false, true ),
 111+ );
 112+
84113 $s = '';
85114 $sep = wfMsg( 'pipe-separator' );
86115 $skin = $wgUser->getSkin();
87 - foreach ( $this->subpages as $subpage ) {
88 - $title = $this->entryPage->parent->getTitle( "$subpage/$id" );
89 - $linkText = wfMsg( "securepoll-subpage-$subpage" );
90 - if ( $s !== '' ) {
91 - $s .= $sep;
 116+ foreach ( $links as $subpage => $criteria ) {
 117+ if( ( $this->isAdmin || $criteria[0] )
 118+ && ( !$this->election->isFinished() || $criteria[1] )
 119+ ){
 120+ $title = $this->entryPage->parent->getTitle( "$subpage/$id" );
 121+ $linkText = wfMsgExt( "securepoll-subpage-$subpage", 'parseinline' );
 122+ if ( $s !== '' ) {
 123+ $s .= $sep;
 124+ }
 125+ $s .= $skin->makeKnownLinkObj( $title, $linkText );
92126 }
93 - $s .= $skin->makeKnownLinkObj( $title, $linkText );
94127 }
95128 return $s;
96129 }
Index: trunk/extensions/SecurePoll/includes/pages/ListPage.php
@@ -175,7 +175,6 @@
176176 var $listPage, $isAdmin, $election;
177177
178178 static $publicFields = array(
179 - 'details',
180179 'vote_timestamp',
181180 'vote_voter_name',
182181 'vote_voter_domain',
@@ -220,10 +219,14 @@
221220 }
222221
223222 function formatValue( $name, $value ) {
224 - global $wgLang;
225 - $critical = Xml::element( 'img',
226 - array( 'src' => $GLOBALS['wgScriptPath'] . '/extensions/SecurePoll/resources/critical-32.png' )
 223+ global $wgLang, $wgScriptPath;
 224+ $critical = Xml::element( 'img', array(
 225+ 'src' => "$wgScriptPath/extensions/SecurePoll/resources/critical-32.png" )
227226 );
 227+ $voter = SecurePoll_Voter::newFromId(
 228+ $this->listPage->context,
 229+ $this->mCurrentRow->vote_voter
 230+ );
228231
229232 switch ( $name ) {
230233 case 'vote_timestamp':
@@ -264,6 +267,15 @@
265268 'value' => $label,
266269 'onclick' => "securepoll_strike_popup(event, $action, $voteId)"
267270 ) );
 271+ case 'vote_voter_name':
 272+ $msg = $voter->isRemote()
 273+ ? 'securepoll-votername-remote'
 274+ : 'securepoll-votername-local';
 275+ return wfMsgExt(
 276+ $msg,
 277+ 'parseinline',
 278+ array( $value )
 279+ );
268280 default:
269281 return htmlspecialchars( $value );
270282 }
Index: trunk/extensions/SecurePoll/includes/main/Base.php
@@ -1,5 +1,10 @@
22 <?php
33
 4+/**
 5+ * The page that's initially called by MediaWiki when navigating to
 6+ * Special:SecurePoll. The actual pages are not actually subclasses of
 7+ * this or of SpecialPage, they're subclassed from SecurePoll_Page.
 8+ */
49 class SecurePoll_BasePage extends UnlistedSpecialPage {
510 static $pages = array(
611 'details' => 'SecurePoll_DetailsPage',
@@ -31,8 +36,6 @@
3237 public function execute( $paramString ) {
3338 global $wgOut, $wgUser, $wgRequest, $wgScriptPath;
3439
35 - wfLoadExtensionMessages( 'SecurePoll' );
36 -
3740 $this->setHeaders();
3841 $wgOut->addLink( array(
3942 'rel' => 'stylesheet',
Index: trunk/extensions/SecurePoll/resources/SecurePoll.css
@@ -94,3 +94,6 @@
9595 .securepoll-error-jump {
9696 margin-right: 0.5em;
9797 }
 98+.securepoll-election-closed {
 99+ color: #aaa;
 100+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r58434Follow-up r58430: set messages to ignore for translatewikiraymond18:22, 2 November 2009
r58801* Added histogram/range tallier...tstarling03:11, 9 November 2009

Comments

#Comment by Tim Starling (talk | contribs)   06:04, 5 January 2010

Marking resolved on the assumption that I knew what I was doing when I rewrote part of this in r58801.

Status & tagging log