r66911 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66910‎ | r66911 | r66912 >
Date:08:22, 26 May 2010
Author:tisane
Status:deferred
Tags:
Comment:
=New extension, MassBlank; like Nuke but for wikis that use PureWikiDeletion
Modified paths:
  • /trunk/extensions/MassBlank (added) (history)
  • /trunk/extensions/MassBlank/MassBlank.alias.php (added) (history)
  • /trunk/extensions/MassBlank/MassBlank.i18n.php (added) (history)
  • /trunk/extensions/MassBlank/MassBlank.php (added) (history)
  • /trunk/extensions/MassBlank/MassBlank_body.php (added) (history)

Diff [purge]

Index: trunk/extensions/MassBlank/MassBlank.i18n.php
@@ -0,0 +1,37 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for the MassBlank extension
 5+ * @addtogroup Extensions
 6+ * @author Tisane
 7+ */
 8+
 9+$messages = array();
 10+
 11+/** English
 12+ * @author Tisane
 13+ */
 14+$messages['en'] = array(
 15+ 'massblank' => 'Mass blank',
 16+ 'massblank-desc' => 'Gives administrators the ability to [[Special:MassBlank|mass blank]] pages',
 17+ 'massblank-nopages' => "No new pages by [[Special:Contributions/$1|$1]] in recent changes.",
 18+ 'massblank-list' => "The following pages were recently created by [[Special:Contributions/$1|$1]];
 19+put in a comment and hit the button to blank them.",
 20+ 'massblank-defaultreason' => "Mass blanking of pages added by $1",
 21+ 'massblank-tools' => 'This tool allows for mass blanking of pages recently added by a given user or IP.
 22+Input the username or IP to get a list of pages to blank.',
 23+ 'massblank-submit-user' => 'Go',
 24+ 'massblank-submit-blank' => 'Blank selected',
 25+ 'right-massblank' => 'Mass blank pages',
 26+ 'massblank-blankcomment' => 'Reason for blanking: ',
 27+);
 28+
 29+/** Message documentation (Message documentation)
 30+ * @author Jon Harald Søby
 31+ * @author Meno25
 32+ * @author Purodha
 33+ */
 34+$messages['qqq'] = array(
 35+ 'massblank-desc' => 'Short description of the MassBlank extension, shown in [[Special:Version]]. Do not translate or change links.',
 36+ 'massblank-submit-user' => '{{Identical|Go}}',
 37+ 'right-massblank' => '{{doc-right}}',
 38+);
\ No newline at end of file
Index: trunk/extensions/MassBlank/MassBlank.php
@@ -0,0 +1,38 @@
 2+<?php
 3+/**
 4+ * MassBlank by Tisane (adapted from Nuke by Brion Vibber)
 5+ * URL: http://www.mediawiki.org/wiki/Extension:MassBlank
 6+ *
 7+ * This program is free software. You can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version. You can also redistribute and/or modify
 11+ * those portions written by Tisane under the terms of the Creative Commons
 12+ * Attribution-ShareAlike 3.0 license.
 13+ *
 14+ * This program gives sysops the ability to mass blank pages.
 15+ */
 16+
 17+if( !defined( 'MEDIAWIKI' ) )
 18+ die( 'Not an entry point.' );
 19+
 20+$dir = dirname(__FILE__) . '/';
 21+
 22+$wgExtensionMessagesFiles['MassBlank'] = $dir . 'MassBlank.i18n.php';
 23+$wgExtensionAliasesFiles['MassBlank'] = $dir . 'MassBlank.alias.php';
 24+
 25+$wgExtensionCredits['specialpage'][] = array(
 26+ 'path' => __FILE__,
 27+ 'name' => 'MassBlank',
 28+ 'descriptionmsg' => 'massblank-desc',
 29+ 'author' => 'Tisane',
 30+ 'version' => '0.0.1',
 31+ 'url' => 'http://www.mediawiki.org/wiki/Extension:MassBlank'
 32+);
 33+
 34+$wgGroupPermissions['sysop']['massblank'] = true;
 35+$wgAvailableRights[] = 'massblank';
 36+
 37+$wgAutoloadClasses['SpecialMassBlank'] = $dir . 'MassBlank_body.php';
 38+$wgSpecialPages['MassBlank'] = 'SpecialMassBlank';
 39+$wgSpecialPageGroups['MassBlank'] = 'pagetools';
Index: trunk/extensions/MassBlank/MassBlank.alias.php
@@ -0,0 +1,15 @@
 2+<?php
 3+/**
 4+ * Aliases for Special:MassBlank
 5+ *
 6+ * @addtogroup Extensions
 7+ */
 8+
 9+$aliases = array();
 10+
 11+/** English
 12+ * @author Tisane
 13+ */
 14+$aliases['en'] = array(
 15+ 'MassBlank' => array( 'MassBlank' ),
 16+);
\ No newline at end of file
Index: trunk/extensions/MassBlank/MassBlank_body.php
@@ -0,0 +1,151 @@
 2+<?php
 3+
 4+if( !defined( 'MEDIAWIKI' ) )
 5+ die( 'Not an entry point.' );
 6+
 7+class SpecialMassBlank extends SpecialPage {
 8+ function __construct() {
 9+ wfLoadExtensionMessages( 'MassBlank' );
 10+ parent::__construct( 'MassBlank', 'massblank' );
 11+ }
 12+
 13+ function execute( $par ){
 14+ global $wgUser, $wgRequest;
 15+
 16+ if( !$this->userCanExecute( $wgUser ) ){
 17+ $this->displayRestrictionError();
 18+ return;
 19+ }
 20+
 21+ $this->setHeaders();
 22+ $this->outputHeader();
 23+
 24+ $target = $wgRequest->getText( 'target', $par );
 25+
 26+ // Normalise name
 27+ if ( $target !== '' ) {
 28+ $user = User::newFromName( $target );
 29+ if ( $user ) $target = $user->getName();
 30+ }
 31+
 32+ $reason = $wgRequest->getText( 'wpReason',
 33+ wfMsgForContent( 'massblank-defaultreason', $target ) );
 34+ $posted = $wgRequest->wasPosted() &&
 35+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
 36+ if( $posted ) {
 37+ $pages = $wgRequest->getArray( 'pages' );
 38+ if( $pages ) {
 39+ return $this->doBlank( $pages, $reason );
 40+ }
 41+ }
 42+ if( $target != '' ) {
 43+ $this->listForm( $target, $reason );
 44+ } else {
 45+ $this->promptForm();
 46+ }
 47+ }
 48+
 49+ function promptForm() {
 50+ global $wgOut;
 51+
 52+ $input = Xml::input( 'target', 40 );
 53+ $submit = Xml::submitButton( wfMsg( 'massblank-submit-user' ) );
 54+
 55+ $wgOut->addWikiMsg( 'massblank-tools' );
 56+ $wgOut->addHTML(
 57+ Xml::openElement( 'form', array(
 58+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ),
 59+ 'method' => 'post' )
 60+ ) . "$input\n$submit\n"
 61+ );
 62+
 63+ $wgOut->addHTML( "</form>" );
 64+ }
 65+
 66+ function listForm( $username, $reason ) {
 67+ global $wgUser, $wgOut, $wgLang;
 68+
 69+ $pages = $this->getNewPages( $username );
 70+
 71+ if( count( $pages ) == 0 ) {
 72+ $wgOut->addWikiMsg( 'massblank-nopages', $username );
 73+ return $this->promptForm();
 74+ }
 75+ $wgOut->addWikiMsg( 'massblank-list', $username );
 76+
 77+ $massblank = $this->getTitle();
 78+ $submit = Xml::submitButton( wfMsg( 'massblank-submit-blank' ) );
 79+
 80+ $wgOut->addHTML(
 81+ Xml::openElement( 'form', array(
 82+ 'action' => $massblank->getLocalURL( 'action=blank' ),
 83+ 'method' => 'post' )
 84+ ) .
 85+ Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
 86+ Xml::inputLabel(
 87+ wfMsg( 'massblank-blankcomment' ), 'wpReason', 'wpReason', 60, $reason
 88+ ) . '<br /><br />' .
 89+ Xml::submitButton( wfMsg( 'massblank-submit-blank' ) )
 90+ );
 91+
 92+ $wgOut->addHTML( '<ul>' );
 93+
 94+ $sk = $wgUser->getSkin();
 95+ foreach( $pages as $info ) {
 96+ list( $title, $edits ) = $info;
 97+ $image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
 98+ $thumb = $image && $image->exists() ? $image->getThumbnail( 120, 120 ) : false;
 99+
 100+ $changes = wfMsgExt( 'nchanges', 'parsemag', $wgLang->formatNum( $edits ) );
 101+
 102+ $wgOut->addHTML( '<li>' .
 103+ Xml::check( 'pages[]', true,
 104+ array( 'value' => $title->getPrefixedDbKey() )
 105+ ) .
 106+ '&nbsp;' .
 107+ ( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
 108+ $sk->makeKnownLinkObj( $title ) .
 109+ '&nbsp;(' .
 110+ $sk->makeKnownLinkObj( $title, $changes, 'action=history' ) .
 111+ ")</li>\n" );
 112+ }
 113+ $wgOut->addHTML(
 114+ "</ul>\n" .
 115+ Xml::submitButton( wfMsg( 'massblank-submit-blank' ) ) .
 116+ "</form>"
 117+ );
 118+ }
 119+
 120+ function getNewPages( $username ) {
 121+ $dbr = wfGetDB( DB_SLAVE );
 122+ $result = $dbr->select( 'recentchanges',
 123+ array( 'rc_namespace', 'rc_title', 'rc_timestamp', 'COUNT(*) AS edits' ),
 124+ array(
 125+ 'rc_user_text' => $username,
 126+ "(rc_new = 1)"
 127+ ),
 128+ __METHOD__,
 129+ array(
 130+ 'ORDER BY' => 'rc_timestamp DESC',
 131+ 'GROUP BY' => 'rc_namespace, rc_title'
 132+ )
 133+ );
 134+ $pages = array();
 135+ while( $row = $dbr->fetchObject( $result ) ) {
 136+ $pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits );
 137+ }
 138+ $dbr->freeResult( $result );
 139+ return $pages;
 140+ }
 141+
 142+ function doBlank( $pages, $reason ) {
 143+ foreach( $pages as $page ) {
 144+ $title = Title::newFromURL( $page );
 145+ $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
 146+ if ( !$file ) {
 147+ $article = new Article( $title );
 148+ $article->doEdit( '', $reason );
 149+ }
 150+ }
 151+ }
 152+}

Status & tagging log