r49612 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49611‎ | r49612 | r49613 >
Date:04:52, 18 April 2009
Author:laner
Status:deferred
Tags:
Comment:
* Fix for compatibility with SemanticMediaWiki 1.4
* Clean up formatting to more closely match MediaWiki's formatting standards
* Upped version to 1.1
Modified paths:
  • /trunk/extensions/SemanticTasks/ST_CheckForReminders.php (modified) (history)
  • /trunk/extensions/SemanticTasks/ST_Notify_Assignment.php (modified) (history)
  • /trunk/extensions/SemanticTasks/SemanticTasks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticTasks/SemanticTasks.php
@@ -18,11 +18,12 @@
1919
2020 #Informations
2121 $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 - );
 22+ 'name' => 'SemanticTasks',
 23+ 'author' =>'Steren Giannini',
 24+ 'version' => '1.1',
 25+ 'url' => 'http://www.creativecommons.org',
 26+ 'description' => 'Email notifications for assigned or updated tasks.'
 27+ );
2728
2829 //Do st_SetupExtension after the mediawiki setup, AND after SemanticMediaWiki setup
2930 $wgExtensionFunctions[] = 'st_SetupExtension';
@@ -31,6 +32,6 @@
3233 $wgExtensionMessagesFiles['SemanticTasks'] = dirname( __FILE__ ) . '/SemanticTasks.i18n.php';
3334
3435 // ST_Notify_Assignment.php
35 -require_once($stIP . "/ST_Notify_Assignment.php");
 36+require_once( $stIP . "/ST_Notify_Assignment.php" );
3637
3738 ?>
Index: trunk/extensions/SemanticTasks/ST_CheckForReminders.php
@@ -6,13 +6,13 @@
77 require_once( "$IP/maintenance/commandLine.inc" );
88
99 global $smwgIP;
10 -require_once($smwgIP . '/includes/SMW_Factbox.php');
 10+require_once( $smwgIP . '/includes/SMW_Factbox.php' );
1111
1212 global $stIP;
13 -require_once($stIP . '/ST_Notify_Assignment.php');
 13+require_once( $stIP . '/ST_Notify_Assignment.php' );
1414
1515 //Let's send reminders
16 -fnRemindAssignees('http://teamspace.creativecommons.org/');
 16+fnRemindAssignees( 'http://teamspace.creativecommons.org/' );
1717
18 -print("ST check for reminders\n");
 18+print( "ST check for reminders\n" );
1919 ?>
Index: trunk/extensions/SemanticTasks/ST_Notify_Assignment.php
@@ -1,114 +1,110 @@
22 <?php
33 # (C) 2008 Steren Giannini
44 # 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' );
 5+function fnMailAssignees_updated_task( $article, $current_user, $text, $summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision ) {
 6+ if ( !$minoredit ) {
 7+ //i18n
 8+ wfLoadExtensionMessages( 'SemanticTasks' );
119
12 - //Grab the wiki name
13 - global $wgSitename;
 10+ //Grab the wiki name
 11+ global $wgSitename;
1412
15 - //Get the revision count to determine if new article
16 - $rev = $article->estimateRevisionCount();
 13+ //Get the revision count to determine if new article
 14+ $rev = $article->estimateRevisionCount();
1715
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;
 16+ if( $rev == 1 ) {
 17+ fnMailAssignees( $article, $current_user, '['.$wgSitename.'] '. wfMsg( 'newtask' ), 'assignedtoyou_msg', /*diff?*/ false, /*Page text*/ true );
 18+ } else {
 19+ fnMailAssignees( $article, $current_user, '['.$wgSitename.'] '. wfMsg( 'taskupdated' ), 'updatedtoyou_msg', /*diff?*/ true, /*Page text*/ false );
 20+ }
 21+ }
 22+ return TRUE;
2723 }
2824
29 -function fnMailAssignees($article, $user, $pre_title, $message, $display_diff, $display_text)
30 -{
31 - $title = $article->getTitle();
 25+function fnMailAssignees( $article, $user, $pre_title, $message, $display_diff, $display_text ) {
 26+ $title = $article->getTitle();
3227
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;
 28+ //Send notifications to assignees and ccs
 29+ fnMailNotification( 'Assigned to', $article, $user, $pre_title, $message, $display_diff, $display_text );
 30+ fnMailNotification( 'Carbon copy', $article, $user, $pre_title, $message, $display_diff, $display_text );
 31+ return TRUE;
3732 }
3833
3934 /**
40 -* Sends mail notifications
 35+* Sends mail notifications
4136 * @param $query_word String: the property that designate the users to notify.
4237 */
43 -function fnMailNotification($query_word, $article, $user, $pre_title, $message, $display_diff, $display_text)
44 -{
45 - $title = $article->getTitle();
 38+function fnMailNotification( $query_word, $article, $user, $pre_title, $message, $display_diff, $display_text ) {
 39+ $title = $article->getTitle();
4640
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);
 41+ //get the result of the query "[[$title]][[$query_word::+]]"
 42+ $properties_to_display = array();
 43+ $properties_to_display[0] = $query_word;
 44+ $results = st_get_query_results( "[[$title]][[$query_word::+]]", $properties_to_display, false );
5145
52 - //In theory, there is only one row
53 - while ($row = $results->getNext())
54 - {
55 - $task_assignees = $row[0];
56 - }
 46+ //In theory, there is only one row
 47+ while ( $row = $results->getNext() ) {
 48+ $task_assignees = $row[0];
 49+ }
5750
58 - //If not any row, do nothing
59 - if( empty($task_assignees) ) { return FALSE; }
 51+ //If not any row, do nothing
 52+ if( empty( $task_assignees ) ) {
 53+ return FALSE;
 54+ }
6055
61 - $subject = "$pre_title $title";
62 - $from = new MailAddress($user->getEmail(),$user->getName());
63 - $link = $title->escapeFullURL();
 56+ $subject = "$pre_title $title";
 57+ $from = new MailAddress( $user->getEmail(), $user->getName() );
 58+ $link = $title->escapeFullURL();
6459
65 - $user_mailer = new UserMailer();
 60+ $user_mailer = new UserMailer();
6661
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); }
 62+ while ( $task_assignee = $task_assignees->getNextObject() ) {
 63+ $assignee_username = $task_assignee->getTitle();
 64+ $assignee_user_name = explode( ":", $assignee_username );
 65+ $assignee_name = $assignee_user_name[1];
 66+ $body = wfMsg( $message , $assignee_name , $title ) . $link;
 67+ if( $display_text ){
 68+ $body .= "\n \n" . wfMsg( 'text-message' ) . "\n" . $article->getContent() ;
 69+ }
 70+ if( $display_diff){
 71+ $body .= "\n \n" . wfMsg( 'diff-message' ) . "\n" . st_generateDiffBody_txt( $title );
 72+ }
7573
76 - //TEST: uncomment this for test mode (Writes body in testFile)
77 - //st_WriteTestFile($body);
 74+ //TEST: uncomment this for test mode (Writes body in testFile)
 75+ //st_WriteTestFile( $body );
7876
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 - }
 77+ $assignee = User::newFromName( $assignee_name );
 78+ //if assignee is the current user, do nothing
 79+ if ( $assignee->getID() != $user->getID() ) {
 80+ $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name );
 81+ $user_mailer->send( $assignee_mail, $from, $subject, $body );
 82+ }
 83+ }
8784
88 - return TRUE;
 85+ return TRUE;
8986 }
9087
9188 /**
92 -* Generates a diff txt
 89+* Generates a diff txt
9390 * @param Title $title
94 -* @return string
 91+* @return string
9592 */
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;
 93+function st_generateDiffBody_txt( $title ) {
 94+ $revision = Revision::newFromTitle( $title, 0 );
 95+ $diff = new DifferenceEngine( $title, $revision->getId(), 'prev' );
 96+ //The getDiffBody() method generates html, so let's generate the txt diff manualy:
 97+ global $wgContLang;
 98+ $diff->loadText();
 99+ $otext = str_replace( "\r\n", "\n", $diff->mOldtext );
 100+ $ntext = str_replace( "\r\n", "\n", $diff->mNewtext );
 101+ $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) );
 102+ $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) );
 103+ //We use here the php diff engine included in MediaWiki
 104+ $diffs = new Diff( $ota, $nta );
 105+ //And we ask for a txt formatted diff
 106+ $formatter = new UnifiedDiffFormatter();
 107+ $diff_text = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) );
 108+ return $diff_text;
113109 }
114110
115111 /**
@@ -119,101 +115,98 @@
120116 * @param $display_title Boolean : add the page title in the result
121117 * @return TODO
122118 */
123 -function st_get_query_results($query_string,$properties_to_display,$display_title)
124 -{
125 - //i18n
126 - wfLoadExtensionMessages( 'SemanticTasks' );
 119+function st_get_query_results( $query_string, $properties_to_display, $display_title ) {
 120+ //i18n
 121+ wfLoadExtensionMessages( 'SemanticTasks' );
127122
128 - //We use the Semantic Media Wiki Processor
129 - global $smwgIP;
130 - include_once($smwgIP . "/includes/SMW_QueryProcessor.php");
 123+ //We use the Semantic Media Wiki Processor
 124+ global $smwgIP;
 125+ include_once( $smwgIP . "/includes/SMW_QueryProcessor.php" );
131126
132 - $params = array();
133 - $inline = true;
134 - $format = 'auto';
135 - $printlabel = "";
136 - $printouts = array();
 127+ $params = array();
 128+ $inline = true;
 129+ $format = 'auto';
 130+ $printlabel = "";
 131+ $printouts = array();
137132
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);
 133+ //add the page name to the printouts
 134+ if( $display_title ) {
 135+ $to_push = new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, $printlabel );
 136+ array_push( $printouts, $to_push );
 137+ }
154138
155 - return $results;
 139+ //Push the properties to display in the printout array.
 140+ foreach( $properties_to_display as $property ) {
 141+ if ( class_exists( 'SMWPropertyValue' ) ) { // SMW 1.4
 142+ $to_push = new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, $printlabel, SMWPropertyValue::makeProperty( $property ) );
 143+ } else {
 144+ $to_push = new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, $printlabel, Title::newFromText( $property, SMW_NS_PROPERTY ) );
 145+ }
 146+ array_push( $printouts, $to_push );
 147+ }
 148+
 149+ $query = SMWQueryProcessor::createQuery( $query_string, $params, $inline, $format, $printouts );
 150+ $results = smwfGetStore()->getQueryResult( $query );
 151+
 152+ return $results;
156153 }
157154
158155
159 -function fnRemindAssignees($wiki_url)
160 -{
161 - global $wgSitename, $wgServer;
 156+function fnRemindAssignees( $wiki_url ) {
 157+ global $wgSitename, $wgServer;
162158
163 - $user_mailer = new UserMailer();
 159+ $user_mailer = new UserMailer();
164160
165 - $t = getdate();
166 - $today = date('F d Y',$t[0]);
 161+ $t = getdate();
 162+ $today = date( 'F d Y', $t[0] );
167163
168 - $query_string = "[[Reminder at::+]][[Status::New||In Progress]][[Target date::> $today]]";
169 - $properties_to_display = array('Reminder at', 'Assigned to', 'Target date');
 164+ $query_string = "[[Reminder at::+]][[Status::New||In Progress]][[Target date::> $today]]";
 165+ $properties_to_display = array( 'Reminder at', 'Assigned to', 'Target date' );
170166
171 - $results = st_get_query_results($query_string, $properties_to_display, true);
172 - if( empty($results) ) { return FALSE; }
 167+ $results = st_get_query_results( $query_string, $properties_to_display, true );
 168+ if( empty( $results ) ) {
 169+ return FALSE;
 170+ }
173171
174 - $sender = new MailAddress("no-reply@$wgServerName","$wgSitename");
 172+ $sender = new MailAddress( "no-reply@$wgServerName", "$wgSitename" );
175173
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();
 174+ while ( $row = $results->getNext() ) {
 175+ $task_name = $row[0]->getNextObject()->getTitle();
 176+ $subject = '[' . $wgSitename . '] ' . wfMsg( 'reminder' ) . $task_name;
 177+ //The following doesn't work, maybe because we use a cron job.
 178+ //$link = $task_name->escapeFullURL();
 179+ //So let's do it manually
 180+ $link = $wiki_url . $task_name->getPartialURL();
184181
185 - $target_date = $row[3]->getNextObject();
186 - $tg_date = new DateTime($target_date->getShortHTMLText());
 182+ $target_date = $row[3]->getNextObject();
 183+ $tg_date = new DateTime( $target_date->getShortHTMLText() );
187184
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");
 185+ while ( $reminder = $row[1]->getNextObject() ) {
 186+ $remind_me_in = $reminder->getShortHTMLText();
 187+ $date = new DateTime( $today );
 188+ $date->modify( "+$remind_me_in day" );
193189
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];
 190+ if( $tg_date-> format( 'F d Y' ) == $date-> format( 'F d Y' ) ) {
 191+ while ( $task_assignee = $row[2]->getNextObject() ) {
 192+ $assignee_username = $task_assignee->getTitle();
 193+ $assignee_user_name = explode( ":", $assignee_username );
 194+ $assignee_name = $assignee_user_name[1];
201195
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;
 196+ $assignee = User::newFromName( $assignee_name );
 197+ $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name );
 198+ $body = wfMsg('reminder-message', $assignee_name, $task_name, $remind_me_in, $link );
 199+ $user_mailer->send( $assignee_mail, $sender, $subject, $body );
 200+ }
 201+ }
 202+ }
 203+ }
 204+ return TRUE;
211205 }
212206
213 -function st_SetupExtension()
214 -{
215 - global $wgHooks;
216 - $wgHooks['ArticleSaveComplete'][] = 'fnMailAssignees_updated_task';
217 - return true;
 207+function st_SetupExtension() {
 208+ global $wgHooks;
 209+ $wgHooks['ArticleSaveComplete'][] = 'fnMailAssignees_updated_task';
 210+ return true;
218211 }
219212
220213 /**
@@ -221,11 +214,10 @@
222215 * This file must be writable for the system and be at the roor of your wiki installation
223216 * @param $stringData String : to write
224217 */
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);
 218+function st_WriteTestFile( $stringData ) {
 219+ $testFile = "testFile.txt";
 220+ $fh = fopen( $testFile, 'w' ) or die( "can't open file" );
 221+ fwrite( $fh, $stringData );
 222+ fclose( $fh );
231223 }
232224 ?>

Status & tagging log