3 * Implements Special:Protectedtitles
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.
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.
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
21 * @ingroup SpecialPage
25 * A special page that list protected titles from creation
27 * @ingroup SpecialPage
29 class SpecialProtectedtitles
extends SpecialPage
{
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
33 public function __construct() {
34 parent
::__construct( 'Protectedtitles' );
37 function execute( $par ) {
39 $this->outputHeader();
40 $this->addHelpLink( 'Help:Protected_pages' );
42 $request = $this->getRequest();
43 $type = $request->getVal( $this->IdType
);
44 $level = $request->getVal( $this->IdLevel
);
45 $sizetype = $request->getVal( 'sizetype' );
46 $size = $request->getIntOrNull( 'size' );
47 $NS = $request->getIntOrNull( 'namespace' );
49 $pager = new ProtectedTitlesPager( $this, [], $type, $level, $NS, $sizetype, $size );
51 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
53 if ( $pager->getNumRows() ) {
54 $this->getOutput()->addHTML(
55 $pager->getNavigationBar() .
56 '<ul>' . $pager->getBody() . '</ul>' .
57 $pager->getNavigationBar()
60 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
65 * Callback function to output a restriction
67 * @param object $row Database row
70 function formatRow( $row ) {
71 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
73 return Html
::rawElement(
78 [ 'class' => 'mw-invalidtitle' ],
79 Linker
::getInvalidTitleDescription(
88 $link = $this->getLinkRenderer()->makeLink( $title );
89 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
90 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
91 $lang = $this->getLanguage();
92 $expiry = strlen( $row->pt_expiry
) ?
93 $lang->formatExpiry( $row->pt_expiry
, TS_MW
) :
96 if ( $expiry !== 'infinity' ) {
97 $user = $this->getUser();
98 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
99 'protect-expiring-local',
100 $lang->userTimeAndDate( $expiry, $user ),
101 $lang->userDate( $expiry, $user ),
102 $lang->userTime( $expiry, $user )
106 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
110 * @param int $namespace
111 * @param string $type
112 * @param string $level
116 function showOptions( $namespace, $type, $level ) {
119 'class' => 'HTMLSelectNamespace',
120 'name' => 'namespace',
122 'cssclass' => 'namespaceselector',
124 'label' => $this->msg( 'namespace' )->text()
126 'levelmenu' => $this->getLevelMenu( $level )
129 $htmlForm = HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() );
132 ->setWrapperLegendMsg( 'protectedtitles' )
133 ->setSubmitText( $this->msg( 'protectedtitles-submit' )->text() );
135 return $htmlForm->prepareForm()->getHTML( false );
139 * @param string $pr_level Determines which option is selected as default
140 * @return string|array
143 function getLevelMenu( $pr_level ) {
145 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
148 // First pass to load the log names
149 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
150 if ( $type != '' && $type != '*' ) {
151 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
152 $text = $this->msg( "restriction-level-$type" )->text();
157 // Is there only one level (aside from "all")?
158 if ( count( $m ) <= 2 ) {
161 // Third pass generates sorted XHTML content
162 foreach ( $m as $text => $type ) {
163 $options[ $text ] = $type;
168 'options' => $options,
169 'label' => $this->msg( 'restriction-level' )->text(),
170 'name' => $this->IdLevel
,
171 'id' => $this->IdLevel
175 protected function getGroupName() {
176 return 'maintenance';