Show error message if article date is in the future
authorMarcel Werk <burntime@woltlab.com>
Fri, 29 Apr 2022 14:38:15 +0000 (16:38 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 29 Apr 2022 14:38:15 +0000 (16:38 +0200)
com.woltlab.wcf/templates/articleAdd.tpl
wcfsetup/install/files/acp/templates/articleAdd.tpl
wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php
wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php

index be093addca61e744a7efc38e61809b4efc4f1031..8406b9f0c66054f41745c8a276facbc2c1989165 100644 (file)
                                        <small class="innerError">
                                                {if $errorType == 'empty'}
                                                        {lang}wcf.global.form.error.empty{/lang}
+                                               {elseif $errorType == 'invalid'}
+                                                       {lang latestDate=TIME_NOW|plainTime}wcf.form.field.date.error.latestDate{/lang}
                                                {else}
                                                        {lang}wcf.acp.article.time.error.{@$errorType}{/lang}
                                                {/if}
index 6c7f059abd97f64b4b2fe23fc5602bba047bd1f8..7eb214f6ad1673c24ef8c5ea29a0d48308a99e5c 100644 (file)
                                        <small class="innerError">
                                                {if $errorType == 'empty'}
                                                        {lang}wcf.global.form.error.empty{/lang}
+                                               {elseif $errorType == 'invalid'}
+                                                       {lang latestDate=TIME_NOW|plainTime}wcf.form.field.date.error.latestDate{/lang}
                                                {else}
                                                        {lang}wcf.acp.article.time.error.{@$errorType}{/lang}
                                                {/if}
index 376f600539383b4d40dcfe6a80dfdf344862ac60..7b920038fa3d0f5e09dff769d38f5f004441e35c 100644 (file)
@@ -375,6 +375,9 @@ class ArticleAddForm extends AbstractForm
         if (empty($this->time) || !$this->timeObj) {
             throw new UserInputException('time');
         }
+        if ($this->timeObj->getTimestamp() > TIME_NOW && $this->publicationStatus == Article::PUBLISHED) {
+            throw new UserInputException('time', 'invalid');
+        }
 
         // publication status
         if ($this->publicationStatus != Article::UNPUBLISHED && $this->publicationStatus != Article::PUBLISHED && $this->publicationStatus != Article::DELAYED_PUBLICATION) {
@@ -488,7 +491,7 @@ class ArticleAddForm extends AbstractForm
         }
 
         $data = [
-            'time' => $this->getArticleTimestamp(),
+            'time' => $this->timeObj->getTimestamp(),
             'categoryID' => $this->categoryID,
             'publicationStatus' => $this->publicationStatus,
             'publicationDate' => $this->publicationStatus == Article::DELAYED_PUBLICATION ? $this->publicationDateObj->getTimestamp() : 0,
@@ -617,19 +620,4 @@ class ArticleAddForm extends AbstractForm
             'labelGroupsToCategories' => $this->labelGroupsToCategories,
         ]);
     }
-
-    /**
-     * Ensures that the date of a published article is not in the future.
-     *
-     * @since 5.5
-     */
-    protected function getArticleTimestamp(): int
-    {
-        $time = $this->timeObj->getTimestamp();
-        if ($time > \TIME_NOW && $this->publicationStatus == Article::PUBLISHED) {
-            $time = \TIME_NOW;
-        }
-
-        return $time;
-    }
 }
index e270ed7f4c745a2ce733cbd38d266586c434762f..10aee38e743ad5c2f218cc8345afc09b66f2bf44 100644 (file)
@@ -125,7 +125,7 @@ class ArticleEditForm extends ArticleAddForm
             'enableComments' => $this->enableComments,
             'userID' => $this->author->userID,
             'username' => $this->author->username,
-            'time' => $this->getArticleTimestamp(),
+            'time' => $this->timeObj->getTimestamp(),
             'hasLabels' => (isset($labelIDs[$this->article->articleID]) && !empty($labelIDs[$this->article->articleID])) ? 1 : 0,
         ];