3 * Formatter for block 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 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
26 * This class formats block log entries.
30 class BlockLogFormatter
extends LogFormatter
{
31 protected function getMessageParameters() {
32 $params = parent
::getMessageParameters();
34 $title = $this->entry
->getTarget();
35 if ( substr( $title->getText(), 0, 1 ) === '#' ) {
36 // autoblock - no user link possible
37 $params[2] = $title->getText();
38 $params[3] = ''; // no user name for gender use
40 // Create a user link for the blocked
41 $username = $title->getText();
42 // @todo Store the user identifier in the parameters
43 // to make this faster for future log entries
44 $targetUser = User
::newFromName( $username, false );
45 $params[2] = Message
::rawParam( $this->makeUserLink( $targetUser, Linker
::TOOL_LINKS_NOBLOCK
) );
46 $params[3] = $username; // plain user name for gender use
49 $subtype = $this->entry
->getSubtype();
50 if ( $subtype === 'block' ||
$subtype === 'reblock' ) {
51 // Localize the duration, and add a tooltip
52 // in English to help visitors from other wikis.
53 // The lrm is needed to make sure that the number
54 // is shown on the correct side of the tooltip text.
55 $durationTooltip = '‎' . htmlspecialchars( $params[4] );
56 $params[4] = Message
::rawParam( "<span class='blockExpiry' title='$durationTooltip'>" .
57 $this->context
->getLanguage()->translateBlockExpiry( $params[4] ) . '</span>' );
58 $params[5] = isset( $params[5] ) ?
59 self
::formatBlockFlags( $params[5], $this->context
->getLanguage() ) : '';
65 protected function extractParameters() {
66 $params = parent
::extractParameters();
67 // Legacy log params returning the params in index 3 and 4, moved to 4 and 5
68 if ( $this->entry
->isLegacy() && isset( $params[3] ) ) {
69 if ( isset( $params[4] ) ) {
70 $params[5] = $params[4];
72 $params[4] = $params[3];
78 public function getPreloadTitles() {
79 $title = $this->entry
->getTarget();
80 // Preload user page for non-autoblocks
81 if ( substr( $title->getText(), 0, 1 ) !== '#' ) {
82 return array( $title->getTalkPage() );
87 public function getActionLinks() {
88 $subtype = $this->entry
->getSubtype();
89 if ( $this->entry
->isDeleted( LogPage
::DELETED_ACTION
) // Action is hidden
90 ||
!( $subtype === 'block' ||
$subtype === 'reblock' )
91 ||
!$this->context
->getUser()->isAllowed( 'block' )
96 // Show unblock/change block link
97 $title = $this->entry
->getTarget();
100 SpecialPage
::getTitleFor( 'Unblock', $title->getDBkey() ),
101 $this->msg( 'unblocklink' )->escaped()
104 SpecialPage
::getTitleFor( 'Block', $title->getDBkey() ),
105 $this->msg( 'change-blocklink' )->escaped()
109 return $this->msg( 'parentheses' )->rawParams(
110 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
114 * Convert a comma-delimited list of block log flags
115 * into a more readable (and translated) form
117 * @param string $flags Flags to format
118 * @param Language $lang
121 public static function formatBlockFlags( $flags, $lang ) {
122 $flags = trim( $flags );
123 if ( $flags === '' ) {
124 return ''; //nothing to do
126 $flags = explode( ',', $flags );
127 $flagsCount = count( $flags );
129 for ( $i = 0; $i < $flagsCount; $i++
) {
130 $flags[$i] = self
::formatBlockFlag( $flags[$i], $lang );
133 return wfMessage( 'parentheses' )->inLanguage( $lang )
134 ->rawParams( $lang->commaList( $flags ) )->escaped();
138 * Translate a block log flag if possible
140 * @param int $flag Flag to translate
141 * @param Language $lang Language object to use
144 public static function formatBlockFlag( $flag, $lang ) {
145 static $messages = array();
147 if ( !isset( $messages[$flag] ) ) {
148 $messages[$flag] = htmlspecialchars( $flag ); // Fallback
150 // For grepping. The following core messages can be used here:
151 // * block-log-flags-angry-autoblock
152 // * block-log-flags-anononly
153 // * block-log-flags-hiddenname
154 // * block-log-flags-noautoblock
155 // * block-log-flags-nocreate
156 // * block-log-flags-noemail
157 // * block-log-flags-nousertalk
158 $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
160 if ( $msg->exists() ) {
161 $messages[$flag] = $msg->escaped();
165 return $messages[$flag];