4 * @addtogroup SpecialPage
9 * @addtogroup SpecialPage
11 class ProtectedPagesForm
{
13 protected $IdLevel = 'level';
14 protected $IdType = 'type';
16 function showList( $msg = '' ) {
17 global $wgOut, $wgRequest;
19 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
21 $wgOut->setSubtitle( $msg );
24 // Purge expired entries on one in every 10 queries
25 if ( !mt_rand( 0, 10 ) ) {
26 Title
::purgeExpiredRestrictions();
29 $type = $wgRequest->getVal( $this->IdType
);
30 $level = $wgRequest->getVal( $this->IdLevel
);
31 $sizetype = $wgRequest->getVal( 'sizetype' );
32 $size = $wgRequest->getIntOrNull( 'size' );
33 $NS = $wgRequest->getIntOrNull( 'namespace' );
35 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
37 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
39 if ( $pager->getNumRows() ) {
40 $s = $pager->getNavigationBar();
44 $s .= $pager->getNavigationBar();
46 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
48 $wgOut->addHTML( $s );
52 * Callback function to output a restriction
54 function formatRow( $row ) {
55 global $wgUser, $wgLang;
57 wfProfileIn( __METHOD__
);
61 if( is_null( $skin ) )
62 $skin = $wgUser->getSkin();
64 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
65 $link = $skin->makeLinkObj( $title );
67 $description_items = array ();
69 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
71 $description_items[] = $protType;
73 if ( $row->pr_cascade
) {
74 $description_items[] = wfMsg( 'protect-summary-cascade' );
77 $expiry_description = ''; $stxt = '';
79 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
80 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
82 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
84 $description_items[] = $expiry_description;
87 if (!is_null($size = $row->page_len
)) {
89 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
91 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
93 wfProfileOut( __METHOD__
);
95 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
99 * @param $namespace int
100 * @param $type string
101 * @param $level string
102 * @param $minsize int
105 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
107 $action = htmlspecialchars( $wgScript );
108 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
109 $special = htmlspecialchars( $title->getPrefixedDBkey() );
110 return "<form action=\"$action\" method=\"get\">\n" .
112 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
113 Xml
::hidden( 'title', $special ) . " \n" .
114 $this->getNamespaceMenu( $namespace ) . " \n" .
115 $this->getTypeMenu( $type ) . " \n" .
116 $this->getLevelMenu( $level ) . "<br/>\n" .
117 $this->getSizeLimit( $sizetype, $size ) . "\n" .
118 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
119 "</fieldset></form>";
123 * Prepare the namespace filter drop-down; standard namespace
124 * selector, sans the MediaWiki namespace
126 * @param mixed $namespace Pre-select namespace
129 function getNamespaceMenu( $namespace = null ) {
130 return Xml
::label( wfMsg( 'namespace' ), 'namespace' )
132 . Xml
::namespaceSelector( $namespace, '' );
136 * @return string Formatted HTML
139 function getSizeLimit( $sizetype, $size ) {
140 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
141 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
142 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
143 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
144 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
145 $out .= ' '.wfMsgHtml('pagesize');
150 * @return string Formatted HTML
153 function getTypeMenu( $pr_type ) {
154 global $wgRestrictionTypes;
156 $m = array(); // Temporary array
159 // First pass to load the log names
160 foreach( $wgRestrictionTypes as $type ) {
161 $text = wfMsg("restriction-$type");
165 // Third pass generates sorted XHTML content
166 foreach( $m as $text => $type ) {
167 $selected = ($type == $pr_type );
168 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
172 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
174 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
175 implode( "\n", $options ) );
179 * @return string Formatted HTML
182 function getLevelMenu( $pr_level ) {
183 global $wgRestrictionLevels;
185 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
188 // First pass to load the log names
189 foreach( $wgRestrictionLevels as $type ) {
190 if ( $type !='' && $type !='*') {
191 $text = wfMsg("restriction-level-$type");
196 // Third pass generates sorted XHTML content
197 foreach( $m as $text => $type ) {
198 $selected = ($type == $pr_level );
199 $options[] = Xml
::option( $text, $type, $selected );
203 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
205 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
206 implode( "\n", $options ) );
214 class ProtectedPagesPager
extends AlphabeticPager
{
215 public $mForm, $mConds;
217 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
218 $this->mForm
= $form;
219 $this->mConds
= $conds;
220 $this->type
= ( $type ) ?
$type : 'edit';
221 $this->level
= $level;
222 $this->namespace = $namespace;
223 $this->sizetype
= $sizetype;
224 $this->size
= intval($size);
225 parent
::__construct();
228 function getStartBody() {
229 wfProfileIn( __METHOD__
);
230 # Do a link batch query
231 $this->mResult
->seek( 0 );
234 while ( $row = $this->mResult
->fetchObject() ) {
235 $lb->add( $row->page_namespace
, $row->page_title
);
239 wfProfileOut( __METHOD__
);
243 function formatRow( $row ) {
244 return $this->mForm
->formatRow( $row );
247 function getQueryInfo() {
248 $conds = $this->mConds
;
249 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
250 $conds[] = 'page_id=pr_page';
251 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
253 if( $this->sizetype
=='min' ) {
254 $conds[] = 'page_len>=' . $this->size
;
255 } else if( $this->sizetype
=='max' ) {
256 $conds[] = 'page_len<=' . $this->size
;
260 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
261 if( !is_null($this->namespace) )
262 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
264 'tables' => array( 'page_restrictions', 'page' ),
265 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
270 function getIndexField() {
278 function wfSpecialProtectedpages() {
280 $ppForm = new ProtectedPagesForm();