From: Alexandre Emsenhuber Date: Sat, 18 Aug 2012 11:24:19 +0000 (+0200) Subject: Use LogFormatter to format rights log. X-Git-Tag: 1.31.0-rc.0~21769^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=4c69cd3ad68de9eb987b93a31e04fa38d07381bb;p=lhc%2Fweb%2Fwiklou.git Use LogFormatter to format rights log. * Has to keep actual messages for IRC notification * Catch really old log entries with no parameters and use an appropriate message in that case to not always display erroneous "X changed group membership for Y from (none) to (none)". Change-Id: Ie188bc6fcdf672fe31f0f389a158aab6256031fa --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 1cf66348d6..8109c6ec44 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -700,6 +700,7 @@ $wgAutoloadLocalClasses = array( 'PatrolLog' => 'includes/logging/PatrolLog.php', 'PatrolLogFormatter' => 'includes/logging/LogFormatter.php', 'RCDatabaseLogEntry' => 'includes/logging/LogEntry.php', + 'RightsLogFormatter' => 'includes/logging/LogFormatter.php', # includes/media 'BitmapHandler' => 'includes/media/Bitmap.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index cea63e07a3..cc90ffe1a1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5641,8 +5641,6 @@ $wgLogActions = array( 'protect/modify' => 'modifiedarticleprotection', 'protect/unprotect' => 'unprotectedarticle', 'protect/move_prot' => 'movedarticleprotection', - 'rights/rights' => 'rightslogentry', - 'rights/autopromote' => 'rightslogentry-autopromote', 'upload/upload' => 'uploadedimage', 'upload/overwrite' => 'overwroteimage', 'upload/revert' => 'uploadedimage', @@ -5660,16 +5658,18 @@ $wgLogActions = array( * @see LogFormatter */ $wgLogActionsHandlers = array( - 'move/move' => 'MoveLogFormatter', - 'move/move_redir' => 'MoveLogFormatter', - 'delete/delete' => 'DeleteLogFormatter', - 'delete/restore' => 'DeleteLogFormatter', - 'delete/revision' => 'DeleteLogFormatter', - 'delete/event' => 'DeleteLogFormatter', - 'suppress/revision' => 'DeleteLogFormatter', - 'suppress/event' => 'DeleteLogFormatter', - 'suppress/delete' => 'DeleteLogFormatter', - 'patrol/patrol' => 'PatrolLogFormatter', + 'move/move' => 'MoveLogFormatter', + 'move/move_redir' => 'MoveLogFormatter', + 'delete/delete' => 'DeleteLogFormatter', + 'delete/restore' => 'DeleteLogFormatter', + 'delete/revision' => 'DeleteLogFormatter', + 'delete/event' => 'DeleteLogFormatter', + 'suppress/revision' => 'DeleteLogFormatter', + 'suppress/event' => 'DeleteLogFormatter', + 'suppress/delete' => 'DeleteLogFormatter', + 'patrol/patrol' => 'PatrolLogFormatter', + 'rights/rights' => 'RightsLogFormatter', + 'rights/autopromote' => 'RightsLogFormatter', ); /** diff --git a/includes/User.php b/includes/User.php index a197077011..062bd6dae7 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1155,13 +1155,17 @@ class User { } $newGroups = array_merge( $oldGroups, $toPromote ); // all groups - $log = new LogPage( 'rights', $wgAutopromoteOnceLogInRC /* in RC? */ ); - $log->addEntry( 'autopromote', - $this->getUserPage(), - '', // no comment - // These group names are "list to texted"-ed in class LogPage. - array( implode( ', ', $oldGroups ), implode( ', ', $newGroups ) ) - ); + $logEntry = new ManualLogEntry( 'rights', 'autopromote' ); + $logEntry->setPerformer( $this ); + $logEntry->setTarget( $this->getUserPage() ); + $logEntry->setParameters( array( + '4::oldgroups' => $oldGroups, + '5::newgroups' => $newGroups, + ) ); + $logid = $logEntry->insert(); + if ( $wgAutopromoteOnceLogInRC ) { + $logEntry->publish( $logid ); + } } } return $toPromote; diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 7d94a30bd4..8c1e294b3e 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -293,6 +293,28 @@ class LogFormatter { } break; + case 'rights': + if ( count( $parameters['4::oldgroups'] ) ) { + $oldgroups = implode( ', ', $parameters['4::oldgroups'] ); + } else { + $oldgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped(); + } + if ( count( $parameters['5::newgroups'] ) ) { + $newgroups = implode( ', ', $parameters['5::newgroups'] ); + } else { + $newgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped(); + } + switch( $entry->getSubtype() ) { + case 'rights': + $text = wfMessage( 'rightslogentry' ) + ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped(); + break; + case 'autopromote': + $text = wfMessage( 'rightslogentry-autopromote' ) + ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped(); + break; + } + break; // case 'suppress' --private log -- aaron (sign your messages so we know who to blame in a few years :-D) // default: @@ -1009,3 +1031,88 @@ class NewUsersLogFormatter extends LogFormatter { return array(); } } + +/** + * This class formats rights log entries. + * @since 1.21 + */ +class RightsLogFormatter extends LogFormatter { + protected function makePageLink( Title $title = null, $parameters = array() ) { + global $wgContLang, $wgUserrightsInterwikiDelimiter; + + if ( !$this->plaintext ) { + $text = $wgContLang->ucfirst( $title->getText() ); + $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 ); + + if ( count( $parts ) === 2 ) { + $titleLink = WikiMap::foreignUserLink( $parts[1], $parts[0], + htmlspecialchars( $title->getPrefixedText() ) ); + + if ( $titleLink !== false ) { + return $titleLink; + } + } + } + + return parent::makePageLink( $title, $parameters ); + } + + protected function getMessageKey() { + $key = parent::getMessageKey(); + $params = $this->getMessageParameters(); + if ( !isset( $params[3] ) && !isset( $params[4] ) ) { + $key .= '-legacy'; + } + return $key; + } + + protected function getMessageParameters() { + $params = parent::getMessageParameters(); + + // Really old entries + if ( !isset( $params[3] ) && !isset( $params[4] ) ) { + return $params; + } + + $oldGroups = $params[3]; + $newGroups = $params[4]; + + // Less old entries + if ( $oldGroups === '' ) { + $oldGroups = array(); + } elseif ( is_string( $oldGroups ) ) { + $oldGroups = array_map( 'trim', explode( ',', $oldGroups ) ); + } + if ( $newGroups === '' ) { + $newGroups = array(); + } elseif ( is_string( $newGroups ) ) { + $newGroups = array_map( 'trim', explode( ',', $newGroups ) ); + } + + $userName = $this->entry->getTarget()->getText(); + if ( !$this->plaintext && count( $oldGroups ) ) { + foreach ( $oldGroups as &$group ) { + $group = User::getGroupMember( $group, $userName ); + } + } + if ( !$this->plaintext && count( $newGroups ) ) { + foreach ( $newGroups as &$group ) { + $group = User::getGroupMember( $group, $userName ); + } + } + + $lang = $this->context->getLanguage(); + if ( count( $oldGroups ) ) { + $params[3] = $lang->listToText( $oldGroups ); + } else { + $params[3] = $this->msg( 'rightsnone' )->text(); + } + if ( count( $newGroups ) ) { + $params[4] = $lang->listToText( $newGroups ); + } else { + $params[4] = $this->msg( 'rightsnone' )->text(); + } + + return $params; + } +} diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 90393ea8d6..07238a053a 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -253,29 +253,6 @@ class LogPage { } else { $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params ); - if( preg_match( '/^rights\/(rights|autopromote)/', $key ) ) { - $rightsnone = wfMessage( 'rightsnone' )->inLanguage( $langObj )->text(); - - if( $skin ) { - $username = $title->getText(); - foreach ( $params as &$param ) { - $groupArray = array_map( 'trim', explode( ',', $param ) ); - foreach( $groupArray as &$group ) { - $group = User::getGroupMember( $group, $username ); - } - $param = $wgLang->listToText( $groupArray ); - } - } - - if( !isset( $params[0] ) || trim( $params[0] ) == '' ) { - $params[0] = $rightsnone; - } - - if( !isset( $params[1] ) || trim( $params[1] ) == '' ) { - $params[1] = $rightsnone; - } - } - if( count( $params ) == 0 ) { $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )->inLanguage( $langObj )->escaped(); } else { @@ -350,8 +327,6 @@ class LogPage { * @return String */ protected static function getTitleLink( $type, $lang, $title, &$params ) { - global $wgContLang, $wgUserrightsInterwikiDelimiter; - if( !$lang ) { return $title->getPrefixedText(); } @@ -388,20 +363,6 @@ class LogPage { . Linker::userToolLinks( $id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK ); } break; - case 'rights': - $text = $wgContLang->ucfirst( $title->getText() ); - $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 ); - - if ( count( $parts ) == 2 ) { - $titleLink = WikiMap::foreignUserLink( $parts[1], $parts[0], - htmlspecialchars( $title->getPrefixedText() ) ); - - if ( $titleLink !== false ) { - break; - } - } - $titleLink = Linker::link( Title::makeTitle( NS_USER, $text ) ); - break; case 'merge': $titleLink = Linker::link( $title, diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 56ae302013..42ede97723 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -245,16 +245,16 @@ class UserrightsPage extends SpecialPage { * Add a rights log entry for an action. */ function addLogEntry( $user, $oldGroups, $newGroups, $reason ) { - $log = new LogPage( 'rights' ); - - $log->addEntry( 'rights', - $user->getUserPage(), - $reason, - array( - $this->makeGroupNameListForLog( $oldGroups ), - $this->makeGroupNameListForLog( $newGroups ) - ) - ); + $logEntry = new ManualLogEntry( 'rights', 'rights' ); + $logEntry->setPerformer( $this->getUser() ); + $logEntry->setTarget( $user->getUserPage() ); + $logEntry->setComment( $reason ); + $logEntry->setParameters( array( + '4::oldgroups' => $oldGroups, + '5::newgroups' => $newGroups, + ) ); + $logid = $logEntry->insert(); + $logEntry->publish( $logid ); } /** @@ -355,7 +355,16 @@ class UserrightsPage extends SpecialPage { } } + /** + * Make a list of group names to be stored as parameter for log entries + * + * @deprecated in 1.21; use LogFormatter instead. + * @param $ids array + * @return string + */ function makeGroupNameListForLog( $ids ) { + wfDeprecated( __METHOD__, '1.21' ); + if( empty( $ids ) ) { return ''; } else { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index dc5fb52788..64e29155fb 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2047,11 +2047,14 @@ Your e-mail address is not revealed when other users contact you.', 'right-passwordreset' => 'View password reset e-mails', # User rights log -'rightslog' => 'User rights log', -'rightslogtext' => 'This is a log of changes to user rights.', -'rightslogentry' => 'changed group membership for $1 from $2 to $3', -'rightslogentry-autopromote' => 'was automatically promoted from $2 to $3', -'rightsnone' => '(none)', +'rightslog' => 'User rights log', +'rightslogtext' => 'This is a log of changes to user rights.', +'rightslogentry' => 'changed group membership for $1 from $2 to $3', +'rightslogentry-autopromote' => 'was automatically promoted from $2 to $3', +'logentry-rights-rights' => '$1 changed group membership for $3 from $4 to $5', +'logentry-rights-rights-legacy' => '$1 changed group membership for $3', +'logentry-rights-autopromote' => '$1 was automatically promoted from $4 to $5', +'rightsnone' => '(none)', # Associated actions - in the sentence "You do not have permission to X" 'action-read' => 'read this page', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 60e0f30e59..765c2dcd37 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1190,6 +1190,9 @@ $wgMessageStructure = array( 'rightslogtext', 'rightslogentry', 'rightslogentry-autopromote', + 'logentry-rights-rights', + 'logentry-rights-rights-legacy', + 'logentry-rights-autopromote', 'rightsnone', ), 'action' => array(