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