MarkAHershberger has uploaded a new change for review.
https://gerrit.wikimedia.org/r/120479
Change subject: files from thepetwiki
......................................................................
files from thepetwiki
Change-Id: Id596596b7e8da8e9595077f068b0480d30617cab
(cherry picked from commit f84b9e98ed6f42d17e0ed975b0e51347c7215ee8)
---
A BlockandNuke.body.php
A BlockandNuke.i18n.php
A BlockandNuke.php
A whitelist.txt
4 files changed, 287 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlockAndNuke
refs/changes/79/120479/1
diff --git a/BlockandNuke.body.php b/BlockandNuke.body.php
new file mode 100644
index 0000000..222a624
--- /dev/null
+++ b/BlockandNuke.body.php
@@ -0,0 +1,201 @@
+<?php
+
+if( !defined( 'MEDIAWIKI' ) )
+ die( 'Not an entry point.' );
+
+class SpecialBlock_Nuke extends SpecialPage {
+ function __construct() {
+ wfLoadExtensionMessages( 'BlockandNuke' );
+ //restrict access only to admin
+ parent::__construct( 'BlockandNuke', 'blockandnuke' );
+
+ }
+
+ function execute( $par ){
+ global $wgUser, $wgRequest, $wgOut;
+
+ if( !$this->userCanExecute( $wgUser ) ){
+ $this->displayRestrictionError();
+ return;
+ }
+
+ $this->setHeaders();
+ $this->outputHeader();
+
+ $posted = $wgRequest->wasPosted();
+ if( $posted ) {
+ $user_id = $wgRequest->getArray('userid');
+ $user = $wgRequest->getArray('names');
+ $pages = $wgRequest->getArray( 'pages' );
+ $user_2 = $wgRequest->getArray('names_2');
+
+ if($user){
+ $wgOut->addHTML("To block the selected users
and delete all their contributions click the button below.");
+ $this->getNewPages($user);
+ }else { }
+
+ if($pages){
+ $this->blockUser($user_2, $user_id);
+ $this->doDelete( $pages, $reason );
+ }else { }
+ }
+ else {
+ $this->whiteList();
+ }
+
+ }
+
+ function whiteList() {
+ global $wgOut, $wgUser;
+
+ $whitelist_file =
("http://thepetwiki.com/extensions/BlockandNuke/whitelist.txt");
+ $fh = fopen($whitelist_file, 'r');
+ $file = fread($fh,200);
+ $pieces = (preg_split('/\r\n|\r|\n/', $file));
+ fclose($fh);
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $result = $dbr->query("SELECT DISTINCT rc_user, rc_user_text
+ FROM mw_recentchanges
+ WHERE rc_new=1 OR (rc_log_type = 'upload' AND
rc_log_action = 'upload')
+ ORDER BY rc_user_text ASC"
+ );
+ $names=array();
+ while( $row = $dbr->fetchObject( $result ) ) {
+ $names[]=array($row->rc_user_text, $row->rc_user);
+ }
+
+ $wgOut->addWikiMsg( 'block-tools' );
+ $wgOut->addHTML(
+ Xml::openElement( 'form', array(
+ 'action' => $this->getTitle()->getLocalURL(
'action=submit' ),
+ 'method' => 'post')).
+ HTML::hidden( 'wpEditToken', $wgUser->editToken() ).
+ ( '<ul>' )
+ );
+
+ //make into links $sk = $wgUser->getSkin();
+
+ foreach($names as $user_info){
+ list($user, $user_id) = $user_info;
+
+ if (!in_array($user, $pieces)){
+ $wgOut->addHTML( '<li>'.
+ Xml::check( 'names[]', true,
+ array( 'value' => $user)).
+ ($user).
+ "</li>\n" );
+ }
+
+ }
+ $wgOut->addHTML(
+ "</ul>\n" .
+ Xml::submitButton( wfMsg( 'block-submit-user' ) ).
+ "</form>"
+ );
+
+
+ }
+
+ function getNewPages($user) {
+ global $wgOut, $wgUser;
+
+ $wgOut->addHTML(
+ Xml::openElement( 'form', array(
+ 'action' => $this->getTitle()->getLocalURL(
'action=delete' ),
+ 'method' => 'post')).
+ HTML::hidden( 'wpEditToken', $wgUser->editToken() ).
+ ( '<ul>' )
+ );
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $result = $dbr->select( 'recentchanges',
+ array( 'rc_namespace', 'rc_title', 'rc_timestamp',
'COUNT(*) AS edits' ),
+ array(
+ 'rc_user_text' => $user,
+ '(rc_new = 1) OR (rc_log_type = "upload" AND
rc_log_action = "upload")'
+ ),
+ __METHOD__,
+ array(
+ 'ORDER BY' => 'rc_timestamp DESC',
+ 'GROUP BY' => 'rc_namespace, rc_title'
+ )
+ );
+
+ $pages = array();
+ while( $row = $dbr->fetchObject( $result ) ) {
+ $pages[] = array( Title::makeTitle( $row->rc_namespace,
$row->rc_title ), $row->edits );
+ }
+
+ foreach( $pages as $info ) {
+ list($title, $edits) = $info;
+ $wgOut->addHtml(HTML::hidden( 'pages[]', $title));
+ }
+
+ foreach($user as $users){
+ $dbr = wfGetDB( DB_SLAVE );
+ $result = $dbr->query("SELECT DISTINCT rc_user,
rc_user_text
+ FROM mw_recentchanges
+ WHERE rc_user_text = '$users'
+ ORDER BY rc_user ASC"
+ );
+ $name=array();
+ while( $row = $dbr->fetchObject( $result ) ) {
+ $name[]=array($row->rc_user_text, $row->rc_user);
+ }
+
+ foreach($name as $infos) {
+ list($user_2, $user_id) = $infos;
+ $wgOut->addHTML(HTML::hidden( 'names_2[]',
$user_2).
+ HTML::hidden( 'userid[]', $user_id));
+ }
+ }
+
+ $wgOut->addHTML(
+ "</ul>\n" .
+ XML::submitButton( wfMsg( 'blockandnuke' ) ).
+ "</form>"
+ );
+ }
+
+
+ function blockUser($user, $user_id) {
+ global $wgUser, $wgOut;
+
+ // if($user_id[$c]== 0){$user_id = $this->uid}
+
+ for($c = 0; $c < max( count($user), count($user_id) ); $c++ ){
+
+ $blk = new Block($user[$c], $user_id[$c],
$wgUser->getID(), wfMsg('block-message'),
+ wfTimestamp(), 0, Block::infinity(), 0,
1, 0, 0, 1);
+ if($blk->insert()) {
+ $log = new LogPage('block');
+ $log->addEntry('block', Title::makeTitle( NS_USER,
$this->targetUser ),
+ 'Blocked through Special:BlockandNuke',
array('infinite', $user[$c], 'nocreate')
+ );
+
+
+ }
+ }
+ }
+
+ function doDelete( $pages, $reason ) {
+
+ foreach($pages as $page) {
+
+ $title = Title::newFromURL($page);
+ $file = $title->getNamespace() == NS_IMAGE ?
wfLocalFile( $title ) : false;
+ if ($file) {
+ $reason="BlockandNuke delete spam";
+ $oldimage = null; // Must be passed by reference
+ FileDeleteForm::doDelete( $title, $file,
$oldimage, $reason, false );
+ } else {
+ $reason="BlockandNuke delete spam articles.";
+ $article = new Article( $title );
+ $article->doDelete( $reason );
+ }
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/BlockandNuke.i18n.php b/BlockandNuke.i18n.php
new file mode 100644
index 0000000..a708626
--- /dev/null
+++ b/BlockandNuke.i18n.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Internationalisation file for the BlockandNuke extension
+ * @addtogroup Extensions
+ * @author Eliora Stahl
+ */
+
+$aliases = array();
+
+/** English
+ * @author Brion Vibber
+ */
+$aliases['en'] = array(
+ 'BlockandNuke' => array( 'BlockandNuke' ),
+);
+
+$messages = array();
+
+/** English
+ * @author Eliora Stahl
+ */
+$messages['en'] = array(
+
+ 'blockandnuke' => 'BlockandNuke',
+ 'block' => 'Mass delete do you read me',
+ 'block-confirm' => 'Click the BlockandNuke button to block the
selected users and delete all their contributions. <br>
+ (Do not uncheck any of the boxes
below)',
+ 'block-desc' => 'Gives administrators the ability to
[[Special:BlockandNuke]] pages',
+ 'block-nopages' => "No new pages by
[[Special:Contributions/$1|$1]] in recent changes.",
+ 'block-list' => "The following pages were recently created by
[[Special:Contributions/$1|$1]]; put in a comment and hit the button to delete
them.",
+ 'block-defaultreason' => "Mass removal of pages added by $1",
+ 'block-tools' => "List of Users who have recently contributed
and are not found on the Whitelist: <br>
+ To add a user to the whitelist edit
extensions/BlockandNuke/whitelist.txt",
+ 'block-submit-user' => 'Select Users',
+ 'block-submit-delete' => 'BlockandNuke',
+ 'block-block' => 'Selected users have been blocked and their
contributions deleted.',
+ 'block-message' => 'Users blocked by BlockandNuke.',
+);
\ No newline at end of file
diff --git a/BlockandNuke.php b/BlockandNuke.php
new file mode 100644
index 0000000..ab36bb5
--- /dev/null
+++ b/BlockandNuke.php
@@ -0,0 +1,31 @@
+<?php
+//user will get this message if the haven't installed the extension
+if( !defined( 'MEDIAWIKI' ) )
+ die( 'Not an entry point.' );
+//path of the extension
+$dir = dirname(__FILE__) . '/';
+
+//load internationalization file.
+$wgExtensionMessagesFiles['BlockandNuke'] = $dir . 'BlockandNuke.i18n.php';
+
+//setup instructions
+$wgExtensionCredits['specialpage'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'BlockandNuke',
+ 'description' => 'Gives sysops the ability to mass delete users and
their pages',
+ 'descriptionmsg' => 'block-desc',
+ 'author' => 'Eliora Stahl',
+ 'url' =>
'http://www.mediawiki.org/wiki/Extension:BlockandNuke',
+);
+
+//Permissions - not recognised as admin
+$wgGroupPermissions['sysop']['blockandnuke'] = true;
+$wgAvailableRights[] = 'blockandnuke';
+
+// Location of the Special:Extension class 'Block_Nuke'. Load this php code.
+$wgAutoloadClasses['SpecialBlock_Nuke'] = $dir . 'BlockandNuke.body.php';
+
+//Tell MediaWiki about the new special page and its class name 'Block_Nuke'
+$wgSpecialPages['BlockandNuke'] = 'SpecialBlock_Nuke';
+//Under heading 'pagetools' on Special Pages
+$wgSpecialPageGroups['BlockandNuke'] = 'pagetools';
diff --git a/whitelist.txt b/whitelist.txt
new file mode 100644
index 0000000..21a2b5b
--- /dev/null
+++ b/whitelist.txt
@@ -0,0 +1,17 @@
+Example
+Name
+AnimalLover
+Mamairis
+Petfan
+Hadassah
+Jessie
+Rachelv
+Sarab
+TheWhiteRider
+Scotlund
+Rena.reich
+Caseyjmc
+Nirel
+Rony Perez
+Dronyentad
+Admin
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/120479
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id596596b7e8da8e9595077f068b0480d30617cab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlockAndNuke
Gerrit-Branch: REL1_22
Gerrit-Owner: MarkAHershberger <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits