r12049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12048‎ | r12049 | r12050 >
Date:23:15, 10 December 2005
Author:magnus_manske
Status:old
Tags:
Comment:
Some fixes
Modified paths:
  • /trunk/extensions/Tasks/Tasks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Tasks/Tasks.php
@@ -7,22 +7,28 @@
88 include ( "extensions/Tasks.php" ) ;
99
1010 Also, you need to run the following SQL statement:
11 -CREATE TABLE `tasks` (
12 - `task_id` int(8) unsigned NOT NULL auto_increment,
13 - `task_page_id` int(8) unsigned NOT NULL default '0',
14 - `task_page_title` varchar(255) NOT NULL default '',
15 - `task_user_id` int(8) unsigned NOT NULL default '0',
16 - `task_user_text` varchar(255) NOT NULL default '',
17 - `task_user_assigned` int(8) unsigned NOT NULL default '0',
18 - `task_status` int(4) unsigned NOT NULL default '0',
19 - `task_comment` mediumtext NOT NULL,
20 - `task_type` int(4) unsigned NOT NULL default '0',
21 - `task_timestamp` varchar(14) binary NOT NULL default '',
22 - `task_user_close` int(8) unsigned NOT NULL default '0',
23 - PRIMARY KEY (`task_id`),
24 - KEY `task_page_id` (`task_page_id`,`task_status`,`task_type`),
25 - KEY `task_page_title` (`task_page_title`)
26 -) TYPE=InnoDB ;
 11+CREATE TABLE tasks (
 12+ task_id int(8) unsigned NOT NULL auto_increment,
 13+ task_page_id int(8) unsigned NOT NULL default '0',
 14+ task_page_title varchar(255) NOT NULL default '',
 15+ task_user_id int(8) unsigned NOT NULL default '0',
 16+ task_user_text varchar(255) NOT NULL default '',
 17+ task_user_assigned int(8) unsigned NOT NULL default '0',
 18+ task_status int(4) unsigned NOT NULL default '0',
 19+ task_comment mediumtext NOT NULL,
 20+ task_type int(4) unsigned NOT NULL default '0',
 21+ task_timestamp varchar(14) binary NOT NULL default '',
 22+ task_user_close int(8) unsigned NOT NULL default '0',
 23+ task_timestamp_closed varchar(14) NOT NULL default '',
 24+ PRIMARY KEY (task_id),
 25+ KEY task_page_id (task_page_id,task_status,task_type),
 26+ KEY task_page_title (task_page_title)
 27+) TYPE=InnoDB;
 28+
 29+Known bugs:
 30+* setPageTitle in page_management doesn't work for some reason
 31+* Both the "article" and "tasks" tabs are displayed as active when viewing the "tasks" tab
 32+
2733 */
2834
2935 if (!defined('MEDIAWIKI')) die();
@@ -42,6 +48,7 @@
4349 $wgHooks['UnknownAction'][] = 'wfTasksExtensionAction' ;
4450 $wgHooks['ArticleSaveComplete'][] = 'wfTasksExtensionArticleSaveComplete' ;
4551 $wgHooks['ArticleDeleteComplete'][] = 'wfTasksExtensionArticleDeleteComplete' ;
 52+$wgHooks['SpecialMovepageAfterMove'][] = 'wfTasksExtensionAfterMove' ;
4653
4754
4855 # BEGIN logging functions
@@ -76,15 +83,31 @@
7784
7885
7986
80 -#----------------------------------------------------------------
 87+#___________________________________________________________________
 88+# Hook functions
8189
8290 /**
 91+* Catch page movement, fix internal task_page_title values
 92+*/
 93+function wfTasksExtensionAfterMove ( &$special_page , &$old_title , &$new_title ) {
 94+ if ( $new_title->isTalkPage() ) return false ; # No tasks for talk pages, no need to bother the database...
 95+
 96+ wfTasksAddCache() ;
 97+
 98+ $st = new SpecialTasks ;
 99+ $st->rename_tasks_page ( $old_title , $new_title ) ;
 100+ return false ;
 101+}
 102+
 103+
 104+/**
83105 * Catch article deletion, remove all tasks
84106 */
85107 function wfTasksExtensionArticleDeleteComplete ( &$article , &$user , $reason ) {
86108 # return false ; # Uncomment this line to prevent deletion of tasks upon deletion of article
87109 wfTasksAddCache() ;
88110 $t = $article->getTitle() ;
 111+ if ( $t->isTalkPage() ) return false ; # No tasks for talk pages, no need to bother the database...
89112
90113 $st = new SpecialTasks ;
91114 $st->delete_all_tasks ( $t ) ;
@@ -97,15 +120,15 @@
98121 function wfTasksExtensionArticleSaveComplete ( &$article , &$user , $text , $summary, $isminor, $watchthis, $something ) {
99122 wfTasksAddCache() ;
100123 $t = $article->getTitle() ;
 124+ if ( $t->isTalkPage() ) return false ; # No tasks for talk pages, no need to bother the database...
101125 $new_id = $t->mArticleID ;
102126 $t->mArticleID = -1 ; # Fake non-existing page
103127
104128 $st = new SpecialTasks ;
105129 $tasks = $st->get_tasks_for_page ( $t , true ) ;
106130 foreach ( $tasks AS $task ) {
107 - if ( $st->task_types[$task->task_type] != 'create' ) continue ; # Not a "create" task
108 - $status = $st->status_types[$task->task_status] ;
109 - if ( $status != 'open' && $status != 'assigned' ) continue ; # Not open
 131+ if ( !$st->is_creation_task ( $task->task_type ) ) continue ; # Not a "create" task
 132+ if ( $sk->is_closed ( $task->task_status ) ) continue ; # Not open
110133 $st->change_task_status ( $task->task_id , 3 ) ; # "Closed"
111134 $t->mArticleID = $new_id ;
112135 $st->set_new_article_id ( $t ) ;
@@ -120,6 +143,7 @@
121144 */
122145 function wfTasksExtensionTab ( &$skin , &$content_actions ) {
123146 global $wgTitle , $action ;
 147+ if ( $wgTitle->isTalkPage() ) return false ; # No tasks for talk pages, no need to bother the database...
124148 wfTasksAddCache() ;
125149 $content_actions['tasks'] = array(
126150 'class' => ($action == 'tasks') ? 'selected' : false,
@@ -132,7 +156,7 @@
133157 * This is where the action is :-)
134158 */
135159 function wfTasksExtensionAction ( $action , $article ) {
136 - if ( $action != 'tasks' ) return true ;
 160+ if ( $action != 'tasks' ) return true ; # Not my kind of action!
137161
138162 wfTasksAddCache() ;
139163
@@ -142,6 +166,8 @@
143167 return false ;
144168 }
145169
 170+#_____________________________________________________________________________
 171+
146172 /**
147173 * Text adding function
148174 */
@@ -152,22 +178,23 @@
153179 $wgMessageCache->addMessages(
154180 array(
155181 'tasks_tab' => 'Tasks',
 182+ 'tasks_title' => "Tasks for $1",
156183 'tasks_form_new' => "Create new task",
157184 'tasks_form_comment' => "Comment",
158185 'tasks_error1' => "Task was not created: there is already such a task!<br/>",
159186 'tasks_ok1' => "New task has been created!<br/>",
160187 'tasks_create_header' => "Create a new task",
161188 'tasks_existing_header' => "Existing tasks",
162 - 'tasks_existing_table_header' => "<th>Task</th><th>Created</th><th>Comment</th><th>Assignment/Actions/Page</th>",
 189+ 'tasks_existing_table_header' => "<th>Task</th><th>Dates</th><th>Initial comment</th><th>Assignment/Actions/Page</th>",
163190 'tasks_noone' => "noone",
164191 'tasks_assign_me' => "<a href=\"$1\">Assign myself</a>",
165192 'tasks_close' => "<a href=\"$1\">Close task</a>",
166193 'tasks_wontfix' => "<a href=\"$1\">Won't fix</a>",
167194 'tasks_reopen' => "<a href=\"$1\">Reopen task</a>",
168195 'tasks_assignedto' => "Assigned to $1",
169 - 'tasks_created_by' => "By $1",
 196+ 'tasks_created_by' => "Created by $1",
170197 'tasks_discussion_page_link' => "Task discussion page",
171 - 'tasks_closedby' => "(by $1)",
 198+ 'tasks_closedby' => "Closed by $1",
172199
173200 'tasks_status_open' => "Open" ,
174201 'tasks_status_assigned' => "Assigned" ,
@@ -177,7 +204,8 @@
178205 'tasks_type_wikify' => "Wikify" ,
179206 'tasks_type_rewrite' => "Rewrite" ,
180207 'tasks_type_delete' => "Delete" ,
181 - 'tasks_type_create' => "Create" ,
 208+ 'tasks_type_create' => "Create blank page" ,
 209+ 'tasks_type_write' => "Write article" ,
182210 'tasks_status_bgcol_open' => "#FF9999" ,
183211 'tasks_status_bgcol_assigned' => "#FFF380" ,
184212 'tasks_status_bgcol_closed' => "#99FF99" ,
@@ -227,7 +255,10 @@
228256 3 => 'rewrite',
229257 4 => 'delete',
230258 5 => 'create',
 259+ 6 => 'write',
231260 ) ;
 261+
 262+ var $creation_tasks = array ( 5 , 6 ) ;
232263
233264 /**
234265 * Constructor
@@ -237,6 +268,20 @@
238269 $this->includable( true );
239270 }
240271
 272+ function is_creation_task ( &$task_type ) {
 273+ return in_array ( $task_type , $this->creation_tasks ) ;
 274+ }
 275+
 276+ function is_open ( $status ) {
 277+ if ( $status == 1 || $status == 2 )
 278+ return true ;
 279+ return false ;
 280+ }
 281+
 282+ function is_closed ( $status ) {
 283+ return !$this->is_open ( $status ) ;
 284+ }
 285+
241286 /**
242287 * Takes a title and a list of existing tasks, and decides which new tasks can be created.
243288 * There's no point in having a dozen "wikify" tasks for a single article, now is there? :-)
@@ -249,7 +294,7 @@
250295 foreach ( $tasks AS $t )
251296 $tg[$t->task_type] = 1 ;
252297 for ( $a = min ( array_keys ( $this->task_types ) ) ; $a <= max ( array_keys ( $this->task_types ) ) ; $a++ ) {
253 - if ( !$exists AND $a != 5 ) continue ; # Article does not exits; only valid action: create
 298+ if ( !$exists AND $this->is_creation_task ( $a ) ) continue ; # Article does not exits; only valid action: create
254299 if ( isset ( $tg[$a] ) AND ( $tg[$a]->task_status < 3 ) ) continue ; # Task exists and is not closed
255300 $tk = $this->task_types[$a] ;
256301 if ( $tk == 'create' && $exists ) continue ; # Can't create an existing article...
@@ -280,8 +325,8 @@
281326 'task_page_title' => $title->getPrefixedDBkey() ,
282327 'task_user_id' => $wgUser->getID() ,
283328 'task_user_text' => $wgUser->getName() ,
284 - 'task_user_assigned' => '0' , # default
285 - 'task_status' => '1' , # Hack, should check for the numerical value assigned to 'open'
 329+ 'task_user_assigned' => '0' , # default: No user assigned
 330+ 'task_status' => $this->get_status_number('open') ,
286331 'task_comment' => $comment ,
287332 'task_type' => $type ,
288333 'task_timestamp' => $dbw->timestamp()
@@ -308,18 +353,24 @@
309354
310355 $out .= "<tr>" ;
311356 $out .= "<td valign='top' align='left' nowrap bgcolor='" . wfMsg('tasks_status_bgcol_'.$this->status_types[$status]) . "'>" ;
312 - $out .= "<b>" . $ttype . "</b><br/>" ;
 357+ $out .= "<b>" . $ttype . "</b><br/><i>" ;
313358 $out .= wfMsg ( 'tasks_status_' . $this->status_types[$status] ) ;
314 - if ( $task->task_user_close != 0 && ( $status == 3 || $status == 4 ) ) {
 359+ $out .= "</i></td>" ;
 360+ $out .= "<td align='left' valign='top' nowrap>" ;
 361+ $out .= wfMsg ( 'tasks_created_by' , $sk->makeLink ( $cu->getPrefixedText() , $task->task_user_text ) ) ;
 362+ $out .= "<br/>{$ct}" ;
 363+
 364+ # Closing information
 365+ if ( $task->task_user_close != 0 && $this->is_closed ( $status ) ) {
315366 $user_close = new User ;
316367 $user_close->setID ( $task->task_user_close ) ;
317368 $uct = Title::makeTitleSafe( NS_USER, $user_close->getName() ) ; # Assigned user title
318369 $out .= "<br/>" . wfMsg ( 'tasks_closedby' , $sk->makeLink ( $uct->getPrefixedText() , $user_close->getName() ) ) ;
 370+ if ( $task->task_timestamp_closed != "" )
 371+ $out .= "<br/>" . $wgContLang->timeanddate ( $task->task_timestamp_closed ) ;
319372 }
320373 $out .= "</td>" ;
321 - $out .= "<td align='left' valign='top' nowrap>" ;
322 - $out .= wfMsg ( 'tasks_created_by' , $sk->makeLink ( $cu->getPrefixedText() , $task->task_user_text ) ) ;
323 - $out .= "<br/>{$ct}</td>" ;
 374+
324375 $out .= "<td align='left' valign='top'>" . $comment . "</td>" ;
325376 $out .= "<td align='left' valign='top'>" ;
326377 if ( $task->task_user_assigned == 0 ) { # Noone is assigned this task
@@ -336,7 +387,7 @@
337388 $url = $sk->makeUrl ( $title->getPrefixedText() , "action=tasks&mode=assignme&taskid={$tid}" ) ;
338389 $txt[] = wfMsg ( 'tasks_assign_me' , $url ) ;
339390 }
340 - if ( $status < 3 ) { # Open or assigned
 391+ if ( $this->is_open ( $status ) ) { # Open or assigned
341392 $url = $sk->makeUrl ( $title->getPrefixedText() , "action=tasks&mode=close&taskid={$tid}" ) ;
342393 $txt[] = wfMsg ( 'tasks_close' , $url ) ;
343394 $url = $sk->makeUrl ( $title->getPrefixedText() , "action=tasks&mode=wontfix&taskid={$tid}" ) ;
@@ -375,7 +426,7 @@
376427 }
377428
378429 /**
379 - * Checks if there's a "mode" set (performs changes on tasks, like assigning or closing them)
 430+ * Checks if there's a "mode" set in the URL of the current page (performs changes on tasks, like assigning or closing them)
380431 */
381432 function check_mode ( &$title ) {
382433 global $wgUser , $wgRequest ;
@@ -392,7 +443,7 @@
393444 $dbw->update( 'tasks',
394445 array( # SET
395446 'task_user_assigned' => $wgUser->getID(),
396 - 'task_status' => 2
 447+ 'task_status' => $this->get_status_number('assigned')
397448 ),
398449 $conditions,
399450 $fname );
@@ -406,30 +457,38 @@
407458 return $out ;
408459 }
409460
410 - function get_status_number ( $mode ) {
 461+ /**
 462+ * Returns the number for the status
 463+ */
 464+ function get_status_number ( $status ) {
411465 foreach ( $this->status_types AS $k => $v ) {
412 - if ( $v == $mode )
 466+ if ( $v == $status )
413467 return $k ;
414468 }
415469 return 0 ; # Invalid status
416470 }
417471
 472+ /**
 473+ * Changes the status of a task, performs some associated cleanup, and logs the action
 474+ */
418475 function change_task_status ( $taskid , $new_status ) {
419476 global $wgUser ;
420477 $fname = "Tasks:change_task_status" ;
 478+ $dbw =& wfGetDB( DB_MASTER );
421479
422480 $as = array ( 'task_status' => $new_status ) ; # What to chenge
423481 $aw = array ( 'task_id' => $taskid ) ; # Where to change it
424482
425 - if ( $new_status == 3 || $new_status == 4 ) { # When closing, set closing user ID, and reset assignment
 483+ if ( $this->is_closed ( $new_status ) ) { # When closing, set closing user ID, and reset assignment
426484 $as['task_user_close'] = $wgUser->getID() ;
427485 $as['task_user_assigned'] = 0 ;
428 - } else if ( $new_status == 1 ) { # Change to "open", no assigned user or closing user
 486+ $as['task_timestamp_closed'] = $dbw->timestamp() ;
 487+ } else if ( $new_status == $this->get_status_number('open') ) { # Change to "open", no assigned user or closing user
429488 $as['task_user_assigned'] = 0 ;
430489 $as['task_user_close'] = 0 ;
 490+ $as['task_timestamp_closed'] = "" ;
431491 }
432492
433 - $dbw =& wfGetDB( DB_MASTER );
434493 $dbw->update( 'tasks',
435494 $as , # SET
436495 $aw , # WHERE
@@ -479,19 +538,35 @@
480539 */
481540 function delete_all_tasks ( &$title ) {
482541 $fname = "Tasks:delete_all_tasks" ;
 542+ if ( $title->getArticleID() == 0 )
 543+ $conds = array ( 'task_page_title' => $title->getPrefixedDBkey() ) ;
 544+ else
 545+ $conds = array ( 'task_page_id' => $title->getArticleID() ) ;
483546 $dbw =& wfGetDB( DB_MASTER );
484547 $dbw->delete ( 'tasks' ,
485 - array ( 'task_page_title' => $title->getPrefixedDBkey() ) ,
 548+ $conds ,
486549 $fname ) ;
487550 }
488551
 552+ function rename_tasks_page ( $old_title , $new_title ) {
 553+ $fname = "Tasks:rename_tasks_page" ;
 554+ $dbw =& wfGetDB( DB_MASTER );
 555+ $dbw->update( 'tasks',
 556+ array ( 'task_page_title' => $new_title->getPrefixedDBkey() ) , # SET
 557+ array ( "task_page_title" => $old_title->getPrefixedDBkey() ) , # WHERE
 558+ $fname );
 559+ }
 560+
489561 /**
490562 * THIS IS THE MAIN FUNCTION FOR THE TAB-BASED INTERFACE
491563 */
492564 function page_management ( $title ) {
493 - global $wgOut ;
 565+ if ( $title->isTalkPage() ) return ; # No tasks for talk pages, no need to bother the database...
 566+
 567+ global $wgOut , $action ;
494568 $out = "" ;
495569 $tasks = array() ;
 570+ $wgOut->setPageTitle ( wfMsg('tasks_title',$title->getPrefixedText()) ) ; # Doesn't work for some reason...
496571
497572 # Create from form
498573 $out .= $this->create_from_form ( $title ) ;

Status & tagging log