MediaWiki/NukePlus/Nuke body.php

Updates

 * 2013-01-20
 * now lists uploads that are not in recentchanges
 * edits belonging to users with "nonuke" ability are left unchecked in the list
 * to do: figure out how to leave them out altogether

Code
userCanExecute( $this->getUser ) ) { $this->displayRestrictionError; }		$this->setHeaders; $this->outputHeader;

if ( $this->getUser->isBlocked ) { $block = $this->getUser->getBlock; throw new UserBlockedError( $block ); }		$this->checkReadOnly;

$req = $this->getRequest;

$target = trim( $req->getText( 'target', $par ) );

// Normalise name if ( $target !== '' ) { $user = User::newFromName( $target ); if ( $user ) $target = $user->getName; }

$reason = $req->getText( 'wpReason',			$target === '' ?				wfMsgForContent( 'nuke-multiplepeople' ) :				wfMsgForContent( 'nuke-defaultreason', "$target" )		);

if( $req->wasPosted			&& $this->getUser->matchEditToken( $req->getVal( 'wpEditToken' ) ) ) {

if ( $req->getVal( 'action' ) == 'delete' ) { $pages = $req->getArray( 'pages' );

if( $pages ) { $this->doDelete( $pages, $reason ); return; }			} elseif ( $req->getVal( 'action' ) == 'submit' ) { $this->listForm( $target, $reason, $req->getInt( 'limit', 500 ) ); } else { $this->promptForm; }		} elseif ( $target === '' ) { $this->promptForm; } else { $this->listForm( $target, $reason, $req->getInt( 'limit', 500 ) ); }	}

/**	 * Prompt for a username or IP address. *	 * @param $userName string */	protected function promptForm( $userName = '' ) { $out = $this->getOutput;

$out->addWikiMsg( 'nuke-tools' );

$out->addHTML(			Xml::openElement( 'form', array(					'action' => $this->getTitle->getLocalURL( 'action=submit' ),					'method' => 'post'				) )			. ' '			. Html::hidden( 'wpEditToken', $this->getUser->editToken )			. Xml::closeElement( 'form' )		); }

/**	 * Display list of pages to delete. *	 * @param string $username * @param string $reason * @param integer $limit */	protected function listForm( $username, $reason, $limit ) { global $wgUser;	// need this for displaying "mark as patrolled" link

$out = $this->getOutput;

$pages = $this->getNewPages( $username, $limit );

if( count( $pages ) == 0 ) { if ( $username === '' ) { $out->addWikiMsg( 'nuke-nopages-global' ); } else { $out->addWikiMsg( 'nuke-nopages', $username ); }

$this->promptForm( $username ); return; }

if ( $username === '' ) { $out->addWikiMsg( 'nuke-list-multiple' ); } else { $out->addWikiMsg( 'nuke-list', $username ); }

$nuke = $this->getTitle;

$out->addModules( 'ext.nuke' );

$out->addHTML(			Xml::openElement( 'form', array(				'action' => $nuke->getLocalURL( 'action=delete' ),				'method' => 'post',				'name' => 'nukelist') ) .			Html::hidden( 'wpEditToken', $this->getUser->editToken ) .			Xml::tags( 'p', null, Xml::inputLabel(					wfMsg( 'deletecomment' ), 'wpReason', 'wpReason', 70, $reason				) )		);

// Select: All, None $links = array; $links[] = ''. wfMsg( 'powersearch-toggleall' ). ''; $links[] = ''. wfMsg( 'powersearch-togglenone' ). ''; $out->addHTML(			Xml::tags( 'p', null, wfMsg( 'nuke-select', $this->getLanguage->commaList( $links ) ) )		);

// Delete button $out->addHTML(			Xml::submitButton( wfMsg( 'nuke-submit-delete' ) )		);

$out->addHTML( '' );

foreach( $pages as $info ) { /**			 * @var $title Title */			list( $title, $userName, $idRev ) = $info;

// (Wzl) look up user rights -- are they trusted? $mwoUser = User::newFromName($userName); // later: query should fetch user ID as well as name -- names can change, in theory -- and this should use that $doCheck = !$mwoUser->isAllowed('nonuke');

$image = $title->getNamespace == NS_IMAGE ? wfLocalFile( $title ) : false; $thumb = $image && $image->exists ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : false; // (Wzl) for marking as patrolled if (is_null($idRev)) { $token = NULL; } else { $token = $wgUser->getEditToken( $idRev ); }

$out->addHTML( '' .				Xml::check( 'pages[]', $doCheck, array( 'value' => $title->getPrefixedDbKey ) ) .				'&#160;' .				( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .				Linker::linkKnown( $title ) .				'&#160;('. ( $userName ? wfMsgExt( 'nuke-editby', 'parseinline', $userName ) . ',&#160;' : '' ). Linker::linkKnown(					$title,					wfMsg( 'nuke-viewchanges' ),					array,					array( 'action' => 'history' )				) );			if (!is_null($token)) { // (Wzl) show "mark as patrolled" link				$out->addHTML(', '. Linker::link(						$title,						wfMsgHtml( 'markaspatrolledtext' ),						array,						array( 'action' => 'markpatrolled', 'rcid' => $idRev, 'token' => $token, ),						array( 'known', 'noclasses' )					) );			} // (Wzl) END					$out->addHTML(")\n"); }

$out->addHTML(			"\n" .			Xml::submitButton( wfMsg( 'nuke-submit-delete' ) ) .			' '		); }

/**	 * Gets a list of new pages by the specified user or everyone when none is specified. *	 * @param string $username * @param integer $limit *	 * @return array */	protected function getNewPages( $username, $limit ) { $dbr = wfGetDB( DB_SLAVE );

$what = array(			'rc_namespace',			'rc_title',			'rc_timestamp',			'rc_id',	// (Wzl) for marking as patrolled		);

// original //$where = array( "(rc_new = 1) OR (rc_log_type = 'upload' AND rc_log_action = 'upload')" ); // Wzl improvement #1 $sqlFilt = "(page_id IS NOT NULL)" ." AND (NOT rc_patrolled)" ." AND ((rc_new = 1)"			." OR (rc_log_type = 'upload' AND rc_log_action = 'upload'))"; $where = array( $sqlFilt );

$hasUserFilter = ($username !== ''); if ( $hasUserFilter ) { $where['rc_user_text'] = $username; } else { $what[] = 'rc_user_text'; }

$pattern = $this->getRequest->getText( 'pattern' ); if ( !is_null( $pattern ) && trim( $pattern ) !== '' ) { $where[] = 'rc_title LIKE '. $dbr->addQuotes( $pattern ); }		$group = implode( ', ', $what );

// (Wzl) was just 'recentchanges', but we need to look at 'page' to make sure the page actually still exists (is this a MW bug?) $result = $dbr->select( 'recentchanges LEFT JOIN page ON (rc_title=page_title) AND (rc_namespace=page_namespace)',			$what,			$where,			__METHOD__,			array( 'ORDER BY' => 'rc_timestamp DESC', 'GROUP BY' => $group, 'LIMIT' => $limit )		);

$pages = array;

foreach ( $result as $row ) { $pages[] = array(				Title::makeTitle( $row->rc_namespace, $row->rc_title ),				$hasUserFilter ? FALSE : $row->rc_user_text,				$row->rc_id	// (Wzl) for marking as patrolled			); }

// (Wzl) if limit not exceeded, get new uploads too $qPages = count($pages); if ($qPages < $limit) { $what = array(				'img_name',				'img_timestamp',				'rc_id',	// for marking as patrolled			); $where = array('(NOT rc_patrolled) OR (rc_id IS NULL)'); if ( $hasUserFilter ) { $where['img_user_text'] = $username; } else { $what[] = 'img_user_text'; }			$group = implode( ', ', $what );

$result = $dbr->select( 'image LEFT JOIN recentchanges ON img_name=rc_title',				$what,				$where,				__METHOD__,				array( 'ORDER BY' => 'img_timestamp DESC', 'GROUP BY' => $group, 'LIMIT' => $limit - $qPages )			);			foreach ( $result as $row ) { $pages[] = array(					Title::makeTitle( NS_FILE, $row->img_name ),					$hasUserFilter ? FALSE : $row->img_user_text,					$row->rc_id				); }		} // (Wzl) END

return $pages; }

/**	 * Does the actual deletion of the pages. *	 * @param array $pages The pages to delete * @param string $reason */	protected function doDelete( array $pages, $reason ) { $res = array;

foreach( $pages as $page ) { $title = Title::newFromURL( $page ); $file = $title->getNamespace == NS_FILE ? wfLocalFile( $title ) : false;

$permission_errors = $title->getUserPermissionsErrors( 'delete', $this->getUser);

if ( count( $permission_errors )) { throw new PermissionsError( 'delete', $permission_errors ); }

if ( $file ) { $oldimage = null; // Must be passed by reference $ok = FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, false )->isOK; } else { $article = new Article( $title, 0 ); $ok = $article->doDeleteArticle( $reason ); }

if ( $ok ) { $res[] = wfMsgExt( 'nuke-deleted', array( 'parseinline' ), $title->getPrefixedText ); } else { $res[] = wfMsgExt( 'nuke-not-deleted', array( 'parseinline' ), $title->getPrefixedText ); }		}

$this->getOutput->addHTML( "\n" . implode( "\n", $res ) . "\n\n" );

$this->getOutput->addWikiMsg( 'nuke-delete-more' ); }

}