diff options
author | Alexandre Emsenhuber <ialex.wiki@gmail.com> | 2012-07-13 21:50:25 +0200 |
---|---|---|
committer | Alexandre Emsenhuber <ialex.wiki@gmail.com> | 2012-07-13 21:54:00 +0200 |
commit | 81fb02e93915a41a74b6582c69a9f579cb5a026f (patch) | |
tree | 9f3703a0831ae31da2370e9448cbeef433e3dd36 /includes/RecentChange.php | |
parent | e9e59c1b2f8996de82b8b85de764f8ef3d45a3d7 (diff) | |
download | mediawikicore-81fb02e93915a41a74b6582c69a9f579cb5a026f.tar.gz mediawikicore-81fb02e93915a41a74b6582c69a9f579cb5a026f.zip |
Store the Title and User objects passed RecentChange::notify*()
* Set RecentChange::$mTitle when calling RecentChange::notify*();
avoid having to create new Title objects when making the IRC text
and email notification
* Added RecentChange::$mPerformer to store the User doing the change
and avoid having to mess with $wgUser to get back the object when
doing email notification
Change-Id: I505c3818b9baea0e7b5ddf8f5645a79743dd305a
Diffstat (limited to 'includes/RecentChange.php')
-rw-r--r-- | includes/RecentChange.php | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/includes/RecentChange.php b/includes/RecentChange.php index fb8e0224e26a..62c539bc1e5f 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -71,6 +71,11 @@ class RecentChange { var $mTitle = false; /** + * @var User + */ + private $mPerformer = false; + + /** * @var Title */ var $mMovedToTitle = false; @@ -169,11 +174,27 @@ class RecentChange { } /** + * Get the User object of the person who performed this change. + * + * @return User + */ + public function getPerformer() { + if ( $this->mPerformer === false ) { + if ( $this->mAttribs['rc_user'] ) { + $this->mPerformer = User::newFromID( $this->mAttribs['rc_user'] ); + } else { + $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false ); + } + } + return $this->mPerformer; + } + + /** * Writes the data in this object to the database * @param $noudp bool */ public function save( $noudp = false ) { - global $wgLocalInterwiki, $wgPutIPinRC, $wgContLang; + global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang; $dbw = wfGetDB( DB_MASTER ); if( !is_array($this->mExtra) ) { @@ -218,18 +239,9 @@ class RecentChange { } # E-mail notifications - global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser; if( $wgUseEnotif || $wgShowUpdatedMarker ) { - // Users - if( $this->mAttribs['rc_user'] ) { - $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ? - $wgUser : User::newFromID( $this->mAttribs['rc_user'] ); - // Anons - } else { - $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ? - $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false ); - } - $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] ); + $editor = $this->getPerformer(); + $title = $this->getTitle(); # @todo FIXME: This would be better as an extension hook $enotif = new EmailNotification(); @@ -391,6 +403,8 @@ class RecentChange { public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) { $rc = new RecentChange; + $rc->mTitle = $title; + $rc->mPerformer = $user; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, 'rc_cur_time' => $timestamp, @@ -449,6 +463,8 @@ class RecentChange { public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, $ip='', $size=0, $newId=0, $patrol=0 ) { $rc = new RecentChange; + $rc->mTitle = $title; + $rc->mPerformer = $user; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, 'rc_cur_time' => $timestamp, @@ -536,6 +552,8 @@ class RecentChange { global $wgRequest; $rc = new RecentChange; + $rc->mTitle = $target; + $rc->mPerformer = $user; $rc->mAttribs = array( 'rc_timestamp' => $timestamp, 'rc_cur_time' => $timestamp, |