Convert Special:AllMessages to use OOUI
[lhc/web/wiklou.git] / includes / specials / SpecialAllMessages.php
1 <?php
2 /**
3 * Implements Special:Allmessages
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23 use MediaWiki\MediaWikiServices;
24
25 /**
26 * Use this special page to get a list of the MediaWiki system messages.
27 *
28 * @file
29 * @ingroup SpecialPage
30 */
31 class SpecialAllMessages extends SpecialPage {
32
33 public function __construct() {
34 parent::__construct( 'Allmessages' );
35 }
36
37 /**
38 * Show the special page
39 *
40 * @param string $par Parameter passed to the page or null
41 */
42 public function execute( $par ) {
43 $out = $this->getOutput();
44
45 $this->setHeaders();
46
47 if ( !$this->getConfig()->get( 'UseDatabaseMessages' ) ) {
48 $out->addWikiMsg( 'allmessagesnotsupportedDB' );
49
50 return;
51 }
52
53 $out->addModuleStyles( 'mediawiki.special' );
54 $this->addHelpLink( 'Help:System message' );
55
56 $contLang = MediaWikiServices::getInstance()->getContentLanguage()->getCode();
57 $lang = $this->getLanguage();
58
59 $opts = new FormOptions();
60
61 $opts->add( 'prefix', '' );
62 $opts->add( 'filter', 'all' );
63 $opts->add( 'lang', $contLang );
64 $opts->add( 'limit', 50 );
65
66 $opts->fetchValuesFromRequest( $this->getRequest() );
67 $opts->validateIntBounds( 'limit', 0, 5000 );
68
69 $pager = new AllMessagesTablePager( $this->getContext(), $opts );
70
71 $formDescriptor = [
72 'prefix' => [
73 'type' => 'text',
74 'name' => 'prefix',
75 'label-message' => 'allmessages-prefix',
76 ],
77
78 'filter' => [
79 'type' => 'radio',
80 'name' => 'filter',
81 'label-message' => 'allmessages-filter',
82 'options' => [
83 $this->msg( 'allmessages-filter-unmodified' )->text() => 'unmodified',
84 $this->msg( 'allmessages-filter-all' )->text() => 'all',
85 $this->msg( 'allmessages-filter-modified' )->text() => 'modified',
86 ],
87 'default' => 'all',
88 'flatlist' => true,
89 ],
90
91 'lang' => [
92 'type' => 'language',
93 'name' => 'lang',
94 'label-message' => 'allmessages-language',
95 'default' => $opts->getValue( 'lang' ),
96 ],
97
98 'limit' => [
99 'type' => 'limitselect',
100 'name' => 'limit',
101 'label-message' => 'table_pager_limit_label',
102 'options' => [
103 $lang->formatNum( 20 ) => 20,
104 $lang->formatNum( 50 ) => 50,
105 $lang->formatNum( 100 ) => 100,
106 $lang->formatNum( 250 ) => 250,
107 $lang->formatNum( 500 ) => 500,
108 $lang->formatNum( 5000 ) => 5000,
109 ],
110 'default' => $opts->getValue( 'limit' ),
111 ],
112 ];
113
114 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
115 $htmlForm
116 ->setMethod( 'get' )
117 ->setIntro( $this->msg( 'allmessagestext' ) )
118 ->setWrapperLegendMsg( 'allmessages' )
119 ->setSubmitTextMsg( 'allmessages-filter-submit' )
120 ->prepareForm()
121 ->displayForm( false );
122
123 $out->addParserOutputContent( $pager->getFullOutput() );
124 }
125
126 protected function getGroupName() {
127 return 'wiki';
128 }
129 }