MediaWiki master
SpecialAllMessages.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
36
44
45 private LanguageFactory $languageFactory;
46 private LanguageNameUtils $languageNameUtils;
47 private IConnectionProvider $dbProvider;
48 private LocalisationCache $localisationCache;
49
56 public function __construct(
57 LanguageFactory $languageFactory,
58 LanguageNameUtils $languageNameUtils,
59 LocalisationCache $localisationCache,
60 IConnectionProvider $dbProvider
61 ) {
62 parent::__construct( 'Allmessages' );
63 $this->languageFactory = $languageFactory;
64 $this->languageNameUtils = $languageNameUtils;
65 $this->localisationCache = $localisationCache;
66 $this->dbProvider = $dbProvider;
67 }
68
72 public function execute( $par ) {
73 $out = $this->getOutput();
74
75 $this->setHeaders();
76
77 if ( !$this->getConfig()->get( MainConfigNames::UseDatabaseMessages ) ) {
78 $out->addWikiMsg( 'allmessages-not-supported-database' );
79
80 return;
81 }
82
83 $out->addModuleStyles( 'mediawiki.special' );
84 $this->addHelpLink( 'Help:System message' );
85
86 $contLangCode = $this->getContentLanguage()->getCode();
87 $lang = $this->getLanguage();
88
89 $opts = new FormOptions();
90
91 $opts->add( 'prefix', '' );
92 $opts->add( 'filter', 'all' );
93 $opts->add( 'lang', $contLangCode );
94 $opts->add( 'limit', 50 );
95
96 $opts->fetchValuesFromRequest( $this->getRequest() );
97 $opts->validateIntBounds( 'limit', 0, 5000 );
98
99 if ( !$this->languageNameUtils->isKnownLanguageTag( $opts->getValue( 'lang' ) ) ) {
100 // Show a warning message and fallback to content language
101 $out->addHTML(
102 Html::warningBox(
103 $this->msg( 'allmessages-unknown-language' )
104 ->plaintextParams( $opts->getValue( 'lang' ) )
105 ->parse()
106 )
107 );
108 $opts->setValue( 'lang', $contLangCode );
109 }
110
111 $pager = new AllMessagesTablePager(
112 $this->getContext(),
113 $this->getContentLanguage(),
114 $this->languageFactory,
115 $this->getLinkRenderer(),
116 $this->dbProvider,
117 $this->localisationCache,
118 $opts
119 );
120
121 $formDescriptor = [
122 'prefix' => [
123 'type' => 'text',
124 'name' => 'prefix',
125 'label-message' => 'allmessages-prefix',
126 ],
127
128 'filter' => [
129 'type' => 'radio',
130 'name' => 'filter',
131 'label-message' => 'allmessages-filter',
132 'options-messages' => [
133 'allmessages-filter-unmodified' => 'unmodified',
134 'allmessages-filter-all' => 'all',
135 'allmessages-filter-modified' => 'modified',
136 ],
137 'default' => 'all',
138 'flatlist' => true,
139 ],
140
141 'lang' => [
142 'type' => 'language',
143 'name' => 'lang',
144 'label-message' => 'allmessages-language',
145 'default' => $opts->getValue( 'lang' ),
146 ],
147
148 'limit' => [
149 'type' => 'limitselect',
150 'name' => 'limit',
151 'label-message' => 'table_pager_limit_label',
152 'options' => [
153 $lang->formatNum( 20 ) => 20,
154 $lang->formatNum( 50 ) => 50,
155 $lang->formatNum( 100 ) => 100,
156 $lang->formatNum( 250 ) => 250,
157 $lang->formatNum( 500 ) => 500,
158 $lang->formatNum( 5000 ) => 5000,
159 ],
160 'default' => $opts->getValue( 'limit' ),
161 ],
162 ];
163
164 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
165 $htmlForm
166 ->setMethod( 'get' )
167 ->setPreHtml( $this->msg( 'allmessagestext' )->parse() )
168 ->setWrapperLegendMsg( 'allmessages' )
169 ->setSubmitTextMsg( 'allmessages-filter-submit' )
170 ->prepareForm()
171 ->displayForm( false );
172
173 $out->addParserOutputContent( $pager->getFullOutput() );
174 }
175
176 protected function getGroupName() {
177 return 'wiki';
178 }
179}
180
182class_alias( SpecialAllMessages::class, 'SpecialAllMessages' );
Caching for the contents of localisation files.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
Helper class to keep track of options when mixing links and form elements.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
A service that provides utilities to do with language names and codes.
A class containing constants representing the names of configuration variables.
const UseDatabaseMessages
Name constant for the UseDatabaseMessages setting, for use with Config::get()
Use TablePager for prettified output.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getContentLanguage()
Shortcut to get content language.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
__construct(LanguageFactory $languageFactory, LanguageNameUtils $languageNameUtils, LocalisationCache $localisationCache, IConnectionProvider $dbProvider)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Provide primary and replica IDatabase connections.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...