Remove useless comments from search output
[mediawiki.git] / includes / specials / SpecialProtectedtitles.php
blobcb6ec3c9f71b52150e851f12d6d1c4cc5c0a970d
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
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 ) {
38 $this->setHeaders();
39 $this->outputHeader();
41 // Purge expired entries on one in every 10 queries
42 if ( !mt_rand( 0, 10 ) ) {
43 Title::purgeExpiredRestrictions();
46 $request = $this->getRequest();
47 $type = $request->getVal( $this->IdType );
48 $level = $request->getVal( $this->IdLevel );
49 $sizetype = $request->getVal( 'sizetype' );
50 $size = $request->getIntOrNull( 'size' );
51 $NS = $request->getIntOrNull( 'namespace' );
53 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
55 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
57 if ( $pager->getNumRows() ) {
58 $this->getOutput()->addHTML(
59 $pager->getNavigationBar() .
60 '<ul>' . $pager->getBody() . '</ul>' .
61 $pager->getNavigationBar()
63 } else {
64 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
68 /**
69 * Callback function to output a restriction
71 * @param object $row Database row
72 * @return string
74 function formatRow( $row ) {
75 wfProfileIn( __METHOD__ );
77 static $infinity = null;
79 if ( is_null( $infinity ) ) {
80 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
83 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
84 if ( !$title ) {
85 wfProfileOut( __METHOD__ );
87 return Html::rawElement(
88 'li',
89 array(),
90 Html::element(
91 'span',
92 array( 'class' => 'mw-invalidtitle' ),
93 Linker::getInvalidTitleDescription(
94 $this->getContext(),
95 $row->pt_namespace,
96 $row->pt_title
99 ) . "\n";
102 $link = Linker::link( $title );
103 $description_items = array();
104 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
105 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
106 $description_items[] = $protType;
107 $lang = $this->getLanguage();
108 $expiry = strlen( $row->pt_expiry ) ?
109 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
110 $infinity;
112 if ( $expiry != $infinity ) {
113 $user = $this->getUser();
114 $description_items[] = $this->msg(
115 'protect-expiring-local',
116 $lang->userTimeAndDate( $expiry, $user ),
117 $lang->userDate( $expiry, $user ),
118 $lang->userTime( $expiry, $user )
119 )->escaped();
122 wfProfileOut( __METHOD__ );
124 // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
125 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
129 * @param int $namespace
130 * @param string $type
131 * @param string $level
132 * @return string
133 * @private
135 function showOptions( $namespace, $type = 'edit', $level ) {
136 global $wgScript;
137 $action = htmlspecialchars( $wgScript );
138 $title = $this->getPageTitle();
139 $special = htmlspecialchars( $title->getPrefixedDBkey() );
141 return "<form action=\"$action\" method=\"get\">\n" .
142 '<fieldset>' .
143 Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
144 Html::hidden( 'title', $special ) . "&#160;\n" .
145 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
146 $this->getLevelMenu( $level ) . "&#160;\n" .
147 "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
148 "</fieldset></form>";
152 * Prepare the namespace filter drop-down; standard namespace
153 * selector, sans the MediaWiki namespace
155 * @param string|null $namespace Pre-select namespace
156 * @return string
158 function getNamespaceMenu( $namespace = null ) {
159 return Html::namespaceSelector(
160 array(
161 'selected' => $namespace,
162 'all' => '',
163 'label' => $this->msg( 'namespace' )->text()
164 ), array(
165 'name' => 'namespace',
166 'id' => 'namespace',
167 'class' => 'namespaceselector',
173 * @param string $pr_level Determines which option is selected as default
174 * @return string Formatted HTML
175 * @private
177 function getLevelMenu( $pr_level ) {
178 global $wgRestrictionLevels;
180 // Temporary array
181 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
182 $options = array();
184 // First pass to load the log names
185 foreach ( $wgRestrictionLevels as $type ) {
186 if ( $type != '' && $type != '*' ) {
187 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
188 $text = $this->msg( "restriction-level-$type" )->text();
189 $m[$text] = $type;
193 // Is there only one level (aside from "all")?
194 if ( count( $m ) <= 2 ) {
195 return '';
197 // Third pass generates sorted XHTML content
198 foreach ( $m as $text => $type ) {
199 $selected = ( $type == $pr_level );
200 $options[] = Xml::option( $text, $type, $selected );
203 return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
204 Xml::tags( 'select',
205 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
206 implode( "\n", $options ) );
209 protected function getGroupName() {
210 return 'maintenance';
215 * @todo document
216 * @ingroup Pager
218 class ProtectedTitlesPager extends AlphabeticPager {
219 public $mForm, $mConds;
221 function __construct( $form, $conds = array(), $type, $level, $namespace,
222 $sizetype = '', $size = 0
224 $this->mForm = $form;
225 $this->mConds = $conds;
226 $this->level = $level;
227 $this->namespace = $namespace;
228 $this->size = intval( $size );
229 parent::__construct( $form->getContext() );
232 function getStartBody() {
233 wfProfileIn( __METHOD__ );
234 # Do a link batch query
235 $this->mResult->seek( 0 );
236 $lb = new LinkBatch;
238 foreach ( $this->mResult as $row ) {
239 $lb->add( $row->pt_namespace, $row->pt_title );
242 $lb->execute();
243 wfProfileOut( __METHOD__ );
245 return '';
249 * @return Title
251 function getTitle() {
252 return $this->mForm->getTitle();
255 function formatRow( $row ) {
256 return $this->mForm->formatRow( $row );
260 * @return array
262 function getQueryInfo() {
263 $conds = $this->mConds;
264 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
265 if ( $this->level ) {
266 $conds['pt_create_perm'] = $this->level;
269 if ( !is_null( $this->namespace ) ) {
270 $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
273 return array(
274 'tables' => 'protected_titles',
275 'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
276 'pt_expiry', 'pt_timestamp' ),
277 'conds' => $conds
281 function getIndexField() {
282 return 'pt_timestamp';