Index: trunk/phase3/includes/UserMailer.php |
— | — | @@ -262,38 +262,41 @@ |
263 | 263 | * The recipient is appended to the arguments given to messageCompositionFunction. |
264 | 264 | * Both callbacks are to be given in the same formats accepted by the hook system. |
265 | 265 | */ |
266 | | - static function notify($editor, $timestamp, $userListFunction, $messageCompositionFunction) { |
| 266 | + static function notify( $editor, $timestamp, $userListFunction, $messageCompositionFunction ) { |
267 | 267 | global $wgEnotifUseRealName, $wgEnotifImpersonal; |
268 | 268 | global $wgLang; |
269 | 269 | |
270 | | - $common_keys = self::commonMessageKeys($editor); |
271 | | - $users = wfInvoke("userList", $userListFunction); |
272 | | - foreach($users as $u) { |
273 | | - list($user_keys, $body_msg_name, $subj_msg_name) = |
274 | | - wfInvoke("message", $messageCompositionFunction, array($u)); |
275 | | - $keys = array_merge($common_keys, $user_keys); |
| 270 | + $users = wfInvoke( 'userList', $userListFunction ); |
| 271 | + if( !count( $users ) ) |
| 272 | + return; |
276 | 273 | |
| 274 | + $common_keys = self::commonMessageKeys( $editor ); |
| 275 | + foreach( $users as $u ) { |
| 276 | + list( $user_keys, $body_msg_name, $subj_msg_name ) = |
| 277 | + wfInvoke( 'message', $messageCompositionFunction, array( $u ) ); |
| 278 | + $keys = array_merge( $common_keys, $user_keys ); |
| 279 | + |
277 | 280 | if( $wgEnotifImpersonal ) { |
278 | | - $keys['$WATCHINGUSERNAME'] = wfMsgForContent('enotif_impersonal_salutation'); |
279 | | - $keys['$PAGEEDITDATE'] = $wgLang->timeanddate($timestamp, true, false, false); |
| 281 | + $keys['$WATCHINGUSERNAME'] = wfMsgForContent( 'enotif_impersonal_salutation' ); |
| 282 | + $keys['$PAGEEDITDATE'] = $wgLang->timeanddate( $timestamp, true, false, false ); |
280 | 283 | } else { |
281 | 284 | $keys['$WATCHINGUSERNAME'] = $wgEnotifUseRealName ? $u->getRealName() : $u->getName(); |
282 | | - $keys['$PAGEEDITDATE'] = $wgLang->timeAndDate($timestamp, true, false, |
283 | | - $u->getOption('timecorrection')); |
| 285 | + $keys['$PAGEEDITDATE'] = $wgLang->timeAndDate( $timestamp, true, false, |
| 286 | + $u->getOption( 'timecorrection' ) ); |
284 | 287 | } |
285 | 288 | |
286 | | - $subject = strtr(wfMsgForContent( $subj_msg_name ), $keys); |
| 289 | + $subject = strtr( wfMsgForContent( $subj_msg_name ), $keys ); |
287 | 290 | $body = wordwrap( strtr( wfMsgForContent( $body_msg_name ), $keys ), 72 ); |
288 | 291 | |
289 | | - $to = new MailAddress($u); |
| 292 | + $to = new MailAddress( $u ); |
290 | 293 | $from = $keys['$FROM_HEADER']; |
291 | 294 | $replyto = $keys['$REPLYTO_HEADER']; |
292 | | - UserMailer::send($to, $from, $subject, $body, $replyto); |
| 295 | + UserMailer::send( $to, $from, $subject, $body, $replyto ); |
293 | 296 | } |
294 | 297 | } |
295 | 298 | |
296 | 299 | |
297 | | - static function commonMessageKeys($editor) { |
| 300 | + static function commonMessageKeys( $editor ) { |
298 | 301 | global $wgEnotifUseRealName, $wgEnotifRevealEditorAddress; |
299 | 302 | global $wgNoReplyAddress, $wgPasswordSender; |
300 | 303 | |
— | — | @@ -320,11 +323,11 @@ |
321 | 324 | $keys['$REPLYTO_HEADER'] = $replyto; |
322 | 325 | |
323 | 326 | if( $editor->isAnon() ) { |
324 | | - $keys['$PAGEEDITOR'] = wfMsgForContent('enotif_anon_editor', $name); |
| 327 | + $keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $name ); |
325 | 328 | $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' ); |
326 | 329 | } else{ |
327 | 330 | $keys['$PAGEEDITOR'] = $name; |
328 | | - $keys['$PAGEEDITOR_EMAIL'] = SpecialPage::getSafeTitleFor('Emailuser', $name)->getFullUrl(); |
| 331 | + $keys['$PAGEEDITOR_EMAIL'] = SpecialPage::getSafeTitleFor( 'Emailuser', $name )->getFullUrl(); |
329 | 332 | } |
330 | 333 | $keys['$PAGEEDITOR_WIKI'] = $editor->getUserPage()->getFullUrl(); |
331 | 334 | |
— | — | @@ -357,13 +360,13 @@ |
358 | 361 | * @param $minorEdit |
359 | 362 | * @param $oldid (default: false) |
360 | 363 | */ |
361 | | - static function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) { |
| 364 | + static function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) { |
362 | 365 | global $wgEnotifUseJobQ; |
363 | 366 | |
364 | | - if( $title->getNamespace() < 0 ) |
| 367 | + if ( $title->getNamespace() < 0 ) |
365 | 368 | return; |
366 | 369 | |
367 | | - if ($wgEnotifUseJobQ) { |
| 370 | + if ( $wgEnotifUseJobQ ) { |
368 | 371 | $params = array( |
369 | 372 | "editor" => $editor->getName(), |
370 | 373 | "editorID" => $editor->getID(), |
— | — | @@ -374,7 +377,7 @@ |
375 | 378 | $job = new EnotifNotifyJob( $title, $params ); |
376 | 379 | $job->insert(); |
377 | 380 | } else { |
378 | | - self::actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid); |
| 381 | + self::actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid ); |
379 | 382 | } |
380 | 383 | |
381 | 384 | } |
— | — | @@ -392,15 +395,15 @@ |
393 | 396 | * @param $minorEdit |
394 | 397 | * @param $oldid (default: false) |
395 | 398 | */ |
396 | | - static function actuallyNotifyOnPageChange($editor, $title, $timestamp, |
397 | | - $summary, $minorEdit, $oldid=false) { |
| 399 | + static function actuallyNotifyOnPageChange( $editor, $title, $timestamp, |
| 400 | + $summary, $minorEdit, $oldid = false ) { |
398 | 401 | global $wgShowUpdatedMarker, $wgEnotifWatchlist; |
399 | 402 | |
400 | 403 | wfProfileIn( __METHOD__ ); |
401 | 404 | |
402 | | - EmailNotification::notify($editor, $timestamp, |
403 | | - array('PageChangeNotification::usersList', array($editor, $title, $minorEdit)), |
404 | | - array('PageChangeNotification::message', array($oldid, $minorEdit, $summary, $title, $editor) ) ); |
| 405 | + EmailNotification::notify( $editor, $timestamp, |
| 406 | + array( 'PageChangeNotification::usersList', array( $editor, $title, $minorEdit ) ), |
| 407 | + array( 'PageChangeNotification::message', array( $oldid, $minorEdit, $summary, $title, $editor ) ) ); |
405 | 408 | |
406 | 409 | $latestTimestamp = Revision::getTimestampFromId( $title, $title->getLatestRevID() ); |
407 | 410 | // Do not update watchlists if something else already did. |
— | — | @@ -428,7 +431,7 @@ |
429 | 432 | static function message( $stuff ) { |
430 | 433 | global $wgEnotifImpersonal; |
431 | 434 | |
432 | | - list($oldid, $medit, $summary, $title, $user) = $stuff; |
| 435 | + list( $oldid, $medit, $summary, $title, $user ) = $stuff; |
433 | 436 | $keys = array(); |
434 | 437 | |
435 | 438 | # regarding the use of oldid as an indicator for the last visited version, see also |
— | — | @@ -448,28 +451,28 @@ |
449 | 452 | |
450 | 453 | if ($wgEnotifImpersonal && $oldid) { |
451 | 454 | # For impersonal mail, show a diff link to the last revision. |
452 | | - $keys['$NEWPAGE'] = wfMsgForContent('enotif_lastdiff', |
453 | | - $title->getFullURL("oldid={$oldid}&diff=prev")); |
| 455 | + $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff', |
| 456 | + $title->getFullURL( "oldid={$oldid}&diff=prev" ) ); |
454 | 457 | } |
455 | 458 | |
456 | 459 | $keys['$PAGETITLE'] = $title->getPrefixedText(); |
457 | 460 | $keys['$PAGETITLE_URL'] = $title->getFullUrl(); |
458 | 461 | $keys['$PAGEMINOREDIT'] = $medit ? wfMsg( 'minoredit' ) : ''; |
459 | | - $keys['$PAGESUMMARY'] = ($summary == '') ? ' - ' : $summary; |
| 462 | + $keys['$PAGESUMMARY'] = ( $summary == '' ) ? ' - ' : $summary; |
460 | 463 | |
461 | | - return array($keys, 'enotif_body', 'enotif_subject'); |
| 464 | + return array( $keys, 'enotif_body', 'enotif_subject' ); |
462 | 465 | } |
463 | 466 | |
464 | | - static function usersList($stuff) { |
| 467 | + static function usersList( $stuff ) { |
465 | 468 | global $wgEnotifWatchlist, $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges; |
466 | 469 | |
467 | | - list($editor, $title, $minorEdit) = $stuff; |
| 470 | + list( $editor, $title, $minorEdit ) = $stuff; |
468 | 471 | $recipients = array(); |
469 | 472 | |
470 | 473 | # User talk pages: |
471 | 474 | $userTalkId = false; |
472 | | - if( $title->getNamespace() == NS_USER_TALK && (!$minorEdit || $wgEnotifMinorEdits) ) { |
473 | | - $targetUser = User::newFromName($title->getText()); |
| 475 | + if( $title->getNamespace() == NS_USER_TALK && ( !$minorEdit || $wgEnotifMinorEdits ) ) { |
| 476 | + $targetUser = User::newFromName( $title->getText() ); |
474 | 477 | |
475 | 478 | if ( !$targetUser || $targetUser->isAnon() ) |
476 | 479 | $msg = "user talk page edited, but user does not exist"; |
— | — | @@ -477,7 +480,7 @@ |
478 | 481 | else if ( $targetUser->getId() == $editor->getId() ) |
479 | 482 | $msg = "user edited their own talk page, no notification sent"; |
480 | 483 | |
481 | | - else if ( !$targetUser->getOption('enotifusertalkpages') ) |
| 484 | + else if ( !$targetUser->getOption( 'enotifusertalkpages' ) ) |
482 | 485 | $msg = "talk page owner doesn't want notifications"; |
483 | 486 | |
484 | 487 | else if ( !$targetUser->isEmailConfirmed() ) |
— | — | @@ -488,11 +491,11 @@ |
489 | 492 | $recipients[] = $targetUser; |
490 | 493 | $userTalkId = $targetUser->getId(); # won't be included in watchlist, below. |
491 | 494 | } |
492 | | - wfDebug( __METHOD__ .": ". $msg . "\n" ); |
| 495 | + wfDebug( __METHOD__ . ': ' . $msg . "\n" ); |
493 | 496 | } |
494 | | - wfDebug("Did not send a user-talk notification.\n"); |
| 497 | + wfDebug( "Did not send a user-talk notification.\n" ); |
495 | 498 | |
496 | | - if( $wgEnotifWatchlist && (!$minorEdit || $wgEnotifMinorEdits) ) { |
| 499 | + if( $wgEnotifWatchlist && ( !$minorEdit || $wgEnotifMinorEdits ) ) { |
497 | 500 | // Send updates to watchers other than the current editor |
498 | 501 | $userCondition = 'wl_user != ' . $editor->getID(); |
499 | 502 | |
— | — | @@ -525,7 +528,7 @@ |
526 | 529 | } |
527 | 530 | |
528 | 531 | foreach ( $wgUsersNotifiedOnAllChanges as $name ) { |
529 | | - $recipients[] = User::newFromName($name); |
| 532 | + $recipients[] = User::newFromName( $name ); |
530 | 533 | } |
531 | 534 | |
532 | 535 | return $recipients; |
Index: trunk/phase3/includes/Hooks.php |
— | — | @@ -23,40 +23,39 @@ |
24 | 24 | */ |
25 | 25 | |
26 | 26 | /* Private */ |
27 | | -function _wfInvokeInternalGoop($event, $hook) { |
| 27 | +function _wfInvokeInternalGoop( $event, $hook ) { |
28 | 28 | $object = NULL; |
29 | 29 | $method = NULL; |
30 | 30 | $func = NULL; |
31 | 31 | $data = NULL; |
32 | 32 | $have_data = false; |
33 | 33 | |
34 | | - if (is_array($hook)) { |
35 | | - if (count($hook) < 1) { |
36 | | - throw new MWException("Empty array in hooks for " . $event . "\n"); |
37 | | - } else if (is_object($hook[0])) { |
| 34 | + if ( is_array( $hook ) ) { |
| 35 | + if ( count( $hook ) < 1 ) { |
| 36 | + throw new MWException( "Empty array in hooks for " . $event . "\n" ); |
| 37 | + } else if ( is_object( $hook[0] ) ) { |
38 | 38 | $object = $hook[0]; |
39 | | - if (count($hook) < 2) { |
| 39 | + if ( count( $hook ) < 2 ) { |
40 | 40 | $method = "on" . $event; |
41 | 41 | } else { |
42 | 42 | $method = $hook[1]; |
43 | | - if (count($hook) > 2) { |
| 43 | + if ( count( $hook ) > 2 ) { |
44 | 44 | $data = $hook[2]; |
45 | 45 | $have_data = true; |
46 | 46 | } |
47 | 47 | } |
48 | | - } else if (is_string($hook[0])) { |
| 48 | + } else if ( is_string( $hook[0] ) ) { |
49 | 49 | $func = $hook[0]; |
50 | | - if (count($hook) > 1) { |
| 50 | + if ( count( $hook ) > 1 ) { |
51 | 51 | $data = $hook[1]; |
52 | 52 | $have_data = true; |
53 | 53 | } |
54 | 54 | } else { |
55 | | - var_dump( $wgHooks ); |
56 | | - throw new MWException("Unknown datatype in hooks for " . $event . "\n"); |
| 55 | + throw new MWException( "Unknown datatype in hooks for " . $event . "\n" ); |
57 | 56 | } |
58 | | - } else if (is_string($hook)) { # functions look like strings, too |
| 57 | + } else if ( is_string( $hook ) ) { # functions look like strings, too |
59 | 58 | $func = $hook; |
60 | | - } else if (is_object($hook)) { |
| 59 | + } else if ( is_object( $hook ) ) { |
61 | 60 | $object = $hook; |
62 | 61 | $method = "on" . $event; |
63 | 62 | } else { |
— | — | @@ -76,8 +75,8 @@ |
77 | 76 | } |
78 | 77 | |
79 | 78 | /* Return a string describing the hook for debugging purposes. */ |
80 | | -function wfFormatInvocation($event, $hook, $args = array()) { |
81 | | - list($callback, $func, $data) = _wfInvokeInternalGoop($event, $hook, $args); |
| 79 | +function wfFormatInvocation( $event, $hook, $args = array() ) { |
| 80 | + list( $callback, $func, $data ) = _wfInvokeInternalGoop( $event, $hook, $args ); |
82 | 81 | |
83 | 82 | if( is_array( $callback ) ) { |
84 | 83 | if( is_object( $callback[0] ) ) { |
— | — | @@ -103,12 +102,12 @@ |
104 | 103 | * If arguments are provided both as part of the hook itself, and when |
105 | 104 | * calling wfCallFancyCallback, the two arrays are merged. |
106 | 105 | */ |
107 | | -function wfInvoke($event, $hook, $args = array()) { |
108 | | - list($callback, $func, $data) = _wfInvokeInternalGoop($event, $hook, $args); |
| 106 | +function wfInvoke( $event, $hook, $args = array() ) { |
| 107 | + list( $callback, $func, $data ) = _wfInvokeInternalGoop( $event, $hook, $args ); |
109 | 108 | |
110 | 109 | /* We put the first data element on, if needed. */ |
111 | | - if ($data) { |
112 | | - $hook_args = array_merge(array($data), $args); |
| 110 | + if ( $data ) { |
| 111 | + $hook_args = array_merge( array( $data ), $args ); |
113 | 112 | } else { |
114 | 113 | $hook_args = $args; |
115 | 114 | } |
— | — | @@ -129,40 +128,40 @@ |
130 | 129 | * careful about its contents. So, there's a lot more error-checking |
131 | 130 | * in here than would normally be necessary. |
132 | 131 | */ |
133 | | -function wfRunHooks($event, $args = array()) { |
| 132 | +function wfRunHooks( $event, $args = array() ) { |
134 | 133 | |
135 | 134 | global $wgHooks; |
136 | 135 | |
137 | | - if (!is_array($wgHooks)) { |
138 | | - throw new MWException("Global hooks array is not an array!\n"); |
| 136 | + if ( !is_array( $wgHooks ) ) { |
| 137 | + throw new MWException( "Global hooks array is not an array!\n" ); |
139 | 138 | return false; |
140 | 139 | } |
141 | 140 | |
142 | | - if (!array_key_exists($event, $wgHooks)) { |
| 141 | + if (!array_key_exists( $event, $wgHooks ) ) { |
143 | 142 | return true; |
144 | 143 | } |
145 | 144 | |
146 | | - if (!is_array($wgHooks[$event])) { |
147 | | - throw new MWException("Hooks array for event '$event' is not an array!\n"); |
| 145 | + if ( !is_array( $wgHooks[$event] ) ) { |
| 146 | + throw new MWException( "Hooks array for event '$event' is not an array!\n" ); |
148 | 147 | return false; |
149 | 148 | } |
150 | 149 | |
151 | | - foreach ($wgHooks[$event] as $index => $hook) { |
| 150 | + foreach ( $wgHooks[$event] as $index => $hook ) { |
152 | 151 | |
153 | | - $retval = wfInvoke($event, $hook, $args); |
| 152 | + $retval = wfInvoke( $event, $hook, $args ); |
154 | 153 | |
155 | 154 | /* String return is an error; false return means stop processing. */ |
156 | 155 | |
157 | | - if (is_string($retval)) { |
| 156 | + if ( is_string( $retval ) ) { |
158 | 157 | global $wgOut; |
159 | | - $wgOut->showFatalError($retval); |
| 158 | + $wgOut->showFatalError( $retval ); |
160 | 159 | return false; |
161 | 160 | } elseif( $retval === null ) { |
162 | | - $prettyFunc = wfFormatInvocation($event, $hook, $args); |
| 161 | + $prettyFunc = wfFormatInvocation( $event, $hook, $args ); |
163 | 162 | throw new MWException( "Detected bug in an extension! " . |
164 | 163 | "Hook $prettyFunc failed to return a value; " . |
165 | 164 | "should return true to continue hook processing or false to abort." ); |
166 | | - } else if (!$retval) { |
| 165 | + } else if ( !$retval ) { |
167 | 166 | return false; |
168 | 167 | } |
169 | 168 | } |