Merge "Change "permissions errors" message to "permission error""
[lhc/web/wiklou.git] / includes / logging / RightsLogFormatter.php
1 <?php
2 /**
3 * Formatter for user rights log entries.
4 *
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.
9 *
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.
14 *
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
19 *
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
24 */
25
26 /**
27 * This class formats rights log entries.
28 *
29 * @since 1.21
30 */
31 class RightsLogFormatter extends LogFormatter {
32 protected function makePageLink( Title $title = null, $parameters = array() ) {
33 global $wgContLang, $wgUserrightsInterwikiDelimiter;
34
35 if ( !$this->plaintext ) {
36 $text = $wgContLang->ucfirst( $title->getText() );
37 $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
38
39 if ( count( $parts ) === 2 ) {
40 $titleLink = WikiMap::foreignUserLink( $parts[1], $parts[0],
41 htmlspecialchars( $title->getPrefixedText() ) );
42
43 if ( $titleLink !== false ) {
44 return $titleLink;
45 }
46 }
47 }
48
49 return parent::makePageLink( $title, $parameters );
50 }
51
52 protected function getMessageKey() {
53 $key = parent::getMessageKey();
54 $params = $this->getMessageParameters();
55 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
56 $key .= '-legacy';
57 }
58 return $key;
59 }
60
61 protected function getMessageParameters() {
62 $params = parent::getMessageParameters();
63
64 // Really old entries
65 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
66 return $params;
67 }
68
69 $oldGroups = $params[3];
70 $newGroups = $params[4];
71
72 // Less old entries
73 if ( $oldGroups === '' ) {
74 $oldGroups = array();
75 } elseif ( is_string( $oldGroups ) ) {
76 $oldGroups = array_map( 'trim', explode( ',', $oldGroups ) );
77 }
78 if ( $newGroups === '' ) {
79 $newGroups = array();
80 } elseif ( is_string( $newGroups ) ) {
81 $newGroups = array_map( 'trim', explode( ',', $newGroups ) );
82 }
83
84 $userName = $this->entry->getTarget()->getText();
85 if ( !$this->plaintext && count( $oldGroups ) ) {
86 foreach ( $oldGroups as &$group ) {
87 $group = User::getGroupMember( $group, $userName );
88 }
89 }
90 if ( !$this->plaintext && count( $newGroups ) ) {
91 foreach ( $newGroups as &$group ) {
92 $group = User::getGroupMember( $group, $userName );
93 }
94 }
95
96 $lang = $this->context->getLanguage();
97 if ( count( $oldGroups ) ) {
98 $params[3] = $lang->listToText( $oldGroups );
99 } else {
100 $params[3] = $this->msg( 'rightsnone' )->text();
101 }
102 if ( count( $newGroups ) ) {
103 // Array_values is used here because of bug 42211
104 // see use of array_unique in UserrightsPage::doSaveUserGroups on $newGroups.
105 $params[4] = $lang->listToText( array_values( $newGroups ) );
106 } else {
107 $params[4] = $this->msg( 'rightsnone' )->text();
108 }
109
110 return $params;
111 }
112 }