Add spacing in Special:Protectedpages.
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 * @todo document
9 * @ingroup SpecialPage
10 */
11 class ProtectedPagesForm {
12
13 protected $IdLevel = 'level';
14 protected $IdType = 'type';
15
16 public function showList( $msg = '' ) {
17 global $wgOut, $wgRequest;
18
19 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
20 if ( "" != $msg ) {
21 $wgOut->setSubtitle( $msg );
22 }
23
24 // Purge expired entries on one in every 10 queries
25 if ( !mt_rand( 0, 10 ) ) {
26 Title::purgeExpiredRestrictions();
27 }
28
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;
35
36 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly );
37
38 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly ) );
39
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>';
48 }
49 $wgOut->addHTML( $s );
50 }
51
52 /**
53 * Callback function to output a restriction
54 * @param $row object Protected title
55 * @return string Formatted <li> element
56 */
57 public function formatRow( $row ) {
58 global $wgUser, $wgLang, $wgContLang;
59
60 wfProfileIn( __METHOD__ );
61
62 static $skin=null;
63
64 if( is_null( $skin ) )
65 $skin = $wgUser->getSkin();
66
67 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
68 $link = $skin->makeLinkObj( $title );
69
70 $description_items = array ();
71
72 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
73
74 $description_items[] = $protType;
75
76 if ( $row->pr_cascade ) {
77 $description_items[] = wfMsg( 'protect-summary-cascade' );
78 }
79
80 $expiry_description = '';
81 $stxt = '';
82
83 if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
84 $expiry = Block::decodeExpiry( $row->pr_expiry );
85
86 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
87
88 $description_items[] = $expiry_description;
89 }
90
91 if (!is_null($size = $row->page_len)) {
92 if ($size == 0) {
93 $stxt = wfMsg('historyempty');
94 } else {
95 $stxt = wfMsg('nbytes', $wgLang->formatNum( $size ) );
96 $stxt = "($stxt)";
97 }
98 $stxt = htmlspecialchars( $stxt );
99 $stxt = $wgContLang->getDirMark() . ' ' . $stxt;
100 }
101
102 # Show a link to the change protection form for allowed users otherwise a link to the protection log
103 if( $wgUser->isAllowed( 'protect' ) ) {
104 $changeProtection = ' (' . $skin->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ), 'action=unprotect' ) . ')';
105 } else {
106 $ltitle = SpecialPage::getTitleFor( 'Log' );
107 $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ), 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
108 }
109
110 wfProfileOut( __METHOD__ );
111
112 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
113 }
114
115 /**
116 * @param $namespace int
117 * @param $type string
118 * @param $level string
119 * @param $minsize int
120 * @param $indefOnly bool
121 * @return string Input form
122 * @private
123 */
124 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
125 global $wgScript;
126 $title = SpecialPage::getTitleFor( 'ProtectedPages' );
127 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
128 Xml::openElement( 'fieldset' ) .
129 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
130 Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "&nbsp;\n" .
131 $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
132 $this->getTypeMenu( $type ) . "&nbsp;\n" .
133 $this->getLevelMenu( $level ) . "&nbsp;\n" .
134 "<br /><span style='white-space: nowrap'>&nbsp;&nbsp;" .
135 $this->getExpiryCheck( $indefOnly ) . "&nbsp;\n" .
136 $this->getSizeLimit( $sizetype, $size ) . "&nbsp;\n" .
137 "</span>" .
138 "&nbsp;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
139 Xml::closeElement( 'fieldset' ) .
140 Xml::closeElement( 'form' );
141 }
142
143 /**
144 * Prepare the namespace filter drop-down; standard namespace
145 * selector, sans the MediaWiki namespace
146 *
147 * @param mixed $namespace Pre-select namespace
148 * @return string
149 */
150 protected function getNamespaceMenu( $namespace = null ) {
151 return "<span style='white-space: nowrap'>" .
152 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&nbsp;'
153 . Xml::namespaceSelector( $namespace, '' ) . "</span>";
154 }
155
156 /**
157 * @return string Formatted HTML
158 */
159 protected function getExpiryCheck( $indefOnly ) {
160 return
161 Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
162 }
163
164 /**
165 * @return string Formatted HTML
166 */
167 protected function getSizeLimit( $sizetype, $size ) {
168 $max = $sizetype === 'max';
169
170 return
171 Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
172 '&nbsp;' .
173 Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
174 '&nbsp;' .
175 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
176 '&nbsp;' .
177 Xml::label( wfMsg('pagesize'), 'wpsize' );
178 }
179
180 /**
181 * @return string Formatted HTML
182 */
183 protected function getTypeMenu( $pr_type ) {
184 global $wgRestrictionTypes;
185
186 $m = array(); // Temporary array
187 $options = array();
188
189 // First pass to load the log names
190 foreach( $wgRestrictionTypes as $type ) {
191 $text = wfMsg("restriction-$type");
192 $m[$text] = $type;
193 }
194
195 // Third pass generates sorted XHTML content
196 foreach( $m as $text => $type ) {
197 $selected = ($type == $pr_type );
198 $options[] = Xml::option( $text, $type, $selected ) . "\n";
199 }
200
201 return "<span style='white-space: nowrap'>" .
202 Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&nbsp;' .
203 Xml::tags( 'select',
204 array( 'id' => $this->IdType, 'name' => $this->IdType ),
205 implode( "\n", $options ) ) . "</span>";
206 }
207
208 /**
209 * @return string Formatted HTML
210 */
211 protected function getLevelMenu( $pr_level ) {
212 global $wgRestrictionLevels;
213
214 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
215 $options = array();
216
217 // First pass to load the log names
218 foreach( $wgRestrictionLevels as $type ) {
219 if ( $type !='' && $type !='*') {
220 $text = wfMsg("restriction-level-$type");
221 $m[$text] = $type;
222 }
223 }
224
225 // Third pass generates sorted XHTML content
226 foreach( $m as $text => $type ) {
227 $selected = ($type == $pr_level );
228 $options[] = Xml::option( $text, $type, $selected );
229 }
230
231 return
232 Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
233 Xml::tags( 'select',
234 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
235 implode( "\n", $options ) );
236 }
237 }
238
239 /**
240 * @todo document
241 * @ingroup Pager
242 */
243 class ProtectedPagesPager extends AlphabeticPager {
244 public $mForm, $mConds;
245 private $type, $level, $namespace, $sizetype, $size, $indefonly;
246
247 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false ) {
248 $this->mForm = $form;
249 $this->mConds = $conds;
250 $this->type = ( $type ) ? $type : 'edit';
251 $this->level = $level;
252 $this->namespace = $namespace;
253 $this->sizetype = $sizetype;
254 $this->size = intval($size);
255 $this->indefonly = (bool)$indefonly;
256 parent::__construct();
257 }
258
259 function getStartBody() {
260 wfProfileIn( __METHOD__ );
261 # Do a link batch query
262 $lb = new LinkBatch;
263 while( $row = $this->mResult->fetchObject() ) {
264 $lb->add( $row->page_namespace, $row->page_title );
265 }
266 $lb->execute();
267
268 wfProfileOut( __METHOD__ );
269 return '';
270 }
271
272 function formatRow( $row ) {
273 return $this->mForm->formatRow( $row );
274 }
275
276 function getQueryInfo() {
277 $conds = $this->mConds;
278 $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
279 $conds[] = 'page_id=pr_page';
280 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
281
282 if( $this->sizetype=='min' ) {
283 $conds[] = 'page_len>=' . $this->size;
284 } else if( $this->sizetype=='max' ) {
285 $conds[] = 'page_len<=' . $this->size;
286 }
287
288 if( $this->indefonly ) {
289 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
290 }
291
292 if( $this->level )
293 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
294 if( !is_null($this->namespace) )
295 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
296 return array(
297 'tables' => array( 'page_restrictions', 'page' ),
298 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
299 'conds' => $conds
300 );
301 }
302
303 function getIndexField() {
304 return 'pr_id';
305 }
306 }
307
308 /**
309 * Constructor
310 */
311 function wfSpecialProtectedpages() {
312
313 $ppForm = new ProtectedPagesForm();
314
315 $ppForm->showList();
316 }