3 * Implements Special:Protectedpages
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 lists protected pages
27 * @ingroup SpecialPage
29 class SpecialProtectedpages
extends SpecialPage
{
31 protected $IdLevel = 'level';
32 protected $IdType = 'type';
34 public function __construct() {
35 parent
::__construct( 'Protectedpages' );
38 public function execute( $par ) {
39 global $wgOut, $wgRequest;
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' );
54 $indefOnly = $wgRequest->getBool( 'indefonly' ) ?
1 : 0;
55 $cascadeOnly = $wgRequest->getBool('cascadeonly') ?
1 : 0;
57 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
59 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
61 if( $pager->getNumRows() ) {
62 $s = $pager->getNavigationBar();
66 $s .= $pager->getNavigationBar();
68 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
70 $wgOut->addHTML( $s );
74 * Callback function to output a restriction
75 * @param $row object Protected title
76 * @return string Formatted <li> element
78 public function formatRow( $row ) {
79 global $wgUser, $wgLang, $wgContLang;
81 wfProfileIn( __METHOD__
);
85 if( is_null( $skin ) )
86 $skin = $wgUser->getSkin();
88 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
89 $link = $skin->link( $title );
91 $description_items = array ();
93 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
95 $description_items[] = $protType;
97 if( $row->pr_cascade
) {
98 $description_items[] = wfMsg( 'protect-summary-cascade' );
101 $expiry_description = '';
104 if( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
105 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
107 $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) ,
108 $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
110 $description_items[] = htmlspecialchars($expiry_description);
113 if(!is_null($size = $row->page_len
)) {
114 $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
117 # Show a link to the change protection form for allowed users otherwise a link to the protection log
118 if( $wgUser->isAllowed( 'protect' ) ) {
119 $changeProtection = ' (' . $skin->linkKnown(
121 wfMsgHtml( 'protect_change' ),
123 array( 'action' => 'unprotect' )
126 $ltitle = SpecialPage
::getTitleFor( 'Log' );
127 $changeProtection = ' (' . $skin->linkKnown(
129 wfMsgHtml( 'protectlogpage' ),
133 'page' => $title->getPrefixedText()
138 wfProfileOut( __METHOD__
);
140 return Html
::rawElement(
143 wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
147 * @param $namespace Integer
148 * @param $type String: restriction type
149 * @param $level String: restriction level
150 * @param $sizetype String: "min" or "max"
151 * @param $size Integer
152 * @param $indefOnly Boolean: only indefinie protection
153 * @param $cascadeOnly Boolean: only cascading protection
154 * @return String: input form
156 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
158 $title = SpecialPage
::getTitleFor( 'Protectedpages' );
159 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
160 Xml
::openElement( 'fieldset' ) .
161 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
162 Xml
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
163 $this->getNamespaceMenu( $namespace ) . " \n" .
164 $this->getTypeMenu( $type ) . " \n" .
165 $this->getLevelMenu( $level ) . " \n" .
166 "<br /><span style='white-space: nowrap'>" .
167 $this->getExpiryCheck( $indefOnly ) . " \n" .
168 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
169 "</span><br /><span style='white-space: nowrap'>" .
170 $this->getSizeLimit( $sizetype, $size ) . " \n" .
172 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
173 Xml
::closeElement( 'fieldset' ) .
174 Xml
::closeElement( 'form' );
178 * Prepare the namespace filter drop-down; standard namespace
179 * selector, sans the MediaWiki namespace
181 * @param $namespace Mixed: pre-select namespace
184 protected function getNamespaceMenu( $namespace = null ) {
185 return "<span style='white-space: nowrap'>" .
186 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
187 . Xml
::namespaceSelector( $namespace, '' ) . "</span>";
191 * @return string Formatted HTML
193 protected function getExpiryCheck( $indefOnly ) {
195 Xml
::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
199 * @return string Formatted HTML
201 protected function getCascadeCheck( $cascadeOnly ) {
203 Xml
::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
207 * @return string Formatted HTML
209 protected function getSizeLimit( $sizetype, $size ) {
210 $max = $sizetype === 'max';
213 Xml
::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
215 Xml
::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
217 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
219 Xml
::label( wfMsg('pagesize'), 'wpsize' );
223 * Creates the input label of the restriction type
224 * @param $pr_type string Protection type
225 * @return string Formatted HTML
227 protected function getTypeMenu( $pr_type ) {
228 global $wgRestrictionTypes;
230 $m = array(); // Temporary array
233 // First pass to load the log names
234 foreach( $wgRestrictionTypes as $type ) {
235 $text = wfMsg("restriction-$type");
239 // Third pass generates sorted XHTML content
240 foreach( $m as $text => $type ) {
241 $selected = ($type == $pr_type );
242 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
245 return "<span style='white-space: nowrap'>" .
246 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
248 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
249 implode( "\n", $options ) ) . "</span>";
253 * Creates the input label of the restriction level
254 * @param $pr_level string Protection level
255 * @return string Formatted HTML
257 protected function getLevelMenu( $pr_level ) {
258 global $wgRestrictionLevels;
260 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
263 // First pass to load the log names
264 foreach( $wgRestrictionLevels as $type ) {
265 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
266 if( $type !='' && $type !='*') {
267 $text = wfMsg("restriction-level-$type");
272 // Third pass generates sorted XHTML content
273 foreach( $m as $text => $type ) {
274 $selected = ($type == $pr_level );
275 $options[] = Xml
::option( $text, $type, $selected );
278 return "<span style='white-space: nowrap'>" .
279 Xml
::label( wfMsg( 'restriction-level' ) , $this->IdLevel
) . ' ' .
281 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
282 implode( "\n", $options ) ) . "</span>";
290 class ProtectedPagesPager
extends AlphabeticPager
{
291 public $mForm, $mConds;
292 private $type, $level, $namespace, $sizetype, $size, $indefonly;
294 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
295 $indefonly = false, $cascadeonly = false )
297 $this->mForm
= $form;
298 $this->mConds
= $conds;
299 $this->type
= ( $type ) ?
$type : 'edit';
300 $this->level
= $level;
301 $this->namespace = $namespace;
302 $this->sizetype
= $sizetype;
303 $this->size
= intval($size);
304 $this->indefonly
= (bool)$indefonly;
305 $this->cascadeonly
= (bool)$cascadeonly;
306 parent
::__construct();
309 function getStartBody() {
310 # Do a link batch query
312 while( $row = $this->mResult
->fetchObject() ) {
313 $lb->add( $row->page_namespace
, $row->page_title
);
319 function formatRow( $row ) {
320 return $this->mForm
->formatRow( $row );
323 function getQueryInfo() {
324 $conds = $this->mConds
;
325 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
326 'OR pr_expiry IS NULL)';
327 $conds[] = 'page_id=pr_page';
328 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
330 if( $this->sizetype
=='min' ) {
331 $conds[] = 'page_len>=' . $this->size
;
332 } else if( $this->sizetype
=='max' ) {
333 $conds[] = 'page_len<=' . $this->size
;
336 if( $this->indefonly
) {
337 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
339 if( $this->cascadeonly
) {
340 $conds[] = "pr_cascade = '1'";
344 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
345 if( !is_null($this->namespace) )
346 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
348 'tables' => array( 'page_restrictions', 'page' ),
349 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
354 function getIndexField() {