MediaWiki master
PageLangLogFormatter.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Logging;
27
29
36 private LanguageNameUtils $languageNameUtils;
37
38 public function __construct(
40 LanguageNameUtils $languageNameUtils
41 ) {
42 parent::__construct( $entry );
43 $this->languageNameUtils = $languageNameUtils;
44 }
45
46 protected function getMessageParameters() {
47 // Get the user language for displaying language names
48 $userLang = $this->context->getLanguage()->getCode();
49 $params = parent::getMessageParameters();
50
51 // Get the language codes from log
52 $oldLang = $params[3];
53 $kOld = strrpos( $oldLang, '[' );
54 if ( $kOld ) {
55 $oldLang = substr( $oldLang, 0, $kOld );
56 }
57
58 $newLang = $params[4];
59 $kNew = strrpos( $newLang, '[' );
60 if ( $kNew ) {
61 $newLang = substr( $newLang, 0, $kNew );
62 }
63
64 // Convert language codes to names in user language
65 $logOld = $this->languageNameUtils->getLanguageName( $oldLang, $userLang )
66 . ' (' . $oldLang . ')';
67 $logNew = $this->languageNameUtils->getLanguageName( $newLang, $userLang )
68 . ' (' . $newLang . ')';
69
70 // Add the default message to languages if required
71 $params[3] = !$kOld ? $logOld : $logOld . ' [' . $this->msg( 'default' ) . ']';
72 $params[4] = !$kNew ? $logNew : $logNew . ' [' . $this->msg( 'default' ) . ']';
73 return $params;
74 }
75}
76
78class_alias( PageLangLogFormatter::class, 'PageLangLogFormatter' );
A service that provides utilities to do with language names and codes.
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.
__construct(LogEntry $entry, LanguageNameUtils $languageNameUtils)
An individual log entry.
Definition LogEntry.php:37
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...