Sethakill has uploaded a new change for review. https://gerrit.wikimedia.org/r/296630
Change subject: [WIP] Allow users to change edit summary ...................................................................... [WIP] Allow users to change edit summary Bug: T15937 Change-Id: I1d715a160ec43b99eb8ff978ecb300e11046404b --- M includes/DefaultSettings.php A includes/actions/EditsummaryAction.php M includes/actions/HistoryAction.php A includes/logging/EditsummaryLogFormatter.php M languages/i18n/en.json 5 files changed, 252 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/30/296630/1 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 39e22a0..4d2e687 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5080,6 +5080,7 @@ $wgGroupPermissions['user']['sendemail'] = true; $wgGroupPermissions['user']['applychangetags'] = true; $wgGroupPermissions['user']['changetags'] = true; +$wgGroupPermissions['user']['editsummary'] = true; // Implicit group for accounts that pass $wgAutoConfirmAge $wgGroupPermissions['autoconfirmed']['autoconfirmed'] = true; @@ -7349,6 +7350,7 @@ 'tag', 'managetags', 'contentmodel', + 'editsummary', ]; /** @@ -7459,6 +7461,7 @@ 'delete/event' => 'DeleteLogFormatter', 'delete/restore' => 'DeleteLogFormatter', 'delete/revision' => 'DeleteLogFormatter', + 'editsummary/edit' => 'EditsummaryLogFormatter', 'import/interwiki' => 'ImportLogFormatter', 'import/upload' => 'ImportLogFormatter', 'managetags/activate' => 'LogFormatter', @@ -7615,6 +7618,7 @@ 'delete' => true, 'edit' => true, 'editchangetags' => 'SpecialPageAction', + 'editsummary' => true, 'history' => true, 'info' => true, 'markpatrolled' => true, diff --git a/includes/actions/EditsummaryAction.php b/includes/actions/EditsummaryAction.php new file mode 100644 index 0000000..26ebf44 --- /dev/null +++ b/includes/actions/EditsummaryAction.php @@ -0,0 +1,139 @@ +<?php +/** + * 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 + * + * @file + * @ingroup Actions + */ + +/** + * @ingroup Actions + */ +class EditsummaryAction extends FormAction { + /** @var Revision */ + protected $rev; + + /** @var int */ + protected $revId; + + /** @var RevisionList */ + protected $revsList; + + public function getName() { + return 'editsummary'; + } + + public function getRestriction() { + return 'editsummary'; + } + + public function getDescription() { + return Linker::linkKnown( + SpecialPage::getTitleFor( 'Log', 'editsummary' ), + $this->msg( 'viewpagelogs' )->escaped() + ); + } + + public function show() { + $this->checkCanExecute( $this->getUser() ); + + $revId = $this->getRequest()->getInt( 'id', -1 ); + $rev = Revision::newFromId( $revId ); + if ( $rev === null ) { + throw new ErrorPageError( 'Actionfailed', 'editsummary-error-invalidtarget' ); + } + + $revsList = new RevisionList( $this->getContext(), $rev->getTitle() ); + + if ( $rev->getUserText( Revision::RAW ) !== $this->getUser()->getName() || + // FIXME: Revision::getId() should return integer but it isn't. + intval( $revsList->reset()->getId() ) !== $revId || + $rev->isDeleted( Revision::DELETED_COMMENT ) + ) { + throw new ErrorPageError( 'Actionfailed', 'editsummary-error-revision' ); + } + + $this->rev = $rev; + $this->revId = $revId; + $this->revsList = $revsList; + + parent::show(); + } + + public function getFormFields() { + return [ + 'summary' => [ + 'type' => 'text', + 'label-message' => 'summary', + 'default' => $this->rev->getComment(), + 'maxlength' => 255, + ], + 'id' => [ + 'type' => 'hidden', + 'default' => $this->revId, + ] + ]; + } + + public function alterForm( $form ) { + $title = $this->rev->getTitle(); + $diff = $this->msg( 'editsummary-diff-text' ) + ->rawParams( Linker::linkKnown( $title, $title->getPrefixedText() ) ) + ->parseAsBlock() . + '<ul>' . $this->revsList->current()->getHTML() . '</ul>'; + + $form->addPreText( $diff ); + $form->setAction( $this->getTitle()->getLocalURL( [ + 'action' => $this->getName(), + 'id' => $this->revId, + ] ) ); + } + + public function onSubmit( $data ) { + $newSummary = $data['summary']; + $oldSummary = $this->rev->getComment(); + + if ( $newSummary === $oldSummary ) { + return Status::newFatal( 'editsummary-error-same' ); + } + + $dbr = wfGetDB( DB_MASTER ); + $dbr->update( + 'revision', [ 'rev_comment' => $newSummary ], + [ 'rev_id' => $this->revId ], __METHOD__ ); + + $logEntry = new ManualLogEntry( 'editsummary', 'edit' ); + $logEntry->setTarget( $this->rev->getTitle() ); + $logEntry->setPerformer( $this->getUser() ); + $logEntry->setParameters( [ + '4::oldSummary' => $oldSummary, + '5::newSummary' => $newSummary, + '6::revisionId' => $this->revId, + ] ); + $logid = $logEntry->insert(); + $logEntry->publish( $logid ); + + return true; + } + + public function onSuccess() { + $this->getOutput()->addWikiMsg( 'editsummary-success' ); + $this->getOutput()->returnToMain( false, $this->getTitle() ); + } + + public function doesWrites() { + return true; + } +} diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 700e201..a2982bd 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -743,6 +743,21 @@ $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>"; } } + if ( $latest && $user->isAllowed( 'editsummary' ) && + !$rev->isDeleted( Revision::DELETED_COMMENT ) && + $rev->getUserText( Revision::RAW ) === $this->getUser()->getName() + ) { + $editSummaryLink = Linker::linkKnown( + $this->getTitle(), + $this->msg( 'editsummary-text' )->escaped(), + [], + [ + 'action' => 'editsummary', + 'id' => $rev->getId(), + ] + ); + $tools[] = "<span class=\"mw-history-editsummary\">{$editSummaryLink}</span>"; + } // Allow extension to add their own links here Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] ); diff --git a/includes/logging/EditsummaryLogFormatter.php b/includes/logging/EditsummaryLogFormatter.php new file mode 100644 index 0000000..da3f96d --- /dev/null +++ b/includes/logging/EditsummaryLogFormatter.php @@ -0,0 +1,82 @@ +<?php +/** + * 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 + */ + +class EditsummaryLogFormatter extends LogFormatter { + public function getMessageParameters() { + $params = parent::getMessageParameters(); + $rev = Revision::newFromId( $params[5] ); + + $params[3] = $this->generateComment( $params[3], $rev ); + $params[4] = $this->generateComment( $params[4], $rev ); + + return $params; + } + + /** + * @param $comment + * @param Revision $revision + */ + public function generateComment( $comment, Revision $revision ) { + $comment = Linker::commentBlock( $params[$param] ); + $element = ltrim( $comment ); + $canView = $this->context->getUser()->isAllowed( 'deletedhistory' ); + + if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) { + if ( $canView ) { + $element = $this->styleRestricedElement( $element ); + } else { + $element = $this->getRestrictedElement( 'rev-deleted-comment' ); + } + } + + return $this->formatParameterValue( 'raw', $element ); + } + + public function getActionLinks() { + $params = $this->extractParameters(); + $links = []; + + $links[] = Linker::linkKnown( + $this->entry->getTarget(), + $this->msg( 'diff' )->escaped(), + [], + [ + 'diff' => $params[5], + 'unhide' => 1 + ] + ); + + if ( $this->context->getUser()->isAllowed( 'deletedhistory' ) ) { + $links[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Revisiondelete' ), + $this->msg( 'revdel-restore' )->escaped(), + [], + [ + 'target' => $this->entry->getTarget()->getPrefixedText(), + 'type' => 'revision', + 'ids' => $params[5], + ] + ); + } + + return $this->msg( 'parentheses' )->rawParams( + $this->context->getLanguage()->pipeList( $links ) )->escaped(); + } +} \ No newline at end of file diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 1de7b23..6f5db11 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -4187,5 +4187,16 @@ "linkaccounts-submit": "Link accounts", "unlinkaccounts": "Unlink accounts", "unlinkaccounts-success": "The account was unlinked.", - "authenticationdatachange-ignored": "The authentication data change was not handled. Maybe no provider was configured?" + "authenticationdatachange-ignored": "The authentication data change was not handled. Maybe no provider was configured?", + "action-editsummary": "change summary", + "editsummary-diff-text": "<strong>Selected revision of $1:</strong>", + "editsummary-error-invalidtarget": "You have either not specified any target revision on which to perform this function, or the specified revision does not exist.", + "editsummary-error-revision": "This is not current revision, or you are not the contributor of this revision, or summary was deleted.", + "editsummary-error-same": "Summaries are the same.", + "editsummary-success": "Summary updated.", + "editsummary-text": "change summary", + "log-name-editsummary": "Summary change log", + "log-description-editsummary": "", + "logentry-editsummary-edit": "$1 {{GENDER:$2|changed}} summary of a revision on page $3 from $4 to $5", + "right-editsummary": "Edit summary of the revision" } -- To view, visit https://gerrit.wikimedia.org/r/296630 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1d715a160ec43b99eb8ff978ecb300e11046404b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sethakill <sethak...@outlook.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits