11 class ProtectedTitlesForm
{
13 protected $IdLevel = 'level';
14 protected $IdType = 'type';
16 function showList( $msg = '' ) {
17 global $wgOut, $wgRequest;
19 $wgOut->setPagetitle( wfMsg( "protectedtitles" ) );
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 ProtectedTitlesPager( $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( 'protectedtitlesempty' ) . '</p>';
48 $wgOut->addHTML( $s );
52 * Callback function to output a restriction
54 function formatRow( $row ) {
55 global $wgUser, $wgLang, $wgContLang;
57 wfProfileIn( __METHOD__
);
61 if( is_null( $skin ) )
62 $skin = $wgUser->getSkin();
64 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
65 $link = $skin->makeLinkObj( $title );
67 $description_items = array ();
69 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm
);
71 $description_items[] = $protType;
73 $expiry_description = ''; $stxt = '';
75 if ( $row->pt_expiry
!= 'infinity' && strlen($row->pt_expiry
) ) {
76 $expiry = Block
::decodeExpiry( $row->pt_expiry
);
78 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
80 $description_items[] = $expiry_description;
83 wfProfileOut( __METHOD__
);
85 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
89 * @param $namespace int
91 * @param $level string
95 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
97 $action = htmlspecialchars( $wgScript );
98 $title = SpecialPage
::getTitleFor( 'ProtectedTitles' );
99 $special = htmlspecialchars( $title->getPrefixedDBkey() );
100 return "<form action=\"$action\" method=\"get\">\n" .
102 Xml
::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
103 Xml
::hidden( 'title', $special ) . " \n" .
104 $this->getNamespaceMenu( $namespace ) . " \n" .
105 $this->getLevelMenu( $level ) . " \n" .
106 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
107 "</fieldset></form>";
111 * Prepare the namespace filter drop-down; standard namespace
112 * selector, sans the MediaWiki namespace
114 * @param mixed $namespace Pre-select namespace
117 function getNamespaceMenu( $namespace = null ) {
118 return Xml
::label( wfMsg( 'namespace' ), 'namespace' )
120 . Xml
::namespaceSelector( $namespace, '' );
124 * @return string Formatted HTML
127 function getLevelMenu( $pr_level ) {
128 global $wgRestrictionLevels;
130 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
133 // First pass to load the log names
134 foreach( $wgRestrictionLevels as $type ) {
135 if ( $type !='' && $type !='*') {
136 $text = wfMsg("restriction-level-$type");
140 // Is there only one level (aside from "all")?
141 if( count($m) <= 2 ) {
144 // Third pass generates sorted XHTML content
145 foreach( $m as $text => $type ) {
146 $selected = ($type == $pr_level );
147 $options[] = Xml
::option( $text, $type, $selected );
151 Xml
::label( wfMsg('restriction-level') , $this->IdLevel
) . ' ' .
153 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
154 implode( "\n", $options ) );
162 class ProtectedtitlesPager
extends AlphabeticPager
{
163 public $mForm, $mConds;
165 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
166 $this->mForm
= $form;
167 $this->mConds
= $conds;
168 $this->level
= $level;
169 $this->namespace = $namespace;
170 $this->size
= intval($size);
171 parent
::__construct();
174 function getStartBody() {
175 wfProfileIn( __METHOD__
);
176 # Do a link batch query
177 $this->mResult
->seek( 0 );
180 while ( $row = $this->mResult
->fetchObject() ) {
181 $lb->add( $row->pt_namespace
, $row->pt_title
);
185 wfProfileOut( __METHOD__
);
189 function formatRow( $row ) {
190 return $this->mForm
->formatRow( $row );
193 function getQueryInfo() {
194 $conds = $this->mConds
;
195 $conds[] = 'pt_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
197 $conds['pt_create_perm'] = $this->level
;
198 if( !is_null($this->namespace) )
199 $conds[] = 'pt_namespace=' . $this->mDb
->addQuotes( $this->namespace );
201 'tables' => 'protected_titles',
202 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
207 function getIndexField() {
208 return 'pt_timestamp';
215 function wfSpecialProtectedtitles() {
217 $ppForm = new ProtectedTitlesForm();