r67216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67215‎ | r67216 | r67217 >
Date:13:28, 2 June 2010
Author:werdna
Status:deferred (Comments)
Tags:
Comment:
Updates in accordance with Eugene's mailed request:
* Display coloured boxes instead of numbers.
* Add sortability based on ranking (inbound links), number of recent edits, or number of task force members.
Modified paths:
  • /trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.i18n.php (modified) (history)
  • /trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.php (modified) (history)
  • /trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php (modified) (history)
  • /trunk/extensions/StrategyWiki/ActiveStrategy/ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php
@@ -1,73 +1,135 @@
22 <?php
33
44 class ActiveStrategy {
5 - static function getSQL() {
6 - global $wgActiveStrategyPeriod;
7 -
 5+ static function getTaskForces() {
86 $dbr = wfGetDB( DB_SLAVE );
9 - $revisionTable = $dbr->tableName( 'revision' );
10 - $pageTable = $dbr->tableName( 'page' );
11 - $start = time() - $wgActiveStrategyPeriod;
12 - $encPeriodStart = $dbr->addQuotes( $dbr->timestamp( $start ) );
13 -
14 - $sql = <<<SQL
15 - SELECT
16 - page_namespace AS namespace,
17 - substring_index(page_title, '/', 2) AS title,
18 - COUNT(*) AS edits
19 - FROM $revisionTable
20 - JOIN $pageTable ON page_id = rev_page
21 - WHERE
22 - page_namespace = 0 AND
23 - page_title LIKE 'Task_force/%' AND
24 - rev_timestamp > $encPeriodStart
25 - GROUP BY page_namespace, title
26 -SQL;
27 - $sql = strtr( $sql, "\r\n\t", ' ' );
28 - return $sql;
 7+
 8+ $res = $dbr->select( "page",
 9+ array(
 10+ 'page_id',
 11+ 'page_namespace',
 12+ 'page_title',
 13+ "substring_index(page_title, '/', -1) AS tf_name"
 14+ ),
 15+ array(
 16+ 'page_namespace' => 0,
 17+ "page_title LIKE 'Task_force/%'",
 18+ ), __METHOD__ );
 19+
 20+ return $res;
2921 }
3022
31 - static function formatResult( $skin, $result ) {
32 - global $wgContLang, $wgLang;
 23+ static function formatResult( $skin, $taskForce, $number, $type ) {
 24+ global $wgContLang, $wgLang, $wgActiveStrategyColors;
3325
34 - $title = Title::makeTitle( $result->namespace, $result->title );
 26+ $title = Title::newFromText( $taskForce );
3527 $text = $wgContLang->convert( $title->getPrefixedText() );
3628 $pageLink = $skin->linkKnown( $title, $text );
37 - $members = self::getMemberCount( $title->getPrefixedText() );
38 - $details = array();
39 -
40 - $numberLink = $skin->linkKnown(
41 - $title,
42 - wfMsgExt( 'nrevisions', array( 'parsemag', 'escape' ),
43 - $wgLang->formatNum( $result->edits ) ),
44 - array(),
45 - array( 'action' => 'history' )
46 - );
 29+ $colors = null;
 30+ $color = null;
4731
48 - $details = array( $numberLink );
 32+ if ( isset( $wgActiveStrategyColors[$type] ) ) {
 33+ $colors = $wgActiveStrategyColors[$type];
 34+ } else {
 35+ $colors = $wgActiveStrategyColors['default'];
 36+ }
4937
50 - if ($members >= 0) {
51 - $details[] = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
52 - $wgLang->formatNum( $members ) );
 38+ ksort($colors);
 39+
 40+ foreach( $colors as $threshold => $curColor ) {
 41+ if ( $number >= $threshold ) {
 42+ $color = $curColor;
 43+ } else {
 44+ break;
 45+ }
5346 }
54 -
55 - $details = $wgLang->commaList( $details );
5647
57 - return wfSpecialList( $pageLink, $details );
 48+ $style = 'padding-left: 3px; border-left: 1em solid #'.$color;
 49+
 50+ $pageLink .= " <!-- $number -->";
 51+
 52+ $item = Xml::tags( 'li', array( 'style' => $style ), $pageLink );
 53+
 54+ return $item;
5855 }
5956
60 - static function getOutput() {
61 - global $wgUser;
 57+ static function getOutput( $args ) {
 58+ global $wgUser, $wgActiveStrategyPeriod;
6259
6360 $html = '';
64 - $sql = self::getSQL();
6561 $db = wfGetDB( DB_MASTER );
6662 $sk = $wgUser->getSkin();
6763
68 - $result = $db->query( $sql, __METHOD__ );
 64+ $sortField = 'members';
6965
 66+ if ( isset($args['sort']) ) {
 67+ $sortField = $args['sort'];
 68+ }
 69+
 70+ $taskForces = self::getTaskForces();
 71+ $categories = array();
 72+
 73+ // Sorting by number of members doesn't require any
 74+ if ($sortField == 'members' ) {
 75+ return self::handleSortByMembers( $taskForces );
 76+ }
 77+
 78+ foreach( $taskForces as $row ) {
 79+ $tempTitle = Title::makeTitleSafe( NS_CATEGORY, $row->tf_name );
 80+ $categories[] = $tempTitle->getDBkey();
 81+ }
 82+
 83+ $tables = array( 'page', 'categorylinks' );
 84+ $fields = array( 'categorylinks.cl_to' );
 85+ $conds = array( 'categorylinks.cl_to' => $categories );
 86+ $options = array( 'GROUP BY' => 'categorylinks.cl_to' );
 87+ $joinConds = array( 'categorylinks' =>
 88+ array( 'left join', 'categorylinks.cl_from=page.page_id' ) );
 89+
 90+ // Extra categories to consider
 91+ $tables[] = 'categorylinks as tfcategory';
 92+ $tables[] = 'categorylinks as finishedcategory';
 93+
 94+ $joinConds['categorylinks as tfcategory'] =
 95+ array( 'left join',
 96+ array(
 97+ 'tfcategory.cl_from=page.page_id',
 98+ 'tfcategory.cl_to' => 'Task_force'
 99+ ),
 100+ );
 101+ $joinConds['categorylinks as finishedcategory'] =
 102+ array( 'left join',
 103+ array(
 104+ 'finishedcategory.cl_from=page.page_id',
 105+ 'finishedcategory.cl_to' => 'Task_force_finished'
 106+ ),
 107+ );
 108+
 109+ $conds[] = 'tfcategory.cl_from IS NOT NULL';
 110+ $conds[] = 'finishedcategory.cl_from IS NULL';
 111+
 112+ if ( $sortField == 'edits' ) {
 113+ $tables[] = 'revision';
 114+ $joinConds['revision'] =
 115+ array( 'left join', 'rev_page=page_id' );
 116+ $fields[] = 'count(distinct rev_id) as value';
 117+ $cutoff = $db->timestamp( time() - $wgActiveStrategyPeriod );
 118+ $conds[] = "rev_timestamp > $cutoff";
 119+ } elseif ( $sortField == 'ranking' ) {
 120+ $tables[] = 'pagelinks';
 121+ $joinConds['pagelinks'] = array( 'left join',
 122+ array( 'pl_namespace=page_namespace', 'pl_title=page_title' ) );
 123+ $fields[] = 'count(distinct pl_from) as value';
 124+ }
 125+
 126+ $result = $db->select( $tables, $fields, $conds,
 127+ __METHOD__, $options, $joinConds );
 128+
70129 foreach( $result as $row ) {
71 - $html .= Xml::tags( 'li', null, self::formatResult( $sk, $row ) );
 130+ $number = $row->value;
 131+ $taskForce = $row->cl_to;
 132+
 133+ $html .= self::formatResult( $sk, $taskForce, $number, $sortField );
72134 }
73135
74136 $html = Xml::tags( 'ul', null, $html );
@@ -75,6 +137,31 @@
76138 return $html;
77139 }
78140
 141+ static function handleSortByMembers( $taskForces ) {
 142+ global $wgUser;
 143+
 144+ $memberCount = array();
 145+ $output = '';
 146+ $sk = $wgUser->getSkin();
 147+
 148+ foreach( $taskForces as $row ) {
 149+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
 150+ $memberCount[$row->title] =
 151+ self::getMemberCount( $title->getPrefixedText() );
 152+ }
 153+
 154+ asort( $memberCount );
 155+ $memberCount = array_reverse( $memberCount );
 156+
 157+ foreach( $memberCount as $name => $count ) {
 158+ $output .= self::formatResult( $sk, $name, $count, 'members' );
 159+ }
 160+
 161+ $output = Xml::tags( 'ul', null, $output );
 162+
 163+ return $output;
 164+ }
 165+
79166 static function getMemberCount( $taskForce ) {
80167 global $wgMemc;
81168
Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.i18n.php
@@ -5,6 +5,7 @@
66 'activestrategy' => 'Active Strategy',
77 'active-strategy-desc' => 'Shows number of edits to strategic planning pages',
88 'active-strategy-intro' => 'Number of edits to task force pages in the last {{PLURAL:$1|$1 day|$1 days}}.',
 9+ 'nedits' => '$1 {{PLURAL:$1|edit|edits}}',
910 );
1011
1112 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.php
@@ -22,3 +22,15 @@
2323 * Period for edit counts, in seconds
2424 */
2525 $wgActiveStrategyPeriod = 7 * 86400;
 26+
 27+/**
 28+ * Colors to display task forces/proposals in.
 29+ * First looks for the specific sort field, otherwise looks at default.
 30+ */
 31+$wgActiveStrategyColors = array(
 32+ 'default' => array(
 33+ 0 => 'F00',
 34+ 1 => 'FF0',
 35+ 5 => 'AEA',
 36+ ),
 37+);
Index: trunk/extensions/StrategyWiki/ActiveStrategy/ParserFunctions.php
@@ -2,7 +2,7 @@
33
44 class ActiveStrategyPF {
55 static function activityTag( $str, $args, $parser ) {
6 - return ActiveStrategy::getOutput();
 6+ return ActiveStrategy::getOutput( $args );
77 }
88
99 static function setup( $parser ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r67217Merge r67216werdna13:30, 2 June 2010

Comments

#Comment by Raymond (talk | contribs)   14:07, 2 June 2010

Message 'nedits' seems unused. Could you pls check? Btw I would suggest to rename it to "active-strategy-nedits" for the naming conventions.

Status & tagging log