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
21 * @author Alexandre Emsenhuber
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
27 * This class formats rights log entries.
31 class RightsLogFormatter
extends LogFormatter
{
32 protected function makePageLink( Title
$title = null, $parameters = [], $html = null ) {
33 global $wgContLang, $wgUserrightsInterwikiDelimiter;
35 if ( !$this->plaintext
) {
36 $text = $wgContLang->ucfirst( $title->getDBkey() );
37 $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
39 if ( count( $parts ) === 2 ) {
40 $titleLink = WikiMap
::foreignUserLink(
44 strtr( $parts[0], '_', ' ' ) .
45 $wgUserrightsInterwikiDelimiter .
50 if ( $titleLink !== false ) {
56 return parent
::makePageLink( $title, $parameters, $title ?
$title->getText() : null );
59 protected function getMessageKey() {
60 $key = parent
::getMessageKey();
61 $params = $this->getMessageParameters();
62 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
63 // Messages: logentry-rights-rights-legacy
70 protected function getMessageParameters() {
71 $params = parent
::getMessageParameters();
74 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
78 $oldGroups = $this->makeGroupArray( $params[3] );
79 $newGroups = $this->makeGroupArray( $params[4] );
81 $userName = $this->entry
->getTarget()->getText();
82 if ( !$this->plaintext
&& count( $oldGroups ) ) {
83 foreach ( $oldGroups as &$group ) {
84 $group = User
::getGroupMember( $group, $userName );
87 if ( !$this->plaintext
&& count( $newGroups ) ) {
88 foreach ( $newGroups as &$group ) {
89 $group = User
::getGroupMember( $group, $userName );
93 $lang = $this->context
->getLanguage();
94 if ( count( $oldGroups ) ) {
95 $params[3] = $lang->listToText( $oldGroups );
97 $params[3] = $this->msg( 'rightsnone' )->text();
99 if ( count( $newGroups ) ) {
100 // Array_values is used here because of T44211
101 // see use of array_unique in UserrightsPage::doSaveUserGroups on $newGroups.
102 $params[4] = $lang->listToText( array_values( $newGroups ) );
104 $params[4] = $this->msg( 'rightsnone' )->text();
107 $params[5] = $userName;
112 protected function getParametersForApi() {
113 $entry = $this->entry
;
114 $params = $entry->getParameters();
119 '4::oldgroups' => '4:array:oldgroups',
120 '5::newgroups' => '5:array:newgroups',
122 foreach ( $map as $index => $key ) {
123 if ( isset( $params[$index] ) ) {
124 $params[$key] = $params[$index];
125 unset( $params[$index] );
129 // Really old entries does not have log params
130 if ( isset( $params['4:array:oldgroups'] ) ) {
131 $params['4:array:oldgroups'] = $this->makeGroupArray( $params['4:array:oldgroups'] );
133 if ( isset( $params['5:array:newgroups'] ) ) {
134 $params['5:array:newgroups'] = $this->makeGroupArray( $params['5:array:newgroups'] );
140 public function formatParametersForApi() {
141 $ret = parent
::formatParametersForApi();
142 if ( isset( $ret['oldgroups'] ) ) {
143 ApiResult
::setIndexedTagName( $ret['oldgroups'], 'g' );
145 if ( isset( $ret['newgroups'] ) ) {
146 ApiResult
::setIndexedTagName( $ret['newgroups'], 'g' );
151 private function makeGroupArray( $group ) {
152 // Migrate old group params from string to array
153 if ( $group === '' ) {
155 } elseif ( is_string( $group ) ) {
156 $group = array_map( 'trim', explode( ',', $group ) );