r68489 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68488‎ | r68489 | r68490 >
Date:21:39, 23 June 2010
Author:werdna
Status:deferred
Tags:
Comment:
Merge r68488
Modified paths:
  • /branches/wmf/1.16wmf4/extensions/StrategyWiki (modified) (history)
  • /branches/wmf/1.16wmf4/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.16wmf4/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php
@@ -39,8 +39,39 @@
4040
4141 return $res;
4242 }
 43+
 44+ static function getProposals() {
 45+ $dbr = wfGetDB( DB_SLAVE );
 46+
 47+ $res = $dbr->select(
 48+ array( "page",
 49+ 'categorylinks as finishedcategory' ),
 50+ array(
 51+ 'page_id',
 52+ 'page_namespace',
 53+ 'page_title',
 54+ "page_title AS tf_name"
 55+ ),
 56+ array(
 57+ 'page_namespace' => 106 /* Proposal: */,
 58+ 'finishedcategory.cl_from IS NULL',
 59+ ),
 60+ __METHOD__,
 61+ array(),
 62+ array(
 63+ 'categorylinks as finishedcategory' =>
 64+ array( 'left join',
 65+ array(
 66+ 'finishedcategory.cl_from=page.page_id',
 67+ 'finishedcategory.cl_to' => 'Archived Done'
 68+ ),
 69+ ),
 70+ ) );
 71+
 72+ return $res;
 73+ }
4374
44 - static function formatResult( $skin, $taskForce, $number, $type ) {
 75+ static function formatResult( $skin, $taskForce, $number, $sort, $type ) {
4576 global $wgContLang, $wgLang, $wgActiveStrategyColors;
4677
4778 if ( ! $taskForce ) {
@@ -50,14 +81,19 @@
5182
5283 $title = Title::newFromText( $taskForce );
5384 $text = $wgContLang->convert( $title->getPrefixedText() );
54 - $text = self::getTaskForceName( $text );
 85+ if ( $type == 'taskforce' ) {
 86+ $text = self::getTaskForceName( $text );
 87+ } else {
 88+ $title = Title::newFromText( $text );
 89+ $text = $title->getText();
 90+ }
5591 $pageLink = $skin->linkKnown( $title, $text );
5692 $colors = null;
5793 $color = null;
5894 $style = '';
5995
60 - if ( isset( $wgActiveStrategyColors[$type] ) ) {
61 - $colors = $wgActiveStrategyColors[$type];
 96+ if ( isset( $wgActiveStrategyColors[$sort] ) ) {
 97+ $colors = $wgActiveStrategyColors[$sort];
6298 } else {
6399 $colors = $wgActiveStrategyColors['default'];
64100 }
@@ -76,7 +112,7 @@
77113 $style = 'padding-left: 3px; border-left: 1em solid #'.$color;
78114 }
79115
80 - if ( $type == 'members' ) {
 116+ if ( $sort == 'members' ) {
81117 $pageLink .= ' ('.wfMsg( 'nmembers', $number ).')';
82118 }
83119
@@ -103,6 +139,41 @@
104140 return $text;
105141 }
106142
 143+ static function getTaskForcePageConditions( $taskForces, &$tables, &$fields, &$conds,
 144+ &$join_conds, &$lookup ) {
 145+ $categories = array();
 146+ foreach( $taskForces as $row ) {
 147+ $text = self::getTaskForceName( $row->tf_name );
 148+ $tempTitle = Title::makeTitleSafe( NS_CATEGORY, $text );
 149+ $categories[$tempTitle->getDBkey()] = $row->tf_name;
 150+ $categories[$tempTitle->getDBkey()."_task_force"] = $row->tf_name;
 151+ $categories[$tempTitle->getDBkey()."_Task_Force"] = $row->tf_name;
 152+ }
 153+
 154+ $tables[] = 'categorylinks';
 155+ $fields[] = 'categorylinks.cl_to AS keyfield';
 156+ $conds['categorylinks.cl_to'] = array_keys($categories);
 157+ $joinConds = array( 'categorylinks' =>
 158+ array( 'left join', 'categorylinks.cl_from=page.page_id' ) );
 159+
 160+ $lookup = $categories;
 161+ }
 162+
 163+ static function getProposalPageConditions( $proposals, &$tables, &$fields, &$conds,
 164+ &$join_conds, &$lookup ) {
 165+ $fields[] = 'page.page_title AS keyfield';
 166+ $conds['page_namespace'] = 106;
 167+ $titles = array();
 168+ foreach( $proposals as $row ) {
 169+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
 170+ $titles[$row->page_title] = $title->getPrefixedText();
 171+ }
 172+
 173+ $conds['page_title'] = array_keys($titles);
 174+
 175+ $lookup = $titles;
 176+ }
 177+
107178 static function getOutput( $args ) {
108179 global $wgUser, $wgActiveStrategyPeriod;
109180
@@ -110,34 +181,42 @@
111182 $db = wfGetDB( DB_MASTER );
112183 $sk = $wgUser->getSkin();
113184
 185+ if ( empty( $args['type'] ) ) {
 186+ $args['type'] = 'taskforces';
 187+ }
 188+
114189 $sortField = 'members';
115190
116191 if ( isset($args['sort']) ) {
117192 $sortField = $args['sort'];
118193 }
119194
120 - $taskForces = self::getTaskForces();
121 - $categories = array();
 195+ if ( $args['type'] == 'taskforces' ) {
 196+ $masterPages = self::getTaskForces();
 197+ } elseif ( $args['type'] == 'proposal' ) {
 198+ $masterPages = self::getProposals();
 199+ }
122200
123201 // Sorting by number of members doesn't require any
124202 if ($sortField == 'members' ) {
125 - return self::handleSortByMembers( $taskForces );
 203+ return self::handleSortByMembers( $masterPages );
126204 }
127205
128 - foreach( $taskForces as $row ) {
129 - $text = self::getTaskForceName( $row->tf_name );
130 - $tempTitle = Title::makeTitleSafe( NS_CATEGORY, $text );
131 - $categories[$tempTitle->getDBkey()] = $row->tf_name;
132 - $categories[$tempTitle->getDBkey()."_task_force"] = $row->tf_name;
133 - $categories[$tempTitle->getDBkey()."_Task_Force"] = $row->tf_name;
 206+ $tables = array( );
 207+ $fields = array( );
 208+ $conds = array();
 209+ $options = array( 'GROUP BY' => 'keyfield', 'ORDER BY' => 'value DESC' );
 210+ $lookup = array();
 211+
 212+ if ( $args['type'] == 'taskforces' ) {
 213+ self::getTaskForcePageConditions( $masterPages, $tables, $fields,
 214+ $conds, $join_conds, $lookup );
 215+ } elseif( $args['type'] == 'proposal' ) {
 216+ self::getProposalPageConditions( $masterPages, $tables, $fields,
 217+ $conds, $join_conds, $lookup );
134218 }
135219
136 - $tables = array( 'page', 'categorylinks' );
137 - $fields = array( 'categorylinks.cl_to' );
138 - $conds = array( 'categorylinks.cl_to' => array_keys($categories) );
139 - $options = array( 'GROUP BY' => 'categorylinks.cl_to', 'ORDER BY' => 'value DESC' );
140 - $joinConds = array( 'categorylinks' =>
141 - array( 'left join', 'categorylinks.cl_from=page.page_id' ) );
 220+ $tables[] = 'page';
142221
143222 if ( $sortField == 'edits' ) {
144223 $cutoff = $db->timestamp( time() - $wgActiveStrategyPeriod );
@@ -145,7 +224,7 @@
146225 $tables[] = 'revision';
147226 $joinConds['revision'] =
148227 array( 'left join',
149 - array( 'rev_page=page_id',
 228+ array( 'revision.rev_page=page.page_id',
150229 "rev_timestamp > $cutoff",
151230 "rev_page IS NOT NULL" ) );
152231 $fields[] = 'count(distinct rev_id) + count(distinct thread_id) as value';
@@ -171,7 +250,7 @@
172251
173252 foreach( $result as $row ) {
174253 $number = $row->value;
175 - $taskForce = $categories[$row->cl_to];
 254+ $taskForce = $lookup[$row->keyfield];
176255
177256 if ( isset( $count[$taskForce] ) ) {
178257 $count[$taskForce] += $number;
@@ -182,7 +261,7 @@
183262
184263 foreach( $count as $taskForce => $number ) {
185264 if ( $number > 0 ) {
186 - $html .= self::formatResult( $sk, $taskForce, $number, $sortField );
 265+ $html .= self::formatResult( $sk, $taskForce, $number, $sortField, $args['type'] );
187266 }
188267 }
189268
Property changes on: branches/wmf/1.16wmf4/extensions/StrategyWiki
___________________________________________________________________
Name: svn:mergeinfo
190269 - /branches/wmf-deployment/extensions/StrategyWiki:60970
/trunk/extensions/StrategyWiki:66058-67532,67775,67778,67939-67940,67942,68196,68198,68200,68202,68204,68206
/trunk/phase3/extensions/StrategyWiki:63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816
191270 + /branches/wmf-deployment/extensions/StrategyWiki:60970
/trunk/extensions/StrategyWiki:66058-67532,67775,67778,67939-67940,67942,68196,68198,68200,68202,68204,68206,68488
/trunk/phase3/extensions/StrategyWiki:63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68488Generalise code, and add Proposal functionality.werdna21:35, 23 June 2010

Status & tagging log