4 * @addtogroup SpecialPage
9 * @addtogroup SpecialPage
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;
36 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly );
38 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly ) );
40 if ( $pager->getNumRows() ) {
41 $s = $pager->getNavigationBar();
45 $s .= $pager->getNavigationBar();
47 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
49 $wgOut->addHTML( $s );
53 * Callback function to output a restriction
54 * @param $row object Protected title
55 * @return string Formatted <li> element
57 public function formatRow( $row ) {
58 global $wgUser, $wgLang, $wgContLang;
60 wfProfileIn( __METHOD__
);
64 if( is_null( $skin ) )
65 $skin = $wgUser->getSkin();
67 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
68 $link = $skin->makeLinkObj( $title );
70 $description_items = array ();
72 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
74 $description_items[] = $protType;
76 if ( $row->pr_cascade
) {
77 $description_items[] = wfMsg( 'protect-summary-cascade' );
80 $expiry_description = '';
83 if ( $row->pr_expiry
!= 'infinity' && strlen($row->pr_expiry
) ) {
84 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
86 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
88 $description_items[] = $expiry_description;
91 if (!is_null($size = $row->page_len
)) {
93 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
95 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
96 $stxt = $wgContLang->getDirMark() . $stxt;
99 # Show a link to the change protection form for allowed users otherwise a link to the protection log
100 if( $wgUser->isAllowed( 'protect' ) ) {
101 $changeProtection = ' (' . $skin->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ), 'action=unprotect' ) . ')';
103 $ltitle = SpecialPage
::getTitleFor( 'Log' );
104 $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ), 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
107 wfProfileOut( __METHOD__
);
109 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
113 * @param $namespace int
114 * @param $type string
115 * @param $level string
116 * @param $minsize int
117 * @param $indefOnly bool
118 * @return string Input form
121 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
123 $title = SpecialPage
::getTitleFor( 'ProtectedPages' );
124 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
125 Xml
::openElement( 'fieldset' ) .
126 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
127 Xml
::hidden( 'title', $title->getPrefixedDBkey() ) . " \n" .
128 $this->getNamespaceMenu( $namespace ) . " \n" .
129 $this->getTypeMenu( $type ) . " \n" .
130 $this->getLevelMenu( $level ) . " \n" .
131 "<br /><span style='white-space: nowrap'> " .
132 $this->getExpiryCheck( $indefOnly ) . " \n" .
133 $this->getSizeLimit( $sizetype, $size ) . " \n" .
135 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
136 Xml
::closeElement( 'fieldset' ) .
137 Xml
::closeElement( 'form' );
141 * Prepare the namespace filter drop-down; standard namespace
142 * selector, sans the MediaWiki namespace
144 * @param mixed $namespace Pre-select namespace
147 protected function getNamespaceMenu( $namespace = null ) {
148 return "<span style='white-space: nowrap'>" .
149 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
150 . Xml
::namespaceSelector( $namespace, '' ) . "</span>";
154 * @return string Formatted HTML
156 protected function getExpiryCheck( $indefOnly ) {
158 Xml
::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
162 * @return string Formatted HTML
164 protected function getSizeLimit( $sizetype, $size ) {
165 $max = $sizetype === 'max';
168 Xml
::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
170 Xml
::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
172 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
174 Xml
::label( wfMsg('pagesize'), 'wpsize' );
178 * @return string Formatted HTML
180 protected function getTypeMenu( $pr_type ) {
181 global $wgRestrictionTypes;
183 $m = array(); // Temporary array
186 // First pass to load the log names
187 foreach( $wgRestrictionTypes as $type ) {
188 $text = wfMsg("restriction-$type");
192 // Third pass generates sorted XHTML content
193 foreach( $m as $text => $type ) {
194 $selected = ($type == $pr_type );
195 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
198 return "<span style='white-space: nowrap'>" .
199 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
201 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
202 implode( "\n", $options ) ) . "</span>";
206 * @return string Formatted HTML
208 protected function getLevelMenu( $pr_level ) {
209 global $wgRestrictionLevels;
211 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
214 // First pass to load the log names
215 foreach( $wgRestrictionLevels as $type ) {
216 if ( $type !='' && $type !='*') {
217 $text = wfMsg("restriction-level-$type");
222 // Third pass generates sorted XHTML content
223 foreach( $m as $text => $type ) {
224 $selected = ($type == $pr_level );
225 $options[] = Xml
::option( $text, $type, $selected );
229 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
231 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
232 implode( "\n", $options ) );
240 class ProtectedPagesPager
extends AlphabeticPager
{
241 public $mForm, $mConds;
242 private $type, $level, $namespace, $sizetype, $size, $indefonly;
244 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false ) {
245 $this->mForm
= $form;
246 $this->mConds
= $conds;
247 $this->type
= ( $type ) ?
$type : 'edit';
248 $this->level
= $level;
249 $this->namespace = $namespace;
250 $this->sizetype
= $sizetype;
251 $this->size
= intval($size);
252 $this->indefonly
= (bool)$indefonly;
253 parent
::__construct();
256 function getStartBody() {
257 wfProfileIn( __METHOD__
);
258 # Do a link batch query
260 while( $row = $this->mResult
->fetchObject() ) {
261 $lb->add( $row->page_namespace
, $row->page_title
);
265 wfProfileOut( __METHOD__
);
269 function formatRow( $row ) {
270 return $this->mForm
->formatRow( $row );
273 function getQueryInfo() {
274 $conds = $this->mConds
;
275 $conds[] = 'pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
276 $conds[] = 'page_id=pr_page';
277 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
279 if( $this->sizetype
=='min' ) {
280 $conds[] = 'page_len>=' . $this->size
;
281 } else if( $this->sizetype
=='max' ) {
282 $conds[] = 'page_len<=' . $this->size
;
285 if( $this->indefonly
) {
286 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
290 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
291 if( !is_null($this->namespace) )
292 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
294 'tables' => array( 'page_restrictions', 'page' ),
295 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
300 function getIndexField() {
308 function wfSpecialProtectedpages() {
310 $ppForm = new ProtectedPagesForm();