<?php
/**
- *
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup SpecialPage
*/
/**
* @todo document
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
*/
class ProtectedPagesForm {
- function showList( $msg = '' ) {
+
+ protected $IdLevel = 'level';
+ protected $IdType = 'type';
+
+ public function showList( $msg = '' ) {
global $wgOut, $wgRequest;
$wgOut->setPagetitle( wfMsg( "protectedpages" ) );
Title::purgeExpiredRestrictions();
}
- $type = $wgRequest->getText( 'type' );
- $level = $wgRequest->getText( 'level' );
- $minsize = $wgRequest->getIntOrNull( 'minsize' );
+ $type = $wgRequest->getVal( $this->IdType );
+ $level = $wgRequest->getVal( $this->IdLevel );
+ $sizetype = $wgRequest->getVal( 'sizetype' );
+ $size = $wgRequest->getIntOrNull( 'size' );
$NS = $wgRequest->getIntOrNull( 'namespace' );
+ $indefOnly = $wgRequest->getBool( 'indefonly' ) ? 1 : 0;
- $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $minsize );
+ $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly );
- $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $minsize ) );
+ $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly ) );
if ( $pager->getNumRows() ) {
$s = $pager->getNavigationBar();
- $s .= "<ul>" .
+ $s .= "<ul>" .
$pager->getBody() .
"</ul>";
$s .= $pager->getNavigationBar();
} else {
- $s = '<p>' . wfMsgHTML( 'protectedpagesempty' ) . '</p>';
+ $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
}
$wgOut->addHTML( $s );
}
/**
* Callback function to output a restriction
+ * @param $row object Protected title
+ * @return string Formatted <li> element
*/
- function formatRow( $row ) {
- global $wgUser, $wgLang;
+ public function formatRow( $row ) {
+ global $wgUser, $wgLang, $wgContLang;
wfProfileIn( __METHOD__ );
if( is_null( $skin ) )
$skin = $wgUser->getSkin();
-
+
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
$link = $skin->makeLinkObj( $title );
$description_items[] = $protType;
- $expiry_description = ''; $stxt = '';
+ if ( $row->pr_cascade ) {
+ $description_items[] = wfMsg( 'protect-summary-cascade' );
+ }
+
+ $expiry_description = '';
+ $stxt = '';
if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
$expiry = Block::decodeExpiry( $row->pr_expiry );
-
+
$expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
$description_items[] = $expiry_description;
}
-
+
if (!is_null($size = $row->page_len)) {
if ($size == 0)
$stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
else
$stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
+ $stxt = $wgContLang->getDirMark() . $stxt;
+ }
+
+ # Show a link to the change protection form for allowed users otherwise a link to the protection log
+ if( $wgUser->isAllowed( 'protect' ) ) {
+ $changeProtection = ' (' . $skin->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ), 'action=unprotect' ) . ')';
+ } else {
+ $ltitle = SpecialPage::getTitleFor( 'Log' );
+ $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ), 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
}
+
wfProfileOut( __METHOD__ );
- return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
+ return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
}
-
+
/**
* @param $namespace int
* @param $type string
* @param $level string
* @param $minsize int
+ * @param $indefOnly bool
+ * @return string Input form
* @private
*/
- function showOptions( $namespace, $type='edit', $level, $minsize ) {
+ protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
global $wgScript;
- $action = htmlspecialchars( $wgScript );
$title = SpecialPage::getTitleFor( 'ProtectedPages' );
- $special = htmlspecialchars( $title->getPrefixedDBkey() );
- return "<form action=\"$action\" method=\"get\">\n" .
- '<fieldset>' .
+ return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+ Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
- Xml::hidden( 'title', $special ) . "\n" .
- $this->getNamespaceMenu( $namespace ) . "\n" .
- $this->getTypeMenu( $type ) . "\n" .
- $this->getLevelMenu( $level ) . "<br/>\n" .
- $this->getSizeLimit( $minsize ) . "\n" .
- Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
- "</fieldset></form>";
+ Xml::hidden( 'title', $title->getPrefixedDBkey() ) . " \n" .
+ $this->getNamespaceMenu( $namespace ) . " \n" .
+ $this->getTypeMenu( $type ) . " \n" .
+ $this->getLevelMenu( $level ) . " \n" .
+ "<br /><span style='white-space: nowrap'> " .
+ $this->getExpiryCheck( $indefOnly ) . " \n" .
+ $this->getSizeLimit( $sizetype, $size ) . " \n" .
+ "</span>" .
+ " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
+ Xml::closeElement( 'fieldset' ) .
+ Xml::closeElement( 'form' );
}
-
- function getNamespaceMenu( $namespace=NULL ) {
- return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
+
+ /**
+ * Prepare the namespace filter drop-down; standard namespace
+ * selector, sans the MediaWiki namespace
+ *
+ * @param mixed $namespace Pre-select namespace
+ * @return string
+ */
+ protected function getNamespaceMenu( $namespace = null ) {
+ return "<span style='white-space: nowrap'>" .
+ Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
+ . Xml::namespaceSelector( $namespace, '' ) . "</span>";
}
/**
* @return string Formatted HTML
- * @private
*/
- function getSizeLimit( $minsize=0 ) {
- $out = Xml::input('minsize', 9, $minsize, array( 'id' => 'minsize' ) );
- return "<label for='minsize'>" . wfMsgHtml('minimum-size') . "</label>: " . $out;
+ protected function getExpiryCheck( $indefOnly ) {
+ return
+ Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
}
-
+
/**
* @return string Formatted HTML
- * @private
*/
- function getTypeMenu( $pr_type ) {
- global $wgRestrictionTypes, $wgUser;
-
- $out = "<select name='type'>\n";
+ protected function getSizeLimit( $sizetype, $size ) {
+ $max = $sizetype === 'max';
+
+ return
+ Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
+ ' ' .
+ Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
+ ' ' .
+ Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
+ ' ' .
+ Xml::label( wfMsg('pagesize'), 'wpsize' );
+ }
+
+ /**
+ * @return string Formatted HTML
+ */
+ protected function getTypeMenu( $pr_type ) {
+ global $wgRestrictionTypes;
+
$m = array(); // Temporary array
+ $options = array();
// First pass to load the log names
foreach( $wgRestrictionTypes as $type ) {
- $text = wfMsgHtml("restriction-$type");
+ $text = wfMsg("restriction-$type");
$m[$text] = $type;
}
- // Second pass to sort by name
- ksort($m);
-
// Third pass generates sorted XHTML content
foreach( $m as $text => $type ) {
$selected = ($type == $pr_type );
- $out .= Xml::option( $text, $type, $selected ) . "\n";
+ $options[] = Xml::option( $text, $type, $selected ) . "\n";
}
- $out .= '</select>';
- return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
+ return "<span style='white-space: nowrap'>" .
+ Xml::label( wfMsg('restriction-type') , $this->IdType ) . ' ' .
+ Xml::tags( 'select',
+ array( 'id' => $this->IdType, 'name' => $this->IdType ),
+ implode( "\n", $options ) ) . "</span>";
}
/**
* @return string Formatted HTML
- * @private
- */
- function getLevelMenu( $pr_level ) {
- global $wgRestrictionLevels, $wgUser;
-
- $out = "<select name='level'>\n";
- $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
+ */
+ protected function getLevelMenu( $pr_level ) {
+ global $wgRestrictionLevels;
+
+ $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
+ $options = array();
// First pass to load the log names
foreach( $wgRestrictionLevels as $type ) {
if ( $type !='' && $type !='*') {
- $text = wfMsgHtml("restriction-level-$type");
+ $text = wfMsg("restriction-level-$type");
$m[$text] = $type;
}
}
- // Second pass to sort by name
- ksort($m);
-
// Third pass generates sorted XHTML content
foreach( $m as $text => $type ) {
$selected = ($type == $pr_level );
- $out .= Xml::option( $text, $type, $selected ) . "\n";
+ $options[] = Xml::option( $text, $type, $selected );
}
- $out .= '</select>';
- return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
+ return
+ Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . ' ' .
+ Xml::tags( 'select',
+ array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
+ implode( "\n", $options ) );
}
}
/**
* @todo document
+ * @ingroup Pager
*/
-class ProtectedPagesPager extends ReverseChronologicalPager {
+class ProtectedPagesPager extends AlphabeticPager {
public $mForm, $mConds;
+ private $type, $level, $namespace, $sizetype, $size, $indefonly;
- function __construct( $form, $conds = array(), $type, $level, $namespace, $minsize ) {
+ function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false ) {
$this->mForm = $form;
$this->mConds = $conds;
$this->type = ( $type ) ? $type : 'edit';
$this->level = $level;
$this->namespace = $namespace;
- $this->minsize = intval($minsize);
+ $this->sizetype = $sizetype;
+ $this->size = intval($size);
+ $this->indefonly = (bool)$indefonly;
parent::__construct();
}
function getStartBody() {
wfProfileIn( __METHOD__ );
# Do a link batch query
- $this->mResult->seek( 0 );
$lb = new LinkBatch;
-
- while ( $row = $this->mResult->fetchObject() ) {
- $name = str_replace( ' ', '_', $row->page_title );
- $lb->add( $row->page_namespace, $name );
+ while( $row = $this->mResult->fetchObject() ) {
+ $lb->add( $row->page_namespace, $row->page_title );
}
-
$lb->execute();
+
wfProfileOut( __METHOD__ );
return '';
}
-
+
function formatRow( $row ) {
- $block = new Block;
return $this->mForm->formatRow( $row );
}
$conds = $this->mConds;
$conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
$conds[] = 'page_id=pr_page';
- $conds[] = 'page_len>=' . $this->minsize;
$conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
- if ( $this->level )
+
+ if( $this->sizetype=='min' ) {
+ $conds[] = 'page_len>=' . $this->size;
+ } else if( $this->sizetype=='max' ) {
+ $conds[] = 'page_len<=' . $this->size;
+ }
+
+ if( $this->indefonly ) {
+ $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
+ }
+
+ if( $this->level )
$conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
- if ( !is_null($this->namespace) )
+ if( !is_null($this->namespace) )
$conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
return array(
'tables' => array( 'page_restrictions', 'page' ),
- 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry',
- 'conds' => $conds,
- 'options' => array( 'GROUP BY' => 'page_namespace,page_title,pr_level,pr_expiry,page_len,pr_type' ),
+ 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
+ 'conds' => $conds
);
}
*/
function wfSpecialProtectedpages() {
- list( $limit, $offset ) = wfCheckLimits();
-
$ppForm = new ProtectedPagesForm();
$ppForm->showList();
}
-
-?>