MtDu has uploaded a new change for review. ( 
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, 14 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter 
refs/changes/48/371648/1

diff --git a/i18n/en.json b/i18n/en.json
index a0ccb9a..76ca162 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -14,8 +14,6 @@
        "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-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..3dc2818 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,8 +21,6 @@
        "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-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..3adc6de 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 = [];
 
@@ -155,11 +150,16 @@
                                                ->params( 
$undoRevision->getId(), $undoRevision->getUserText() )
                                                ->inContentLanguage()
                                                ->text();
-                       } else {
-                               throw new BadRequestError(
-                                       'newsletter-oldrev-update-error-title',
-                                       'newsletter-oldrev-update-error-body'
-                               );
+                       }
+               } else if ( $oldId ) {
+                       $oldRevision = Revision::newFromId( $oldId );
+                       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'] = '';
                        }
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f1c1cde19391457a0fa71f082c5269fc1ddf4d9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: MtDu <justin.d...@gmail.com>

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

Reply via email to