diff options
Diffstat (limited to 'includes/specials/SpecialRevisiondelete.php')
-rw-r--r-- | includes/specials/SpecialRevisiondelete.php | 170 |
1 files changed, 62 insertions, 108 deletions
diff --git a/includes/specials/SpecialRevisiondelete.php b/includes/specials/SpecialRevisiondelete.php index 5a5f8ffb..825be6c4 100644 --- a/includes/specials/SpecialRevisiondelete.php +++ b/includes/specials/SpecialRevisiondelete.php @@ -49,68 +49,43 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { /** Array of checkbox specs (message, name, deletion bits) */ var $checks; - /** Information about the current type */ - var $typeInfo; + /** UI Labels about the current type */ + var $typeLabels; /** The RevDel_List object, storing the list of items to be deleted/undeleted */ var $list; /** - * Assorted information about each type, needed by the special page. - * TODO Move some of this to the list class + * UI labels for each type. */ - static $allowedTypes = array( + static $UILabels = array( 'revision' => array( 'check-label' => 'revdelete-hide-text', - 'deletion-bits' => Revision::DELETED_TEXT, 'success' => 'revdelete-success', 'failure' => 'revdelete-failure', - 'list-class' => 'RevDel_RevisionList', - 'permission' => 'deleterevision', ), 'archive' => array( 'check-label' => 'revdelete-hide-text', - 'deletion-bits' => Revision::DELETED_TEXT, 'success' => 'revdelete-success', 'failure' => 'revdelete-failure', - 'list-class' => 'RevDel_ArchiveList', - 'permission' => 'deleterevision', ), - 'oldimage'=> array( + 'oldimage' => array( 'check-label' => 'revdelete-hide-image', - 'deletion-bits' => File::DELETED_FILE, 'success' => 'revdelete-success', 'failure' => 'revdelete-failure', - 'list-class' => 'RevDel_FileList', - 'permission' => 'deleterevision', ), 'filearchive' => array( 'check-label' => 'revdelete-hide-image', - 'deletion-bits' => File::DELETED_FILE, 'success' => 'revdelete-success', 'failure' => 'revdelete-failure', - 'list-class' => 'RevDel_ArchivedFileList', - 'permission' => 'deleterevision', ), 'logging' => array( 'check-label' => 'revdelete-hide-name', - 'deletion-bits' => LogPage::DELETED_ACTION, 'success' => 'logdelete-success', 'failure' => 'logdelete-failure', - 'list-class' => 'RevDel_LogList', - 'permission' => 'deletelogentry', ), ); - /** Type map to support old log entries */ - static $deprecatedTypeMap = array( - 'oldid' => 'revision', - 'artimestamp' => 'archive', - 'oldimage' => 'oldimage', - 'fileid' => 'filearchive', - 'logid' => 'logging', - ); - public function __construct() { parent::__construct( 'Revisiondelete', 'deletedhistory' ); } @@ -147,19 +122,6 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { } else { $this->typeName = $request->getVal( 'type' ); $this->targetObj = Title::newFromText( $request->getText( 'target' ) ); - if ( $this->targetObj && $this->targetObj->isSpecial( 'Log' ) && count( $this->ids ) !== 0 ) { - $result = wfGetDB( DB_SLAVE )->select( 'logging', - 'log_type', - array( 'log_id' => $this->ids ), - __METHOD__, - array( 'DISTINCT' ) - ); - - if ( $result->numRows() == 1 ) { - // If there's only one type, the target can be set to include it. - $this->targetObj = SpecialPage::getTitleFor( 'Log', $result->current()->log_type ); - } - } } # For reviewing deleted files... @@ -170,28 +132,21 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { return; } - if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) { - $this->typeName = self::$deprecatedTypeMap[$this->typeName]; - } + $this->typeName = RevisionDeleter::getCanonicalTypeName( $this->typeName ); # No targets? - if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) { + if ( !$this->typeName || count( $this->ids ) == 0 ) { throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); } - $this->typeInfo = self::$allowedTypes[$this->typeName]; - $this->mIsAllowed = $user->isAllowed( $this->typeInfo['permission'] ); - - # If we have revisions, get the title from the first one - # since they should all be from the same page. This allows - # for more flexibility with page moves... - if( $this->typeName == 'revision' ) { - $rev = Revision::newFromId( $this->ids[0] ); - $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj; - } + $this->typeLabels = self::$UILabels[$this->typeName]; + $this->mIsAllowed = $user->isAllowed( RevisionDeleter::getRestriction( $this->typeName ) ); + + # Allow the list type to adjust the passed target + $this->targetObj = RevisionDeleter::suggestTarget( $this->typeName, $this->targetObj, $this->ids ); $this->otherReason = $request->getVal( 'wpReason' ); # We need a target page! - if( is_null( $this->targetObj ) ) { + if ( is_null( $this->targetObj ) ) { $output->addWikiMsg( 'undelete-header' ); return; } @@ -200,17 +155,19 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { # Initialise checkboxes $this->checks = array( - array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ), + array( $this->typeLabels['check-label'], 'wpHidePrimary', + RevisionDeleter::getRevdelConstant( $this->typeName ) + ), array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ), array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ) ); - if( $user->isAllowed( 'suppressrevision' ) ) { + if ( $user->isAllowed( 'suppressrevision' ) ) { $this->checks[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ); } # Either submit or create our form - if( $this->mIsAllowed && $this->submitClicked ) { + if ( $this->mIsAllowed && $this->submitClicked ) { $this->submit( $request ); } else { $this->showForm(); @@ -223,7 +180,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { LogEventsList::showLogExtract( $output, 'delete', $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) ); # Show relevant lines from the suppression log - if( $user->isAllowed( 'suppressionlog' ) ) { + if ( $user->isAllowed( 'suppressionlog' ) ) { $suppressLogPage = new LogPage( 'suppress' ); $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" ); LogEventsList::showLogExtract( $output, 'suppress', @@ -236,7 +193,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function showConvenienceLinks() { # Give a link to the logs/hist for this page - if( $this->targetObj ) { + if ( $this->targetObj ) { $links = array(); $links[] = Linker::linkKnown( SpecialPage::getTitleFor( 'Log' ), @@ -253,7 +210,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { array( 'action' => 'history' ) ); # Link to deleted edits - if( $this->getUser()->isAllowed( 'undelete' ) ) { + if ( $this->getUser()->isAllowed( 'undelete' ) ) { $undelete = SpecialPage::getTitleFor( 'Undelete' ); $links[] = Linker::linkKnown( $undelete, @@ -296,8 +253,8 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { return; } $user = $this->getUser(); - if( !$oimage->userCan( File::DELETED_FILE, $user ) ) { - if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) { + if ( !$oimage->userCan( File::DELETED_FILE, $user ) ) { + if ( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) { throw new PermissionsError( 'suppressrevision' ); } else { throw new PermissionsError( 'deletedtext' ); @@ -312,10 +269,11 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $this->getOutput()->addHTML( Xml::openElement( 'form', array( 'method' => 'POST', - 'action' => $this->getTitle()->getLocalUrl( - 'target=' . urlencode( $this->targetObj->getPrefixedDBkey() ) . - '&file=' . urlencode( $archiveName ) . - '&token=' . urlencode( $user->getEditToken( $archiveName ) ) ) + 'action' => $this->getTitle()->getLocalURL( array( + 'target' => $this->targetObj->getPrefixedDBkey(), + 'file' => $archiveName, + 'token' => $user->getEditToken( $archiveName ), + ) ) ) ) . Xml::submitButton( $this->msg( 'revdelete-show-file-submit' )->text() ) . @@ -342,8 +300,9 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function getList() { if ( is_null( $this->list ) ) { - $class = $this->typeInfo['list-class']; - $this->list = new $class( $this->getContext(), $this->targetObj, $this->ids ); + $this->list = RevisionDeleter::createList( + $this->typeName, $this->getContext(), $this->targetObj, $this->ids + ); } return $this->list; } @@ -370,7 +329,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { for ( $list->reset(); $list->current(); $list->next() ) { $item = $list->current(); if ( !$item->canView() ) { - if( !$this->submitClicked ) { + if ( !$this->submitClicked ) { throw new PermissionsError( 'suppressrevision' ); } $UserAllowed = false; @@ -379,7 +338,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $this->getOutput()->addHTML( $item->getHTML() ); } - if( !$numRevisions ) { + if ( !$numRevisions ) { throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); } @@ -388,12 +347,14 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $this->addUsageText(); // Normal sysops can always see what they did, but can't always change it - if( !$UserAllowed ) return; + if ( !$UserAllowed ) { + return; + } // Show form if the user can submit - if( $this->mIsAllowed ) { + if ( $this->mIsAllowed ) { $out = Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ), 'id' => 'mw-revdel-form-revisions' ) ) . Xml::fieldset( $this->msg( 'revdelete-legend' )->text() ) . $this->buildCheckBoxes() . @@ -406,7 +367,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { Xml::listDropDown( 'wpRevDeleteReasonList', $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->text(), $this->msg( 'revdelete-reasonotherlist' )->inContentLanguage()->text(), - '', 'wpReasonDropDown', 1 + $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' ), 'wpReasonDropDown', 1 ) . '</td>' . "</tr><tr>\n" . @@ -432,10 +393,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { } else { $out = ''; } - if( $this->mIsAllowed ) { + if ( $this->mIsAllowed ) { $out .= Xml::closeElement( 'form' ) . "\n"; // Show link to edit the dropdown reasons - if( $this->getUser()->isAllowed( 'editinterface' ) ) { + if ( $this->getUser()->isAllowed( 'editinterface' ) ) { $title = Title::makeTitle( NS_MEDIAWIKI, 'Revdelete-reason-dropdown' ); $link = Linker::link( $title, @@ -455,10 +416,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function addUsageText() { $this->getOutput()->addWikiMsg( 'revdelete-text' ); - if( $this->getUser()->isAllowed( 'suppressrevision' ) ) { + if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) { $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' ); } - if( $this->mIsAllowed ) { + if ( $this->mIsAllowed ) { $this->getOutput()->addWikiMsg( 'revdelete-confirm' ); } } @@ -470,17 +431,18 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $html = '<table>'; // If there is just one item, use checkboxes $list = $this->getList(); - if( $list->length() == 1 ) { + if ( $list->length() == 1 ) { $list->reset(); $bitfield = $list->current()->getBits(); // existing field - if( $this->submitClicked ) { + if ( $this->submitClicked ) { $bitfield = $this->extractBitfield( $this->extractBitParams(), $bitfield ); } - foreach( $this->checks as $item ) { + foreach ( $this->checks as $item ) { list( $message, $name, $field ) = $item; $innerHTML = Xml::checkLabel( $this->msg( $message )->text(), $name, $name, $bitfield & $field ); - if( $field == Revision::DELETED_RESTRICTED ) + if ( $field == Revision::DELETED_RESTRICTED ) { $innerHTML = "<b>$innerHTML</b>"; + } $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML ); $html .= "<tr>$line</tr>\n"; } @@ -491,10 +453,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-unset' )->escaped() . '</th>'; $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-set' )->escaped() . '</th>'; $html .= "<th></th></tr>\n"; - foreach( $this->checks as $item ) { + foreach ( $this->checks as $item ) { list( $message, $name, $field ) = $item; // If there are several items, use third state by default... - if( $this->submitClicked ) { + if ( $this->submitClicked ) { $selected = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); } else { $selected = -1; // use existing field @@ -503,7 +465,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>'; $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>'; $label = $this->msg( $message )->escaped(); - if( $field == Revision::DELETED_RESTRICTED ) { + if ( $field == Revision::DELETED_RESTRICTED ) { $label = "<b>$label</b>"; } $line .= "<td>$label</td>"; @@ -523,21 +485,21 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { protected function submit() { # Check edit token on submission $token = $this->getRequest()->getVal( 'wpEditToken' ); - if( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) { + if ( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) { $this->getOutput()->addWikiMsg( 'sessionfailure' ); return false; } $bitParams = $this->extractBitParams(); $listReason = $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown $comment = $listReason; - if( $comment != 'other' && $this->otherReason != '' ) { + if ( $comment != 'other' && $this->otherReason != '' ) { // Entry from drop down menu + additional comment $comment .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->otherReason; - } elseif( $comment == 'other' ) { + } elseif ( $comment == 'other' ) { $comment = $this->otherReason; } # Can the user set this field? - if( $bitParams[Revision::DELETED_RESTRICTED] == 1 && !$this->getUser()->isAllowed( 'suppressrevision' ) ) { + if ( $bitParams[Revision::DELETED_RESTRICTED] == 1 && !$this->getUser()->isAllowed( 'suppressrevision' ) ) { throw new PermissionsError( 'suppressrevision' ); } # If the save went through, go to success message... @@ -557,7 +519,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function success() { $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) ); - $this->getOutput()->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeInfo['success'] ); + $this->getOutput()->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeLabels['success'] ); $this->list->reloadFromMaster(); $this->showForm(); } @@ -567,7 +529,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function failure( $status ) { $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) ); - $this->getOutput()->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) ); + $this->getOutput()->addWikiText( $status->getWikiText( $this->typeLabels['failure'] ) ); $this->showForm(); } @@ -578,15 +540,15 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { */ protected function extractBitParams() { $bitfield = array(); - foreach( $this->checks as $item ) { + foreach ( $this->checks as $item ) { list( /* message */, $name, $field ) = $item; $val = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); - if( $val < -1 || $val > 1) { + if ( $val < -1 || $val > 1 ) { $val = -1; // -1 for existing value } $bitfield[$field] = $val; } - if( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) { + if ( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) { $bitfield[Revision::DELETED_RESTRICTED] = 0; } return $bitfield; @@ -594,21 +556,13 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { /** * Put together a rev_deleted bitfield + * @deprecated since 1.22, use RevisionDeleter::extractBitfield instead * @param array $bitPars extractBitParams() params * @param int $oldfield current bitfield * @return array */ public static function extractBitfield( $bitPars, $oldfield ) { - // Build the actual new rev_deleted bitfield - $newBits = 0; - foreach( $bitPars as $const => $val ) { - if( $val == 1 ) { - $newBits |= $const; // $const is the *_deleted const - } elseif( $val == -1 ) { - $newBits |= ($oldfield & $const); // use existing - } - } - return $newBits; + return RevisionDeleter::extractBitfield( $bitPars, $oldfield ); } /** |