MediaWiki master
PageLangLogFormatter.php
Go to the documentation of this file.
1<?php
27
34 private LanguageNameUtils $languageNameUtils;
35
36 public function __construct(
38 LanguageNameUtils $languageNameUtils
39 ) {
40 parent::__construct( $entry );
41 $this->languageNameUtils = $languageNameUtils;
42 }
43
44 protected function getMessageParameters() {
45 // Get the user language for displaying language names
46 $userLang = $this->context->getLanguage()->getCode();
47 $params = parent::getMessageParameters();
48
49 // Get the language codes from log
50 $oldLang = $params[3];
51 $kOld = strrpos( $oldLang, '[' );
52 if ( $kOld ) {
53 $oldLang = substr( $oldLang, 0, $kOld );
54 }
55
56 $newLang = $params[4];
57 $kNew = strrpos( $newLang, '[' );
58 if ( $kNew ) {
59 $newLang = substr( $newLang, 0, $kNew );
60 }
61
62 // Convert language codes to names in user language
63 $logOld = $this->languageNameUtils->getLanguageName( $oldLang, $userLang )
64 . ' (' . $oldLang . ')';
65 $logNew = $this->languageNameUtils->getLanguageName( $newLang, $userLang )
66 . ' (' . $newLang . ')';
67
68 // Add the default message to languages if required
69 $params[3] = !$kOld ? $logOld : $logOld . ' [' . $this->msg( 'default' ) . ']';
70 $params[4] = !$kNew ? $logNew : $logNew . ' [' . $this->msg( 'default' ) . ']';
71 return $params;
72 }
73}
array $params
The job parameters.
Implements the default log formatting.
LogEntryBase $entry
msg( $key,... $params)
Shortcut for wfMessage which honors local context.
A service that provides utilities to do with language names and codes.
This class formats language change log entries.
__construct(LogEntry $entry, LanguageNameUtils $languageNameUtils)
getMessageParameters()
Formats parameters intended for action message from array of all parameters.
An individual log entry.
Definition LogEntry.php:35