getVal( 'target' ); $oldid = $wgRequest->getIntArray( 'oldid' ); $sk = $wgUser->getSkin(); $page = Title::newFromUrl( $target ); if( is_null( $page ) ) { $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } if( is_null( $oldid ) ) { $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); return; } $form = new RevisionDeleteForm( $wgRequest ); if( $wgRequest->wasPosted() ) { $form->submit( $wgRequest ); } else { $form->show( $wgRequest ); } } class RevisionDeleteForm { /** * @param Title $page * @param int $oldid */ function __construct( $request ) { global $wgUser; $target = $request->getVal( 'target' ); $this->page = Title::newFromUrl( $target ); $this->revisions = $request->getIntArray( 'oldid', array() ); $this->skin = $wgUser->getSkin(); $this->checks = array( array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT ), array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ), array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ), array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) ); } /** * @param WebRequest $request */ function show( $request ) { global $wgOut, $wgUser; $wgOut->addWikiText( wfMsg( 'revdelete-selected', $this->page->getPrefixedText() ) ); $wgOut->addHtml( "" ); $wgOut->addWikiText( wfMsg( 'revdelete-text' ) ); $items = array( wfInputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ), wfSubmitButton( wfMsg( 'revdelete-submit' ) ) ); $hidden = array( wfHidden( 'wpEditToken', $wgUser->editToken() ), wfHidden( 'target', $this->page->getPrefixedText() ) ); foreach( $this->revisions as $revid ) { $hidden[] = wfHidden( 'oldid[]', $revid ); } $special = Title::makeTitle( NS_SPECIAL, 'Revisiondelete' ); $wgOut->addHtml( wfElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ) ), null ) ); $wgOut->addHtml( '
' . wfMsgHtml( 'revdelete-legend' ) . '' ); foreach( $this->checks as $item ) { list( $message, $name, $field ) = $item; $wgOut->addHtml( '
' . wfCheckLabel( wfMsg( $message), $name, $name, $rev->isDeleted( $field ) ) . '
' ); } $wgOut->addHtml( '
' ); foreach( $items as $item ) { $wgOut->addHtml( '

' . $item . '

' ); } foreach( $hidden as $item ) { $wgOut->addHtml( $item ); } $wgOut->addHtml( '' ); } /** * @param Revision $rev * @returns string */ function historyLine( $rev ) { global $wgContLang; $date = $wgContLang->timeanddate( $rev->getTimestamp() ); return "
  • " . $this->skin->makeLinkObj( $this->page, $date, 'oldid=' . $rev->getId() ) . " " . $this->skin->revUserLink( $rev ) . " " . $this->skin->revComment( $rev ) . "
  • "; } /** * @param WebRequest $request */ function submit( $request ) { $bitfield = $this->extractBitfield( $request ); $comment = $request->getText( 'wpReason' ); if( $this->save( $bitfield, $comment ) ) { return $this->success( $request ); } else { return $this->show( $request ); } } function success( $request ) { global $wgOut; $wgOut->addWikiText( 'woo' ); } /** * Put together a rev_deleted bitfield from the submitted checkboxes * @param WebRequest $request * @return int */ function extractBitfield( $request ) { $bitfield = 0; foreach( $this->checks as $item ) { list( $message, $name, $field ) = $item; if( $request->getCheck( $name ) ) { $bitfield |= $field; } } return $bitfield; } function save( $bitfield, $reason ) { $dbw = wfGetDB( DB_MASTER ); $deleter = new RevisionDeleter( $dbw ); $ok = $deleter->setVisibility( $this->revisions, $bitfield, $reason ); } } class RevisionDeleter { function __construct( $db ) { $this->db = $db; } /** * @param array $items list of revision ID numbers * @param int $bitfield new rev_deleted value * @param string $comment Comment for log records */ function setVisibility( $items, $bitfield, $comment ) { $pages = array(); // To work! foreach( $items as $revid ) { $rev = Revision::newFromId( $revid ); if( !isset( $rev ) ) { return false; } $this->updateRevision( $rev, $bitfield ); $this->updateRecentChanges( $rev, $bitfield ); // For logging, maintain a count of revisions per page $pageid = $rev->getPage(); if( isset( $pages[$pageid] ) ) { $pages[$pageid]++; } else { $pages[$pageid] = 1; } } // Clear caches... foreach( $pages as $pageid => $count ) { $title = Title::newFromId( $pageid ); $this->updatePage( $title ); $this->updateLog( $title, $count, $bitfield, $comment ); } return true; } /** * Update the revision's rev_deleted field * @param Revision $rev * @param int $bitfield new rev_deleted bitfield value */ function updateRevision( $rev, $bitfield ) { $this->db->update( 'revision', array( 'rev_deleted' => $bitfield ), array( 'rev_id' => $rev->getId() ), 'RevisionDeleter::updateRevision' ); } /** * Update the revision's recentchanges record if fields have been hidden * @param Revision $rev * @param int $bitfield new rev_deleted bitfield value */ function updateRecentChanges( $rev, $bitfield ) { $this->db->update( 'recentchanges', array( 'rc_user' => ($bitfield & Revision::DELETED_USER) ? 0 : $rev->getUser(), 'rc_user_text' => ($bitfield & Revision::DELETED_USER) ? wfMsg( 'rev-deleted-user' ) : $rev->getUserText(), 'rc_comment' => ($bitfield & Revision::DELETED_COMMENT) ? wfMsg( 'rev-deleted-comment' ) : $rev->getComment() ), array( 'rc_this_oldid' => $rev->getId() ), 'RevisionDeleter::updateRecentChanges' ); } /** * Touch the page's cache invalidation timestamp; this forces cached * history views to refresh, so any newly hidden or shown fields will * update properly. * @param Title $title */ function updatePage( $title ) { $title->invalidateCache(); } /** * Record a log entry on the action * @param Title $title * @param int $count the number of revisions altered for this page * @param int $bitfield the new rev_deleted value * @param string $comment */ function updateLog( $title, $count, $bitfield, $comment ) { $log = new LogPage( 'delete' ); $reason = "changed $count revisions to $bitfield"; $reason .= ": $comment"; $log->addEntry( 'revision', $title, $reason ); } } ?>