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 $sizetype = $wgRequest->getVal( 'sizetype' );
28 $size = $wgRequest->getIntOrNull( 'size' );
29 $NS = $wgRequest->getIntOrNull( 'namespace' );
31 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
33 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
35 if ( $pager->getNumRows() ) {
36 $s = $pager->getNavigationBar();
40 $s .= $pager->getNavigationBar();
42 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
44 $wgOut->addHTML( $s );
48 * Callback function to output a restriction
50 function formatRow( $row ) {
51 global $wgUser, $wgLang;
53 wfProfileIn( __METHOD__
);
57 if( is_null( $skin ) )
58 $skin = $wgUser->getSkin();
60 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
61 $link = $skin->makeLinkObj( $title );
63 $description_items = array ();
65 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
67 $description_items[] = $protType;
69 $expiry_description = ''; $stxt = '';
71 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
72 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
74 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
76 $description_items[] = $expiry_description;
79 if (!is_null($size = $row->page_len
)) {
81 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
83 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
85 wfProfileOut( __METHOD__
);
87 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
91 * @param $namespace int
93 * @param $level string
97 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
99 $action = htmlspecialchars( $wgScript );
100 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
101 $special = htmlspecialchars( $title->getPrefixedDBkey() );
102 return "<form action=\"$action\" method=\"get\">\n" .
104 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
105 Xml
::hidden( 'title', $special ) . " \n" .
106 $this->getNamespaceMenu( $namespace ) . " \n" .
107 $this->getTypeMenu( $type ) . " \n" .
108 $this->getLevelMenu( $level ) . "<br/>\n" .
109 $this->getSizeLimit( $sizetype, $size ) . "\n" .
110 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
111 "</fieldset></form>";
114 function getNamespaceMenu( $namespace=NULL ) {
115 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
119 * @return string Formatted HTML
122 function getSizeLimit( $sizetype, $size ) {
123 $out = Xml
::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
124 $out .= Xml
::label( wfMsg("minimum-size"), 'wpmin' );
125 $out .= " ".Xml
::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
126 $out .= Xml
::label( wfMsg("maximum-size"), 'wpmax' );
127 $out .= " ".Xml
::input('size', 9, $size, array( 'id' => 'wpsize' ) );
128 $out .= ' '.wfMsg('pagesize');
133 * @return string Formatted HTML
136 function getTypeMenu( $pr_type ) {
137 global $wgRestrictionTypes, $wgUser;
139 $out = "<select name='type'>\n";
140 $m = array(); // Temporary array
142 // First pass to load the log names
143 foreach( $wgRestrictionTypes as $type ) {
144 $text = wfMsgHtml("restriction-$type");
148 // Second pass to sort by name
151 // Third pass generates sorted XHTML content
152 foreach( $m as $text => $type ) {
153 $selected = ($type == $pr_type );
154 $out .= Xml
::option( $text, $type, $selected ) . "\n";
158 return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
162 * @return string Formatted HTML
165 function getLevelMenu( $pr_level ) {
166 global $wgRestrictionLevels, $wgUser;
168 $out = "<select name='level'>\n";
169 $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
171 // First pass to load the log names
172 foreach( $wgRestrictionLevels as $type ) {
173 if ( $type !='' && $type !='*') {
174 $text = wfMsgHtml("restriction-level-$type");
179 // Second pass to sort by name
182 // Third pass generates sorted XHTML content
183 foreach( $m as $text => $type ) {
184 $selected = ($type == $pr_level );
185 $out .= Xml
::option( $text, $type, $selected ) . "\n";
189 return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
197 class ProtectedPagesPager
extends AlphabeticPager
{
198 public $mForm, $mConds;
200 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
201 $this->mForm
= $form;
202 $this->mConds
= $conds;
203 $this->type
= ( $type ) ?
$type : 'edit';
204 $this->level
= $level;
205 $this->namespace = $namespace;
206 $this->sizetype
= $sizetype;
207 $this->size
= intval($size);
208 parent
::__construct();
211 function getStartBody() {
212 wfProfileIn( __METHOD__
);
213 # Do a link batch query
214 $this->mResult
->seek( 0 );
217 while ( $row = $this->mResult
->fetchObject() ) {
218 $name = str_replace( ' ', '_', $row->page_title
);
219 $lb->add( $row->page_namespace
, $name );
223 wfProfileOut( __METHOD__
);
227 function formatRow( $row ) {
229 return $this->mForm
->formatRow( $row );
232 function getQueryInfo() {
233 $conds = $this->mConds
;
234 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
235 $conds[] = 'page_id=pr_page';
236 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
238 if( $this->sizetype
=='min' )
239 $conds[] = 'page_len>=' . $this->size
;
240 else if( $this->sizetype
=='max' )
241 $conds[] = 'page_len<=' . $this->size
;
244 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
245 if( !is_null($this->namespace) )
246 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
248 'tables' => array( 'page_restrictions', 'page' ),
249 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry',
251 'options' => array( 'GROUP BY' => 'page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry' ),
255 function getIndexField() {
263 function wfSpecialProtectedpages() {
265 list( $limit, $offset ) = wfCheckLimits();
267 $ppForm = new ProtectedPagesForm();