Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 89 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SpecialAllMessages | |
0.00% |
0 / 88 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 82 |
|
0.00% |
0 / 1 |
12 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Specials; |
22 | |
23 | use LocalisationCache; |
24 | use MediaWiki\Html\FormOptions; |
25 | use MediaWiki\Html\Html; |
26 | use MediaWiki\HTMLForm\HTMLForm; |
27 | use MediaWiki\Languages\LanguageFactory; |
28 | use MediaWiki\Languages\LanguageNameUtils; |
29 | use MediaWiki\MainConfigNames; |
30 | use MediaWiki\Pager\AllMessagesTablePager; |
31 | use MediaWiki\SpecialPage\SpecialPage; |
32 | use Wikimedia\Rdbms\IConnectionProvider; |
33 | |
34 | /** |
35 | * List of the MediaWiki interface messages. |
36 | * |
37 | * @ingroup SpecialPage |
38 | */ |
39 | class SpecialAllMessages extends SpecialPage { |
40 | |
41 | private LanguageFactory $languageFactory; |
42 | private LanguageNameUtils $languageNameUtils; |
43 | private IConnectionProvider $dbProvider; |
44 | private LocalisationCache $localisationCache; |
45 | |
46 | /** |
47 | * @param LanguageFactory $languageFactory |
48 | * @param LanguageNameUtils $languageNameUtils |
49 | * @param LocalisationCache $localisationCache |
50 | * @param IConnectionProvider $dbProvider |
51 | */ |
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 | |
65 | /** |
66 | * @param string|null $par Parameter passed to the page or null |
67 | */ |
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 | |
177 | /** @deprecated class alias since 1.41 */ |
178 | class_alias( SpecialAllMessages::class, 'SpecialAllMessages' ); |