Index: trunk/extensions/DeletedContributions/SpecialDeletedContributions.php |
— | — | @@ -16,10 +16,13 @@ |
17 | 17 | |
18 | 18 | # Internationalisation |
19 | 19 | $wgExtensionMessagesFiles['DeletedContributions'] = dirname(__FILE__) . '/DeletedContributions.i18n.php'; |
20 | | -$wgExtensionFunctions[] = 'efLoadDeletedContribs'; |
| 20 | +$wgAutoloadClasses['DeletedContributionsPage'] |
| 21 | + = $wgAutoloadClasses['DeletedContributionsPage'] |
| 22 | + = dirname(__FILE__) . '/DeletedContributions_body.php'; |
21 | 23 | |
22 | 24 | $wgHooks['ContributionsToolLinks'][] = 'wfLoadContribsLink'; |
23 | | -$wgHooks['SpecialPageExecuteBeforeHeader'][] = 'wfDeletedContributionsMessages'; |
| 25 | +$wgSpecialPages['DeletedContributions'] = 'DeletedContributionsPage'; |
| 26 | +$wgSpecialPageGroups['DeletedContributions'] = 'users'; |
24 | 27 | |
25 | 28 | /** |
26 | 29 | * Add a "Deleted contributions" link to Special:Contributions for sysops. |
— | — | @@ -37,19 +40,3 @@ |
38 | 41 | return true; |
39 | 42 | } |
40 | 43 | |
41 | | -function wfDeletedContributionsMessages( $specialpage, $par, $func ) { |
42 | | - if( $specialpage->name() == 'DeletedContributions' ) { |
43 | | - wfLoadExtensionMessages( 'DeletedContributions' ); |
44 | | - $specialpage->setHeaders(); // set again so that it actually has the fucking message |
45 | | - } |
46 | | - return true; |
47 | | -} |
48 | | - |
49 | | -# Load once IndexPager and stuff is loaded |
50 | | -function efLoadDeletedContribs() { |
51 | | - require( dirname( __FILE__ ) . '/DeletedContributions_body.php' ); |
52 | | -} |
53 | | - |
54 | | -$wgSpecialPages['DeletedContributions'] = array( 'SpecialPage', 'DeletedContributions', 'deletedhistory', |
55 | | - /*listed*/ true, /*function*/ false, /*file*/ false ); |
56 | | -$wgSpecialPageGroups['DeletedContributions'] = 'users'; |
Index: trunk/extensions/DeletedContributions/DeletedContributions_body.php |
— | — | @@ -180,169 +180,189 @@ |
181 | 181 | |
182 | 182 | } |
183 | 183 | |
184 | | -/** |
185 | | - * Special page "deleted user contributions". |
186 | | - * Shows a list of the deleted contributions of a user. |
187 | | - * |
188 | | - * @return none |
189 | | - * @param $par String: (optional) user name of the user for which to show the contributions |
190 | | - */ |
191 | | -function wfSpecialDeletedContributions( $par = null ) { |
192 | | - global $wgUser, $wgOut, $wgLang, $wgRequest; |
| 184 | +class DeletedContributionsPage extends SpecialPage { |
| 185 | + function __construct() { |
| 186 | + parent::__construct( 'DeletedContributions', 'deletedhistory', |
| 187 | + /*listed*/ true, /*function*/ false, /*file*/ false ); |
| 188 | + } |
193 | 189 | |
194 | | - $options = array(); |
| 190 | + /** |
| 191 | + * Special page "deleted user contributions". |
| 192 | + * Shows a list of the deleted contributions of a user. |
| 193 | + * |
| 194 | + * @return none |
| 195 | + * @param $par String: (optional) user name of the user for which to show the contributions |
| 196 | + */ |
| 197 | + function execute( $par ) { |
| 198 | + global $wgUser; |
| 199 | + wfLoadExtensionMessages( 'DeletedContributions' ); |
| 200 | + $this->setHeaders(); |
195 | 201 | |
196 | | - if ( isset( $par ) ) { |
197 | | - $target = $par; |
198 | | - } else { |
199 | | - $target = $wgRequest->getVal( 'target' ); |
200 | | - } |
| 202 | + if ( !$this->userCanExecute( $wgUser ) ) { |
| 203 | + $this->displayRestrictionError(); |
| 204 | + return; |
| 205 | + } |
| 206 | + |
| 207 | + global $wgUser, $wgOut, $wgLang, $wgRequest; |
201 | 208 | |
202 | | - if ( !strlen( $target ) ) { |
203 | | - $wgOut->addHTML( deletedContributionsForm( '' ) ); |
204 | | - return; |
205 | | - } |
| 209 | + $options = array(); |
206 | 210 | |
207 | | - $options['limit'] = $wgRequest->getInt( 'limit', 50 ); |
208 | | - $options['target'] = $target; |
| 211 | + if ( isset( $par ) ) { |
| 212 | + $target = $par; |
| 213 | + } else { |
| 214 | + $target = $wgRequest->getVal( 'target' ); |
| 215 | + } |
209 | 216 | |
210 | | - $nt = Title::makeTitleSafe( NS_USER, $target ); |
211 | | - if ( !$nt ) { |
212 | | - $wgOut->addHTML( deletedContributionsForm( '' ) ); |
213 | | - return; |
214 | | - } |
215 | | - $id = User::idFromName( $nt->getText() ); |
| 217 | + if ( !strlen( $target ) ) { |
| 218 | + $wgOut->addHTML( $this->getForm( '' ) ); |
| 219 | + return; |
| 220 | + } |
216 | 221 | |
217 | | - $target = $nt->getText(); |
218 | | - $wgOut->setSubtitle( deletedContributionsSub( $nt, $id ) ); |
| 222 | + $options['limit'] = $wgRequest->getInt( 'limit', 50 ); |
| 223 | + $options['target'] = $target; |
219 | 224 | |
220 | | - if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) { |
221 | | - $options['namespace'] = intval( $ns ); |
222 | | - } else { |
223 | | - $options['namespace'] = ''; |
224 | | - } |
| 225 | + $nt = Title::makeTitleSafe( NS_USER, $target ); |
| 226 | + if ( !$nt ) { |
| 227 | + $wgOut->addHTML( $this->getForm( '' ) ); |
| 228 | + return; |
| 229 | + } |
| 230 | + $id = User::idFromName( $nt->getText() ); |
225 | 231 | |
226 | | - $wgOut->addHTML( deletedContributionsForm( $options ) ); |
| 232 | + $target = $nt->getText(); |
| 233 | + $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) ); |
227 | 234 | |
228 | | - $pager = new DeletedContribsPager( $target, $options['namespace'] ); |
229 | | - if ( !$pager->getNumRows() ) { |
230 | | - $wgOut->addWikiText( wfMsg( 'nocontribs' ) ); |
231 | | - return; |
232 | | - } |
| 235 | + if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) { |
| 236 | + $options['namespace'] = intval( $ns ); |
| 237 | + } else { |
| 238 | + $options['namespace'] = ''; |
| 239 | + } |
233 | 240 | |
234 | | - # Show a message about slave lag, if applicable |
235 | | - if( ( $lag = $pager->getDatabase()->getLag() ) > 0 ) |
236 | | - $wgOut->showLagWarning( $lag ); |
| 241 | + $wgOut->addHTML( $this->getForm( $options ) ); |
237 | 242 | |
238 | | - $wgOut->addHTML( |
239 | | - '<p>' . $pager->getNavigationBar() . '</p>' . |
240 | | - $pager->getBody() . |
241 | | - '<p>' . $pager->getNavigationBar() . '</p>' ); |
| 243 | + $pager = new DeletedContribsPager( $target, $options['namespace'] ); |
| 244 | + if ( !$pager->getNumRows() ) { |
| 245 | + $wgOut->addWikiText( wfMsg( 'nocontribs' ) ); |
| 246 | + return; |
| 247 | + } |
242 | 248 | |
243 | | - # If there were contributions, and it was a valid user or IP, show |
244 | | - # the appropriate "footer" message - WHOIS tools, etc. |
245 | | - if( $target != 'newbies' ) { |
246 | | - $message = IP::isIPAddress( $target ) |
247 | | - ? 'sp-contributions-footer-anon' |
248 | | - : 'sp-contributions-footer'; |
| 249 | + # Show a message about slave lag, if applicable |
| 250 | + if( ( $lag = $pager->getDatabase()->getLag() ) > 0 ) |
| 251 | + $wgOut->showLagWarning( $lag ); |
249 | 252 | |
| 253 | + $wgOut->addHTML( |
| 254 | + '<p>' . $pager->getNavigationBar() . '</p>' . |
| 255 | + $pager->getBody() . |
| 256 | + '<p>' . $pager->getNavigationBar() . '</p>' ); |
250 | 257 | |
251 | | - $text = wfMsg( $message, $target ); |
252 | | - if( !wfEmptyMsg( $message, $text ) && $text != '-' ) { |
253 | | - $wgOut->addHtml( '<div class="mw-contributions-footer">' ); |
254 | | - $wgOut->addWikiText( $text ); |
255 | | - $wgOut->addHtml( '</div>' ); |
| 258 | + # If there were contributions, and it was a valid user or IP, show |
| 259 | + # the appropriate "footer" message - WHOIS tools, etc. |
| 260 | + if( $target != 'newbies' ) { |
| 261 | + $message = IP::isIPAddress( $target ) |
| 262 | + ? 'sp-contributions-footer-anon' |
| 263 | + : 'sp-contributions-footer'; |
| 264 | + |
| 265 | + |
| 266 | + $text = wfMsg( $message, $target ); |
| 267 | + if( !wfEmptyMsg( $message, $text ) && $text != '-' ) { |
| 268 | + $wgOut->addHtml( '<div class="mw-contributions-footer">' ); |
| 269 | + $wgOut->addWikiText( $text ); |
| 270 | + $wgOut->addHtml( '</div>' ); |
| 271 | + } |
256 | 272 | } |
257 | 273 | } |
258 | | -} |
259 | 274 | |
260 | | -/** |
261 | | - * Generates the subheading with links |
262 | | - * @param $nt @see Title object for the target |
263 | | - */ |
264 | | -function deletedContributionsSub( $nt, $id ) { |
265 | | - global $wgSysopUserBans, $wgLang, $wgUser; |
| 275 | + /** |
| 276 | + * Generates the subheading with links |
| 277 | + * @param $nt @see Title object for the target |
| 278 | + */ |
| 279 | + function getSubTitle( $nt, $id ) { |
| 280 | + global $wgSysopUserBans, $wgLang, $wgUser; |
266 | 281 | |
267 | | - $sk = $wgUser->getSkin(); |
| 282 | + $sk = $wgUser->getSkin(); |
268 | 283 | |
269 | | - if ( 0 == $id ) { |
270 | | - $user = $nt->getText(); |
271 | | - } else { |
272 | | - $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) ); |
273 | | - } |
274 | | - $talk = $nt->getTalkPage(); |
275 | | - if( $talk ) { |
276 | | - # Talk page link |
277 | | - $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) ); |
278 | | - if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) { |
279 | | - # Block link |
280 | | - if( $wgUser->isAllowed( 'block' ) ) |
281 | | - $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ), wfMsgHtml( 'blocklink' ) ); |
282 | | - # Block log link |
283 | | - $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() ); |
| 284 | + if ( 0 == $id ) { |
| 285 | + $user = $nt->getText(); |
| 286 | + } else { |
| 287 | + $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) ); |
284 | 288 | } |
285 | | - # Other logs link |
286 | | - $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() ); |
287 | | - # Link to undeleted contributions |
288 | | - $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ), wfMsgHtml( 'contributions' ) ); |
| 289 | + $talk = $nt->getTalkPage(); |
| 290 | + if( $talk ) { |
| 291 | + # Talk page link |
| 292 | + $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) ); |
| 293 | + if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) { |
| 294 | + # Block link |
| 295 | + if( $wgUser->isAllowed( 'block' ) ) |
| 296 | + $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ), |
| 297 | + wfMsgHtml( 'blocklink' ) ); |
| 298 | + # Block log link |
| 299 | + $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), |
| 300 | + wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() ); |
| 301 | + } |
| 302 | + # Other logs link |
| 303 | + $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), |
| 304 | + wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() ); |
| 305 | + # Link to undeleted contributions |
| 306 | + $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ), |
| 307 | + wfMsgHtml( 'contributions' ) ); |
289 | 308 | |
290 | | - $links = implode( ' | ', $tools ); |
291 | | - } |
| 309 | + $links = implode( ' | ', $tools ); |
| 310 | + } |
292 | 311 | |
293 | | - // Old message 'contribsub' had one parameter, but that doesn't work for |
294 | | - // languages that want to put the "for" bit right after $user but before |
295 | | - // $links. If 'contribsub' is around, use it for reverse compatibility, |
296 | | - // otherwise use 'contribsub2'. |
297 | | - if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) { |
298 | | - return wfMsgHtml( 'contribsub2', $user, $links ); |
299 | | - } else { |
300 | | - return wfMsgHtml( 'contribsub', "$user ($links)" ); |
| 312 | + // Old message 'contribsub' had one parameter, but that doesn't work for |
| 313 | + // languages that want to put the "for" bit right after $user but before |
| 314 | + // $links. If 'contribsub' is around, use it for reverse compatibility, |
| 315 | + // otherwise use 'contribsub2'. |
| 316 | + if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) { |
| 317 | + return wfMsgHtml( 'contribsub2', $user, $links ); |
| 318 | + } else { |
| 319 | + return wfMsgHtml( 'contribsub', "$user ($links)" ); |
| 320 | + } |
301 | 321 | } |
302 | | -} |
303 | 322 | |
304 | | -/** |
305 | | - * Generates the namespace selector form with hidden attributes. |
306 | | - * @param $options Array: the options to be included. |
307 | | - */ |
308 | | -function deletedContributionsForm( $options ) { |
309 | | - global $wgScript, $wgTitle, $wgRequest; |
| 323 | + /** |
| 324 | + * Generates the namespace selector form with hidden attributes. |
| 325 | + * @param $options Array: the options to be included. |
| 326 | + */ |
| 327 | + function getForm( $options ) { |
| 328 | + global $wgScript, $wgTitle, $wgRequest; |
310 | 329 | |
311 | | - $options['title'] = $wgTitle->getPrefixedText(); |
312 | | - if ( !isset( $options['target'] ) ) { |
313 | | - $options['target'] = ''; |
314 | | - } else { |
315 | | - $options['target'] = str_replace( '_' , ' ' , $options['target'] ); |
316 | | - } |
| 330 | + $options['title'] = $wgTitle->getPrefixedText(); |
| 331 | + if ( !isset( $options['target'] ) ) { |
| 332 | + $options['target'] = ''; |
| 333 | + } else { |
| 334 | + $options['target'] = str_replace( '_' , ' ' , $options['target'] ); |
| 335 | + } |
317 | 336 | |
318 | | - if ( !isset( $options['namespace'] ) ) { |
319 | | - $options['namespace'] = ''; |
320 | | - } |
| 337 | + if ( !isset( $options['namespace'] ) ) { |
| 338 | + $options['namespace'] = ''; |
| 339 | + } |
321 | 340 | |
322 | | - if ( !isset( $options['contribs'] ) ) { |
323 | | - $options['contribs'] = 'user'; |
324 | | - } |
| 341 | + if ( !isset( $options['contribs'] ) ) { |
| 342 | + $options['contribs'] = 'user'; |
| 343 | + } |
325 | 344 | |
326 | | - if ( $options['contribs'] == 'newbie' ) { |
327 | | - $options['target'] = ''; |
328 | | - } |
| 345 | + if ( $options['contribs'] == 'newbie' ) { |
| 346 | + $options['target'] = ''; |
| 347 | + } |
329 | 348 | |
330 | | - $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); |
| 349 | + $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); |
331 | 350 | |
332 | | - foreach ( $options as $name => $value ) { |
333 | | - if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) { |
334 | | - continue; |
| 351 | + foreach ( $options as $name => $value ) { |
| 352 | + if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) { |
| 353 | + continue; |
| 354 | + } |
| 355 | + $f .= "\t" . Xml::hidden( $name, $value ) . "\n"; |
335 | 356 | } |
336 | | - $f .= "\t" . Xml::hidden( $name, $value ) . "\n"; |
| 357 | + |
| 358 | + $f .= Xml::openElement( 'fieldset' ) . |
| 359 | + Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) . |
| 360 | + Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . |
| 361 | + Xml::input( 'target', 20, $options['target']) . ' '. |
| 362 | + Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' . |
| 363 | + Xml::namespaceSelector( $options['namespace'], '' ) . |
| 364 | + Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) . |
| 365 | + Xml::closeElement( 'fieldset' ) . |
| 366 | + Xml::closeElement( 'form' ); |
| 367 | + return $f; |
337 | 368 | } |
338 | | - |
339 | | - $f .= Xml::openElement( 'fieldset' ) . |
340 | | - Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) . |
341 | | - Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . |
342 | | - Xml::input( 'target', 20, $options['target']) . ' '. |
343 | | - Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' . |
344 | | - Xml::namespaceSelector( $options['namespace'], '' ) . |
345 | | - Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) . |
346 | | - Xml::closeElement( 'fieldset' ) . |
347 | | - Xml::closeElement( 'form' ); |
348 | | - return $f; |
349 | 369 | } |