Index: trunk/extensions/Tasks/Tasks.php |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | Known bugs: |
30 | 30 | * setPageTitle in page_management doesn't work for some reason |
31 | 31 | * Both the "article" and "tasks" tabs are displayed as active when viewing the "tasks" tab |
| 32 | +* sidebar task list for Monobook only? |
32 | 33 | |
33 | 34 | */ |
34 | 35 | |
— | — | @@ -49,6 +50,7 @@ |
50 | 51 | $wgHooks['ArticleSaveComplete'][] = 'wfTasksExtensionArticleSaveComplete' ; |
51 | 52 | $wgHooks['ArticleDeleteComplete'][] = 'wfTasksExtensionArticleDeleteComplete' ; |
52 | 53 | $wgHooks['SpecialMovepageAfterMove'][] = 'wfTasksExtensionAfterMove' ; |
| 54 | +$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfTasksExtensionAfterToolbox' ; |
53 | 55 | |
54 | 56 | |
55 | 57 | # BEGIN logging functions |
— | — | @@ -80,13 +82,102 @@ |
81 | 83 | # END logging functions |
82 | 84 | |
83 | 85 | |
| 86 | +#_______________________________________________________________________________ |
84 | 87 | |
| 88 | +/** |
| 89 | +* Text adding function |
| 90 | +*/ |
| 91 | +function wfTasksAddCache () { |
| 92 | + global $wgMessageCache , $wgTasksAddCache ; |
| 93 | + if ( $wgTasksAddCache ) return ; |
| 94 | + $wgTasksAddCache = true ; |
| 95 | + $wgMessageCache->addMessages( |
| 96 | + array( |
| 97 | + 'tasks_tab' => 'Tasks', |
| 98 | + 'tasks_title' => "Tasks for $1", |
| 99 | + 'tasks_form_new' => "Create new task", |
| 100 | + 'tasks_form_comment' => "Comment", |
| 101 | + 'tasks_error1' => "Task was not created: there is already such a task!<br/>", |
| 102 | + 'tasks_ok1' => "New task has been created!<br/>", |
| 103 | + 'tasks_create_header' => "Create a new task", |
| 104 | + 'tasks_existing_header' => "Existing tasks", |
| 105 | + 'tasks_existing_table_header' => "<th>Task</th><th>Dates</th><th>Initial comment</th><th>Assignment/Actions/Page</th>", |
| 106 | + 'tasks_noone' => "noone", |
| 107 | + 'tasks_assign_me' => "<a href=\"$1\">Assign myself</a>", |
| 108 | + 'tasks_close' => "<a href=\"$1\">Close task</a>", |
| 109 | + 'tasks_wontfix' => "<a href=\"$1\">Won't fix</a>", |
| 110 | + 'tasks_reopen' => "<a href=\"$1\">Reopen task</a>", |
| 111 | + 'tasks_assignedto' => "Assigned to $1", |
| 112 | + 'tasks_created_by' => "Created by $1", |
| 113 | + 'tasks_discussion_page_link' => "Task discussion page", |
| 114 | + 'tasks_closedby' => "Closed by $1", |
| 115 | + |
| 116 | + 'tasks_sidebar_title' => "Tasks", |
| 117 | + |
| 118 | + 'tasks_task_types' => "1:cleanup:Cleanup|2:wikify:Wikify|3:rewrite:Rewrite|4:delete:Delete|5:create:Create|6:write:Write", |
| 119 | + 'tasks_status_open' => "Open" , |
| 120 | + 'tasks_status_assigned' => "Assigned" , |
| 121 | + 'tasks_status_closed' => "Closed" , |
| 122 | + 'tasks_status_wontfix' => "Won't fix" , |
| 123 | + 'tasks_status_bgcol_open' => "#FF9999" , |
| 124 | + 'tasks_status_bgcol_assigned' => "#FFF380" , |
| 125 | + 'tasks_status_bgcol_closed' => "#99FF99" , |
| 126 | + 'tasks_status_bgcol_wontfix' => "#9999FF" , |
| 127 | + 'tasks_action_open' => "Task \"$1\" opened." , |
| 128 | + 'tasks_action_assigned' => "Task \"$1\" assigned." , |
| 129 | + 'tasks_action_closed' => "Task \"$1\" closed." , |
| 130 | + 'tasks_action_wontfix' => "Won't fix task \"$1\"." , |
| 131 | + |
| 132 | + 'tasks_logpage' => "Tasks log" , |
| 133 | + 'tasks_logpagetext' => 'This is a log of changes to tasks', |
| 134 | + 'tasks_logentry' => 'For "[[$1]]"', |
| 135 | + ) |
| 136 | + ); |
| 137 | +} |
85 | 138 | |
86 | 139 | |
87 | 140 | #___________________________________________________________________ |
88 | 141 | # Hook functions |
89 | 142 | |
90 | 143 | /** |
| 144 | +* Display in sidebar |
| 145 | +*/ |
| 146 | +function wfTasksExtensionAfterToolbox (&$tpl) { |
| 147 | + global $wgTitle ; |
| 148 | + if ( $wgTitle->isTalkPage() ) return ; # No talk pages please |
| 149 | + if ( $wgTitle->getNamespace() < 0 ) return ; # No special pages please |
| 150 | + |
| 151 | + wfTasksAddCache() ; |
| 152 | + $st = new SpecialTasks ; |
| 153 | + $tasks = $st->get_open_task_list ( $wgTitle ) ; |
| 154 | + if ( count ( $tasks ) == 0 ) return ; # No tasks |
| 155 | + |
| 156 | +?> |
| 157 | + |
| 158 | + </ul> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + <div class="portlet" id="p-tb"> |
| 162 | + <h5><?php $tpl->msg('tasks_sidebar_title') ?></h5> |
| 163 | + <div class="pBody"> |
| 164 | + <ul> |
| 165 | +<?php |
| 166 | + foreach ( $tasks AS $task ) { |
| 167 | + $ttype = $st->task_types[$task->task_type] ; |
| 168 | +?> |
| 169 | + <li id="task_sidebar_<?php echo $ttype ?>"> |
| 170 | + <a href="<?php |
| 171 | + $nt = Title::newFromText ( $st->get_task_discussion_page ( $task ) ) ; |
| 172 | + echo $nt->getLocalURL () ; |
| 173 | + ?>"><?php |
| 174 | + echo $st->get_type_text ( $ttype ) ; |
| 175 | + ?></a></li> |
| 176 | +<?php |
| 177 | + |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +/** |
91 | 182 | * Catch page movement, fix internal task_page_title values |
92 | 183 | */ |
93 | 184 | function wfTasksExtensionAfterMove ( &$special_page , &$old_title , &$new_title ) { |
— | — | @@ -143,7 +234,9 @@ |
144 | 235 | */ |
145 | 236 | function wfTasksExtensionTab ( &$skin , &$content_actions ) { |
146 | 237 | global $wgTitle , $action ; |
147 | | - if ( $wgTitle->isTalkPage() ) return false ; # No tasks for talk pages, no need to bother the database... |
| 238 | + if ( $wgTitle->isTalkPage() ) return false ; # No talk pages please |
| 239 | + if ( $wgTitle->getNamespace() < 0 ) return false ; # No special pages please |
| 240 | + |
148 | 241 | wfTasksAddCache() ; |
149 | 242 | $content_actions['tasks'] = array( |
150 | 243 | 'class' => ($action == 'tasks') ? 'selected' : false, |
— | — | @@ -169,68 +262,6 @@ |
170 | 263 | #_____________________________________________________________________________ |
171 | 264 | |
172 | 265 | /** |
173 | | -* Text adding function |
174 | | -*/ |
175 | | -function wfTasksAddCache () { |
176 | | - global $wgMessageCache , $wgTasksAddCache ; |
177 | | - if ( $wgTasksAddCache ) return ; |
178 | | - $wgTasksAddCache = true ; |
179 | | - $wgMessageCache->addMessages( |
180 | | - array( |
181 | | - 'tasks_tab' => 'Tasks', |
182 | | - 'tasks_title' => "Tasks for $1", |
183 | | - 'tasks_form_new' => "Create new task", |
184 | | - 'tasks_form_comment' => "Comment", |
185 | | - 'tasks_error1' => "Task was not created: there is already such a task!<br/>", |
186 | | - 'tasks_ok1' => "New task has been created!<br/>", |
187 | | - 'tasks_create_header' => "Create a new task", |
188 | | - 'tasks_existing_header' => "Existing tasks", |
189 | | - 'tasks_existing_table_header' => "<th>Task</th><th>Dates</th><th>Initial comment</th><th>Assignment/Actions/Page</th>", |
190 | | - 'tasks_noone' => "noone", |
191 | | - 'tasks_assign_me' => "<a href=\"$1\">Assign myself</a>", |
192 | | - 'tasks_close' => "<a href=\"$1\">Close task</a>", |
193 | | - 'tasks_wontfix' => "<a href=\"$1\">Won't fix</a>", |
194 | | - 'tasks_reopen' => "<a href=\"$1\">Reopen task</a>", |
195 | | - 'tasks_assignedto' => "Assigned to $1", |
196 | | - 'tasks_created_by' => "Created by $1", |
197 | | - 'tasks_discussion_page_link' => "Task discussion page", |
198 | | - 'tasks_closedby' => "Closed by $1", |
199 | | - |
200 | | - 'tasks_status_open' => "Open" , |
201 | | - 'tasks_status_assigned' => "Assigned" , |
202 | | - 'tasks_status_closed' => "Closed" , |
203 | | - 'tasks_status_wontfix' => "Won't fix" , |
204 | | - 'tasks_type_cleanup' => "Cleanup" , |
205 | | - 'tasks_type_wikify' => "Wikify" , |
206 | | - 'tasks_type_rewrite' => "Rewrite" , |
207 | | - 'tasks_type_delete' => "Delete" , |
208 | | - 'tasks_type_create' => "Create blank page" , |
209 | | - 'tasks_type_write' => "Write article" , |
210 | | - 'tasks_status_bgcol_open' => "#FF9999" , |
211 | | - 'tasks_status_bgcol_assigned' => "#FFF380" , |
212 | | - 'tasks_status_bgcol_closed' => "#99FF99" , |
213 | | - 'tasks_status_bgcol_wontfix' => "#9999FF" , |
214 | | - 'tasks_action_open' => "Task \"$1\" opened." , |
215 | | - 'tasks_action_assigned' => "Task \"$1\" assigned." , |
216 | | - 'tasks_action_closed' => "Task \"$1\" closed." , |
217 | | - 'tasks_action_wontfix' => "Won't fix task \"$1\"." , |
218 | | - |
219 | | - 'tasks_logpage' => "Tasks log" , |
220 | | - 'tasks_logpagetext' => 'This is a log of changes to tasks', |
221 | | - 'tasks_logentry' => 'For "[[$1]]"', |
222 | | - |
223 | | -/* 'stableversion_reset_log' => 'Stable version has been removed.', |
224 | | - 'stableversion_logpage' => 'Stable version log', |
225 | | - 'stableversion_logpagetext' => 'This is a log of changes to stable versions', |
226 | | - 'stableversion_logentry' => '', |
227 | | - 'stableversion_log' => 'Revision #$1 is now the stable version.', |
228 | | - 'stableversion_before_no' => 'There was no stable revision before.', |
229 | | - 'stableversion_before_yes' => 'The last stable revision was #$1.',*/ |
230 | | - ) |
231 | | - ); |
232 | | -} |
233 | | - |
234 | | -/** |
235 | 266 | * The special page |
236 | 267 | */ |
237 | 268 | function wfTasksExtension() { |
— | — | @@ -249,14 +280,8 @@ |
250 | 281 | 3 => 'closed' , |
251 | 282 | 4 => 'wontfix' |
252 | 283 | ) ; |
253 | | - var $task_types = array ( |
254 | | - 1 => 'cleanup', |
255 | | - 2 => 'wikify', |
256 | | - 3 => 'rewrite', |
257 | | - 4 => 'delete', |
258 | | - 5 => 'create', |
259 | | - 6 => 'write', |
260 | | - ) ; |
| 284 | + var $task_types ; # e.g., 0 => 'cleanup' |
| 285 | + var $task_types_text ; # e.g., 'cleanup' => 'Clean up' |
261 | 286 | |
262 | 287 | var $creation_tasks = array ( 5 , 6 ) ; |
263 | 288 | |
— | — | @@ -266,7 +291,26 @@ |
267 | 292 | function SpecialTasks() { |
268 | 293 | SpecialPage::SpecialPage( 'Tasks' ); |
269 | 294 | $this->includable( true ); |
| 295 | + $this->update_types () ; |
270 | 296 | } |
| 297 | + |
| 298 | + function update_types () { |
| 299 | + wfTasksAddCache () ; |
| 300 | + |
| 301 | + $this->task_types = array () ; |
| 302 | + $s = explode ( "|" , wfMsg ( 'tasks_task_types' ) ) ; |
| 303 | + foreach ( $s AS $l ) { |
| 304 | + $l = explode ( ":" , trim ( $l ) , 3 ) ; |
| 305 | + if ( count ( $l ) != 3 ) continue ; # Invalid line |
| 306 | + $this->task_types[trim($l[0])] = trim($l[1]) ; |
| 307 | + $this->task_types_text[trim($l[1])] = trim($l[2]) ; |
| 308 | + } |
| 309 | + |
| 310 | + } |
| 311 | + |
| 312 | + function get_type_text ( $type_key ) { |
| 313 | + return $this->task_types_text[$type_key] ; |
| 314 | + } |
271 | 315 | |
272 | 316 | function is_creation_task ( &$task_type ) { |
273 | 317 | return in_array ( $task_type , $this->creation_tasks ) ; |
— | — | @@ -349,7 +393,7 @@ |
350 | 394 | $comment = str_replace ( "\n" , "<br/>" , $comment ) ; |
351 | 395 | $status = $task->task_status ; |
352 | 396 | $tid = $task->task_id ; |
353 | | - $ttype = wfMsg ( 'tasks_type_' . $this->task_types[$task->task_type]) ; |
| 397 | + $ttype = $this->get_type_text ( $this->task_types[$task->task_type] ) ; |
354 | 398 | |
355 | 399 | $out .= "<tr>" ; |
356 | 400 | $out .= "<td valign='top' align='left' nowrap bgcolor='" . wfMsg('tasks_status_bgcol_'.$this->status_types[$status]) . "'>" ; |
— | — | @@ -400,8 +444,7 @@ |
401 | 445 | if ( count ( $txt ) > 0 ) |
402 | 446 | $out .= "<br/>" . implode ( " - " , $txt ) ; |
403 | 447 | |
404 | | - $tdp = substr ( $title->getPrefixedText() , 0 , 200 ) ; |
405 | | - $tdp = $wgExtraNamespaces[$wgTasksNamespace] . ":" . $ttype . ' "' . $tdp . '" (' . $task->task_id . ")" ; |
| 448 | + $tdp = $this->get_task_discussion_page ( $task ) ; |
406 | 449 | $out .= "<br/>" . $sk->makeLink ( $tdp , wfMsg('tasks_discussion_page_link') ) ; |
407 | 450 | } |
408 | 451 | $out .="</td>" ; |
— | — | @@ -409,6 +452,15 @@ |
410 | 453 | return $out ; |
411 | 454 | } |
412 | 455 | |
| 456 | + function get_task_discussion_page ( &$task ) { |
| 457 | + global $wgExtraNamespaces , $wgTasksNamespace ; |
| 458 | + #$tdp = substr ( $title->getPrefixedText() , 0 , 200 ) ; |
| 459 | + #$tdp = $wgExtraNamespaces[$wgTasksNamespace] . ":" . $ttype . ' "' . $tdp . '" (' . $task->task_id . ")" ; |
| 460 | + $ttype = $this->get_type_text ( $this->task_types[$task->task_type]) ; |
| 461 | + $tdp = $wgExtraNamespaces[$wgTasksNamespace] . ":" . $ttype . ' (' . $task->task_id . ")" ; |
| 462 | + return $tdp ; |
| 463 | + } |
| 464 | + |
413 | 465 | /** |
414 | 466 | * On the "tasks" tab, show the list of existing tasks for that article |
415 | 467 | */ |
— | — | @@ -502,6 +554,19 @@ |
503 | 555 | } |
504 | 556 | |
505 | 557 | /** |
| 558 | + * Returns the list of active tasks for this page, for display in the sidebar |
| 559 | + */ |
| 560 | + function get_open_task_list ( &$title ) { |
| 561 | + $tasks = $this->get_tasks_for_page ( $title ) ; |
| 562 | + $ret = array () ; |
| 563 | + foreach ( $tasks AS $task ) { |
| 564 | + if ( $this->is_open ( $task->task_status ) ) |
| 565 | + $ret[] = $task ; |
| 566 | + } |
| 567 | + return $ret ; |
| 568 | + } |
| 569 | + |
| 570 | + /** |
506 | 571 | * Returns the title object for a task, and the task data through reference |
507 | 572 | */ |
508 | 573 | function get_title_from_task ( $task_id , &$task ) { |
— | — | @@ -601,7 +666,7 @@ |
602 | 667 | $out .= "<select name='type'>" ; |
603 | 668 | $o = array () ; |
604 | 669 | foreach ( $new_tasks AS $k => $v ) { |
605 | | - $o[$v] = "<option value='{$k}'>" . wfMsg ( 'tasks_type_' . $v ) . "</option>" ; |
| 670 | + $o[$v] = "<option value='{$k}'>" . $this->get_type_text ( $v ) . "</option>" ; |
606 | 671 | } |
607 | 672 | ksort ( $o ) ; |
608 | 673 | $out .= implode ( "" , $o ) ; |