Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/70749
Change subject: Add API action=revisiondelete
......................................................................
Add API action=revisiondelete
Add action=revisiondelete to the API, and some functions to the
revisiondelete backend to support this.
Bug: 23005
Change-Id: Iee146fed648603b86a35927518f850771fc69bd2
---
M RELEASE-NOTES-1.22
M includes/AutoLoader.php
M includes/api/ApiMain.php
A includes/api/ApiRevisiondelete.php
M includes/revisiondelete/RevisionDelete.php
M includes/revisiondelete/RevisionDeleteAbstracts.php
6 files changed, 385 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/49/70749/1
diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 997dbc6..8f60292 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -113,6 +113,8 @@
* (bug 46513) Vector: Add the collapsibleTabs script from the Vector extension.
* Added $wgRecentChangesFlags for defining new flags for RecentChanges and
watchlists.
+* Revision deletion backend code is moved out of SpecialRevisiondelete, and
+ RevDel_Item gets a new method to support ApiRevisiondelete.
=== Bug fixes in 1.22 ===
* Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
@@ -192,6 +194,7 @@
* (bug 48201) action=parse&text=foo now assumes wikitext if no title is given,
rather than using the content model of the page "API".
* action=watch may now return errors.
+* (bug 23005) Added action=revisiondelete.
=== Languages updated in 1.22===
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 6f8cd4b..b890e81 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -422,6 +422,7 @@
'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',
'ApiQueryWatchlistRaw' => 'includes/api/ApiQueryWatchlistRaw.php',
'ApiResult' => 'includes/api/ApiResult.php',
+ 'ApiRevisiondelete' => 'includes/api/ApiRevisiondelete.php',
'ApiRollback' => 'includes/api/ApiRollback.php',
'ApiRsd' => 'includes/api/ApiRsd.php',
'ApiSetNotificationTimestamp' =>
'includes/api/ApiSetNotificationTimestamp.php',
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 5ddb3ab..fce158f 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -84,6 +84,7 @@
'userrights' => 'ApiUserrights',
'options' => 'ApiOptions',
'imagerotate' => 'ApiImageRotate',
+ 'revisiondelete' => 'ApiRevisiondelete',
);
/**
diff --git a/includes/api/ApiRevisiondelete.php
b/includes/api/ApiRevisiondelete.php
new file mode 100644
index 0000000..fa6e4e6
--- /dev/null
+++ b/includes/api/ApiRevisiondelete.php
@@ -0,0 +1,241 @@
+<?php
+/**
+ * Created on Jun 25, 2013
+ *
+ * Copyright © 2013 Brad Jorsch <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @since 1.22
+ */
+
+/**
+ * API interface to RevDel. The API equivalent of Special:RevisionDelete.
+ * Requires API write mode to be enabled.
+ *
+ * @ingroup API
+ */
+class ApiRevisiondelete extends ApiBase {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $user = $this->getUser();
+
+ if ( !$user->isAllowed( RevisionDeleter::getRestriction(
$params['type'] ) ) ) {
+ $this->dieUsageMsg( 'badaccess-group0' );
+ }
+
+ if ( !$params['ids'] ) {
+ $this->dieUsage( "At least one value is required for
'ids'", 'badparams' );
+ }
+
+ $bits = array(
+ 'content' => RevisionDeleter::getRevdelConstant(
$params['type'] ),
+ 'comment' => Revision::DELETED_COMMENT,
+ 'user' => Revision::DELETED_USER,
+ );
+ $hide = $params['hide'] ?: array();
+ $show = $params['show'] ?: array();
+ if ( $hide && $show && array_intersect( $hide, $show ) ) {
+ $this->dieUsage( "Mutually exclusive values for 'hide'
and 'show'", 'badparams' );
+ }
+ if ( !$hide && !$show ) {
+ $this->dieUsage( "At least one value is required for
'hide' or 'show'", 'badparams' );
+ }
+ $bitfield = array();
+ foreach ( $bits as $key => $bit ) {
+ if ( in_array( $key, $hide ) ) {
+ $bitfield[$bit] = 1;
+ } elseif ( in_array( $key, $show ) ) {
+ $bitfield[$bit] = 0;
+ } else {
+ $bitfield[$bit] = -1;
+ }
+ }
+
+ if ( $params['suppress'] === 'yes' ) {
+ if ( !$user->isAllowed( 'suppressrevision' ) ) {
+ $this->dieUsageMsg( 'badaccess-group0' );
+ }
+ $bitfield[Revision::DELETED_RESTRICTED] = 1;
+ } elseif ( $params['suppress'] === 'no' ) {
+ $bitfield[Revision::DELETED_RESTRICTED] = 0;
+ } else {
+ $bitfield[Revision::DELETED_RESTRICTED] = -1;
+ }
+
+ $targetObj = null;
+ if ( $params['target'] ) {
+ $targetObj = Title::newFromText( $params['target'] );
+ }
+ $targetObj = RevisionDeleter::suggestTarget( $params['type'],
$targetObj, $params['ids'] );
+ if ( $targetObj === null ) {
+ $this->dieUsage( 'A target title is required for this
RevDel type', 'needtarget' );
+ }
+
+ $list = RevisionDeleter::createList(
+ $params['type'], $this->getContext(), $targetObj,
$params['ids']
+ );
+ $status = $list->setVisibility(
+ array( 'value' => $bitfield, 'comment' =>
$params['reason'], 'perItemStatus' => true )
+ );
+
+ $result = $this->getResult();
+ $data = $this->extractStatusInfo( $status );
+ $data['target'] = $targetObj->getFullText();
+ $data['items'] = array();
+ foreach ( $status->itemStatuses as $id => $s ) {
+ $data['items'][$id] = $this->extractStatusInfo( $s );
+ $data['items'][$id]['id'] = $id;
+ }
+ $list->reloadFromMaster();
+ for ( $list->reset(); $list->current(); $list->next() ) {
+ $item = $list->current();
+ $i = $item->getApiData( $this->getResult() );
+ $data['items'][$item->getId()] +=
$list->current()->getApiData( $this->getResult() );
+ }
+ $data['items'] = array_values( $data['items'] );
+ $result->setIndexedTagName( $data['items'], 'i' );
+ $result->addValue( null, $this->getModuleName(), $data );
+ }
+
+ private function extractStatusInfo( $status ) {
+ $ret = array(
+ 'status' => $status->isOK() ? 'Success' : 'Fail',
+ );
+ $errors = $this->formatStatusMessages(
$status->getErrorsByType( 'error' ) );
+ if ( $errors ) {
+ $this->getResult()->setIndexedTagName( $errors, 'e' );
+ $ret['errors'] = $errors;
+ }
+ $warnings = $this->formatStatusMessages(
$status->getErrorsByType( 'warning' ) );
+ if ( $warnings ) {
+ $this->getResult()->setIndexedTagName( $warnings, 'w' );
+ $ret['warnings'] = $warnings;
+ }
+ return $ret;
+ }
+
+ private function formatStatusMessages( $messages ) {
+ if ( !$messages ) {
+ return array();
+ }
+ $result = $this->getResult();
+ $ret = array();
+ foreach ( $messages as $m ) {
+ $message = array( 'message' => $m['message'] );
+ $msg = wfMessage( $m['message'] )->useDatabase( false
)->inLanguage( 'en' );
+ if ( isset( $m['params'] ) ) {
+ $message['params'] = $m['params'];
+ $result->setIndexedTagName( $message['params'],
'p' );
+ $msg->params( $m['params'] );
+ }
+ $message['rendered'] = $msg->plain();
+ $ret[] = $message;
+ }
+ return $ret;
+ }
+
+ public function mustBePosted() {
+ return true;
+ }
+
+ public function isWriteMode() {
+ return true;
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'type' => array(
+ ApiBase::PARAM_TYPE =>
RevisionDeleter::getTypes(),
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'target' => null,
+ 'ids' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'hide' => array(
+ ApiBase::PARAM_TYPE => array( 'content',
'comment', 'user' ),
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ 'show' => array(
+ ApiBase::PARAM_TYPE => array( 'content',
'comment', 'user' ),
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ 'suppress' => array(
+ ApiBase::PARAM_TYPE => array( 'yes', 'no',
'nochange' ),
+ ApiBase::PARAM_DFLT => 'nochange',
+ ),
+ 'token' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'reason' => null,
+ );
+ }
+
+ public function getParamDescription() {
+ $p = $this->getModulePrefix();
+ return array(
+ 'type' => 'Type of revision deletion being performed',
+ 'target' => 'Page title for the revision deletion, if
required for the type',
+ 'ids' => 'Identifiers for the revisions to be deleted',
+ 'hide' => 'What to hide for each revision',
+ 'show' => 'What to unhide for each revision',
+ 'suppress' => 'Whether to suppress data from
administrators as well as others',
+ 'token' => 'A delete token previously retrieved through
action=tokens',
+ 'reason' => 'Reason for the deletion/undeletion',
+ );
+ }
+
+ public function getDescription() {
+ return 'Delete/undelete revisions';
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(),
+ array(
+ 'needtarget' => 'A target title is required for
this RevDel type',
+ 'badparams' => "Mutually exclusive values for
'hide' and 'show'",
+ 'badparams' => "At least one value is required
for 'hide' or 'show'",
+ 'badparams' => "At least one value is required
for 'ids'",
+ )
+ );
+ }
+
+ public function needsToken() {
+ return true;
+ }
+
+ public function getTokenSalt() {
+ return '';
+ }
+
+ public function getExamples() {
+ return array(
+
'api.php?action=revisiondelete&title=Main%20Page&type=revision&ids=12345&hide=content&token=123ABC'
+ => 'Hide content for revision 12345 on the Main Page',
+
'api.php?action=revisiondelete&type=logging&ids=67890&hide=content|comment|user&reason=BLP%20violation&token=123ABC'
+ => 'Hide all data on log entry 67890 with the reason
"BLP violation"',
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Revisiondelete';
+ }
+}
diff --git a/includes/revisiondelete/RevisionDelete.php
b/includes/revisiondelete/RevisionDelete.php
index 68e4e60..e5d1e45 100644
--- a/includes/revisiondelete/RevisionDelete.php
+++ b/includes/revisiondelete/RevisionDelete.php
@@ -279,6 +279,30 @@
}
return "<li>$difflink $revlink $userlink $comment</li>";
}
+
+ public function getApiData( ApiResult $result ) {
+ $rev = $this->revision;
+ $user = $this->list->getUser();
+ $ret = array(
+ 'id' => $rev->getId(),
+ 'timestamp' => wfTimestamp( TS_ISO_8601,
$rev->getTimestamp() ),
+ );
+ $ret += $rev->isDeleted( Revision::DELETED_USER ) ? array(
'userhidden' => '' ) : array();
+ $ret += $rev->isDeleted( Revision::DELETED_COMMENT ) ? array(
'commenthidden' => '' ) : array();
+ $ret += $rev->isDeleted( Revision::DELETED_TEXT ) ? array(
'texthidden' => '' ) : array();
+ if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
+ $ret += array(
+ 'userid' => $rev->getUser(
Revision::FOR_THIS_USER ),
+ 'user' => $rev->getUserText(
Revision::FOR_THIS_USER ),
+ );
+ }
+ if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
+ $ret += array(
+ 'comment' => $rev->getComment(
Revision::FOR_THIS_USER ),
+ );
+ }
+ return $ret;
+ }
}
/**
@@ -696,6 +720,50 @@
return '<li>' . $this->getLink() . ' ' . $this->getUserTools()
. ' ' .
$data . ' ' . $this->getComment() . '</li>';
}
+
+ public function getApiData( ApiResult $result ) {
+ $file = $this->file;
+ $user = $this->list->getUser();
+ $ret = array(
+ 'title' => $this->list->title->getPrefixedText(),
+ 'archivename' => $file->getArchiveName(),
+ 'timestamp' => wfTimestamp( TS_ISO_8601,
$file->getTimestamp() ),
+ 'width' => $file->getWidth(),
+ 'height' => $file->getHeight(),
+ 'size' => $file->getSize(),
+ );
+ $ret += $file->isDeleted( Revision::DELETED_USER ) ? array(
'userhidden' => '' ) : array();
+ $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array(
'commenthidden' => '' ) : array();
+ $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) :
array();
+ if ( !$this->isDeleted() ) {
+ $ret += array(
+ 'url' => $file->getUrl(),
+ );
+ } elseif ( $this->canViewContent() ) {
+ $ret += array(
+ 'url' => SpecialPage::getTitleFor(
'Revisiondelete' )->getLinkURL(
+ array(
+ 'target' =>
$this->list->title->getPrefixedText(),
+ 'file' =>
$file->getArchiveName(),
+ 'token' => $user->getEditToken(
$file->getArchiveName() )
+ ),
+ false, PROTO_RELATIVE
+ ),
+ );
+ }
+ if ( $file->userCan( Revision::DELETED_USER, $user ) ) {
+ $ret += array(
+ 'userid' => $file->user,
+ 'user' => $file->user_text,
+ );
+ }
+ if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) {
+ $ret += array(
+ 'comment' => $file->description,
+ );
+ }
+ return $ret;
+ }
}
/**
@@ -950,4 +1018,41 @@
return "<li>$loglink $date $action $comment</li>";
}
+
+ public function getApiData( ApiResult $result ) {
+ $logEntry = DatabaseLogEntry::newFromRow( $this->row );
+ $user = $this->list->getUser();
+ $ret = array(
+ 'id' => $logEntry->getId(),
+ 'type' => $logEntry->getType(),
+ 'action' => $logEntry->getSubtype(),
+ );
+ $ret += $logEntry->isDeleted( LogPage::DELETED_USER ) ? array(
'userhidden' => '' ) : array();
+ $ret += $logEntry->isDeleted( LogPage::DELETED_COMMENT ) ?
array( 'commenthidden' => '' ) : array();
+ $ret += $logEntry->isDeleted( LogPage::DELETED_ACTION ) ?
array( 'actionhidden' => '' ) : array();
+
+ if ( LogEventsList::userCan( $this->row,
LogPage::DELETED_ACTION, $user ) ) {
+ ApiQueryLogEvents::addLogParams(
+ $result,
+ $ret,
+ $logEntry->getParameters(),
+ $logEntry->getType(),
+ $logEntry->getSubtype(),
+ $logEntry->getTimestamp(),
+ $logEntry->isLegacy()
+ );
+ }
+ if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER,
$user ) ) {
+ $ret += array(
+ 'userid' => $this->row->log_user,
+ 'user' => $this->row->log_user_text,
+ );
+ }
+ if ( LogEventsList::userCan( $this->row,
LogPage::DELETED_COMMENT, $user ) ) {
+ $ret += array(
+ 'comment' => $this->row->log_comment,
+ );
+ }
+ return $ret;
+ }
}
diff --git a/includes/revisiondelete/RevisionDeleteAbstracts.php
b/includes/revisiondelete/RevisionDeleteAbstracts.php
index 59118bc..f69390a 100644
--- a/includes/revisiondelete/RevisionDeleteAbstracts.php
+++ b/includes/revisiondelete/RevisionDeleteAbstracts.php
@@ -80,13 +80,16 @@
* transactions are done here.
*
* @param array $params Associative array of parameters. Members are:
- * value: The integer value to set the visibility to
- * comment: The log comment.
+ * value: The integer value to set the visibility to
+ * comment: The log comment.
+ * perItemStatus: Set if you want per-item status reports
* @return Status
+ * @since 1.22 Added 'perItemStatus' param
*/
public function setVisibility( $params ) {
$bitPars = $params['value'];
$comment = $params['comment'];
+ $perItemStatus = $params['perItemStatus'] || false;
$this->res = false;
$dbw = wfGetDB( DB_MASTER );
@@ -98,16 +101,27 @@
$idsForLog = array();
$authorIds = $authorIPs = array();
+ if ( $perItemStatus ) {
+ $status->itemStatuses = array();
+ }
+
for ( $this->reset(); $this->current(); $this->next() ) {
$item = $this->current();
unset( $missing[$item->getId()] );
+
+ if ( $perItemStatus ) {
+ $itemStatus = Status::newGood();
+ $status->itemStatuses[$item->getId()] =
$itemStatus;
+ } else {
+ $itemStatus = $status;
+ }
$oldBits = $item->getBits();
// Build the actual new rev_deleted bitfield
$newBits = RevisionDeleter::extractBitfield( $bitPars,
$oldBits );
if ( $oldBits == $newBits ) {
- $status->warning( 'revdelete-no-change',
$item->formatDate(), $item->formatTime() );
+ $itemStatus->warning( 'revdelete-no-change',
$item->formatDate(), $item->formatTime() );
$status->failCount++;
continue;
} elseif ( $oldBits == 0 && $newBits != 0 ) {
@@ -120,7 +134,7 @@
if ( $item->isHideCurrentOp( $newBits ) ) {
// Cannot hide current version text
- $status->error( 'revdelete-hide-current',
$item->formatDate(), $item->formatTime() );
+ $itemStatus->error( 'revdelete-hide-current',
$item->formatDate(), $item->formatTime() );
$status->failCount++;
continue;
}
@@ -128,13 +142,13 @@
// Cannot access this revision
$msg = ( $opType == 'show' ) ?
'revdelete-show-no-access' :
'revdelete-modify-no-access';
- $status->error( $msg, $item->formatDate(),
$item->formatTime() );
+ $itemStatus->error( $msg, $item->formatDate(),
$item->formatTime() );
$status->failCount++;
continue;
}
// Cannot just "hide from Sysops" without hiding any
fields
if ( $newBits == Revision::DELETED_RESTRICTED ) {
- $status->warning( 'revdelete-only-restricted',
$item->formatDate(), $item->formatTime() );
+ $itemStatus->warning(
'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
$status->failCount++;
continue;
}
@@ -151,19 +165,22 @@
$authorIPs[] = $item->getAuthorName();
}
} else {
- $status->error( 'revdelete-concurrent-change',
$item->formatDate(), $item->formatTime() );
+ $itemStatus->error(
'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
$status->failCount++;
}
}
// Handle missing revisions
foreach ( $missing as $id => $unused ) {
- $status->error( 'revdelete-modify-missing', $id );
+ if ( $perItemStatus ) {
+ $status->itemStatuses[$id] = Status::newFatal(
'revdelete-modify-missing', $id );
+ } else {
+ $status->error( 'revdelete-modify-missing', $id
);
+ }
$status->failCount++;
}
if ( $status->successCount == 0 ) {
- $status->ok = false;
$dbw->rollback( __METHOD__ );
return $status;
}
@@ -325,4 +342,12 @@
* @return boolean success
*/
abstract public function setBits( $newBits );
+
+ /**
+ * Get the return information about the revision for the API
+ * @since 1.22
+ * @param ApiResult $result API result object
+ * @return array Data for the API result
+ */
+ abstract public function getApiData( ApiResult $result );
}
--
To view, visit https://gerrit.wikimedia.org/r/70749
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee146fed648603b86a35927518f850771fc69bd2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits