Index: trunk/extensions/SemanticTasks/SemanticTasks.php |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +### |
| 5 | +# This is the path to your installation of SemanticTasks as |
| 6 | +# seen from the web. Change it if required ($wgScriptPath is the |
| 7 | +# path to the base directory of your wiki). No final slash. |
| 8 | +## |
| 9 | +$stScriptPath = $wgScriptPath . '/extensions/SemanticTasks'; |
| 10 | +## |
| 11 | + |
| 12 | +### |
| 13 | +# This is the path to your installation of SemanticTasks as |
| 14 | +# seen on your local filesystem. Used against some PHP file path |
| 15 | +# issues. |
| 16 | +## |
| 17 | +$stIP = $IP . '/extensions/SemanticTasks'; |
| 18 | +## |
| 19 | + |
| 20 | +#Informations |
| 21 | +$wgExtensionCredits['parserhook'][] = array( |
| 22 | + 'name' => 'SemanticTasks', |
| 23 | + 'author' =>'Steren Giannini', |
| 24 | + 'url' => 'http://www.creativecommons.org', |
| 25 | + 'description' => 'Email notifications for assigned or updated tasks.' |
| 26 | + ); |
| 27 | + |
| 28 | +//Do st_SetupExtension after the mediawiki setup, AND after SemanticMediaWiki setup |
| 29 | +$wgExtensionFunctions[] = 'st_SetupExtension'; |
| 30 | + |
| 31 | +//i18n |
| 32 | +$wgExtensionMessagesFiles['SemanticTasks'] = dirname( __FILE__ ) . '/SemanticTasks.i18n.php'; |
| 33 | + |
| 34 | +// ST_Notify_Assignment.php |
| 35 | +require_once($stIP . "/ST_Notify_Assignment.php"); |
| 36 | + |
| 37 | +?> |
Property changes on: trunk/extensions/SemanticTasks/SemanticTasks.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 38 | + native |
Index: trunk/extensions/SemanticTasks/Teamspace ST reminder |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +Here are things to add to the current teamspace structure : |
| 3 | + |
| 4 | +* Create Property:Reminder at" |
| 5 | + [[Has type::Type:Integer]] |
| 6 | + |
| 7 | + |
| 8 | +*In the Template:Task |
| 9 | + = Reminders = |
| 10 | + '''Reminder at:''' {{ #if: {{{reminder|}}} | {{#arraymap:{{{reminder}}}|,|x|[[Reminder at::x]]}} | 0 }} |
| 11 | + |
| 12 | + |
| 13 | +*In the Form:Task |
| 14 | + __NOTOC__ |
| 15 | + |
| 16 | +and |
| 17 | + |
| 18 | + = Reminders = |
| 19 | + <p><strong>Remind me </strong> {{{field|reminder|default=20,15,7,3}}} days before Target date</p> |
Index: trunk/extensions/SemanticTasks/INSTALL |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +[[Semantic Tasks 1.0]] |
| 3 | + |
| 4 | +== Installation == |
| 5 | + |
| 6 | +(1) Extract the archive to obtain the directory "SemanticTasks" |
| 7 | + that contains all relevant files. Copy this directory (or |
| 8 | + extract/download it) to "[wikipath]/extensions/". |
| 9 | +(2) Insert the following line into the file "[wikipath]/LocalSettings.php": |
| 10 | + require_once( "$IP/extensions/SemanticTasks/SemanticTasks.php" ); |
Index: trunk/extensions/SemanticTasks/ST_CheckForReminders.php |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +<?php |
| 3 | +# (C) 2008 Steren Giannini |
| 4 | +# Licensed under the GNU GPLv2 (or later). |
| 5 | + |
| 6 | +$IP = realpath( dirname( __FILE__ ) . "/../.."); |
| 7 | +require_once( "$IP/maintenance/commandLine.inc" ); |
| 8 | + |
| 9 | +global $smwgIP; |
| 10 | +require_once($smwgIP . '/includes/SMW_Factbox.php'); |
| 11 | + |
| 12 | +global $stIP; |
| 13 | +require_once($stIP . '/ST_Notify_Assignment.php'); |
| 14 | + |
| 15 | +//Let's send reminders |
| 16 | +fnRemindAssignees('http://teamspace.creativecommons.org/'); |
| 17 | + |
| 18 | +print("ST check for reminders\n"); |
| 19 | +?> |
Property changes on: trunk/extensions/SemanticTasks/ST_CheckForReminders.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 20 | + native |
Index: trunk/extensions/SemanticTasks/ST_Notify_Assignment.php |
— | — | @@ -0,0 +1,231 @@ |
| 2 | +<?php |
| 3 | +# (C) 2008 Steren Giannini |
| 4 | +# Licensed under the GNU GPLv2 (or later). |
| 5 | +function fnMailAssignees_updated_task(&$article, &$current_user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags, &$revision) |
| 6 | +{ |
| 7 | + if ( !$minoredit ) |
| 8 | + { |
| 9 | + //i18n |
| 10 | + wfLoadExtensionMessages( 'SemanticTasks' ); |
| 11 | + |
| 12 | + //Grab the wiki name |
| 13 | + global $wgSitename; |
| 14 | + |
| 15 | + //Get the revision count to determine if new article |
| 16 | + $rev = $article->estimateRevisionCount(); |
| 17 | + |
| 18 | + if($rev == 1) |
| 19 | + { |
| 20 | + fnMailAssignees(&$article, $current_user,'['.$wgSitename.'] '. wfMsg('newtask'), 'assignedtoyou_msg', /*diff?*/ false , /*Page text*/ true); |
| 21 | + }else |
| 22 | + { |
| 23 | + fnMailAssignees(&$article, $current_user,'['.$wgSitename.'] '. wfMsg('taskupdated'), 'updatedtoyou_msg', /*diff?*/ true , /*Page text*/ false ); |
| 24 | + } |
| 25 | + } |
| 26 | + return TRUE; |
| 27 | +} |
| 28 | + |
| 29 | +function fnMailAssignees($article, $user, $pre_title, $message, $display_diff, $display_text) |
| 30 | +{ |
| 31 | + $title = $article->getTitle(); |
| 32 | + |
| 33 | + //Send notifications to assignees and ccs |
| 34 | + fnMailNotification('Assigned to', $article, $user, $pre_title, $message, $display_diff, $display_text); |
| 35 | + fnMailNotification('Carbon copy', $article, $user, $pre_title, $message, $display_diff, $display_text); |
| 36 | + return TRUE; |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | +* Sends mail notifications |
| 41 | +* @param $query_word String: the property that designate the users to notify. |
| 42 | +*/ |
| 43 | +function fnMailNotification($query_word, $article, $user, $pre_title, $message, $display_diff, $display_text) |
| 44 | +{ |
| 45 | + $title = $article->getTitle(); |
| 46 | + |
| 47 | + //get the result of the query "[[$title]][[$query_word::+]]" |
| 48 | + $properties_to_display = array(); |
| 49 | + $properties_to_display[0] = $query_word; |
| 50 | + $results= st_get_query_results("[[$title]][[$query_word::+]]", $properties_to_display, false); |
| 51 | + |
| 52 | + //In theory, there is only one row |
| 53 | + while ($row = $results->getNext()) |
| 54 | + { |
| 55 | + $task_assignees = $row[0]; |
| 56 | + } |
| 57 | + |
| 58 | + //If not any row, do nothing |
| 59 | + if( empty($task_assignees) ) { return FALSE; } |
| 60 | + |
| 61 | + $subject = "$pre_title $title"; |
| 62 | + $from = new MailAddress($user->getEmail(),$user->getName()); |
| 63 | + $link = $title->escapeFullURL(); |
| 64 | + |
| 65 | + $user_mailer = new UserMailer(); |
| 66 | + |
| 67 | + while ($task_assignee = $task_assignees->getNextObject()) |
| 68 | + { |
| 69 | + $assignee_username = $task_assignee->getTitle(); |
| 70 | + $assignee_user_name = explode(":",$assignee_username); |
| 71 | + $assignee_name = $assignee_user_name[1]; |
| 72 | + $body = wfMsg($message , $assignee_name , $title) . $link; |
| 73 | + if($display_text){ $body .= "\n \n". wfMsg('text-message') . "\n" . $article->getContent() ; } |
| 74 | + if($display_diff){ $body .= "\n \n". wfMsg('diff-message') . "\n" . st_generateDiffBody_txt($title); } |
| 75 | + |
| 76 | + //TEST: uncomment this for test mode (Writes body in testFile) |
| 77 | + //st_WriteTestFile($body); |
| 78 | + |
| 79 | + $assignee = User::newFromName($assignee_name); |
| 80 | + //if assignee is the current user, do nothing |
| 81 | + if ($assignee->getID() != $user->getID()) |
| 82 | + { |
| 83 | + $assignee_mail = new MailAddress($assignee->getEmail(),$assignee_name); |
| 84 | + $user_mailer->send( $assignee_mail, $from, $subject, $body ); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + return TRUE; |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | +* Generates a diff txt |
| 93 | +* @param Title $title |
| 94 | +* @return string |
| 95 | +*/ |
| 96 | +function st_generateDiffBody_txt($title) |
| 97 | +{ |
| 98 | + $revision = Revision::newFromTitle ($title,0); |
| 99 | + $diff = new DifferenceEngine($title,$revision->getId(),'prev'); |
| 100 | + //The getDiffBody() method generates html, so let's generate the txt diff manualy: |
| 101 | + global $wgContLang; |
| 102 | + $diff->loadText(); |
| 103 | + $otext = str_replace( "\r\n", "\n", $diff->mOldtext ); |
| 104 | + $ntext = str_replace( "\r\n", "\n", $diff->mNewtext ); |
| 105 | + $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) ); |
| 106 | + $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) ); |
| 107 | + //We use here the php diff engine included in MediaWiki |
| 108 | + $diffs = new Diff( $ota, $nta ); |
| 109 | + //And we ask for a txt formatted diff |
| 110 | + $formatter = new UnifiedDiffFormatter(); |
| 111 | + $diff_text = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ); |
| 112 | + return $diff_text; |
| 113 | +} |
| 114 | + |
| 115 | +/** |
| 116 | +* This function returns to results of a certain query |
| 117 | +* Thank you Yaron Koren for advices concerning this code |
| 118 | +* @param $query_string String : the query |
| 119 | +* @param $properties_to_display array(String): array of property names to display |
| 120 | +* @param $display_title Boolean : add the page title in the result |
| 121 | +* @return TODO |
| 122 | +*/ |
| 123 | +function st_get_query_results($query_string,$properties_to_display,$display_title) |
| 124 | +{ |
| 125 | + //i18n |
| 126 | + wfLoadExtensionMessages( 'SemanticTasks' ); |
| 127 | + |
| 128 | + //We use the Semantic Media Wiki Processor |
| 129 | + global $smwgIP; |
| 130 | + include_once($smwgIP . "/includes/SMW_QueryProcessor.php"); |
| 131 | + |
| 132 | + $params = array(); |
| 133 | + $inline = true; |
| 134 | + $format = 'auto'; |
| 135 | + $printlabel = ""; |
| 136 | + $printouts = array(); |
| 137 | + |
| 138 | + //add the page name to the printouts |
| 139 | + if($display_title) |
| 140 | + { |
| 141 | + $to_push = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $printlabel); |
| 142 | + array_push($printouts, $to_push); |
| 143 | + } |
| 144 | + |
| 145 | + //Push the properties to display in the printout array. |
| 146 | + foreach($properties_to_display as $property) |
| 147 | + { |
| 148 | + $to_push = new SMWPrintRequest(SMWPrintRequest::PRINT_PROP, $printlabel, Title::newFromText($property, SMW_NS_PROPERTY)); |
| 149 | + array_push($printouts, $to_push); |
| 150 | + } |
| 151 | + |
| 152 | + $query = SMWQueryProcessor::createQuery($query_string, $params, $inline, $format, $printouts); |
| 153 | + $results = smwfGetStore()->getQueryResult($query); |
| 154 | + |
| 155 | + return $results; |
| 156 | +} |
| 157 | + |
| 158 | + |
| 159 | +function fnRemindAssignees($wiki_url) |
| 160 | +{ |
| 161 | + global $wgSitename, $wgServer; |
| 162 | + |
| 163 | + $user_mailer = new UserMailer(); |
| 164 | + |
| 165 | + $t = getdate(); |
| 166 | + $today = date('F d Y',$t[0]); |
| 167 | + |
| 168 | + $query_string = "[[Reminder at::+]][[Status::New||In Progress]][[Target date::> $today]]"; |
| 169 | + $properties_to_display = array('Reminder at', 'Assigned to', 'Target date'); |
| 170 | + |
| 171 | + $results = st_get_query_results($query_string, $properties_to_display, true); |
| 172 | + if( empty($results) ) { return FALSE; } |
| 173 | + |
| 174 | + $sender = new MailAddress("no-reply@$wgServerName","$wgSitename"); |
| 175 | + |
| 176 | + while ($row = $results->getNext()) |
| 177 | + { |
| 178 | + $task_name = $row[0]->getNextObject()->getTitle(); |
| 179 | + $subject = '['.$wgSitename.'] '.wfMsg('reminder').$task_name; |
| 180 | + //The following doesn't work, maybe because we use a cron job. |
| 181 | + //$link = $task_name->escapeFullURL(); |
| 182 | + //So let's do it manually |
| 183 | + $link = $wiki_url . $task_name->getPartialURL(); |
| 184 | + |
| 185 | + $target_date = $row[3]->getNextObject(); |
| 186 | + $tg_date = new DateTime($target_date->getShortHTMLText()); |
| 187 | + |
| 188 | + while ($reminder = $row[1]->getNextObject()) |
| 189 | + { |
| 190 | + $remind_me_in = $reminder->getShortHTMLText(); |
| 191 | + $date = new DateTime($today); |
| 192 | + $date->modify("+$remind_me_in day"); |
| 193 | + |
| 194 | + if($tg_date-> format('F d Y') == $date-> format('F d Y') ) |
| 195 | + { |
| 196 | + while ($task_assignee = $row[2]->getNextObject()) |
| 197 | + { |
| 198 | + $assignee_username = $task_assignee->getTitle(); |
| 199 | + $assignee_user_name = explode(":",$assignee_username); |
| 200 | + $assignee_name = $assignee_user_name[1]; |
| 201 | + |
| 202 | + $assignee = User::newFromName($assignee_name); |
| 203 | + $assignee_mail = new MailAddress($assignee->getEmail(),$assignee_name); |
| 204 | + $body = wfMsg('reminder-message' , $assignee_name , $task_name , $remind_me_in , $link); |
| 205 | + $user_mailer->send($assignee_mail, $sender, $subject, $body ); |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | + } |
| 210 | + return TRUE; |
| 211 | +} |
| 212 | + |
| 213 | +function st_SetupExtension() |
| 214 | +{ |
| 215 | + global $wgHooks; |
| 216 | + $wgHooks['ArticleSaveComplete'][] = 'fnMailAssignees_updated_task'; |
| 217 | + return true; |
| 218 | +} |
| 219 | + |
| 220 | +/** |
| 221 | +* This function is for test mode only, it write its argument in a specific file. |
| 222 | +* This file must be writable for the system and be at the roor of your wiki installation |
| 223 | +* @param $stringData String : to write |
| 224 | +*/ |
| 225 | +function st_WriteTestFile($stringData) |
| 226 | +{ |
| 227 | + $testFile = "testFile.txt"; |
| 228 | + $fh = fopen($testFile, 'w') or die("can't open file"); |
| 229 | + fwrite($fh, $stringData); |
| 230 | + fclose($fh); |
| 231 | +} |
| 232 | +?> |
Property changes on: trunk/extensions/SemanticTasks/ST_Notify_Assignment.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 233 | + native |
Index: trunk/extensions/SemanticTasks/README |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +== About == |
| 3 | + |
| 4 | +Semantic Tasks is an extension to MediaWiki that works in conjunction with another extension, Semantic MediaWiki, to provide email task notifications and reminders. |
| 5 | + |
| 6 | +Notes on installing Semantic tasks can be found in the file INSTALL. |
| 7 | + |
| 8 | +== Credits == |
| 9 | + |
| 10 | +Semantic Tasks was written by Steren Giannini for CreativeCommons. |
| 11 | + |
| 12 | +== Manual == |
| 13 | + |
| 14 | +* Notification emails are sent when a page is saved. The system looks for the [[Assigned to::*]] and the [[Carbon copy::*]] property. |
| 15 | + |
| 16 | +* Reminders emails. The system looks for the [[Reminder at::*]] and the [[Target date::*]] property. It then send reminders to the assignees. |
| 17 | +You must run a cron job once a day to execute the reminder script: |
| 18 | + * edit your crontab file: |
| 19 | + $ crontab -e |
| 20 | + * add the following line to execute the script every day at 12: |
| 21 | + 0 12 * * * php extensions/SemanticTasks/ST_CheckForReminders.php |
| 22 | + |
| 23 | +== Contact == |
| 24 | + |
| 25 | +For comments, questions, suggestions or bug reports please contact steren.giannini@gmail.com |
Index: trunk/extensions/SemanticTasks/SemanticTasks.i18n.php |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +<?php |
| 3 | +$messages = array(); |
| 4 | +$messages['en'] = array( |
| 5 | + 'newtask' => 'New Task:', |
| 6 | + 'taskupdated' => 'Task Updated:', |
| 7 | + 'assignedtoyou_msg' => "Hello $1,\nThe task \"$2\" has just been assigned to you.\n\n", |
| 8 | + 'updatedtoyou_msg' => "Hello $1,\nThe task \"$2\" has just been updated.\n\n", |
| 9 | + 'reminder' => 'Reminder: ', |
| 10 | + 'reminder-message' => "Hello $1, \nJust to remind you that the task \"$2\" ends in $3 days.\n\n$4", |
| 11 | + 'text-message' => "Here is the Task description:", |
| 12 | + 'diff-message' => "Here are the differences:", |
| 13 | +); |
| 14 | + |
| 15 | + |
| 16 | +$messages['fr'] = array( |
| 17 | + 'newtask' => 'Nouvelle tâche :', |
| 18 | + 'taskupdated' => 'Tâche mise à jour :', |
| 19 | + 'assignedtoyou_msg' => "Bonjour $1,\nLa tâche \"$2\" vous a été assignée.\n\n", |
| 20 | + 'updatedtoyou_msg' => "Bonjour $1,\nLa tâche \"$2\" a été mise à jour.\n\n", |
| 21 | + 'reminder' => 'Rappel: ', |
| 22 | + 'reminder-message' => "Bonjour $1, \nN'oubliez pas que la tâche \"$2\" se termine dans $3 jours.\n\n$4", |
| 23 | + 'text-message' => "Voici la description de la tâche :", |
| 24 | + 'diff-message' => "Les différences sont listées ci-dessous :", |
| 25 | +); |
| 26 | + |
| 27 | +?> |
Property changes on: trunk/extensions/SemanticTasks/SemanticTasks.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 28 | + native |