Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 89
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialAllMessages
0.00% covered (danger)
0.00%
0 / 88
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 1
12
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
24namespace MediaWiki\Specials;
25
26use LocalisationCache;
27use MediaWiki\Html\FormOptions;
28use MediaWiki\Html\Html;
29use MediaWiki\HTMLForm\HTMLForm;
30use MediaWiki\Languages\LanguageFactory;
31use MediaWiki\Languages\LanguageNameUtils;
32use MediaWiki\MainConfigNames;
33use MediaWiki\Pager\AllMessagesTablePager;
34use MediaWiki\SpecialPage\SpecialPage;
35use Wikimedia\Rdbms\IConnectionProvider;
36
37/**
38 * Use this special page to get a list of the MediaWiki system messages.
39 *
40 * @file
41 * @ingroup SpecialPage
42 */
43class SpecialAllMessages extends SpecialPage {
44
45    private LanguageFactory $languageFactory;
46    private LanguageNameUtils $languageNameUtils;
47    private IConnectionProvider $dbProvider;
48    private LocalisationCache $localisationCache;
49
50    /**
51     * @param LanguageFactory $languageFactory
52     * @param LanguageNameUtils $languageNameUtils
53     * @param LocalisationCache $localisationCache
54     * @param IConnectionProvider $dbProvider
55     */
56    public function __construct(
57        LanguageFactory $languageFactory,
58        LanguageNameUtils $languageNameUtils,
59        LocalisationCache $localisationCache,
60        IConnectionProvider $dbProvider
61    ) {
62        parent::__construct( 'Allmessages' );
63        $this->languageFactory = $languageFactory;
64        $this->languageNameUtils = $languageNameUtils;
65        $this->localisationCache = $localisationCache;
66        $this->dbProvider = $dbProvider;
67    }
68
69    /**
70     * @param string|null $par Parameter passed to the page or null
71     */
72    public function execute( $par ) {
73        $out = $this->getOutput();
74
75        $this->setHeaders();
76
77        if ( !$this->getConfig()->get( MainConfigNames::UseDatabaseMessages ) ) {
78            $out->addWikiMsg( 'allmessages-not-supported-database' );
79
80            return;
81        }
82
83        $out->addModuleStyles( 'mediawiki.special' );
84        $this->addHelpLink( 'Help:System message' );
85
86        $contLangCode = $this->getContentLanguage()->getCode();
87        $lang = $this->getLanguage();
88
89        $opts = new FormOptions();
90
91        $opts->add( 'prefix', '' );
92        $opts->add( 'filter', 'all' );
93        $opts->add( 'lang', $contLangCode );
94        $opts->add( 'limit', 50 );
95
96        $opts->fetchValuesFromRequest( $this->getRequest() );
97        $opts->validateIntBounds( 'limit', 0, 5000 );
98
99        if ( !$this->languageNameUtils->isKnownLanguageTag( $opts->getValue( 'lang' ) ) ) {
100            // Show a warning message and fallback to content language
101            $out->addHTML(
102                Html::warningBox(
103                    $this->msg( 'allmessages-unknown-language' )
104                        ->plaintextParams( $opts->getValue( 'lang' ) )
105                        ->parse()
106                )
107            );
108            $opts->setValue( 'lang', $contLangCode );
109        }
110
111        $pager = new AllMessagesTablePager(
112            $this->getContext(),
113            $this->getContentLanguage(),
114            $this->languageFactory,
115            $this->getLinkRenderer(),
116            $this->dbProvider,
117            $this->localisationCache,
118            $opts
119        );
120
121        $formDescriptor = [
122            'prefix' => [
123                'type' => 'text',
124                'name' => 'prefix',
125                'label-message' => 'allmessages-prefix',
126            ],
127
128            'filter' => [
129                'type' => 'radio',
130                'name' => 'filter',
131                'label-message' => 'allmessages-filter',
132                'options-messages' => [
133                    'allmessages-filter-unmodified' => 'unmodified',
134                    'allmessages-filter-all' => 'all',
135                    'allmessages-filter-modified' => 'modified',
136                ],
137                'default' => 'all',
138                'flatlist' => true,
139            ],
140
141            'lang' => [
142                'type' => 'language',
143                'name' => 'lang',
144                'label-message' => 'allmessages-language',
145                'default' => $opts->getValue( 'lang' ),
146            ],
147
148            'limit' => [
149                'type' => 'limitselect',
150                'name' => 'limit',
151                'label-message' => 'table_pager_limit_label',
152                'options' => [
153                    $lang->formatNum( 20 ) => 20,
154                    $lang->formatNum( 50 ) => 50,
155                    $lang->formatNum( 100 ) => 100,
156                    $lang->formatNum( 250 ) => 250,
157                    $lang->formatNum( 500 ) => 500,
158                    $lang->formatNum( 5000 ) => 5000,
159                ],
160                'default' => $opts->getValue( 'limit' ),
161            ],
162        ];
163
164        $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
165        $htmlForm
166            ->setMethod( 'get' )
167            ->setPreHtml( $this->msg( 'allmessagestext' )->parse() )
168            ->setWrapperLegendMsg( 'allmessages' )
169            ->setSubmitTextMsg( 'allmessages-filter-submit' )
170            ->prepareForm()
171            ->displayForm( false );
172
173        $out->addParserOutputContent( $pager->getFullOutput() );
174    }
175
176    protected function getGroupName() {
177        return 'wiki';
178    }
179}
180
181/** @deprecated class alias since 1.41 */
182class_alias( SpecialAllMessages::class, 'SpecialAllMessages' );