r12056 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12055‎ | r12056 | r12057 >
Date:11:04, 11 December 2005
Author:magnus_manske
Status:old
Tags:
Comment:
Now with sidebar support
Modified paths:
  • /trunk/extensions/Tasks/Tasks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Tasks/Tasks.php
@@ -28,6 +28,7 @@
2929 Known bugs:
3030 * setPageTitle in page_management doesn't work for some reason
3131 * Both the "article" and "tasks" tabs are displayed as active when viewing the "tasks" tab
 32+* sidebar task list for Monobook only?
3233
3334 */
3435
@@ -49,6 +50,7 @@
5051 $wgHooks['ArticleSaveComplete'][] = 'wfTasksExtensionArticleSaveComplete' ;
5152 $wgHooks['ArticleDeleteComplete'][] = 'wfTasksExtensionArticleDeleteComplete' ;
5253 $wgHooks['SpecialMovepageAfterMove'][] = 'wfTasksExtensionAfterMove' ;
 54+$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfTasksExtensionAfterToolbox' ;
5355
5456
5557 # BEGIN logging functions
@@ -80,13 +82,102 @@
8183 # END logging functions
8284
8385
 86+#_______________________________________________________________________________
8487
 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+}
85138
86139
87140 #___________________________________________________________________
88141 # Hook functions
89142
90143 /**
 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+/**
91182 * Catch page movement, fix internal task_page_title values
92183 */
93184 function wfTasksExtensionAfterMove ( &$special_page , &$old_title , &$new_title ) {
@@ -143,7 +234,9 @@
144235 */
145236 function wfTasksExtensionTab ( &$skin , &$content_actions ) {
146237 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+
148241 wfTasksAddCache() ;
149242 $content_actions['tasks'] = array(
150243 'class' => ($action == 'tasks') ? 'selected' : false,
@@ -169,68 +262,6 @@
170263 #_____________________________________________________________________________
171264
172265 /**
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 -/**
235266 * The special page
236267 */
237268 function wfTasksExtension() {
@@ -249,14 +280,8 @@
250281 3 => 'closed' ,
251282 4 => 'wontfix'
252283 ) ;
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'
261286
262287 var $creation_tasks = array ( 5 , 6 ) ;
263288
@@ -266,7 +291,26 @@
267292 function SpecialTasks() {
268293 SpecialPage::SpecialPage( 'Tasks' );
269294 $this->includable( true );
 295+ $this->update_types () ;
270296 }
 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+ }
271315
272316 function is_creation_task ( &$task_type ) {
273317 return in_array ( $task_type , $this->creation_tasks ) ;
@@ -349,7 +393,7 @@
350394 $comment = str_replace ( "\n" , "<br/>" , $comment ) ;
351395 $status = $task->task_status ;
352396 $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] ) ;
354398
355399 $out .= "<tr>" ;
356400 $out .= "<td valign='top' align='left' nowrap bgcolor='" . wfMsg('tasks_status_bgcol_'.$this->status_types[$status]) . "'>" ;
@@ -400,8 +444,7 @@
401445 if ( count ( $txt ) > 0 )
402446 $out .= "<br/>" . implode ( " - " , $txt ) ;
403447
404 - $tdp = substr ( $title->getPrefixedText() , 0 , 200 ) ;
405 - $tdp = $wgExtraNamespaces[$wgTasksNamespace] . ":" . $ttype . ' "' . $tdp . '" (' . $task->task_id . ")" ;
 448+ $tdp = $this->get_task_discussion_page ( $task ) ;
406449 $out .= "<br/>" . $sk->makeLink ( $tdp , wfMsg('tasks_discussion_page_link') ) ;
407450 }
408451 $out .="</td>" ;
@@ -409,6 +452,15 @@
410453 return $out ;
411454 }
412455
 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+
413465 /**
414466 * On the "tasks" tab, show the list of existing tasks for that article
415467 */
@@ -502,6 +554,19 @@
503555 }
504556
505557 /**
 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+ /**
506571 * Returns the title object for a task, and the task data through reference
507572 */
508573 function get_title_from_task ( $task_id , &$task ) {
@@ -601,7 +666,7 @@
602667 $out .= "<select name='type'>" ;
603668 $o = array () ;
604669 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>" ;
606671 }
607672 ksort ( $o ) ;
608673 $out .= implode ( "" , $o ) ;

Status & tagging log