(bug 30192) Thumbnails of archived images don't get deleted. Patch by Russ and Sam...
[mediawiki.git] / includes / specials / SpecialProtectedtitles.php
blob40e58bc415629d1e85d77e8304d9899c71ebc382
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 global $wgOut, $wgRequest;
41 $this->setHeaders();
42 $this->outputHeader();
44 // Purge expired entries on one in every 10 queries
45 if ( !mt_rand( 0, 10 ) ) {
46 Title::purgeExpiredRestrictions();
49 $type = $wgRequest->getVal( $this->IdType );
50 $level = $wgRequest->getVal( $this->IdLevel );
51 $sizetype = $wgRequest->getVal( 'sizetype' );
52 $size = $wgRequest->getIntOrNull( 'size' );
53 $NS = $wgRequest->getIntOrNull( 'namespace' );
55 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
57 $wgOut->addHTML( $this->showOptions( $NS, $type, $level ) );
59 if ( $pager->getNumRows() ) {
60 $s = $pager->getNavigationBar();
61 $s .= "<ul>" .
62 $pager->getBody() .
63 "</ul>";
64 $s .= $pager->getNavigationBar();
65 } else {
66 $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
68 $wgOut->addHTML( $s );
71 /**
72 * Callback function to output a restriction
74 * @return string
76 function formatRow( $row ) {
77 global $wgLang;
79 wfProfileIn( __METHOD__ );
81 static $skin = null, $infinity = null;
83 if( is_null( $skin ) ){
84 $skin = $this->getSkin();
85 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
88 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
89 $link = $skin->link( $title );
91 $description_items = array ();
93 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
95 $description_items[] = $protType;
97 $expiry = strlen( $row->pt_expiry ) ? $wgLang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
98 if( $expiry != $infinity ) {
100 $expiry_description = wfMsg(
101 'protect-expiring-local',
102 $wgLang->timeanddate( $expiry, true ),
103 $wgLang->date( $expiry, true ),
104 $wgLang->time( $expiry, true )
107 $description_items[] = htmlspecialchars($expiry_description);
110 wfProfileOut( __METHOD__ );
112 return '<li>' . wfSpecialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
116 * @param $namespace Integer:
117 * @param $type string
118 * @param $level string
119 * @private
121 function showOptions( $namespace, $type='edit', $level ) {
122 global $wgScript;
123 $action = htmlspecialchars( $wgScript );
124 $title = SpecialPage::getTitleFor( 'Protectedtitles' );
125 $special = htmlspecialchars( $title->getPrefixedDBkey() );
126 return "<form action=\"$action\" method=\"get\">\n" .
127 '<fieldset>' .
128 Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
129 Html::hidden( 'title', $special ) . "&#160;\n" .
130 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
131 $this->getLevelMenu( $level ) . "&#160;\n" .
132 "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
133 "</fieldset></form>";
137 * Prepare the namespace filter drop-down; standard namespace
138 * selector, sans the MediaWiki namespace
140 * @param $namespace Mixed: pre-select namespace
141 * @return string
143 function getNamespaceMenu( $namespace = null ) {
144 return Xml::label( wfMsg( 'namespace' ), 'namespace' )
145 . '&#160;'
146 . Xml::namespaceSelector( $namespace, '' );
150 * @return string Formatted HTML
151 * @private
153 function getLevelMenu( $pr_level ) {
154 global $wgRestrictionLevels;
156 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
157 $options = array();
159 // First pass to load the log names
160 foreach( $wgRestrictionLevels as $type ) {
161 if ( $type !='' && $type !='*') {
162 $text = wfMsg("restriction-level-$type");
163 $m[$text] = $type;
166 // Is there only one level (aside from "all")?
167 if( count($m) <= 2 ) {
168 return '';
170 // Third pass generates sorted XHTML content
171 foreach( $m as $text => $type ) {
172 $selected = ($type == $pr_level );
173 $options[] = Xml::option( $text, $type, $selected );
176 return
177 Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&#160;' .
178 Xml::tags( 'select',
179 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
180 implode( "\n", $options ) );
185 * @todo document
186 * @ingroup Pager
188 class ProtectedTitlesPager extends AlphabeticPager {
189 public $mForm, $mConds;
191 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
192 $this->mForm = $form;
193 $this->mConds = $conds;
194 $this->level = $level;
195 $this->namespace = $namespace;
196 $this->size = intval($size);
197 parent::__construct();
200 function getStartBody() {
201 wfProfileIn( __METHOD__ );
202 # Do a link batch query
203 $this->mResult->seek( 0 );
204 $lb = new LinkBatch;
206 foreach ( $this->mResult as $row ) {
207 $lb->add( $row->pt_namespace, $row->pt_title );
210 $lb->execute();
211 wfProfileOut( __METHOD__ );
212 return '';
215 function getTitle() {
216 return SpecialPage::getTitleFor( 'Protectedtitles' );
219 function formatRow( $row ) {
220 return $this->mForm->formatRow( $row );
223 function getQueryInfo() {
224 $conds = $this->mConds;
225 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
226 if( $this->level )
227 $conds['pt_create_perm'] = $this->level;
228 if( !is_null($this->namespace) )
229 $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
230 return array(
231 'tables' => 'protected_titles',
232 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
233 'conds' => $conds
237 function getIndexField() {
238 return 'pt_timestamp';