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