Extension:Tasks Extension

This extension provides the ability to create tasks on any page of your MediaWiki. Tasks may have severity, priority, status, and owner properties set. Also included is a highly configurable Special page for aggregateing tasks on your site by various criteria. All tasks are stored in MySQL, so the Special page is extremely fast.

Original author is Aran Deltac, but he no longer maintained it. I don't guarantee that I'll maintain this extension, but I write here all necessary to make it work, 'cause Aran Deltac only propose the archive to download. Fortunately google cache gave me instructions to make it work! --Iubito 15:54, 10 February 2006 (UTC)

News

 * 2007-03-22: Released version 0.53, fixed the regexp responsible for locating the user name in task text. Now the task description can contain parentheses ( and ) --User:SebM
 * 2006-10-10: Released version 0.52, fixed multiple tasks tags in the same page + clicking on a user show this user's tasks instead of the user personnal page --Guillaumep 18:28, 10 October 2006 (UTC)
 * Patched the 0.52 SpecialTasks.php to avoid "Undefined index" notices that appeared in recent MW. --Iubito 04:22, 22 February 2007 (UTC)
 * 2006-06-08: Released version 0.51, compatible MediaWiki 1.6.7 (parser changes), probably don't work with earlier version of MW, don't know. --Iubito 07:19, 7 July 2006 (UTC)
 * Initializing the parser in SpecialTasks
 * A function to feed the tasks_buffer array seperately from the hook
 * 2006-06-24: Released version 0.5. Affects  only. --Dangerville 22:14, 24 June 2006 (UTC)
 * Added extension credits/info visible on your
 * Added customizable message for link text on  (Tasks instead of  )
 * Added option to restrict access
 * Modified to follow guidelines/examples from Writing_a_new_special_page
 * Created subclass special page (more customizable)
 * 2006-04-03: Released version 0.41.2
 * fixed warning about hidden. Mod by James.
 * 2006-03-12: Released version 0.41.1
 * fixed bug with category links. Mod by Filo.
 * 2006-03-12: Released version 0.41
 * now compatible with popular Calendar extension. Mod by mhc.
 * 2006-02-10: Released version 0.4
 * compatible with MediaWiki 1.4
 * now special page list correctly task in namespaces
 * alt and title on images
 * Iubito write instructions here because Aran Deltac has changed his website.
 * 2005-11-04: Released version 0.3, fixing a bug in the display of the task images.
 * 2005-11-03: Released version 0.2 with the ability to hide tasks.
 * 2005-11-02: Released version 0.1.
 * 2005-11-01: Re-wrote the format of writing tasks and the parameters accepted.
 * 2005-10-31: First version of MediaWiki Tasks released.

Compatibility
Aran Deltac has tested it on MediaWiki 1.5.1, Iubito tested it on MediaWiki 1.4.14 (as of version 0.4). User:Smilner could not get it to work out of the box on 1.5.6. Use at your own risk.

Version 0.41.2 is working on 1.5.8 for James.

Version 0.5 is working on 1.6.5 for Dangerville and working on 1.5.8 for Sider.

Version 0.51 is working on 1.6.7 and 1.9.3 for Iubito and not working on 1.5.8 for Sider.

Version 0.51 is working on 1.7.1 for [mailto:rthijssen@gmail.com Rob Thijssen]

Version 0.51 is working on 1.8.2 for neverhood

Version 0.52 is working on 1.8.2 69.125.35.20

Usage
Each task must be on its own line and start with [ ]. All the tasks must be grouped with a ..

[ ] Regular task (Owner User) [1] High priority task. [2] Medium priority task. [3] Low priority task (Owner User) [!] Urgent task (must be completed immediately!!!) (Owner user). [x] Closed task.

According to the regular expression, owner parsing doesn't work when there is anything, even a space character, after ')'. e.g.  [ ] Regular task (Owner User)  works fine, but  [ ] Regular task (Owner User).  works not right.

The tasks tag may have an optional parameter, called hidden, which hides the tasks from being viewed. To use it you would write the beginning tasks tag like.

Tasks Special Page
This page finds all tasks on all pages of your site and displays them all on one page. To view all tasks access index.php?title=Special:Tasks (or Special pages » Tasks). You can provide several arguments to limit the tasks that are returned.
 * status - Show all tasks with the specified status or higher. So, specifying "status=2" would include tasks with the status codes 2, 1, and !.
 * owner - Only tasks assigned to this user.
 * limit - Number of total tasks to list.
 * hidden - Enable the display of hidden tasks.

These arguments are specified by adding a / after and adding them as regular name/value pairs.

Installation
Copy/paste the following codes in files.

extensions/Tasks.php
<?php


 * 1) MediaWiki Tasks version 0.53
 * 2) Copyright (c) 2005 Aran Clary Deltac
 * 3) http://arandeltac.com/MediaWiki_Tasks
 * 4) Copyright (c) 2006 Sylvain Machefert, mods by mhc, Filo, James,
 * 5) Guillaume Pratte, Dangerville
 * 6) http://meta.wikimedia.org/w/index.php?title=Tasks_Extension
 * 7) Distributed under that same terms as MediaWiki itself.

$wgExtensionFunctions[] = "wfTasksExtension"; $wgHooks['ArticleSave'][] = 'clearTasks'; $wgHooks['ArticleSaveComplete'][] = 'saveTasks'; global $tasks_buffer;

function wfTasksExtension { global $wgParser; $wgParser->setHook( "tasks", "tasksHook" ); }
 * 1) Purpose   : Declare parser extensions.
 * 1) Purpose   : Declare parser extensions.

function tasksHook( $content, $args = null, &$parser) { global $tasks_buffer; clearTasks; addToTaskBuffer($content); $hidden = ''; if (isset($args['hidden'])) { $hidden = 'y'; }	else { $hidden = 'n'; }
 * 1) Purpose   : Display a list of tasks.
 * 2) Parameters: content, A list of tasks, one per line.
 * 3)             args, An array of arguments.
 * 4) Arguments : hidden, All tasks will be hidden in the HTML.
 * 5) Returns   : Tasks HTML.
 * 1) Returns   : Tasks HTML.

$output = ''; foreach ($tasks_buffer as $task) { $task['hidden'] = $hidden; $output .= formatTask(					$task['status'],					$task['summary'],					$task['owner'],					'',					$parser); }	return $output; }
 * 1) if you want tasks create a new section...
 * 2) 	$parserOutput = $parser->parse('== Tasks ==', $parser->mTitle, $parser->mOptions, false, false);
 * 3) 	$output .= $parserOutput->getText;

function addToTaskBuffer($content) { global $tasks_buffer; $tasks = preg_split("/[\n\r]+/", $content); foreach ($tasks as $task) { if (preg_match('/^\s*\[([123x! ])\]\s*(.*)$/',$task,$matches)) { $status = $matches[1]; $summary = $matches[2];

$owner = ''; # the regexp updated by SebM (sebm(at)seren.com.pl) 22 March 2007 # to allow parentheses in task description if (preg_match('/^(.+?)\s*\(([^]+)\)$/',$summary,$matches)) { $summary = $matches[1]; $owner = $matches[2]; }			$tasks_buffer[] = array(				'summary' => $summary,				'status' => $status,				'owner' => $owner,				'hidden' => 'n'			); }	} }

function formatTask( $status, $summary, $owner=, $page=, &$parser ) { global $wgScriptPath, $wgTitle; $imgTitle = 'Regular task'; $alt = '[ ]'; $img = '<img src="'.$wgScriptPath.'/images/task';	switch ($status) {		case 'x': $img .= '_done'; $alt = '[x]'; $imgTitle = 'Closed task'; break;		case '!': $img .= '_alert'; $alt = '[!]'; $imgTitle = 'Urgent task'; break;		case '1': $img .= '_1'; $alt = '[1]'; $imgTitle = 'High priority task'; break;		case '2': $img .= '_2'; $alt = '[2]'; $imgTitle = 'Medium priority task'; break;		case '3': $img .= '_3'; $alt = '[3]'; $imgTitle = 'Low priority task'; break;	}	$img .= '.png" width="13" height="13" alt="'.$alt.'" title="'.$imgTitle.'" /> '; if ($owner) { $summary .= ' ('.$owner.')'; } if ($page) { $summary = "$page: ".$summary; }
 * 1) Purpose   : HTML format a task.
 * 1) Purpose   : HTML format a task.

$parserOutput = $parser->parse($summary, $parser->mTitle, $parser->mOptions, false, false); return $img. ' ' . $parserOutput->getText. ' '; }

function clearTasks { global $tasks_buffer; $tasks_buffer = array; return 1; }
 * 1) Purpose   : Used before saveing a page to clear the tasks buffer.
 * 1) Purpose   : Used before saveing a page to clear the tasks buffer.

function saveTasks( $article, $user, $text ) { global $tasks_buffer; $page_id = $article->getID; $dbr =& wfGetDB( DB_MASTER ); # Delete all tasks for this page. $dbr->delete(		'tasks',		array( 'page_id' => $page_id )	);
 * 1) Purpose   : Used after a page is saved to first delete
 * 2)             all tasks and then save the new ones created
 * 3)             in the tasks buffer.
 * 4) Parameters: article, The article object.
 * 5) rev: 2006-03-12: extension will cause double-logging of
 * 6) tasks rendered on a sub-page.  "Rebuild" section prevents this.
 * 1) tasks rendered on a sub-page.  "Rebuild" section prevents this.

# Rebuild the $tasks_buffer array (in case we're on a page) clearTasks; $matches = array; $elements[] = 'tasks';

$text = Parser::extractTagsAndParams( $elements, $text, $matches ); foreach( $matches as $marker => $data ) { list( $element, $content, $params, $tag ) = $data; addToTaskBuffer($content); }

# Re-insert all tasks that were created when parseing this page. foreach ($tasks_buffer as $task) { $task['page_id'] = $page_id; $dbr->insert(				'tasks',				$task		); }	return 1; } ?>

includes/SpecialTasks.php
'Tasks',	'author'=>'Aran Clary Deltac, Sylvain Machefert',	'url'=>'http://meta.wikimedia.org/wiki/Tasks_Extension',	'description'=>'provides the ability to create tasks on any page of your MediaWiki',	'version'=>'0.52' );

function wfSpecialTasks { require_once('SpecialPage.php');

# complete the messages that will be used : global $wgMessageCache ; $wgMessageCache->addMessages(array( 'tasks' => 'Tasks' , ));	class SpecialPage_Tasks extends SpecialPage {		# constructor function SpecialPage_Tasks($restriction = '') {			SpecialPage::SpecialPage('Tasks', $restriction ) ; }		# override of the abstract execute function, manages the output function execute($args_string = '') {			global $wgOut, $wgTitle, $wgParser; $page_titles = array; $dbr =& wfGetDB( DB_MASTER ); # Parse arguments. $args = array; if ($args_string != '') { foreach (explode('&',$args_string) as $pair) { $pair = explode('=',$pair); $args[$pair[0]] = $pair[1]; }			}			# Define options for the SQL. $options = array( 'ORDER BY'=>'status' ); if (isset($args['limit'])) { $options['LIMIT'] = $args['limit']; }			if (isset($args['owner'])) { $args['owner'] = str_replace( '_', ' ', $args['owner'] ); }			# Create the WHERE clause. $where = array; if (isset($args['status'])) { $where[] = 'status<="'.$args['status'].'"'; }			if (isset($args['owner'])) { $where[] = 'owner="'.$args['owner'].'"'; }			if (!isset($args['hidden'])) { $where[] = 'hidden="n"'; }			# Run the SQL. $res = $dbr->select(				'tasks', 				array('page_id','status','owner','summary'), 				$where, 'Database::select',				$options			); if (!$res) { return; } # Set the title for this page. if (isset($args['owner'])) { $wgOut->setPageTitle( $args['owner'].'\'s Tasks' ); }			else { $wgOut->setPageTitle( 'Tasks' ); }			# Generate HTML list of tasks. #attach title and options $wgParser->parse('nothing', $wgTitle, new ParserOptions, false, true); $count = 0; $last_severity = ''; while ($task = $dbr->fetchRow( $res )) { if (!isset($page_titles[$task['page_id']])) { $page_titles[$task['page_id']] = Title::nameOf($task['page_id']); }				$page_title = $page_titles[$task['page_id']]; $wgOut->addHTML(					formatTask( $task['status'], $task['summary'], $task['owner'], $page_title, $wgParser)					); $count++; }			$dbr->freeResult( $res ); # Display a message if there are no tasks. if (!$count) { $wgOut->addWikiText('No tasks found!'); }			# http://meta.wikimedia.org/wiki/Talk:Permissions (Error message with MediaWiki v1.6.5) # explains line below $wgOut->setArticleFlag( false ); }	}	SpecialPage::addPage ( new SpecialPage_Tasks ) ; } ?>

You can restrict access to the page by replacing in the source SpecialPage::addPage ( new SpecialPage_Tasks ) ; by SpecialPage::addPage ( new SpecialPage_Tasks('onlyuser') ) ;. This will restrict the access to the users with the "onlyuser"-right. If 'onlyuser' is not a naturally available right in MediaWiki (i.e. not listed on User_rights), When you go to the SpecialPages as a user with 'onlyuser' right, the Tasks link should appear at the bottom under Restricted special pages (tested on 1.6.5). See also Preventing access to some SpecialPages. --Dangerville 22:14, 24 June 2006 (UTC)
 * 1) add 'onlyuser' to the available rights with this line in  : $wgAvailableRights[] = 'onlyuser';
 * 2) add this line in   (replace 'user' with any other defined user group you want to give the 'onlyuser' privilege): $wgGroupPermissions['user']['onlyuser'] = true;

Execute SQL
If you are using a prefix on your tables, replace PREFIX_ with your prefix. Otherwise you should create a table just named 'tasks'.

CREATE TABLE PREFIX_tasks (   page_id INT(8) UNSIGNED NOT NULL DEFAULT 0,    status ENUM("!","1","2","3"," ","x") NOT NULL DEFAULT " ",    owner CHAR(255) NOT NULL,    summary MEDIUMTEXT NOT NULL,    hidden ENUM("y","n") NOT NULL DEFAULT "n",    KEY owner_idx (owner) );

Images
Right click and save these images into your images/ folder (image names should be lowercase).



LocalSettings.php
At the end of LocalSettings.php, add : include("extensions/Tasks.php"); include("includes/SpecialTasks.php");

All done !

Online demo
Somebody please link to a working installation.
 * http://www.s23.org/wiki/Special:Tasks

License
This code is distributed under the same terms as MediaWiki itself.