*/
/* Private */
-function _wfInvokeInternalGoop($event, $hook) {
+function _wfInvokeInternalGoop( $event, $hook ) {
$object = NULL;
$method = NULL;
$func = NULL;
$data = NULL;
$have_data = false;
- if (is_array($hook)) {
- if (count($hook) < 1) {
- throw new MWException("Empty array in hooks for " . $event . "\n");
- } else if (is_object($hook[0])) {
+ if ( is_array( $hook ) ) {
+ if ( count( $hook ) < 1 ) {
+ throw new MWException( "Empty array in hooks for " . $event . "\n" );
+ } else if ( is_object( $hook[0] ) ) {
$object = $hook[0];
- if (count($hook) < 2) {
+ if ( count( $hook ) < 2 ) {
$method = "on" . $event;
} else {
$method = $hook[1];
- if (count($hook) > 2) {
+ if ( count( $hook ) > 2 ) {
$data = $hook[2];
$have_data = true;
}
}
- } else if (is_string($hook[0])) {
+ } else if ( is_string( $hook[0] ) ) {
$func = $hook[0];
- if (count($hook) > 1) {
+ if ( count( $hook ) > 1 ) {
$data = $hook[1];
$have_data = true;
}
} else {
- var_dump( $wgHooks );
- throw new MWException("Unknown datatype in hooks for " . $event . "\n");
+ throw new MWException( "Unknown datatype in hooks for " . $event . "\n" );
}
- } else if (is_string($hook)) { # functions look like strings, too
+ } else if ( is_string( $hook ) ) { # functions look like strings, too
$func = $hook;
- } else if (is_object($hook)) {
+ } else if ( is_object( $hook ) ) {
$object = $hook;
$method = "on" . $event;
} else {
}
/* Return a string describing the hook for debugging purposes. */
-function wfFormatInvocation($event, $hook, $args = array()) {
- list($callback, $func, $data) = _wfInvokeInternalGoop($event, $hook, $args);
+function wfFormatInvocation( $event, $hook, $args = array() ) {
+ list( $callback, $func, $data ) = _wfInvokeInternalGoop( $event, $hook, $args );
if( is_array( $callback ) ) {
if( is_object( $callback[0] ) ) {
* If arguments are provided both as part of the hook itself, and when
* calling wfCallFancyCallback, the two arrays are merged.
*/
-function wfInvoke($event, $hook, $args = array()) {
- list($callback, $func, $data) = _wfInvokeInternalGoop($event, $hook, $args);
+function wfInvoke( $event, $hook, $args = array() ) {
+ list( $callback, $func, $data ) = _wfInvokeInternalGoop( $event, $hook, $args );
/* We put the first data element on, if needed. */
- if ($data) {
- $hook_args = array_merge(array($data), $args);
+ if ( $data ) {
+ $hook_args = array_merge( array( $data ), $args );
} else {
$hook_args = $args;
}
* careful about its contents. So, there's a lot more error-checking
* in here than would normally be necessary.
*/
-function wfRunHooks($event, $args = array()) {
+function wfRunHooks( $event, $args = array() ) {
global $wgHooks;
- if (!is_array($wgHooks)) {
- throw new MWException("Global hooks array is not an array!\n");
+ if ( !is_array( $wgHooks ) ) {
+ throw new MWException( "Global hooks array is not an array!\n" );
return false;
}
- if (!array_key_exists($event, $wgHooks)) {
+ if (!array_key_exists( $event, $wgHooks ) ) {
return true;
}
- if (!is_array($wgHooks[$event])) {
- throw new MWException("Hooks array for event '$event' is not an array!\n");
+ if ( !is_array( $wgHooks[$event] ) ) {
+ throw new MWException( "Hooks array for event '$event' is not an array!\n" );
return false;
}
- foreach ($wgHooks[$event] as $index => $hook) {
+ foreach ( $wgHooks[$event] as $index => $hook ) {
- $retval = wfInvoke($event, $hook, $args);
+ $retval = wfInvoke( $event, $hook, $args );
/* String return is an error; false return means stop processing. */
- if (is_string($retval)) {
+ if ( is_string( $retval ) ) {
global $wgOut;
- $wgOut->showFatalError($retval);
+ $wgOut->showFatalError( $retval );
return false;
} elseif( $retval === null ) {
- $prettyFunc = wfFormatInvocation($event, $hook, $args);
+ $prettyFunc = wfFormatInvocation( $event, $hook, $args );
throw new MWException( "Detected bug in an extension! " .
"Hook $prettyFunc failed to return a value; " .
"should return true to continue hook processing or false to abort." );
- } else if (!$retval) {
+ } else if ( !$retval ) {
return false;
}
}
* The recipient is appended to the arguments given to messageCompositionFunction.
* Both callbacks are to be given in the same formats accepted by the hook system.
*/
- static function notify($editor, $timestamp, $userListFunction, $messageCompositionFunction) {
+ static function notify( $editor, $timestamp, $userListFunction, $messageCompositionFunction ) {
global $wgEnotifUseRealName, $wgEnotifImpersonal;
global $wgLang;
- $common_keys = self::commonMessageKeys($editor);
- $users = wfInvoke("userList", $userListFunction);
- foreach($users as $u) {
- list($user_keys, $body_msg_name, $subj_msg_name) =
- wfInvoke("message", $messageCompositionFunction, array($u));
- $keys = array_merge($common_keys, $user_keys);
+ $users = wfInvoke( 'userList', $userListFunction );
+ if( !count( $users ) )
+ return;
+
+ $common_keys = self::commonMessageKeys( $editor );
+ foreach( $users as $u ) {
+ list( $user_keys, $body_msg_name, $subj_msg_name ) =
+ wfInvoke( 'message', $messageCompositionFunction, array( $u ) );
+ $keys = array_merge( $common_keys, $user_keys );
if( $wgEnotifImpersonal ) {
- $keys['$WATCHINGUSERNAME'] = wfMsgForContent('enotif_impersonal_salutation');
- $keys['$PAGEEDITDATE'] = $wgLang->timeanddate($timestamp, true, false, false);
+ $keys['$WATCHINGUSERNAME'] = wfMsgForContent( 'enotif_impersonal_salutation' );
+ $keys['$PAGEEDITDATE'] = $wgLang->timeanddate( $timestamp, true, false, false );
} else {
$keys['$WATCHINGUSERNAME'] = $wgEnotifUseRealName ? $u->getRealName() : $u->getName();
- $keys['$PAGEEDITDATE'] = $wgLang->timeAndDate($timestamp, true, false,
- $u->getOption('timecorrection'));
+ $keys['$PAGEEDITDATE'] = $wgLang->timeAndDate( $timestamp, true, false,
+ $u->getOption( 'timecorrection' ) );
}
- $subject = strtr(wfMsgForContent( $subj_msg_name ), $keys);
+ $subject = strtr( wfMsgForContent( $subj_msg_name ), $keys );
$body = wordwrap( strtr( wfMsgForContent( $body_msg_name ), $keys ), 72 );
- $to = new MailAddress($u);
+ $to = new MailAddress( $u );
$from = $keys['$FROM_HEADER'];
$replyto = $keys['$REPLYTO_HEADER'];
- UserMailer::send($to, $from, $subject, $body, $replyto);
+ UserMailer::send( $to, $from, $subject, $body, $replyto );
}
}
- static function commonMessageKeys($editor) {
+ static function commonMessageKeys( $editor ) {
global $wgEnotifUseRealName, $wgEnotifRevealEditorAddress;
global $wgNoReplyAddress, $wgPasswordSender;
$keys['$REPLYTO_HEADER'] = $replyto;
if( $editor->isAnon() ) {
- $keys['$PAGEEDITOR'] = wfMsgForContent('enotif_anon_editor', $name);
+ $keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $name );
$keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
} else{
$keys['$PAGEEDITOR'] = $name;
- $keys['$PAGEEDITOR_EMAIL'] = SpecialPage::getSafeTitleFor('Emailuser', $name)->getFullUrl();
+ $keys['$PAGEEDITOR_EMAIL'] = SpecialPage::getSafeTitleFor( 'Emailuser', $name )->getFullUrl();
}
$keys['$PAGEEDITOR_WIKI'] = $editor->getUserPage()->getFullUrl();
* @param $minorEdit
* @param $oldid (default: false)
*/
- static function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) {
+ static function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
global $wgEnotifUseJobQ;
- if( $title->getNamespace() < 0 )
+ if ( $title->getNamespace() < 0 )
return;
- if ($wgEnotifUseJobQ) {
+ if ( $wgEnotifUseJobQ ) {
$params = array(
"editor" => $editor->getName(),
"editorID" => $editor->getID(),
$job = new EnotifNotifyJob( $title, $params );
$job->insert();
} else {
- self::actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid);
+ self::actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid );
}
}
* @param $minorEdit
* @param $oldid (default: false)
*/
- static function actuallyNotifyOnPageChange($editor, $title, $timestamp,
- $summary, $minorEdit, $oldid=false) {
+ static function actuallyNotifyOnPageChange( $editor, $title, $timestamp,
+ $summary, $minorEdit, $oldid = false ) {
global $wgShowUpdatedMarker, $wgEnotifWatchlist;
wfProfileIn( __METHOD__ );
- EmailNotification::notify($editor, $timestamp,
- array('PageChangeNotification::usersList', array($editor, $title, $minorEdit)),
- array('PageChangeNotification::message', array($oldid, $minorEdit, $summary, $title, $editor) ) );
+ EmailNotification::notify( $editor, $timestamp,
+ array( 'PageChangeNotification::usersList', array( $editor, $title, $minorEdit ) ),
+ array( 'PageChangeNotification::message', array( $oldid, $minorEdit, $summary, $title, $editor ) ) );
$latestTimestamp = Revision::getTimestampFromId( $title, $title->getLatestRevID() );
// Do not update watchlists if something else already did.
static function message( $stuff ) {
global $wgEnotifImpersonal;
- list($oldid, $medit, $summary, $title, $user) = $stuff;
+ list( $oldid, $medit, $summary, $title, $user ) = $stuff;
$keys = array();
# regarding the use of oldid as an indicator for the last visited version, see also
if ($wgEnotifImpersonal && $oldid) {
# For impersonal mail, show a diff link to the last revision.
- $keys['$NEWPAGE'] = wfMsgForContent('enotif_lastdiff',
- $title->getFullURL("oldid={$oldid}&diff=prev"));
+ $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
+ $title->getFullURL( "oldid={$oldid}&diff=prev" ) );
}
$keys['$PAGETITLE'] = $title->getPrefixedText();
$keys['$PAGETITLE_URL'] = $title->getFullUrl();
$keys['$PAGEMINOREDIT'] = $medit ? wfMsg( 'minoredit' ) : '';
- $keys['$PAGESUMMARY'] = ($summary == '') ? ' - ' : $summary;
+ $keys['$PAGESUMMARY'] = ( $summary == '' ) ? ' - ' : $summary;
- return array($keys, 'enotif_body', 'enotif_subject');
+ return array( $keys, 'enotif_body', 'enotif_subject' );
}
- static function usersList($stuff) {
+ static function usersList( $stuff ) {
global $wgEnotifWatchlist, $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges;
- list($editor, $title, $minorEdit) = $stuff;
+ list( $editor, $title, $minorEdit ) = $stuff;
$recipients = array();
# User talk pages:
$userTalkId = false;
- if( $title->getNamespace() == NS_USER_TALK && (!$minorEdit || $wgEnotifMinorEdits) ) {
- $targetUser = User::newFromName($title->getText());
+ if( $title->getNamespace() == NS_USER_TALK && ( !$minorEdit || $wgEnotifMinorEdits ) ) {
+ $targetUser = User::newFromName( $title->getText() );
if ( !$targetUser || $targetUser->isAnon() )
$msg = "user talk page edited, but user does not exist";
else if ( $targetUser->getId() == $editor->getId() )
$msg = "user edited their own talk page, no notification sent";
- else if ( !$targetUser->getOption('enotifusertalkpages') )
+ else if ( !$targetUser->getOption( 'enotifusertalkpages' ) )
$msg = "talk page owner doesn't want notifications";
else if ( !$targetUser->isEmailConfirmed() )
$recipients[] = $targetUser;
$userTalkId = $targetUser->getId(); # won't be included in watchlist, below.
}
- wfDebug( __METHOD__ .": ". $msg . "\n" );
+ wfDebug( __METHOD__ . ': ' . $msg . "\n" );
}
- wfDebug("Did not send a user-talk notification.\n");
+ wfDebug( "Did not send a user-talk notification.\n" );
- if( $wgEnotifWatchlist && (!$minorEdit || $wgEnotifMinorEdits) ) {
+ if( $wgEnotifWatchlist && ( !$minorEdit || $wgEnotifMinorEdits ) ) {
// Send updates to watchers other than the current editor
$userCondition = 'wl_user != ' . $editor->getID();
}
foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
- $recipients[] = User::newFromName($name);
+ $recipients[] = User::newFromName( $name );
}
return $recipients;