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