Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php |
— | — | @@ -1,73 +1,135 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class ActiveStrategy { |
5 | | - static function getSQL() { |
6 | | - global $wgActiveStrategyPeriod; |
7 | | - |
| 5 | + static function getTaskForces() { |
8 | 6 | $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; |
29 | 21 | } |
30 | 22 | |
31 | | - static function formatResult( $skin, $result ) { |
32 | | - global $wgContLang, $wgLang; |
| 23 | + static function formatResult( $skin, $taskForce, $number, $type ) { |
| 24 | + global $wgContLang, $wgLang, $wgActiveStrategyColors; |
33 | 25 | |
34 | | - $title = Title::makeTitle( $result->namespace, $result->title ); |
| 26 | + $title = Title::newFromText( $taskForce ); |
35 | 27 | $text = $wgContLang->convert( $title->getPrefixedText() ); |
36 | 28 | $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; |
47 | 31 | |
48 | | - $details = array( $numberLink ); |
| 32 | + if ( isset( $wgActiveStrategyColors[$type] ) ) { |
| 33 | + $colors = $wgActiveStrategyColors[$type]; |
| 34 | + } else { |
| 35 | + $colors = $wgActiveStrategyColors['default']; |
| 36 | + } |
49 | 37 | |
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 | + } |
53 | 46 | } |
54 | | - |
55 | | - $details = $wgLang->commaList( $details ); |
56 | 47 | |
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; |
58 | 55 | } |
59 | 56 | |
60 | | - static function getOutput() { |
61 | | - global $wgUser; |
| 57 | + static function getOutput( $args ) { |
| 58 | + global $wgUser, $wgActiveStrategyPeriod; |
62 | 59 | |
63 | 60 | $html = ''; |
64 | | - $sql = self::getSQL(); |
65 | 61 | $db = wfGetDB( DB_MASTER ); |
66 | 62 | $sk = $wgUser->getSkin(); |
67 | 63 | |
68 | | - $result = $db->query( $sql, __METHOD__ ); |
| 64 | + $sortField = 'members'; |
69 | 65 | |
| 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 | + |
70 | 129 | 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 ); |
72 | 134 | } |
73 | 135 | |
74 | 136 | $html = Xml::tags( 'ul', null, $html ); |
— | — | @@ -75,6 +137,31 @@ |
76 | 138 | return $html; |
77 | 139 | } |
78 | 140 | |
| 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 | + |
79 | 166 | static function getMemberCount( $taskForce ) { |
80 | 167 | global $wgMemc; |
81 | 168 | |
Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.i18n.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | 'activestrategy' => 'Active Strategy', |
7 | 7 | 'active-strategy-desc' => 'Shows number of edits to strategic planning pages', |
8 | 8 | '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}}', |
9 | 10 | ); |
10 | 11 | |
11 | 12 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy.php |
— | — | @@ -22,3 +22,15 @@ |
23 | 23 | * Period for edit counts, in seconds |
24 | 24 | */ |
25 | 25 | $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 @@ |
3 | 3 | |
4 | 4 | class ActiveStrategyPF { |
5 | 5 | static function activityTag( $str, $args, $parser ) { |
6 | | - return ActiveStrategy::getOutput(); |
| 6 | + return ActiveStrategy::getOutput( $args ); |
7 | 7 | } |
8 | 8 | |
9 | 9 | static function setup( $parser ) { |