Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
NamespaceSelect
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getInputOOUI
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
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 * @ingroup Extensions
20 */
21
22namespace MediaWiki\Extension\PageAssessments;
23
24use HTMLSelectNamespace;
25use MediaWiki\MediaWikiServices;
26use MediaWiki\Widget\NamespaceInputWidget;
27
28/**
29 * This is an HTML form field for selecting non-talk namespaces. It excludes all namespaces with
30 * an even-numbered ID.
31 *
32 * It only overrides the OOUI widget because that's all that the PageAssessments special page needs.
33 */
34class NamespaceSelect extends HTMLSelectNamespace {
35
36    /**
37     * Get the widget for selecting one or all non-talkspace namespace(s).
38     * @param string $value The currently selected value.
39     * @return NamespaceInputWidget
40     */
41    public function getInputOOUI( $value ) {
42        $namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
43        $nsIds = array_keys( $namespaceInfo->getCanonicalNamespaces() );
44        $excludedNsIds = array_values( array_filter(
45            $nsIds,
46            static function ( $ns ) use ( $namespaceInfo ) {
47                return $namespaceInfo->isTalk( $ns );
48            }
49        ) );
50        $widget = new NamespaceInputWidget( [
51            'value' => $value,
52            'name' => $this->mName,
53            'id' => $this->mID,
54            'exclude' => $excludedNsIds,
55        ] );
56        return $widget;
57    }
58
59}