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