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, $wgContLang;
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>';
92 $stxt = $wgContLang->getDirMark() . $stxt;
94 wfProfileOut( __METHOD__
);
96 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
100 * @param $namespace int
101 * @param $type string
102 * @param $level string
103 * @param $minsize int
106 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
108 $action = htmlspecialchars( $wgScript );
109 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
110 $special = htmlspecialchars( $title->getPrefixedDBkey() );
111 return "<form action=\"$action\" method=\"get\">\n" .
113 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
114 Xml
::hidden( 'title', $special ) . " \n" .
115 $this->getNamespaceMenu( $namespace ) . " \n" .
116 $this->getTypeMenu( $type ) . " \n" .
117 $this->getLevelMenu( $level ) . "<br/>\n" .
118 $this->getSizeLimit( $sizetype, $size ) . "\n" .
119 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
120 "</fieldset></form>";
124 * Prepare the namespace filter drop-down; standard namespace
125 * selector, sans the MediaWiki namespace
127 * @param mixed $namespace Pre-select namespace
130 function getNamespaceMenu( $namespace = null ) {
131 return Xml
::label( wfMsg( 'namespace' ), 'namespace' )
133 . Xml
::namespaceSelector( $namespace, '' );
137 * @return string Formatted HTML
140 function getSizeLimit( $sizetype, $size ) {
141 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
142 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
143 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
144 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
145 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
146 $out .= ' '.wfMsgHtml('pagesize');
151 * @return string Formatted HTML
154 function getTypeMenu( $pr_type ) {
155 global $wgRestrictionTypes;
157 $m = array(); // Temporary array
160 // First pass to load the log names
161 foreach( $wgRestrictionTypes as $type ) {
162 $text = wfMsg("restriction-$type");
166 // Third pass generates sorted XHTML content
167 foreach( $m as $text => $type ) {
168 $selected = ($type == $pr_type );
169 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
173 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
175 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
176 implode( "\n", $options ) );
180 * @return string Formatted HTML
183 function getLevelMenu( $pr_level ) {
184 global $wgRestrictionLevels;
186 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
189 // First pass to load the log names
190 foreach( $wgRestrictionLevels as $type ) {
191 if ( $type !='' && $type !='*') {
192 $text = wfMsg("restriction-level-$type");
197 // Third pass generates sorted XHTML content
198 foreach( $m as $text => $type ) {
199 $selected = ($type == $pr_level );
200 $options[] = Xml
::option( $text, $type, $selected );
204 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
206 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
207 implode( "\n", $options ) );
215 class ProtectedPagesPager
extends AlphabeticPager
{
216 public $mForm, $mConds;
218 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
219 $this->mForm
= $form;
220 $this->mConds
= $conds;
221 $this->type
= ( $type ) ?
$type : 'edit';
222 $this->level
= $level;
223 $this->namespace = $namespace;
224 $this->sizetype
= $sizetype;
225 $this->size
= intval($size);
226 parent
::__construct();
229 function getStartBody() {
230 wfProfileIn( __METHOD__
);
231 # Do a link batch query
232 $this->mResult
->seek( 0 );
235 while ( $row = $this->mResult
->fetchObject() ) {
236 $lb->add( $row->page_namespace
, $row->page_title
);
240 wfProfileOut( __METHOD__
);
244 function formatRow( $row ) {
245 return $this->mForm
->formatRow( $row );
248 function getQueryInfo() {
249 $conds = $this->mConds
;
250 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
251 $conds[] = 'page_id=pr_page';
252 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
254 if( $this->sizetype
=='min' ) {
255 $conds[] = 'page_len>=' . $this->size
;
256 } else if( $this->sizetype
=='max' ) {
257 $conds[] = 'page_len<=' . $this->size
;
261 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
262 if( !is_null($this->namespace) )
263 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
265 'tables' => array( 'page_restrictions', 'page' ),
266 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
271 function getIndexField() {
279 function wfSpecialProtectedpages() {
281 $ppForm = new ProtectedPagesForm();