jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371648 )

Change subject: Support editing previous revisions
......................................................................


Support editing previous revisions

Before, when a user attempted to edit a previous revision, an error
was thrown. This change adds support for attempting this action.

Bug: T173224
Change-Id: I8f1c1cde19391457a0fa71f082c5269fc1ddf4d9
---
M i18n/en.json
M i18n/qqq.json
M includes/NewsletterEditPage.php
3 files changed, 44 insertions(+), 31 deletions(-)

Approvals:
  Brian Wolff: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index a0ccb9a..c12678a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -14,8 +14,8 @@
        "newsletter-title": "Wiki page to be linked as Main page",
        "newsletter-exist-error": "A newsletter with the name \"$1\" already 
exists. Please try again with another name.",
        "newsletter-create-error": "An error occured while trying to create a 
new newsletter. Please try again.",
-       "newsletter-oldrev-update-error-title": "Sorry, this operation is not 
permitted.",
-       "newsletter-oldrev-update-error-body": "Editing a previous revision is 
not supported by the Newsletter extension. Please update the latest revision 
instead",
+       "newsletter-oldrev-undo-error-title": "Sorry, this operation is not 
permitted.",
+       "newsletter-oldrev-undo-error-body": "Undoing a previous revision is 
not supported by the Newsletter extension. Please undo the latest revision 
instead.",
        "newsletter-input-required": "Required input was not entered. Please 
try again.",
        "newsletter-invalid-name": "The name you entered for the newsletter is 
invalid. Please try again.",
        "newslettercreate": "Create newsletter",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index b604712..d8e47e8 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,8 +21,8 @@
        "newsletter-title": "Label of the field which takes the title of Main 
Page of newsletter as input in [[Special:CreateNewsletter]]",
        "newsletter-exist-error": "Error message to be displayed in 
[[Special:CreateNewsletter]] when trying to create a newsletter with same name 
as an existing newsletter. $1- Name of newsletter",
        "newsletter-create-error": "Error message shown on 
[[Special:CreateNewsletter]] if newsletter creation failed.",
-       "newsletter-oldrev-update-error-title": "Page title for error page 
shown on editing a previous revision",
-       "newsletter-oldrev-update-error-body": "Error description body for 
error page shown on editing a previous revision",
+       "newsletter-oldrev-undo-error-title": "Page title for error page shown 
when user attempts to undo a previous revision",
+       "newsletter-oldrev-undo-error-body": "Error description body for error 
page shown when user attempts to undo a previous revision",
        "newsletter-input-required": "Error message shown on 
[[Special:CreateNewsletter]] if required input is missing..",
        "newsletter-invalid-name": "Error message shown on 
[[Special:CreateNewsletter]] if the newsletter name is invalid.",
        "newslettercreate": "Name of [[Special:CreateNewsletter]]. This is used 
as the header on this page and shown in links to the page.",
diff --git a/includes/NewsletterEditPage.php b/includes/NewsletterEditPage.php
index 23d5b87..a6d9b79 100644
--- a/includes/NewsletterEditPage.php
+++ b/includes/NewsletterEditPage.php
@@ -43,16 +43,10 @@
                                        ->params( $this->newsletter->getName() )
                        );
 
-                       // We are not supporting editing a previous diff at 
this moment
-                       if ( $this->context->getRequest()->getVal( 'oldid' ) ) {
-                               throw new BadRequestError( 
'newsletter-oldrev-update-error-title',
-                                       'newsletter-oldrev-update-error-body'
-                               );
-                       }
-
                        $revId = $this->context->getRequest()->getVal( 
'undoafter', null );
                        $undoId = $this->context->getRequest()->getVal( 'undo', 
null );
-                       $this->getManageForm( $revId, $undoId )->show();
+                       $oldId = $this->context->getRequest()->getVal( 'oldid', 
null );
+                       $this->getManageForm( $revId, $undoId, $oldId )->show();
                } else {
                        $permErrors = $this->getPermissionErrors();
                        if ( count( $permErrors ) ) {
@@ -100,9 +94,10 @@
         *
         * @param int $revId
         * @param int $undoId
+        * @param int $oldId
         * @return HTMLForm
         */
-       protected function getManageForm( $revId, $undoId ) {
+       protected function getManageForm( $revId, $undoId, $oldId ) {
                $publishers = UserArray::newFromIDs( 
$this->newsletter->getPublishers() );
                $publishersNames = [];
 
@@ -139,27 +134,45 @@
                        'type' => 'hidden',
                        'default' => false,
                ];
-               if ( $revId && $undoId ) {
-                       $oldRevision = Revision::newFromId( $revId );
-                       $undoRevision = Revision::newFromId( $undoId );
-                       if ( $undoRevision->isCurrent()
-                               && $undoRevision->getContentModel() == 
'NewsletterContent'
-                               && $undoRevision->getContent() !== null
-                       ) {
+
+               // Ensure action is not editing the current revision
+               if ( ( $revId && $undoId ) || $oldId ) {
+                       // Editing a previous revision
+                       if ( $oldId ) {
+                               $oldRevision = Revision::newFromId( $oldId );
+                               if ( $oldRevision->getContentModel() === 
'NewsletterContent'
+                                       && $oldRevision->getContent() !== null 
) {
+                                       $fields['Summary']['default'] = '';
+                               }
+                       } elseif /* Undoing the latest revision */ ( $revId && 
$undoId ) {
+                               $oldRevision = Revision::newFromId( $revId );
+                               $undoRevision = Revision::newFromId( $undoId );
+                               if ( $undoRevision->isCurrent()
+                                       && $undoRevision->getContentModel() === 
'NewsletterContent'
+                                       && $undoRevision->getContent() !== null
+                               ) {
+                                       $fields['Summary']['default'] =
+                                               $this->context->msg( 
'undo-summary' )
+                                                       ->params( 
$undoRevision->getId(), $undoRevision->getUserText() )
+                                                       ->inContentLanguage()
+                                                       ->text();
+                               } else /* User attempts to undo prior revision 
*/ {
+                                       throw new BadRequestError(
+                                               
'newsletter-oldrev-undo-error-title',
+                                               
'newsletter-oldrev-undo-error-body'
+                                       );
+                               }
+                       }
+
+                       // Default fields are the same, regardless of action
+                       if ( $oldRevision->getContentModel() === 
'NewsletterContent'
+                               && $oldRevision->getContent() !== null ) {
                                $fields['MainPage']['default'] =
                                        
$oldRevision->getContent()->getMainPage()->getPrefixedText();
                                $fields['Description']['default'] = 
$oldRevision->getContent()->getDescription();
-                               $fields['Publishers']['default'] = 
$oldRevision->getContent()->getPublishers();
-                               $fields['Summary']['default'] =
-                                       $this->context->msg( 'undo-summary' )
-                                               ->params( 
$undoRevision->getId(), $undoRevision->getUserText() )
-                                               ->inContentLanguage()
-                                               ->text();
-                       } else {
-                               throw new BadRequestError(
-                                       'newsletter-oldrev-update-error-title',
-                                       'newsletter-oldrev-update-error-body'
-                               );
+                               // HTMLUsersMultiselectField expects a string, 
so we implode here
+                               $publisherNames = 
$oldRevision->getContent()->getPublishers();
+                               $fields['Publishers']['default'] = implode( 
"\n", $publishersNames );
                        }
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/371648
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8f1c1cde19391457a0fa71f082c5269fc1ddf4d9
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: MtDu <justin.d...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to