r62945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62944‎ | r62945 | r62946 >
Date:02:40, 25 February 2010
Author:laner
Status:deferred
Tags:
Comment:
* Adding support for emailing on task status set to closed.
* TODO: Make all properties, and values configurable via globals
Modified paths:
  • /trunk/extensions/SemanticTasks/SemanticTasks.classes.php (modified) (history)
  • /trunk/extensions/SemanticTasks/SemanticTasks.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticTasks/SemanticTasks.classes.php
@@ -4,23 +4,33 @@
55 define("NEWTASK", 0);
66 define("UPDATE", 1);
77 define("ASSIGNED", 2);
 8+define("CLOSED", 3);
89
910 /**
1011 * This class handles the creation and sending of notification emails.
1112 */
1213 class SemanticTasksMailer {
13 - private static $class_assignees;
 14+ private static $task_assignees;
 15+ private static $task_status;
1416
1517 function findOldValues( &$article, &$user, &$text, &$summary, $minor, $watch, $sectionanchor, &$flags ) {
1618 $title = $article->getTitle();
1719 $title_text = $title->getText();
1820
1921 $assignees = self::getAssignees( 'Assigned to', $title_text, $user );
 22+ $status = self::getStatus( 'Status', $title_text, $user );
2023
2124 self::printDebug( "Old assignees: ", $assignees );
 25+ self::printDebug( "Old status: " , $status );
2226
23 - self::$class_assignees = $assignees;
 27+ self::$task_assignees = $assignees;
2428
 29+ if ( count( $status ) > 0 ) {
 30+ self::$task_status = $status[0];
 31+ } else {
 32+ self::$task_status = "";
 33+ }
 34+
2535 return true;
2636 }
2737
@@ -46,7 +56,8 @@
4757 }
4858
4959 function mailAssignees( $article, $text, $user, $status ) {
50 - self::printDebug( "Saved assignees:", self::$class_assignees );
 60+ self::printDebug( "Saved assignees:", self::$task_assignees );
 61+ self::printDebug( "Saved task status: " . self::$task_status );
5162
5263 $title = $article->getTitle();
5364 $title_text = $title->getText();
@@ -54,11 +65,11 @@
5566 $assignees_to_task = array();
5667 $current_assignees = self::getAssignees( 'Assigned to', $title_text, $user );
5768
58 - self::printDebug( "Previous assignees: ", self::$class_assignees );
 69+ self::printDebug( "Previous assignees: ", self::$task_assignees );
5970 self::printDebug( "New assignees: ", $current_assignees );
6071
6172 foreach ( $current_assignees as $assignee ) {
62 - if ( !in_array( $assignee, self::$class_assignees ) ) {
 73+ if ( !in_array( $assignee, self::$task_assignees ) ) {
6374 array_push( $assignees_to_task, $assignee );
6475 }
6576 }
@@ -79,6 +90,16 @@
8091
8192 $copies = self::getAssignees( 'Carbon copy', $title_text, $user );
8293
 94+ $current_task_status = self::getStatus( 'Status', $title_text, $user );
 95+ self::printDebug( "New status: ", $current_task_status );
 96+ if ( count( $current_task_status ) > 0 ) {
 97+ $current_task_status = $current_task_status[0];
 98+ if ( $current_task_status == "Closed" && self::$task_status != "Closed" ) {
 99+ $close_mailto = self::getAssigneeAddresses( $copies );
 100+ self::mailNotification( $close_mailto, $text, $title, $user, CLOSED );
 101+ }
 102+ }
 103+
83104 $mailto = array_merge( $current_assignees, $copies, $groups );
84105 $mailto = array_unique( $mailto );
85106 $mailto = self::getAssigneeAddresses( $mailto );
@@ -90,9 +111,9 @@
91112 }
92113
93114 /**
94 - * Returns an array of assignees based on $query_word
95 - * @param $query_word String: the property that designate the users to notify.
96 - */
 115+ * Returns an array of properties based on $query_word
 116+ * @param $query_word String: the property that designate the users to notify.
 117+ */
97118 function getAssignees( $query_word, $title_text, $user ) {
98119 // Array of assignees to return
99120 $assignee_arr = array();
@@ -123,9 +144,41 @@
124145 }
125146
126147 /**
127 - * Returns an array of assignees based on $query_word
128 - * @param $query_word String: the property that designate the users to notify.
129 - */
 148+ * Returns an array of properties based on $query_word
 149+ * @param $query_word String: the property that designate the users to notify.
 150+ */
 151+ function getStatus( $query_word, $title_text, $user ) {
 152+ // Array of assignees to return
 153+ $assignee_arr = array();
 154+
 155+ // get the result of the query "[[$title]][[$query_word::+]]"
 156+ $properties_to_display = array();
 157+ $properties_to_display[0] = $query_word;
 158+ $results = self::getQueryResults( "[[$title_text]][[$query_word::+]]", $properties_to_display, false );
 159+
 160+ // In theory, there is only one row
 161+ while ( $row = $results->getNext() ) {
 162+ $task_assignees = $row[0];
 163+ }
 164+
 165+ // If not any row, do nothing
 166+ if ( !empty( $task_assignees ) ) {
 167+ while ( $task_assignee = $task_assignees->getNextObject() ) {
 168+ $assignee_name = $task_assignee->getWikiValue();
 169+ $assignee_name = $assignee_name;
 170+
 171+ array_push( $assignee_arr, $assignee_name );
 172+ }
 173+ }
 174+
 175+ return $assignee_arr;
 176+ }
 177+
 178+ /**
 179+ /**
 180+ * Returns an array of assignees based on $query_word
 181+ * @param $query_word String: the property that designate the users to notify.
 182+ */
130183 function getGroupAssignees( $query_word, $title_text, $user ) {
131184 // Array of assignees to return
132185 $assignee_arr = array();
@@ -177,17 +230,20 @@
178231 $assignee_arr = array();
179232 foreach ( $assignees as $assignee_name ) {
180233 $assignee = User::newFromName( $assignee_name );
181 - $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name );
182 - array_push( $assignee_arr, $assignee_mail );
183 - self::printDebug( $assignee_name );
 234+ // if assignee is the current user, do nothing
 235+ #if ( $assignee->getID() != $user->getID() ) {
 236+ $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name );
 237+ array_push( $assignee_arr, $assignee_mail );
 238+ self::printDebug( $assignee_name );
 239+ #}
184240 }
185241
186242 return $assignee_arr;
187243 }
188244
189245 /**
190 - * Sends mail notifications
191 - */
 246+ * Sends mail notifications
 247+ */
192248 function mailNotification( $assignees, $text, $title, $user, $status ) {
193249 global $wgSitename;
194250
@@ -209,6 +265,11 @@
210266 $message = 'semantictasks-updatedtoyou-msg2';
211267 $body = wfMsg( $message , $title_text ) . " " . $link;
212268 $body .= "\n \n" . wfMsg( 'semantictasks-diff-message' ) . "\n" . self::generateDiffBodyTxt( $title );
 269+ } else if ( $status == CLOSED ) {
 270+ $subject = '[' . $wgSitename . '] ' . wfMsg( 'semantictasks-taskclosed' ) . ' ' . $title_text;
 271+ $message = 'semantictasks-taskclosed-msg';
 272+ $body = wfMsg( $message , $title_text ) . " " . $link;
 273+ $body .= "\n \n" . wfMsg( 'semantictasks-text-message' ) . "\n" . $text;
213274 } else {
214275 //status == ASSIGNED
215276 $subject = '[' . $wgSitename . '] ' . wfMsg( 'semantictasks-taskassigned' ) . ' ' . $title_text;
@@ -224,10 +285,10 @@
225286 }
226287
227288 /**
228 - * Generates a diff txt
229 - * @param Title $title
230 - * @return string
231 - */
 289+ * Generates a diff txt
 290+ * @param Title $title
 291+ * @return string
 292+ */
232293 function generateDiffBodyTxt( $title ) {
233294 $revision = Revision::newFromTitle( $title, 0 );
234295 $diff = new DifferenceEngine( $title, $revision->getId(), 'prev' );
@@ -247,13 +308,13 @@
248309 }
249310
250311 /**
251 - * This function returns to results of a certain query
252 - * Thank you Yaron Koren for advices concerning this code
253 - * @param $query_string String : the query
254 - * @param $properties_to_display array(String): array of property names to display
255 - * @param $display_title Boolean : add the page title in the result
256 - * @return TODO
257 -*/
 312+ * This function returns to results of a certain query
 313+ * Thank you Yaron Koren for advices concerning this code
 314+ * @param $query_string String : the query
 315+ * @param $properties_to_display array(String): array of property names to display
 316+ * @param $display_title Boolean : add the page title in the result
 317+ * @return TODO
 318+ */
258319 function getQueryResults( $query_string, $properties_to_display, $display_title ) {
259320 // i18n
260321 wfLoadExtensionMessages( 'SemanticTasks' );
@@ -352,8 +413,8 @@
353414 */
354415 function printDebug( $debugText, $debugArr = null ) {
355416 global $wgSemanticTasksDebug;
356 -
357 - if ( $wgSemanticTasksDebug ) {
 417+
 418+ if ( $wgSemanticTasksDebug ) {
358419 if ( isset( $debugArr ) ) {
359420 $text = $debugText . " " . implode( "::", $debugArr );
360421 wfDebugLog( 'semantic-tasks', $text, false );
Index: trunk/extensions/SemanticTasks/SemanticTasks.i18n.php
@@ -14,7 +14,9 @@
1515 'semantictasks-newtask' => 'New task:',
1616 'semantictasks-taskassigned' => 'Task assigned:',
1717 'semantictasks-taskupdated' => 'Task updated:',
 18+ 'semantictasks-taskclosed' => 'Task closed:',
1819 'semantictasks-newtask-msg' => 'The task "$1" has just been created.',
 20+ 'semantictasks-taskclosed-msg' => 'The task "$1" has just been closed.',
1921 'semantictasks-assignedtoyou-msg2' => 'The task "$1" has just been assigned to you.',
2022 'semantictasks-updatedtoyou-msg2' => 'The task "$1" has just been updated.',
2123 'semantictasks-reminder' => 'Reminder:',

Status & tagging log