Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php |
— | — | @@ -39,8 +39,39 @@ |
40 | 40 | |
41 | 41 | return $res; |
42 | 42 | } |
| 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 | + } |
43 | 74 | |
44 | | - static function formatResult( $skin, $taskForce, $number, $type ) { |
| 75 | + static function formatResult( $skin, $taskForce, $number, $sort, $type ) { |
45 | 76 | global $wgContLang, $wgLang, $wgActiveStrategyColors; |
46 | 77 | |
47 | 78 | if ( ! $taskForce ) { |
— | — | @@ -50,14 +81,19 @@ |
51 | 82 | |
52 | 83 | $title = Title::newFromText( $taskForce ); |
53 | 84 | $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 | + } |
55 | 91 | $pageLink = $skin->linkKnown( $title, $text ); |
56 | 92 | $colors = null; |
57 | 93 | $color = null; |
58 | 94 | $style = ''; |
59 | 95 | |
60 | | - if ( isset( $wgActiveStrategyColors[$type] ) ) { |
61 | | - $colors = $wgActiveStrategyColors[$type]; |
| 96 | + if ( isset( $wgActiveStrategyColors[$sort] ) ) { |
| 97 | + $colors = $wgActiveStrategyColors[$sort]; |
62 | 98 | } else { |
63 | 99 | $colors = $wgActiveStrategyColors['default']; |
64 | 100 | } |
— | — | @@ -76,7 +112,7 @@ |
77 | 113 | $style = 'padding-left: 3px; border-left: 1em solid #'.$color; |
78 | 114 | } |
79 | 115 | |
80 | | - if ( $type == 'members' ) { |
| 116 | + if ( $sort == 'members' ) { |
81 | 117 | $pageLink .= ' ('.wfMsg( 'nmembers', $number ).')'; |
82 | 118 | } |
83 | 119 | |
— | — | @@ -103,6 +139,41 @@ |
104 | 140 | return $text; |
105 | 141 | } |
106 | 142 | |
| 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 | + |
107 | 178 | static function getOutput( $args ) { |
108 | 179 | global $wgUser, $wgActiveStrategyPeriod; |
109 | 180 | |
— | — | @@ -110,34 +181,42 @@ |
111 | 182 | $db = wfGetDB( DB_MASTER ); |
112 | 183 | $sk = $wgUser->getSkin(); |
113 | 184 | |
| 185 | + if ( empty( $args['type'] ) ) { |
| 186 | + $args['type'] = 'taskforces'; |
| 187 | + } |
| 188 | + |
114 | 189 | $sortField = 'members'; |
115 | 190 | |
116 | 191 | if ( isset($args['sort']) ) { |
117 | 192 | $sortField = $args['sort']; |
118 | 193 | } |
119 | 194 | |
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 | + } |
122 | 200 | |
123 | 201 | // Sorting by number of members doesn't require any |
124 | 202 | if ($sortField == 'members' ) { |
125 | | - return self::handleSortByMembers( $taskForces ); |
| 203 | + return self::handleSortByMembers( $masterPages ); |
126 | 204 | } |
127 | 205 | |
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 ); |
134 | 218 | } |
135 | 219 | |
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'; |
142 | 221 | |
143 | 222 | if ( $sortField == 'edits' ) { |
144 | 223 | $cutoff = $db->timestamp( time() - $wgActiveStrategyPeriod ); |
— | — | @@ -145,7 +224,7 @@ |
146 | 225 | $tables[] = 'revision'; |
147 | 226 | $joinConds['revision'] = |
148 | 227 | array( 'left join', |
149 | | - array( 'rev_page=page_id', |
| 228 | + array( 'revision.rev_page=page.page_id', |
150 | 229 | "rev_timestamp > $cutoff", |
151 | 230 | "rev_page IS NOT NULL" ) ); |
152 | 231 | $fields[] = 'count(distinct rev_id) + count(distinct thread_id) as value'; |
— | — | @@ -171,7 +250,7 @@ |
172 | 251 | |
173 | 252 | foreach( $result as $row ) { |
174 | 253 | $number = $row->value; |
175 | | - $taskForce = $categories[$row->cl_to]; |
| 254 | + $taskForce = $lookup[$row->keyfield]; |
176 | 255 | |
177 | 256 | if ( isset( $count[$taskForce] ) ) { |
178 | 257 | $count[$taskForce] += $number; |
— | — | @@ -182,7 +261,7 @@ |
183 | 262 | |
184 | 263 | foreach( $count as $taskForce => $number ) { |
185 | 264 | if ( $number > 0 ) { |
186 | | - $html .= self::formatResult( $sk, $taskForce, $number, $sortField ); |
| 265 | + $html .= self::formatResult( $sk, $taskForce, $number, $sortField, $args['type'] ); |
187 | 266 | } |
188 | 267 | } |
189 | 268 | |