4 * @addtogroup SpecialPage
9 * @addtogroup SpecialPage
11 class ProtectedPagesForm
{
12 function showList( $msg = '' ) {
13 global $wgOut, $wgRequest;
15 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
17 $wgOut->setSubtitle( $msg );
20 // Purge expired entries on one in every 10 queries
21 if ( !mt_rand( 0, 10 ) ) {
22 Title
::purgeExpiredRestrictions();
25 $type = $wgRequest->getVal( 'type' );
26 $level = $wgRequest->getVal( 'level' );
27 $minsize = $wgRequest->getIntOrNull( 'minsize' );
28 $NS = $wgRequest->getIntOrNull( 'namespace' );
30 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $minsize );
32 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $minsize ) );
34 if ( $pager->getNumRows() ) {
35 $s = $pager->getNavigationBar();
39 $s .= $pager->getNavigationBar();
41 $s = '<p>' . wfMsgHTML( 'protectedpagesempty' ) . '</p>';
43 $wgOut->addHTML( $s );
47 * Callback function to output a restriction
49 function formatRow( $row ) {
50 global $wgUser, $wgLang;
52 wfProfileIn( __METHOD__
);
56 if( is_null( $skin ) )
57 $skin = $wgUser->getSkin();
59 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
60 $link = $skin->makeLinkObj( $title );
62 $description_items = array ();
64 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
66 $description_items[] = $protType;
68 $expiry_description = ''; $stxt = '';
70 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
71 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
73 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
75 $description_items[] = $expiry_description;
78 if (!is_null($size = $row->page_len
)) {
80 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
82 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
84 wfProfileOut( __METHOD__
);
86 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
90 * @param $namespace int
92 * @param $level string
96 function showOptions( $namespace, $type='edit', $level, $minsize ) {
98 $action = htmlspecialchars( $wgScript );
99 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
100 $special = htmlspecialchars( $title->getPrefixedDBkey() );
101 return "<form action=\"$action\" method=\"get\">\n" .
103 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
104 Xml
::hidden( 'title', $special ) . "\n" .
105 $this->getNamespaceMenu( $namespace ) . "\n" .
106 $this->getTypeMenu( $type ) . "\n" .
107 $this->getLevelMenu( $level ) . "<br/>\n" .
108 $this->getSizeLimit( $minsize ) . "\n" .
109 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
110 "</fieldset></form>";
113 function getNamespaceMenu( $namespace=NULL ) {
114 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
118 * @return string Formatted HTML
121 function getSizeLimit( $minsize=0 ) {
122 $out = Xml
::input('minsize', 9, $minsize, array( 'id' => 'minsize' ) );
123 return "<label for='minsize'>" . wfMsgHtml('minimum-size') . "</label>: " . $out;
127 * @return string Formatted HTML
130 function getTypeMenu( $pr_type ) {
131 global $wgRestrictionTypes, $wgUser;
133 $out = "<select name='type'>\n";
134 $m = array(); // Temporary array
136 // First pass to load the log names
137 foreach( $wgRestrictionTypes as $type ) {
138 $text = wfMsgHtml("restriction-$type");
142 // Second pass to sort by name
145 // Third pass generates sorted XHTML content
146 foreach( $m as $text => $type ) {
147 $selected = ($type == $pr_type );
148 $out .= Xml
::option( $text, $type, $selected ) . "\n";
152 return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
156 * @return string Formatted HTML
159 function getLevelMenu( $pr_level ) {
160 global $wgRestrictionLevels, $wgUser;
162 $out = "<select name='level'>\n";
163 $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
165 // First pass to load the log names
166 foreach( $wgRestrictionLevels as $type ) {
167 if ( $type !='' && $type !='*') {
168 $text = wfMsgHtml("restriction-level-$type");
173 // Second pass to sort by name
176 // Third pass generates sorted XHTML content
177 foreach( $m as $text => $type ) {
178 $selected = ($type == $pr_level );
179 $out .= Xml
::option( $text, $type, $selected ) . "\n";
183 return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
190 class ProtectedPagesPager
extends ReverseChronologicalPager
{
191 public $mForm, $mConds;
193 function __construct( $form, $conds = array(), $type, $level, $namespace, $minsize ) {
194 $this->mForm
= $form;
195 $this->mConds
= $conds;
196 $this->type
= ( $type ) ?
$type : 'edit';
197 $this->level
= $level;
198 $this->namespace = $namespace;
199 $this->minsize
= intval($minsize);
200 parent
::__construct();
203 function getStartBody() {
204 wfProfileIn( __METHOD__
);
205 # Do a link batch query
206 $this->mResult
->seek( 0 );
209 while ( $row = $this->mResult
->fetchObject() ) {
210 $name = str_replace( ' ', '_', $row->page_title
);
211 $lb->add( $row->page_namespace
, $name );
215 wfProfileOut( __METHOD__
);
219 function formatRow( $row ) {
221 return $this->mForm
->formatRow( $row );
224 function getQueryInfo() {
225 $conds = $this->mConds
;
226 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
227 $conds[] = 'page_id=pr_page';
228 $conds[] = 'page_len>=' . $this->minsize
;
229 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
231 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
232 if ( !is_null($this->namespace) )
233 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
235 'tables' => array( 'page_restrictions', 'page' ),
236 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry',
238 'options' => array( 'GROUP BY' => 'page_namespace,page_title,pr_level,pr_expiry,page_len,pr_type' ),
242 function getIndexField() {
250 function wfSpecialProtectedpages() {
252 list( $limit, $offset ) = wfCheckLimits();
254 $ppForm = new ProtectedPagesForm();