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 $expiry_description = ''; $stxt = '';
75 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
76 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
78 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
80 $description_items[] = $expiry_description;
83 if (!is_null($size = $row->page_len
)) {
85 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
87 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
89 wfProfileOut( __METHOD__
);
91 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
95 * @param $namespace int
97 * @param $level string
101 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
103 $action = htmlspecialchars( $wgScript );
104 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
105 $special = htmlspecialchars( $title->getPrefixedDBkey() );
106 return "<form action=\"$action\" method=\"get\">\n" .
108 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
109 Xml
::hidden( 'title', $special ) . " \n" .
110 $this->getNamespaceMenu( $namespace ) . " \n" .
111 $this->getTypeMenu( $type ) . " \n" .
112 $this->getLevelMenu( $level ) . "<br/>\n" .
113 $this->getSizeLimit( $sizetype, $size ) . "\n" .
114 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
115 "</fieldset></form>";
118 function getNamespaceMenu( $namespace=NULL ) {
119 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
123 * @return string Formatted HTML
126 function getSizeLimit( $sizetype, $size ) {
127 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
128 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
129 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
130 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
131 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
132 $out .= ' '.wfMsgHtml('pagesize');
137 * @return string Formatted HTML
140 function getTypeMenu( $pr_type ) {
141 global $wgRestrictionTypes;
143 $m = array(); // Temporary array
146 // First pass to load the log names
147 foreach( $wgRestrictionTypes as $type ) {
148 $text = wfMsg("restriction-$type");
152 // Third pass generates sorted XHTML content
153 foreach( $m as $text => $type ) {
154 $selected = ($type == $pr_type );
155 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
159 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
161 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
162 implode( "\n", $options ) );
166 * @return string Formatted HTML
169 function getLevelMenu( $pr_level ) {
170 global $wgRestrictionLevels;
172 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
175 // First pass to load the log names
176 foreach( $wgRestrictionLevels as $type ) {
177 if ( $type !='' && $type !='*') {
178 $text = wfMsg("restriction-level-$type");
183 // Third pass generates sorted XHTML content
184 foreach( $m as $text => $type ) {
185 $selected = ($type == $pr_level );
186 $options[] = Xml
::option( $text, $type, $selected );
190 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
192 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
193 implode( "\n", $options ) );
201 class ProtectedPagesPager
extends AlphabeticPager
{
202 public $mForm, $mConds;
204 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
205 $this->mForm
= $form;
206 $this->mConds
= $conds;
207 $this->type
= ( $type ) ?
$type : 'edit';
208 $this->level
= $level;
209 $this->namespace = $namespace;
210 $this->sizetype
= $sizetype;
211 $this->size
= intval($size);
212 parent
::__construct();
215 function getStartBody() {
216 wfProfileIn( __METHOD__
);
217 # Do a link batch query
218 $this->mResult
->seek( 0 );
221 while ( $row = $this->mResult
->fetchObject() ) {
222 $lb->add( $row->page_namespace
, $row->page_title
);
226 wfProfileOut( __METHOD__
);
230 function formatRow( $row ) {
232 return $this->mForm
->formatRow( $row );
235 function getQueryInfo() {
236 $conds = $this->mConds
;
237 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
238 $conds[] = 'page_id=pr_page';
239 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
241 if( $this->sizetype
=='min' ) {
242 $conds[] = 'page_len>=' . $this->size
;
243 } else if( $this->sizetype
=='max' ) {
244 $conds[] = 'page_len<=' . $this->size
;
248 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
249 if( !is_null($this->namespace) )
250 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
252 'tables' => array( 'page_restrictions', 'page' ),
253 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry',
258 function getIndexField() {
266 function wfSpecialProtectedpages() {
268 list( $limit, $offset ) = wfCheckLimits();
270 $ppForm = new ProtectedPagesForm();