4 * @addtogroup SpecialPage
9 * @addtogroup SpecialPage
11 class ProtectedPagesForm
{
13 protected $IdLevel = 'level';
14 protected $IdType = 'type';
16 public 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' );
34 $indefOnly = $wgRequest->getBool( 'indefonly' ) ?
1 : 0;
36 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly );
38 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly ) );
40 if ( $pager->getNumRows() ) {
41 $s = $pager->getNavigationBar();
45 $s .= $pager->getNavigationBar();
47 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
49 $wgOut->addHTML( $s );
53 * Callback function to output a restriction
55 public function formatRow( $row ) {
56 global $wgUser, $wgLang, $wgContLang;
58 wfProfileIn( __METHOD__
);
62 if( is_null( $skin ) )
63 $skin = $wgUser->getSkin();
65 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
66 $link = $skin->makeLinkObj( $title );
68 $description_items = array ();
70 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
72 $description_items[] = $protType;
74 if ( $row->pr_cascade
) {
75 $description_items[] = wfMsg( 'protect-summary-cascade' );
78 $expiry_description = ''; $stxt = '';
80 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
81 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
83 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
85 $description_items[] = $expiry_description;
88 if (!is_null($size = $row->page_len
)) {
90 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
92 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
93 $stxt = $wgContLang->getDirMark() . $stxt;
95 wfProfileOut( __METHOD__
);
97 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
101 * @param $namespace int
102 * @param $type string
103 * @param $level string
104 * @param $minsize int
105 * @param $indefOnly bool
108 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
110 $action = htmlspecialchars( $wgScript );
111 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
112 $special = htmlspecialchars( $title->getPrefixedDBkey() );
113 return "<form action=\"$action\" method=\"get\">\n" .
115 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
116 Xml
::hidden( 'title', $special ) . " \n" .
117 $this->getNamespaceMenu( $namespace ) . " \n" .
118 $this->getTypeMenu( $type ) . " \n" .
119 $this->getLevelMenu( $level ) . " \n" .
120 "<br/><span style='white-space: nowrap'> " .
121 $this->getExpiryCheck( $indefOnly ) . " \n" .
122 $this->getSizeLimit( $sizetype, $size ) . " \n" .
124 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
125 "</fieldset></form>";
129 * Prepare the namespace filter drop-down; standard namespace
130 * selector, sans the MediaWiki namespace
132 * @param mixed $namespace Pre-select namespace
135 protected function getNamespaceMenu( $namespace = null ) {
136 return "<span style='white-space: nowrap'>" .
137 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
138 . Xml
::namespaceSelector( $namespace, '' ) . "</span>";
142 * @return string Formatted HTML
144 protected function getExpiryCheck( $indefOnly ) {
145 $out = Xml
::check( 'indefonly', $indefOnly, array('id' => 'indefonly') ) . ' ';
146 $out .= Xml
::label( wfMsg("protectedpages-indef"), 'indefonly' ) . "\n";
151 * @return string Formatted HTML
153 protected function getSizeLimit( $sizetype, $size ) {
154 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
155 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
156 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
157 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
158 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
159 $out .= ' '.wfMsgHtml('pagesize');
164 * @return string Formatted HTML
166 protected function getTypeMenu( $pr_type ) {
167 global $wgRestrictionTypes;
169 $m = array(); // Temporary array
172 // First pass to load the log names
173 foreach( $wgRestrictionTypes as $type ) {
174 $text = wfMsg("restriction-$type");
178 // Third pass generates sorted XHTML content
179 foreach( $m as $text => $type ) {
180 $selected = ($type == $pr_type );
181 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
184 return "<span style='white-space: nowrap'>" .
185 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
187 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
188 implode( "\n", $options ) ) . "</span>";
192 * @return string Formatted HTML
194 protected function getLevelMenu( $pr_level ) {
195 global $wgRestrictionLevels;
197 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
200 // First pass to load the log names
201 foreach( $wgRestrictionLevels as $type ) {
202 if ( $type !='' && $type !='*') {
203 $text = wfMsg("restriction-level-$type");
208 // Third pass generates sorted XHTML content
209 foreach( $m as $text => $type ) {
210 $selected = ($type == $pr_level );
211 $options[] = Xml
::option( $text, $type, $selected );
215 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
217 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
218 implode( "\n", $options ) );
226 class ProtectedPagesPager
extends AlphabeticPager
{
227 public $mForm, $mConds;
228 private $type, $level, $namespace, $sizetype, $size, $indefonly;
230 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false ) {
231 $this->mForm
= $form;
232 $this->mConds
= $conds;
233 $this->type
= ( $type ) ?
$type : 'edit';
234 $this->level
= $level;
235 $this->namespace = $namespace;
236 $this->sizetype
= $sizetype;
237 $this->size
= intval($size);
238 $this->indefonly
= (bool)$indefonly;
239 parent
::__construct();
242 function getStartBody() {
243 wfProfileIn( __METHOD__
);
244 # Do a link batch query
246 while( $row = $this->mResult
->fetchObject() ) {
247 $lb->add( $row->page_namespace
, $row->page_title
);
251 wfProfileOut( __METHOD__
);
255 function formatRow( $row ) {
256 return $this->mForm
->formatRow( $row );
259 function getQueryInfo() {
260 $conds = $this->mConds
;
261 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
262 $conds[] = 'page_id=pr_page';
263 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
265 if( $this->sizetype
=='min' ) {
266 $conds[] = 'page_len>=' . $this->size
;
267 } else if( $this->sizetype
=='max' ) {
268 $conds[] = 'page_len<=' . $this->size
;
271 if( $this->indefonly
) {
272 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
276 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
277 if( !is_null($this->namespace) )
278 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
280 'tables' => array( 'page_restrictions', 'page' ),
281 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
286 function getIndexField() {
294 function wfSpecialProtectedpages() {
296 $ppForm = new ProtectedPagesForm();