Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / specials / SpecialProtectedtitles.php
blob7b916cf519b63e5a00aabddee60340c4d49519cf
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 {
31 protected $IdLevel = 'level';
32 protected $IdType = 'type';
34 public function __construct() {
35 parent::__construct( 'Protectedtitles' );
38 function execute( $par ) {
39 $this->setHeaders();
40 $this->outputHeader();
42 // Purge expired entries on one in every 10 queries
43 if ( !mt_rand( 0, 10 ) ) {
44 Title::purgeExpiredRestrictions();
47 $request = $this->getRequest();
48 $type = $request->getVal( $this->IdType );
49 $level = $request->getVal( $this->IdLevel );
50 $sizetype = $request->getVal( 'sizetype' );
51 $size = $request->getIntOrNull( 'size' );
52 $NS = $request->getIntOrNull( 'namespace' );
54 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
56 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
58 if ( $pager->getNumRows() ) {
59 $this->getOutput()->addHTML(
60 $pager->getNavigationBar() .
61 '<ul>' . $pager->getBody() . '</ul>' .
62 $pager->getNavigationBar()
64 } else {
65 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
69 /**
70 * Callback function to output a restriction
72 * @param object $row Database row
73 * @return string
75 function formatRow( $row ) {
76 wfProfileIn( __METHOD__ );
78 static $infinity = null;
80 if ( is_null( $infinity ) ) {
81 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
84 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
85 if ( !$title ) {
86 wfProfileOut( __METHOD__ );
87 return Html::rawElement( 'li', array(),
88 Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
89 Linker::getInvalidTitleDescription( $this->getContext(), $row->pt_namespace, $row->pt_title ) ) ) . "\n";
92 $link = Linker::link( $title );
94 $description_items = array();
96 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
98 $description_items[] = $protType;
100 $lang = $this->getLanguage();
101 $expiry = strlen( $row->pt_expiry ) ? $lang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
102 if ( $expiry != $infinity ) {
103 $user = $this->getUser();
104 $description_items[] = $this->msg(
105 'protect-expiring-local',
106 $lang->userTimeAndDate( $expiry, $user ),
107 $lang->userDate( $expiry, $user ),
108 $lang->userTime( $expiry, $user )
109 )->escaped();
112 wfProfileOut( __METHOD__ );
114 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
118 * @param $namespace Integer:
119 * @param $type string
120 * @param $level string
121 * @return string
122 * @private
124 function showOptions( $namespace, $type = 'edit', $level ) {
125 global $wgScript;
126 $action = htmlspecialchars( $wgScript );
127 $title = $this->getTitle();
128 $special = htmlspecialchars( $title->getPrefixedDBkey() );
129 return "<form action=\"$action\" method=\"get\">\n" .
130 '<fieldset>' .
131 Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
132 Html::hidden( 'title', $special ) . "&#160;\n" .
133 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
134 $this->getLevelMenu( $level ) . "&#160;\n" .
135 "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
136 "</fieldset></form>";
140 * Prepare the namespace filter drop-down; standard namespace
141 * selector, sans the MediaWiki namespace
143 * @param $namespace Mixed: pre-select namespace
144 * @return string
146 function getNamespaceMenu( $namespace = null ) {
147 return Html::namespaceSelector(
148 array(
149 'selected' => $namespace,
150 'all' => '',
151 'label' => $this->msg( 'namespace' )->text()
152 ), array(
153 'name' => 'namespace',
154 'id' => 'namespace',
155 'class' => 'namespaceselector',
161 * @param string $pr_level Determines which option is selected as default
162 * @return string Formatted HTML
163 * @private
165 function getLevelMenu( $pr_level ) {
166 global $wgRestrictionLevels;
168 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
169 $options = array();
171 // First pass to load the log names
172 foreach ( $wgRestrictionLevels as $type ) {
173 if ( $type != '' && $type != '*' ) {
174 $text = $this->msg( "restriction-level-$type" )->text();
175 $m[$text] = $type;
178 // Is there only one level (aside from "all")?
179 if ( count( $m ) <= 2 ) {
180 return '';
182 // Third pass generates sorted XHTML content
183 foreach ( $m as $text => $type ) {
184 $selected = ($type == $pr_level );
185 $options[] = Xml::option( $text, $type, $selected );
188 return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
189 Xml::tags( 'select',
190 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
191 implode( "\n", $options ) );
194 protected function getGroupName() {
195 return 'maintenance';
200 * @todo document
201 * @ingroup Pager
203 class ProtectedTitlesPager extends AlphabeticPager {
204 public $mForm, $mConds;
206 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype = '', $size = 0 ) {
207 $this->mForm = $form;
208 $this->mConds = $conds;
209 $this->level = $level;
210 $this->namespace = $namespace;
211 $this->size = intval( $size );
212 parent::__construct( $form->getContext() );
215 function getStartBody() {
216 wfProfileIn( __METHOD__ );
217 # Do a link batch query
218 $this->mResult->seek( 0 );
219 $lb = new LinkBatch;
221 foreach ( $this->mResult as $row ) {
222 $lb->add( $row->pt_namespace, $row->pt_title );
225 $lb->execute();
226 wfProfileOut( __METHOD__ );
227 return '';
231 * @return Title
233 function getTitle() {
234 return $this->mForm->getTitle();
237 function formatRow( $row ) {
238 return $this->mForm->formatRow( $row );
242 * @return array
244 function getQueryInfo() {
245 $conds = $this->mConds;
246 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
247 if ( $this->level ) {
248 $conds['pt_create_perm'] = $this->level;
250 if ( !is_null( $this->namespace ) ) {
251 $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
253 return array(
254 'tables' => 'protected_titles',
255 'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
256 'pt_expiry', 'pt_timestamp' ),
257 'conds' => $conds
261 function getIndexField() {
262 return 'pt_timestamp';