MediaWiki master
PageLangLogFormatter.php
Go to the documentation of this file.
1<?php
12namespace MediaWiki\Logging;
13
14use MediaWiki\Languages\LanguageNameUtils;
15
22 private LanguageNameUtils $languageNameUtils;
23
24 public function __construct(
26 LanguageNameUtils $languageNameUtils
27 ) {
28 parent::__construct( $entry );
29 $this->languageNameUtils = $languageNameUtils;
30 }
31
33 protected function getMessageParameters() {
34 // Get the user language for displaying language names
35 $userLang = $this->context->getLanguage()->getCode();
36 $params = parent::getMessageParameters();
37
38 // Get the language codes from log
39 $oldLang = $params[3];
40 $kOld = strrpos( $oldLang, '[' );
41 if ( $kOld ) {
42 $oldLang = substr( $oldLang, 0, $kOld );
43 }
44
45 $newLang = $params[4];
46 $kNew = strrpos( $newLang, '[' );
47 if ( $kNew ) {
48 $newLang = substr( $newLang, 0, $kNew );
49 }
50
51 // Convert language codes to names in user language
52 $logOld = $this->languageNameUtils->getLanguageName( $oldLang, $userLang )
53 . ' (' . $oldLang . ')';
54 $logNew = $this->languageNameUtils->getLanguageName( $newLang, $userLang )
55 . ' (' . $newLang . ')';
56
57 // Add the default message to languages if required
58 $params[3] = !$kOld ? $logOld : $logOld . ' [' . $this->msg( 'default' ) . ']';
59 $params[4] = !$kNew ? $logNew : $logNew . ' [' . $this->msg( 'default' ) . ']';
60 return $params;
61 }
62}
63
65class_alias( PageLangLogFormatter::class, 'PageLangLogFormatter' );
Implements the default log formatting.
msg( $key,... $params)
Shortcut for wfMessage which honors local context.
This class formats language change log entries.
getMessageParameters()
Formats parameters intended for action message from array of all parameters.There are three hardcoded...
__construct(LogEntry $entry, LanguageNameUtils $languageNameUtils)
An individual log entry.
Definition LogEntry.php:23