2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\TranslatorInterface;
6use MediaWiki\Config\Config;
7use MediaWiki\Extension\CLDR\LanguageNames;
8use MediaWiki\Hook\FetchChangesListHook;
9use MediaWiki\Hook\SpecialRecentChangesPanelHook;
10use MediaWiki\Html\Html;
11use MediaWiki\Languages\LanguageNameUtils;
12use MediaWiki\SpecialPage\Hook\ChangesListSpecialPageQueryHook;
14use Wikimedia\Rdbms\ILoadBalancer;
24 ChangesListSpecialPageQueryHook,
25 SpecialRecentChangesPanelHook
27 private Config $config;
28 private LanguageNameUtils $languageNameUtils;
29 private ILoadBalancer $loadBalancer;
31 public function __construct( LanguageNameUtils $languageNameUtils, ILoadBalancer $loadBalancer, Config $config ) {
32 $this->languageNameUtils = $languageNameUtils;
33 $this->loadBalancer = $loadBalancer;
34 $this->config = $config;
42 $name, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts
45 if ( !$this->config->get(
'TranslateRecentChangesLanguageFilter' ) ) {
49 $opts->add(
'trailer',
'' );
50 $trailer = $wgRequest->getVal(
'trailer',
'' );
51 if ( $trailer ===
null ) {
55 $dbr = $this->loadBalancer->getConnection( DB_REPLICA );
56 $conds[] =
'rc_title ' . $dbr->buildLike( $dbr->anyString(), $trailer );
57 $opts->setValue(
'trailer', $trailer );
65 global $wgLang, $wgRequest;
66 if ( !$this->config->get(
'TranslateRecentChangesLanguageFilter' ) ) {
72 $default = $wgRequest->getVal(
'trailer',
'' );
74 if ( is_callable( [ LanguageNames::class,
'getNames' ] ) ) {
76 $languages = LanguageNames::getNames(
78 LanguageNames::FALLBACK_NORMAL
81 $languages = $this->languageNameUtils->getLanguageNames();
84 $optionAttributes = [
'value' =>
'' ];
85 if ( $default ===
'' ) {
86 $optionAttributes[
'selected' ] =
'selected';
89 $options = Html::element(
92 wfMessage(
'tpt-cleanchanges-language-na' )->text()
95 foreach ( $languages as $code => $name ) {
96 $selected = (
"/$code" === $default );
97 $optionAttributes = [
'value' =>
"/$code" ];
99 $optionAttributes[
'selected' ] =
'selected';
101 $options .= Html::element(
'option', $optionAttributes,
"$code - $name" ) .
"\n";
104 Xml::openElement(
'select',
107 'class' =>
'mw-language-selector',
108 'id' =>
'tpt-rc-language',
111 Xml::closeElement(
'select' );
113 $extraOpts[
'tailer'] = [ wfMessage(
'tpt-cleanchanges-language' )->escaped(), $str ];
121 if ( $this->config->get(
'TranslateRecentChangesLanguageFilter' ) && defined(
'ULS_VERSION' ) ) {
122 $skin->getOutput()->addModules(
'ext.translate.cleanchanges' );