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