seek() does nothing here
[mediawiki.git] / includes / SpecialProtectedpages.php
blob445ad62c5047d690f0e2544753765716fef1c761
1 <?php
2 /**
4 * @addtogroup SpecialPage
5 */
7 /**
8 * @todo document
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" ) );
20 if ( "" != $msg ) {
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();
42 $s .= "<ul>" .
43 $pager->getBody() .
44 "</ul>";
45 $s .= $pager->getNavigationBar();
46 } else {
47 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
49 $wgOut->addHTML( $s );
52 /**
53 * Callback function to output a restriction
55 public function formatRow( $row ) {
56 global $wgUser, $wgLang, $wgContLang;
58 wfProfileIn( __METHOD__ );
60 static $skin=null;
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)) {
89 if ($size == 0)
90 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
91 else
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
106 * @private
108 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
109 global $wgScript;
110 $action = htmlspecialchars( $wgScript );
111 $title = SpecialPage::getTitleFor( 'ProtectedPages' );
112 $special = htmlspecialchars( $title->getPrefixedDBkey() );
113 return "<form action=\"$action\" method=\"get\">\n" .
114 '<fieldset>' .
115 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
116 Xml::hidden( 'title', $special ) . "&nbsp;\n" .
117 $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
118 $this->getTypeMenu( $type ) . "&nbsp;\n" .
119 $this->getLevelMenu( $level ) . "&nbsp;\n" .
120 "<span style='white-space: nowrap'>&nbsp;&nbsp;" .
121 $this->getExpiryCheck( $indefOnly ) . "&nbsp;\n" .
122 $this->getSizeLimit( $sizetype, $size ) . "&nbsp;\n" .
123 "</span>" .
124 "&nbsp;" . 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
133 * @return string
135 protected function getNamespaceMenu( $namespace = null ) {
136 return "<span style='white-space: nowrap'>" .
137 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&nbsp;'
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";
147 return $out;
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 .= "&nbsp;".Xml::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
157 $out .= Xml::label( wfMsg("maximum-size"), 'wpmax' );
158 $out .= "&nbsp;".Xml::input('size', 9, $size, array( 'id' => 'wpsize' ) );
159 $out .= ' '.wfMsgHtml('pagesize');
160 return $out;
164 * @return string Formatted HTML
166 protected function getTypeMenu( $pr_type ) {
167 global $wgRestrictionTypes;
169 $m = array(); // Temporary array
170 $options = array();
172 // First pass to load the log names
173 foreach( $wgRestrictionTypes as $type ) {
174 $text = wfMsg("restriction-$type");
175 $m[$text] = $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 ) . '&nbsp;' .
186 Xml::tags( 'select',
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
198 $options = array();
200 // First pass to load the log names
201 foreach( $wgRestrictionLevels as $type ) {
202 if ( $type !='' && $type !='*') {
203 $text = wfMsg("restriction-level-$type");
204 $m[$text] = $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 );
214 return
215 Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
216 Xml::tags( 'select',
217 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
218 implode( "\n", $options ) );
223 * @todo document
224 * @addtogroup Pager
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
245 $lb = new LinkBatch;
246 while( $row = $this->mResult->fetchObject() ) {
247 $lb->add( $row->page_namespace, $row->page_title );
249 $lb->execute();
251 wfProfileOut( __METHOD__ );
252 return '';
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";
275 if( $this->level )
276 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
277 if( !is_null($this->namespace) )
278 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
279 return array(
280 'tables' => array( 'page_restrictions', 'page' ),
281 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
282 'conds' => $conds
286 function getIndexField() {
287 return 'pr_id';
292 * Constructor
294 function wfSpecialProtectedpages() {
296 $ppForm = new ProtectedPagesForm();
298 $ppForm->showList();