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;
35 $cascadeOnly = $wgRequest->getBool('cascadeonly') ?
1 : 0;
37 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
39 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
41 if ( $pager->getNumRows() ) {
42 $s = $pager->getNavigationBar();
46 $s .= $pager->getNavigationBar();
48 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
50 $wgOut->addHTML( $s );
54 * Callback function to output a restriction
55 * @param $row object Protected title
56 * @return string Formatted <li> element
58 public function formatRow( $row ) {
59 global $wgUser, $wgLang, $wgContLang;
61 wfProfileIn( __METHOD__
);
65 if( is_null( $skin ) )
66 $skin = $wgUser->getSkin();
68 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
69 $link = $skin->makeLinkObj( $title );
71 $description_items = array ();
73 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
75 $description_items[] = $protType;
77 if ( $row->pr_cascade
) {
78 $description_items[] = wfMsg( 'protect-summary-cascade' );
81 $expiry_description = '';
84 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
85 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
87 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
89 $description_items[] = $expiry_description;
92 if (!is_null($size = $row->page_len
)) {
93 $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
96 # Show a link to the change protection form for allowed users otherwise a link to the protection log
97 if( $wgUser->isAllowed( 'protect' ) ) {
98 $changeProtection = ' (' . $skin->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ), 'action=unprotect' ) . ')';
100 $ltitle = SpecialPage
::getTitleFor( 'Log' );
101 $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ), 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
104 wfProfileOut( __METHOD__
);
106 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
110 * @param $namespace int
111 * @param $type string
112 * @param $level string
113 * @param $minsize int
114 * @param $indefOnly bool
115 * @param $cascadeOnly bool
116 * @return string Input form
119 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
121 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
122 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
123 Xml
::openElement( 'fieldset' ) .
124 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
125 Xml
::hidden( 'title', $title->getPrefixedDBkey() ) . " \n" .
126 $this->getNamespaceMenu( $namespace ) . " \n" .
127 $this->getTypeMenu( $type ) . " \n" .
128 $this->getLevelMenu( $level ) . " \n" .
129 "<br /><span style='white-space: nowrap'> " .
130 $this->getExpiryCheck( $indefOnly ) . " \n" .
131 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
132 $this->getSizeLimit( $sizetype, $size ) . " \n" .
134 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
135 Xml
::closeElement( 'fieldset' ) .
136 Xml
::closeElement( 'form' );
140 * Prepare the namespace filter drop-down; standard namespace
141 * selector, sans the MediaWiki namespace
143 * @param mixed $namespace Pre-select namespace
146 protected function getNamespaceMenu( $namespace = null ) {
147 return "<span style='white-space: nowrap'>" .
148 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
149 . Xml
::namespaceSelector( $namespace, '' ) . "</span>";
153 * @return string Formatted HTML
155 protected function getExpiryCheck( $indefOnly ) {
157 Xml
::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
161 * @return string Formatted HTML
163 protected function getCascadeCheck( $cascadeOnly ) {
165 Xml
::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
169 * @return string Formatted HTML
171 protected function getSizeLimit( $sizetype, $size ) {
172 $max = $sizetype === 'max';
175 Xml
::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
177 Xml
::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
179 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
181 Xml
::label( wfMsg('pagesize'), 'wpsize' );
185 * @return string Formatted HTML
187 protected function getTypeMenu( $pr_type ) {
188 global $wgRestrictionTypes;
190 $m = array(); // Temporary array
193 // First pass to load the log names
194 foreach( $wgRestrictionTypes as $type ) {
195 $text = wfMsg("restriction-$type");
199 // Third pass generates sorted XHTML content
200 foreach( $m as $text => $type ) {
201 $selected = ($type == $pr_type );
202 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
205 return "<span style='white-space: nowrap'>" .
206 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
208 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
209 implode( "\n", $options ) ) . "</span>";
213 * @return string Formatted HTML
215 protected function getLevelMenu( $pr_level ) {
216 global $wgRestrictionLevels;
218 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
221 // First pass to load the log names
222 foreach( $wgRestrictionLevels as $type ) {
223 if ( $type !='' && $type !='*') {
224 $text = wfMsg("restriction-level-$type");
229 // Third pass generates sorted XHTML content
230 foreach( $m as $text => $type ) {
231 $selected = ($type == $pr_level );
232 $options[] = Xml
::option( $text, $type, $selected );
236 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
238 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
239 implode( "\n", $options ) );
247 class ProtectedPagesPager
extends AlphabeticPager
{
248 public $mForm, $mConds;
249 private $type, $level, $namespace, $sizetype, $size, $indefonly;
251 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='',
252 $size=0, $indefonly = false, $cascadeonly = false ) {
253 $this->mForm
= $form;
254 $this->mConds
= $conds;
255 $this->type
= ( $type ) ?
$type : 'edit';
256 $this->level
= $level;
257 $this->namespace = $namespace;
258 $this->sizetype
= $sizetype;
259 $this->size
= intval($size);
260 $this->indefonly
= (bool)$indefonly;
261 $this->cascadeonly
= (bool)$cascadeonly;
262 parent
::__construct();
265 function getStartBody() {
266 wfProfileIn( __METHOD__
);
267 # Do a link batch query
269 while( $row = $this->mResult
->fetchObject() ) {
270 $lb->add( $row->page_namespace
, $row->page_title
);
274 wfProfileOut( __METHOD__
);
278 function formatRow( $row ) {
279 return $this->mForm
->formatRow( $row );
282 function getQueryInfo() {
283 $conds = $this->mConds
;
284 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
285 $conds[] = 'page_id=pr_page';
286 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
288 if( $this->sizetype
=='min' ) {
289 $conds[] = 'page_len>=' . $this->size
;
290 } else if( $this->sizetype
=='max' ) {
291 $conds[] = 'page_len<=' . $this->size
;
294 if( $this->indefonly
) {
295 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
297 if ( $this->cascadeonly
) {
298 $conds[] = "pr_cascade = '1'";
302 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
303 if( !is_null($this->namespace) )
304 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
306 'tables' => array( 'page_restrictions', 'page' ),
307 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
312 function getIndexField() {
320 function wfSpecialProtectedpages() {
322 $ppForm = new ProtectedPagesForm();