Add items back to group by clause: breaks all other databases except MySQL :)
[lhc/web/wiklou.git] / includes / SpecialProtectedpages.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * @todo document
9 * @addtogroup SpecialPage
10 */
11 class ProtectedPagesForm {
12 function showList( $msg = '' ) {
13 global $wgOut, $wgRequest;
14
15 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
16 if ( "" != $msg ) {
17 $wgOut->setSubtitle( $msg );
18 }
19
20 // Purge expired entries on one in every 10 queries
21 if ( !mt_rand( 0, 10 ) ) {
22 Title::purgeExpiredRestrictions();
23 }
24
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' );
30
31 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
32
33 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
34
35 if ( $pager->getNumRows() ) {
36 $s = $pager->getNavigationBar();
37 $s .= "<ul>" .
38 $pager->getBody() .
39 "</ul>";
40 $s .= $pager->getNavigationBar();
41 } else {
42 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
43 }
44 $wgOut->addHTML( $s );
45 }
46
47 /**
48 * Callback function to output a restriction
49 */
50 function formatRow( $row ) {
51 global $wgUser, $wgLang;
52
53 wfProfileIn( __METHOD__ );
54
55 static $skin=null;
56
57 if( is_null( $skin ) )
58 $skin = $wgUser->getSkin();
59
60 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
61 $link = $skin->makeLinkObj( $title );
62
63 $description_items = array ();
64
65 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
66
67 $description_items[] = $protType;
68
69 $expiry_description = ''; $stxt = '';
70
71 if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
72 $expiry = Block::decodeExpiry( $row->pr_expiry );
73
74 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
75
76 $description_items[] = $expiry_description;
77 }
78
79 if (!is_null($size = $row->page_len)) {
80 if ($size == 0)
81 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
82 else
83 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
84 }
85 wfProfileOut( __METHOD__ );
86
87 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
88 }
89
90 /**
91 * @param $namespace int
92 * @param $type string
93 * @param $level string
94 * @param $minsize int
95 * @private
96 */
97 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
98 global $wgScript;
99 $action = htmlspecialchars( $wgScript );
100 $title = SpecialPage::getTitleFor( 'ProtectedPages' );
101 $special = htmlspecialchars( $title->getPrefixedDBkey() );
102 return "<form action=\"$action\" method=\"get\">\n" .
103 '<fieldset>' .
104 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
105 Xml::hidden( 'title', $special ) . "&nbsp\n" .
106 $this->getNamespaceMenu( $namespace ) . "&nbsp\n" .
107 $this->getTypeMenu( $type ) . "&nbsp\n" .
108 $this->getLevelMenu( $level ) . "<br/>\n" .
109 $this->getSizeLimit( $sizetype, $size ) . "\n" .
110 "&nbsp" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
111 "</fieldset></form>";
112 }
113
114 function getNamespaceMenu( $namespace=NULL ) {
115 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
116 }
117
118 /**
119 * @return string Formatted HTML
120 * @private
121 */
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 .= "&nbsp".Xml::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
126 $out .= Xml::label( wfMsg("maximum-size"), 'wpmax' );
127 $out .= "&nbsp".Xml::input('size', 9, $size, array( 'id' => 'wpsize' ) );
128 $out .= ' '.wfMsg('pagesize');
129 return $out;
130 }
131
132 /**
133 * @return string Formatted HTML
134 * @private
135 */
136 function getTypeMenu( $pr_type ) {
137 global $wgRestrictionTypes, $wgUser;
138
139 $out = "<select name='type'>\n";
140 $m = array(); // Temporary array
141
142 // First pass to load the log names
143 foreach( $wgRestrictionTypes as $type ) {
144 $text = wfMsgHtml("restriction-$type");
145 $m[$text] = $type;
146 }
147
148 // Second pass to sort by name
149 ksort($m);
150
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";
155 }
156
157 $out .= '</select>';
158 return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
159 }
160
161 /**
162 * @return string Formatted HTML
163 * @private
164 */
165 function getLevelMenu( $pr_level ) {
166 global $wgRestrictionLevels, $wgUser;
167
168 $out = "<select name='level'>\n";
169 $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
170
171 // First pass to load the log names
172 foreach( $wgRestrictionLevels as $type ) {
173 if ( $type !='' && $type !='*') {
174 $text = wfMsgHtml("restriction-level-$type");
175 $m[$text] = $type;
176 }
177 }
178
179 // Second pass to sort by name
180 ksort($m);
181
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";
186 }
187
188 $out .= '</select>';
189 return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
190 }
191 }
192
193 /**
194 * @todo document
195 * @addtogroup Pager
196 */
197 class ProtectedPagesPager extends AlphabeticPager {
198 public $mForm, $mConds;
199
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();
209 }
210
211 function getStartBody() {
212 wfProfileIn( __METHOD__ );
213 # Do a link batch query
214 $this->mResult->seek( 0 );
215 $lb = new LinkBatch;
216
217 while ( $row = $this->mResult->fetchObject() ) {
218 $name = str_replace( ' ', '_', $row->page_title );
219 $lb->add( $row->page_namespace, $name );
220 }
221
222 $lb->execute();
223 wfProfileOut( __METHOD__ );
224 return '';
225 }
226
227 function formatRow( $row ) {
228 $block = new Block;
229 return $this->mForm->formatRow( $row );
230 }
231
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 );
237
238 if( $this->sizetype=='min' )
239 $conds[] = 'page_len>=' . $this->size;
240 else if( $this->sizetype=='max' )
241 $conds[] = 'page_len<=' . $this->size;
242
243 if( $this->level )
244 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
245 if( !is_null($this->namespace) )
246 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
247 return array(
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',
250 'conds' => $conds,
251 'options' => array( 'GROUP BY' => 'page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry' ),
252 );
253 }
254
255 function getIndexField() {
256 return 'pr_id';
257 }
258 }
259
260 /**
261 * Constructor
262 */
263 function wfSpecialProtectedpages() {
264
265 list( $limit, $offset ) = wfCheckLimits();
266
267 $ppForm = new ProtectedPagesForm();
268
269 $ppForm->showList();
270 }
271
272 ?>