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;
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>';
93 wfProfileOut( __METHOD__
);
95 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
99 * @param $namespace int
100 * @param $type string
101 * @param $level string
102 * @param $minsize int
105 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
107 $action = htmlspecialchars( $wgScript );
108 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
109 $special = htmlspecialchars( $title->getPrefixedDBkey() );
110 return "<form action=\"$action\" method=\"get\">\n" .
112 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
113 Xml
::hidden( 'title', $special ) . " \n" .
114 $this->getNamespaceMenu( $namespace ) . " \n" .
115 $this->getTypeMenu( $type ) . " \n" .
116 $this->getLevelMenu( $level ) . "<br/>\n" .
117 $this->getSizeLimit( $sizetype, $size ) . "\n" .
118 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
119 "</fieldset></form>";
122 function getNamespaceMenu( $namespace=NULL ) {
123 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
127 * @return string Formatted HTML
130 function getSizeLimit( $sizetype, $size ) {
131 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
132 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
133 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
134 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
135 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
136 $out .= ' '.wfMsgHtml('pagesize');
141 * @return string Formatted HTML
144 function getTypeMenu( $pr_type ) {
145 global $wgRestrictionTypes;
147 $m = array(); // Temporary array
150 // First pass to load the log names
151 foreach( $wgRestrictionTypes as $type ) {
152 $text = wfMsg("restriction-$type");
156 // Third pass generates sorted XHTML content
157 foreach( $m as $text => $type ) {
158 $selected = ($type == $pr_type );
159 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
163 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
165 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
166 implode( "\n", $options ) );
170 * @return string Formatted HTML
173 function getLevelMenu( $pr_level ) {
174 global $wgRestrictionLevels;
176 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
179 // First pass to load the log names
180 foreach( $wgRestrictionLevels as $type ) {
181 if ( $type !='' && $type !='*') {
182 $text = wfMsg("restriction-level-$type");
187 // Third pass generates sorted XHTML content
188 foreach( $m as $text => $type ) {
189 $selected = ($type == $pr_level );
190 $options[] = Xml
::option( $text, $type, $selected );
194 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
196 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
197 implode( "\n", $options ) );
205 class ProtectedPagesPager
extends AlphabeticPager
{
206 public $mForm, $mConds;
208 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
209 $this->mForm
= $form;
210 $this->mConds
= $conds;
211 $this->type
= ( $type ) ?
$type : 'edit';
212 $this->level
= $level;
213 $this->namespace = $namespace;
214 $this->sizetype
= $sizetype;
215 $this->size
= intval($size);
216 parent
::__construct();
219 function getStartBody() {
220 wfProfileIn( __METHOD__
);
221 # Do a link batch query
222 $this->mResult
->seek( 0 );
225 while ( $row = $this->mResult
->fetchObject() ) {
226 $lb->add( $row->page_namespace
, $row->page_title
);
230 wfProfileOut( __METHOD__
);
234 function formatRow( $row ) {
236 return $this->mForm
->formatRow( $row );
239 function getQueryInfo() {
240 $conds = $this->mConds
;
241 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
242 $conds[] = 'page_id=pr_page';
243 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
245 if( $this->sizetype
=='min' ) {
246 $conds[] = 'page_len>=' . $this->size
;
247 } else if( $this->sizetype
=='max' ) {
248 $conds[] = 'page_len<=' . $this->size
;
252 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
253 if( !is_null($this->namespace) )
254 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
256 'tables' => array( 'page_restrictions', 'page' ),
257 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
262 function getIndexField() {
270 function wfSpecialProtectedpages() {
272 list( $limit, $offset ) = wfCheckLimits();
274 $ppForm = new ProtectedPagesForm();