Add all terms to group by, although I'm not sure about the previous commit as it...
[lhc/web/wiklou.git] / includes / SpecialProtectedpages.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
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 $NS = $wgRequest->getIntOrNull( 'namespace' );
28
29 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS );
30
31 $wgOut->addHTML( $this->showOptions( $NS, $type, $level ) );
32
33 if ( $pager->getNumRows() ) {
34 $s = $pager->getNavigationBar();
35 $s .= "<ul>" .
36 $pager->getBody() .
37 "</ul>";
38 $s .= $pager->getNavigationBar();
39 } else {
40 $s = '<p>' . wfMsgHTML( 'protectedpagesempty' ) . '</p>';
41 }
42 $wgOut->addHTML( $s );
43 }
44
45 /**
46 * Callback function to output a restriction
47 */
48 function formatRow( $row ) {
49 global $wgUser, $wgLang;
50
51 wfProfileIn( __METHOD__ );
52
53 static $skin=null;
54
55 if( is_null( $skin ) )
56 $skin = $wgUser->getSkin();
57
58 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
59 $link = $skin->makeLinkObj( $title );
60
61 $description_items = array ();
62
63 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
64
65 $description_items[] = $protType;
66
67 $expiry_description = ''; $stxt = '';
68
69 if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
70 $expiry = Block::decodeExpiry( $row->pr_expiry );
71
72 $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
73
74 $description_items[] = $expiry_description;
75 }
76
77 if (!is_null($size = $row->page_len)) {
78 if ($size == 0)
79 $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
80 else
81 $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum( $size ) ) . '</small>';
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 * @private
93 */
94 function showOptions( $namespace, $type, $level ) {
95 global $wgScript;
96 $action = htmlspecialchars( $wgScript );
97 $title = SpecialPage::getTitleFor( 'ProtectedPages' );
98 $special = htmlspecialchars( $title->getPrefixedDBkey() );
99 return "<form action=\"$action\" method=\"get\">\n" .
100 '<fieldset>' .
101 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
102 Xml::hidden( 'title', $special ) . "\n" .
103 $this->getNamespaceMenu( $namespace ) . "\n" .
104 $this->getTypeMenu( $type ) . "\n" .
105 $this->getLevelMenu( $level ) . "\n" .
106 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
107 "</fieldset></form>";
108 }
109
110 function getNamespaceMenu( $namespace=NULL ) {
111 return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
112 }
113
114 /**
115 * @return string Formatted HTML
116 * @private
117 */
118 function getTypeMenu( $pr_type ) {
119 global $wgRestrictionTypes, $wgUser;
120
121 $out = "<select name='type'>\n";
122 $m = array(); // Temporary array
123
124 // First pass to load the log names
125 foreach( $wgRestrictionTypes as $type ) {
126 $text = wfMsgHtml("restriction-$type");
127 $m[$text] = $type;
128 }
129
130 // Second pass to sort by name
131 ksort($m);
132
133 // Third pass generates sorted XHTML content
134 foreach( $m as $text => $type ) {
135 $selected = ($type == $pr_type );
136 $out .= Xml::option( $text, $type, $selected ) . "\n";
137 }
138
139 $out .= '</select>';
140 return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
141 }
142
143 /**
144 * @return string Formatted HTML
145 * @private
146 */
147 function getLevelMenu( $pr_level ) {
148 global $wgRestrictionLevels, $wgUser;
149
150 $out = "<select name='level'>\n";
151 $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
152
153 // First pass to load the log names
154 foreach( $wgRestrictionLevels as $type ) {
155 if ( $type !='' && $type !='*') {
156 $text = wfMsgHtml("restriction-level-$type");
157 $m[$text] = $type;
158 }
159 }
160
161 // Second pass to sort by name
162 ksort($m);
163
164 // Third pass generates sorted XHTML content
165 foreach( $m as $text => $type ) {
166 $selected = ($type == $pr_level );
167 $out .= Xml::option( $text, $type, $selected ) . "\n";
168 }
169
170 $out .= '</select>';
171 return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
172 }
173 }
174
175 /**
176 *
177 *
178 */
179 class ProtectedPagesPager extends ReverseChronologicalPager {
180 public $mForm, $mConds;
181
182 function __construct( $form, $conds = array(), $type, $level, $namespace ) {
183 $this->mForm = $form;
184 $this->mConds = $conds;
185 $this->type = ( $type ) ? $type : 'edit';
186 $this->level = $level;
187 $this->namespace = $namespace;
188 parent::__construct();
189 }
190
191 function getStartBody() {
192 wfProfileIn( __METHOD__ );
193 # Do a link batch query
194 $this->mResult->seek( 0 );
195 $lb = new LinkBatch;
196
197 while ( $row = $this->mResult->fetchObject() ) {
198 $name = str_replace( ' ', '_', $row->page_title );
199 $lb->add( $row->page_namespace, $name );
200 }
201
202 $lb->execute();
203 wfProfileOut( __METHOD__ );
204 return '';
205 }
206
207 function formatRow( $row ) {
208 $block = new Block;
209 return $this->mForm->formatRow( $row );
210 }
211
212 function getQueryInfo() {
213 $conds = $this->mConds;
214 $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
215 $conds[] = 'page_id=pr_page';
216 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
217 if ( $this->level )
218 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
219 if ( !is_null($this->namespace) )
220 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
221 return array(
222 'tables' => array( 'page_restrictions', 'page' ),
223 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry',
224 'conds' => $conds,
225 'options' => array( 'GROUP BY' => 'page_namespace,page_title,pr_level,pr_expiry,page_len,pr_type' ),
226 );
227 }
228
229 function getIndexField() {
230 return 'page_len';
231 }
232 }
233
234 /**
235 * Constructor
236 */
237 function wfSpecialProtectedpages() {
238
239 list( $limit, $offset ) = wfCheckLimits();
240
241 $ppForm = new ProtectedPagesForm();
242
243 $ppForm->showList();
244 }
245
246 ?>