]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialProtectedtitles.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialProtectedtitles.php
1 <?php
2 /**
3  * @file
4  * @ingroup SpecialPage
5  */
6
7 /**
8  * @todo document
9  * @ingroup SpecialPage
10  */
11 class ProtectedTitlesForm {
12
13         protected $IdLevel = 'level';
14         protected $IdType  = 'type';
15
16         function showList( $msg = '' ) {
17                 global $wgOut, $wgRequest;
18
19                 if ( "" != $msg ) {
20                         $wgOut->setSubtitle( $msg );
21                 }
22
23                 // Purge expired entries on one in every 10 queries
24                 if ( !mt_rand( 0, 10 ) ) {
25                         Title::purgeExpiredRestrictions();
26                 }
27
28                 $type = $wgRequest->getVal( $this->IdType );
29                 $level = $wgRequest->getVal( $this->IdLevel );
30                 $sizetype = $wgRequest->getVal( 'sizetype' );
31                 $size = $wgRequest->getIntOrNull( 'size' );
32                 $NS = $wgRequest->getIntOrNull( 'namespace' );
33
34                 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
35
36                 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
37
38                 if ( $pager->getNumRows() ) {
39                         $s = $pager->getNavigationBar();
40                         $s .= "<ul>" .
41                                 $pager->getBody() .
42                                 "</ul>";
43                         $s .= $pager->getNavigationBar();
44                 } else {
45                         $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
46                 }
47                 $wgOut->addHTML( $s );
48         }
49
50         /**
51          * Callback function to output a restriction
52          */
53         function formatRow( $row ) {
54                 global $wgUser, $wgLang, $wgContLang;
55
56                 wfProfileIn( __METHOD__ );
57
58                 static $skin=null;
59
60                 if( is_null( $skin ) )
61                         $skin = $wgUser->getSkin();
62
63                 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
64                 $link = $skin->makeLinkObj( $title );
65
66                 $description_items = array ();
67
68                 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
69
70                 $description_items[] = $protType;
71
72                 $expiry_description = ''; $stxt = '';
73
74                 if ( $row->pt_expiry != 'infinity' && strlen($row->pt_expiry) ) {
75                         $expiry = Block::decodeExpiry( $row->pt_expiry );
76
77                         $expiry_description = wfMsg( 'protect-expiring', $wgLang->timeanddate( $expiry ) , $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
78
79                         $description_items[] = $expiry_description;
80                 }
81
82                 wfProfileOut( __METHOD__ );
83
84                 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
85         }
86
87         /**
88          * @param $namespace int
89          * @param $type string
90          * @param $level string
91          * @param $minsize int
92          * @private
93          */
94         function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
95                 global $wgScript;
96                 $action = htmlspecialchars( $wgScript );
97                 $title = SpecialPage::getTitleFor( 'ProtectedTitles' );
98                 $special = htmlspecialchars( $title->getPrefixedDBkey() );
99                 return "<form action=\"$action\" method=\"get\">\n" .
100                         '<fieldset>' .
101                         Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
102                         Xml::hidden( 'title', $special ) . "&nbsp;\n" .
103                         $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
104                         $this->getLevelMenu( $level ) . "&nbsp;\n" .
105                         "&nbsp;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
106                         "</fieldset></form>";
107         }
108
109         /**
110          * Prepare the namespace filter drop-down; standard namespace
111          * selector, sans the MediaWiki namespace
112          *
113          * @param mixed $namespace Pre-select namespace
114          * @return string
115          */
116         function getNamespaceMenu( $namespace = null ) {
117                 return Xml::label( wfMsg( 'namespace' ), 'namespace' )
118                         . '&nbsp;'
119                         . Xml::namespaceSelector( $namespace, '' );
120         }
121
122         /**
123          * @return string Formatted HTML
124          * @private
125          */
126         function getLevelMenu( $pr_level ) {
127                 global $wgRestrictionLevels;
128
129                 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
130                 $options = array();
131
132                 // First pass to load the log names
133                 foreach( $wgRestrictionLevels as $type ) {
134                         if ( $type !='' && $type !='*') {
135                                 $text = wfMsg("restriction-level-$type");
136                                 $m[$text] = $type;
137                         }
138                 }
139                 // Is there only one level (aside from "all")?
140                 if( count($m) <= 2 ) {
141                         return '';
142                 }
143                 // Third pass generates sorted XHTML content
144                 foreach( $m as $text => $type ) {
145                         $selected = ($type == $pr_level );
146                         $options[] = Xml::option( $text, $type, $selected );
147                 }
148
149                 return
150                         Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
151                         Xml::tags( 'select',
152                                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
153                                 implode( "\n", $options ) );
154         }
155 }
156
157 /**
158  * @todo document
159  * @ingroup Pager
160  */
161 class ProtectedtitlesPager extends AlphabeticPager {
162         public $mForm, $mConds;
163
164         function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
165                 $this->mForm = $form;
166                 $this->mConds = $conds;
167                 $this->level = $level;
168                 $this->namespace = $namespace;
169                 $this->size = intval($size);
170                 parent::__construct();
171         }
172
173         function getStartBody() {
174                 wfProfileIn( __METHOD__ );
175                 # Do a link batch query
176                 $this->mResult->seek( 0 );
177                 $lb = new LinkBatch;
178
179                 while ( $row = $this->mResult->fetchObject() ) {
180                         $lb->add( $row->pt_namespace, $row->pt_title );
181                 }
182
183                 $lb->execute();
184                 wfProfileOut( __METHOD__ );
185                 return '';
186         }
187
188         function formatRow( $row ) {
189                 return $this->mForm->formatRow( $row );
190         }
191
192         function getQueryInfo() {
193                 $conds = $this->mConds;
194                 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
195                 if( $this->level )
196                         $conds['pt_create_perm'] = $this->level;
197                 if( !is_null($this->namespace) )
198                         $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
199                 return array(
200                         'tables' => 'protected_titles',
201                         'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
202                         'conds' => $conds
203                 );
204         }
205
206         function getIndexField() {
207                 return 'pt_timestamp';
208         }
209 }
210
211 /**
212  * Constructor
213  */
214 function wfSpecialProtectedtitles() {
215
216         $ppForm = new ProtectedTitlesForm();
217
218         $ppForm->showList();
219 }