Merge "Fix positioning of jQuery.tipsy tooltip arrows"
[mediawiki.git] / includes / logging / RightsLogFormatter.php
blob79ffe867a4086b76474251479a20aa7340bd1100
1 <?php
2 /**
3 * Formatter for user rights log entries.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Alexandre Emsenhuber
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
23 * @since 1.22
26 /**
27 * This class formats rights log entries.
29 * @since 1.21
31 class RightsLogFormatter extends LogFormatter {
32 protected function makePageLink( Title $title = null, $parameters = array(), $html = null ) {
33 global $wgContLang, $wgUserrightsInterwikiDelimiter;
35 if ( !$this->plaintext ) {
36 $text = $wgContLang->ucfirst( $title->getText() );
37 $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
39 if ( count( $parts ) === 2 ) {
40 $titleLink = WikiMap::foreignUserLink( $parts[1], $parts[0],
41 htmlspecialchars( $title->getText() ) );
43 if ( $titleLink !== false ) {
44 return $titleLink;
49 return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
52 protected function getMessageKey() {
53 $key = parent::getMessageKey();
54 $params = $this->getMessageParameters();
55 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
56 $key .= '-legacy';
59 return $key;
62 protected function getMessageParameters() {
63 $params = parent::getMessageParameters();
65 // Really old entries
66 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
67 return $params;
70 $oldGroups = $this->makeGroupArray( $params[3] );
71 $newGroups = $this->makeGroupArray( $params[4] );
73 $userName = $this->entry->getTarget()->getText();
74 if ( !$this->plaintext && count( $oldGroups ) ) {
75 foreach ( $oldGroups as &$group ) {
76 $group = User::getGroupMember( $group, $userName );
79 if ( !$this->plaintext && count( $newGroups ) ) {
80 foreach ( $newGroups as &$group ) {
81 $group = User::getGroupMember( $group, $userName );
85 $lang = $this->context->getLanguage();
86 if ( count( $oldGroups ) ) {
87 $params[3] = $lang->listToText( $oldGroups );
88 } else {
89 $params[3] = $this->msg( 'rightsnone' )->text();
91 if ( count( $newGroups ) ) {
92 // Array_values is used here because of bug 42211
93 // see use of array_unique in UserrightsPage::doSaveUserGroups on $newGroups.
94 $params[4] = $lang->listToText( array_values( $newGroups ) );
95 } else {
96 $params[4] = $this->msg( 'rightsnone' )->text();
99 return $params;
102 protected function getParametersForApi() {
103 $entry = $this->entry;
104 $params = $entry->getParameters();
106 static $map = array(
107 '4:array:oldgroups',
108 '5:array:newgroups',
109 '4::oldgroups' => '4:array:oldgroups',
110 '5::newgroups' => '5:array:newgroups',
112 foreach ( $map as $index => $key ) {
113 if ( isset( $params[$index] ) ) {
114 $params[$key] = $params[$index];
115 unset( $params[$index] );
119 // Really old entries does not have log params
120 if ( isset( $params['4:array:oldgroups'] ) ) {
121 $params['4:array:oldgroups'] = $this->makeGroupArray( $params['4:array:oldgroups'] );
123 if ( isset( $params['5:array:newgroups'] ) ) {
124 $params['5:array:newgroups'] = $this->makeGroupArray( $params['5:array:newgroups'] );
127 return $params;
130 public function formatParametersForApi() {
131 $ret = parent::formatParametersForApi();
132 if ( isset( $ret['oldgroups'] ) ) {
133 ApiResult::setIndexedTagName( $ret['oldgroups'], 'g' );
135 if ( isset( $ret['newgroups'] ) ) {
136 ApiResult::setIndexedTagName( $ret['newgroups'], 'g' );
138 return $ret;
141 private function makeGroupArray( $group ) {
142 // Migrate old group params from string to array
143 if ( $group === '' ) {
144 $group = array();
145 } elseif ( is_string( $group ) ) {
146 $group = array_map( 'trim', explode( ',', $group ) );
148 return $group;