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();
41 $request = $this->getRequest();
42 $type = $request->getVal( $this->IdType
);
43 $level = $request->getVal( $this->IdLevel
);
44 $sizetype = $request->getVal( 'sizetype' );
45 $size = $request->getIntOrNull( 'size' );
46 $NS = $request->getIntOrNull( 'namespace' );
48 $pager = new ProtectedTitlesPager( $this, [], $type, $level, $NS, $sizetype, $size );
50 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
52 if ( $pager->getNumRows() ) {
53 $this->getOutput()->addHTML(
54 $pager->getNavigationBar() .
55 '<ul>' . $pager->getBody() . '</ul>' .
56 $pager->getNavigationBar()
59 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
64 * Callback function to output a restriction
66 * @param object $row Database row
69 function formatRow( $row ) {
70 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
72 return Html
::rawElement(
77 [ 'class' => 'mw-invalidtitle' ],
78 Linker
::getInvalidTitleDescription(
87 $link = $this->getLinkRenderer()->makeLink( $title );
88 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
89 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
90 $lang = $this->getLanguage();
91 $expiry = strlen( $row->pt_expiry
) ?
92 $lang->formatExpiry( $row->pt_expiry
, TS_MW
) :
95 if ( $expiry !== 'infinity' ) {
96 $user = $this->getUser();
97 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
98 'protect-expiring-local',
99 $lang->userTimeAndDate( $expiry, $user ),
100 $lang->userDate( $expiry, $user ),
101 $lang->userTime( $expiry, $user )
105 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
109 * @param int $namespace
110 * @param string $type
111 * @param string $level
115 function showOptions( $namespace, $type = 'edit', $level ) {
118 'class' => 'HTMLSelectNamespace',
119 'name' => 'namespace',
121 'cssclass' => 'namespaceselector',
123 'label' => $this->msg( 'namespace' )->text()
125 'levelmenu' => $this->getLevelMenu( $level )
128 $htmlForm = new HTMLForm( $formDescriptor, $this->getContext() );
131 ->setWrapperLegendMsg( 'protectedtitles' )
132 ->setSubmitText( $this->msg( 'protectedtitles-submit' )->text() );
134 return $htmlForm->prepareForm()->getHTML( false );
138 * @param string $pr_level Determines which option is selected as default
139 * @return string Formatted HTML
142 function getLevelMenu( $pr_level ) {
144 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
147 // First pass to load the log names
148 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
149 if ( $type != '' && $type != '*' ) {
150 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
151 $text = $this->msg( "restriction-level-$type" )->text();
156 // Is there only one level (aside from "all")?
157 if ( count( $m ) <= 2 ) {
160 // Third pass generates sorted XHTML content
161 foreach ( $m as $text => $type ) {
162 $options[ $text ] = $type;
167 'options' => $options,
168 'label' => $this->msg( 'restriction-level' )->text(),
169 'name' => $this->IdLevel
,
170 'id' => $this->IdLevel
174 protected function getGroupName() {
175 return 'maintenance';