MediaWiki master
SpecialAllMessages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
33
40
41 private LanguageFactory $languageFactory;
42 private LanguageNameUtils $languageNameUtils;
43 private IConnectionProvider $dbProvider;
44 private LocalisationCache $localisationCache;
45
52 public function __construct(
53 LanguageFactory $languageFactory,
54 LanguageNameUtils $languageNameUtils,
55 LocalisationCache $localisationCache,
56 IConnectionProvider $dbProvider
57 ) {
58 parent::__construct( 'Allmessages' );
59 $this->languageFactory = $languageFactory;
60 $this->languageNameUtils = $languageNameUtils;
61 $this->localisationCache = $localisationCache;
62 $this->dbProvider = $dbProvider;
63 }
64
68 public function execute( $par ) {
69 $out = $this->getOutput();
70
71 $this->setHeaders();
72
73 if ( !$this->getConfig()->get( MainConfigNames::UseDatabaseMessages ) ) {
74 $out->addWikiMsg( 'allmessages-not-supported-database' );
75
76 return;
77 }
78
79 $out->addModuleStyles( 'mediawiki.special' );
80 $this->addHelpLink( 'Help:System message' );
81
82 $contLangCode = $this->getContentLanguage()->getCode();
83 $lang = $this->getLanguage();
84
85 $opts = new FormOptions();
86
87 $opts->add( 'prefix', '' );
88 $opts->add( 'filter', 'all' );
89 $opts->add( 'lang', $contLangCode );
90 $opts->add( 'limit', 50 );
91
92 $opts->fetchValuesFromRequest( $this->getRequest() );
93 $opts->validateIntBounds( 'limit', 0, 5000 );
94
95 if ( !$this->languageNameUtils->isKnownLanguageTag( $opts->getValue( 'lang' ) ) ) {
96 // Show a warning message and fallback to content language
97 $out->addHTML(
98 Html::warningBox(
99 $this->msg( 'allmessages-unknown-language' )
100 ->plaintextParams( $opts->getValue( 'lang' ) )
101 ->parse()
102 )
103 );
104 $opts->setValue( 'lang', $contLangCode );
105 }
106
107 $pager = new AllMessagesTablePager(
108 $this->getContext(),
109 $this->getContentLanguage(),
110 $this->languageFactory,
111 $this->getLinkRenderer(),
112 $this->dbProvider,
113 $this->localisationCache,
114 $opts
115 );
116
117 $formDescriptor = [
118 'prefix' => [
119 'type' => 'text',
120 'name' => 'prefix',
121 'label-message' => 'allmessages-prefix',
122 ],
123
124 'filter' => [
125 'type' => 'radio',
126 'name' => 'filter',
127 'label-message' => 'allmessages-filter',
128 'options-messages' => [
129 'allmessages-filter-unmodified' => 'unmodified',
130 'allmessages-filter-all' => 'all',
131 'allmessages-filter-modified' => 'modified',
132 ],
133 'default' => 'all',
134 'flatlist' => true,
135 ],
136
137 'lang' => [
138 'type' => 'language',
139 'name' => 'lang',
140 'label-message' => 'allmessages-language',
141 'default' => $opts->getValue( 'lang' ),
142 ],
143
144 'limit' => [
145 'type' => 'limitselect',
146 'name' => 'limit',
147 'label-message' => 'table_pager_limit_label',
148 'options' => [
149 $lang->formatNum( 20 ) => 20,
150 $lang->formatNum( 50 ) => 50,
151 $lang->formatNum( 100 ) => 100,
152 $lang->formatNum( 250 ) => 250,
153 $lang->formatNum( 500 ) => 500,
154 $lang->formatNum( 5000 ) => 5000,
155 ],
156 'default' => $opts->getValue( 'limit' ),
157 ],
158 ];
159
160 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
161 $htmlForm
162 ->setMethod( 'get' )
163 ->setPreHtml( $this->msg( 'allmessagestext' )->parse() )
164 ->setWrapperLegendMsg( 'allmessages' )
165 ->setSubmitTextMsg( 'allmessages-filter-submit' )
166 ->prepareForm()
167 ->displayForm( false );
168
169 $out->addParserOutputContent( $pager->getFullOutput() );
170 }
171
172 protected function getGroupName() {
173 return 'wiki';
174 }
175}
176
178class_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.
List of the MediaWiki interface messages.
__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.