Merge branch '5.3'
authorMatthias Schmidt <gravatronics@live.com>
Thu, 15 Apr 2021 05:23:59 +0000 (07:23 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 15 Apr 2021 05:23:59 +0000 (07:23 +0200)
1  2 
wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueActivationAction.class.php
wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueReportAction.class.php
wcfsetup/install/files/style/bbcode/code.scss

index 4e112a11342e63197531336f371919f65a90cf0a,d3610da40fcdbcbcb3e25109be694037a5ae234c..3d02f8963f322772d25fb18c5e88b2258a8458bf
@@@ -10,133 -5,63 +10,137 @@@ use wcf\util\StringUtil
  
  /**
   * Executes actions for reports.
 - * 
 - * @author    Alexander Ebert
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @package   WoltLabSuite\Core\Data\Moderation\Queue
 + *
 + * @author  Alexander Ebert
 + * @copyright   2001-2019 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @package WoltLabSuite\Core\Data\Moderation\Queue
   */
 -class ModerationQueueActivationAction extends ModerationQueueAction {
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $allowGuestAccess = ['enableContent', 'removeContent'];
 -      
 -      /**
 -       * moderation queue editor object
 -       * @var ModerationQueueEditor
 -       */
 -      public $queue = null;
 -      
 -      /**
 -       * Validates parameters to enable content.
 -       */
 -      public function validateEnableContent() {
 -              $this->queue = $this->getSingleObject();
 -              if (!$this->queue->canEdit()) {
 -                      throw new PermissionDeniedException();
 -              }
 -      }
 -      
 -      /**
 -       * Enables content.
 -       */
 -      public function enableContent() {
 -              // enable content
 -              ModerationQueueActivationManager::getInstance()->enableContent($this->queue->getDecoratedObject());
 -              
 -              $this->queue->markAsConfirmed();
 -      }
 -      
 -      /**
 -       * Validates parameters to delete reported content.
 -       */
 -      public function validateRemoveContent() {
 -              $this->readString('message', true);
 -              $this->validateEnableContent();
 -              
 -              if (!ModerationQueueActivationManager::getInstance()->canRemoveContent($this->queue->getDecoratedObject())) {
 -                      throw new PermissionDeniedException();
 -              }
 -      }
 -      
 -      /**
 -       * Deletes reported content.
 -       */
 -      public function removeContent() {
 -              // mark content as deleted
 -              ModerationQueueActivationManager::getInstance()->removeContent($this->queue->getDecoratedObject(), $this->parameters['message']);
 -              
 -              $this->queue->markAsRejected();
 -      }
 +class ModerationQueueActivationAction extends ModerationQueueAction
 +{
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $allowGuestAccess = ['enableContent', 'removeContent'];
 +
 +    /**
 +     * moderation queue editor object
 +     * @var ModerationQueueEditor
 +     */
 +    public $queue;
 +
 +    /**
 +     * Validates parameters to enable content.
 +     */
 +    public function validateEnableContent()
 +    {
 +        if (empty($this->objects)) {
 +            $this->readObjects();
 +
 +            if (empty($this->objects)) {
 +                throw new UserInputException('objectIDs');
 +            }
 +        }
 +
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            if (!$moderationQueueEditor->canEdit()) {
 +                throw new PermissionDeniedException();
 +            }
 +        }
 +    }
 +
 +    /**
 +     * Enables content.
 +     */
 +    public function enableContent()
 +    {
 +        WCF::getDB()->beginTransaction();
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            ModerationQueueActivationManager::getInstance()->enableContent(
 +                $moderationQueueEditor->getDecoratedObject()
 +            );
 +
 +            $moderationQueueEditor->markAsConfirmed();
 +        }
 +        WCF::getDB()->commitTransaction();
 +
 +        $this->unmarkItems();
 +    }
 +
 +    /**
 +     * Validates parameters to delete reported content.
 +     */
 +    public function validateRemoveContent()
 +    {
 +        $this->readString('message', true);
 +        $this->validateEnableContent();
++
++        if (!ModerationQueueActivationManager::getInstance()->canRemoveContent($this->queue->getDecoratedObject())) {
++            throw new PermissionDeniedException();
++        }
 +    }
 +
 +    /**
 +     * Deletes reported content.
 +     */
 +    public function removeContent()
 +    {
 +        // mark content as deleted
 +        ModerationQueueActivationManager::getInstance()->removeContent(
 +            $this->queue->getDecoratedObject(),
 +            $this->parameters['message']
 +        );
 +
 +        $this->queue->markAsRejected();
 +
 +        $this->unmarkItems();
 +    }
 +
 +    /**
 +     * Validates the `removeActivationContent` action.
 +     *
 +     * @since   5.4
 +     */
 +    public function validateRemoveActivationContent(): void
 +    {
 +        if (empty($this->objects)) {
 +            $this->readObjects();
 +
 +            if (empty($this->objects)) {
 +                throw new UserInputException('objectIDs');
 +            }
 +        }
 +
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            if (
 +                !$moderationQueueEditor->canEdit()
 +                || !ModerationQueueActivationManager::getInstance()->canRemoveContent($moderationQueueEditor->getDecoratedObject())
 +            ) {
 +                throw new PermissionDeniedException();
 +            }
 +        }
 +
 +        $this->parameters['message'] = StringUtil::trim($this->parameters['message'] ?? '');
 +    }
 +
 +    /**
 +     * Deletes disabled content via clipboard.
 +     *
 +     * @since   5.4
 +     */
 +    public function removeActivationContent(): void
 +    {
 +        WCF::getDB()->beginTransaction();
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            ModerationQueueActivationManager::getInstance()->removeContent(
 +                $moderationQueueEditor->getDecoratedObject(),
 +                $this->parameters['message']
 +            );
 +
 +            $moderationQueueEditor->markAsConfirmed();
 +        }
 +        WCF::getDB()->commitTransaction();
 +
 +        $this->unmarkItems();
 +    }
  }
index 049c5e399dabad593130ee55c1f06ca26b204acc,8c18a9369d60353599d7fa07a9ea2ddb04e4bf68..b66ece5e6d9ef1022915a8df4d91d3822c39f17f
@@@ -10,271 -8,139 +10,275 @@@ use wcf\util\StringUtil
  
  /**
   * Executes actions for reports.
 - * 
 - * @author    Alexander Ebert
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @package   WoltLabSuite\Core\Data\Moderation\Queue
 + *
 + * @author  Alexander Ebert
 + * @copyright   2001-2019 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @package WoltLabSuite\Core\Data\Moderation\Queue
   */
 -class ModerationQueueReportAction extends ModerationQueueAction {
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $allowGuestAccess = ['prepareReport', 'removeContent', 'removeReport', 'report'];
 -      
 -      /**
 -       * moderation queue editor object
 -       * @var ModerationQueueEditor
 -       */
 -      public $queue = null;
 -      
 -      /**
 -       * Validates parameters to delete reported content.
 -       */
 -      public function validateRemoveContent() {
 -              $this->validateRemoveReport();
 -              
 -              if (!ModerationQueueReportManager::getInstance()->canRemoveContent($this->queue->getDecoratedObject())) {
 -                      throw new PermissionDeniedException();
 -              }
 -              
 -              $this->parameters['message'] = (isset($this->parameters['message']) ? StringUtil::trim($this->parameters['message']) : '');
 -      }
 -      
 -      /**
 -       * Deletes reported content.
 -       */
 -      public function removeContent() {
 -              // mark content as deleted
 -              ModerationQueueReportManager::getInstance()->removeContent($this->queue->getDecoratedObject(), $this->parameters['message']);
 -              
 -              $this->queue->markAsConfirmed();
 -      }
 -      
 -      /**
 -       * Validates parameters to mark this report as done.
 -       */
 -      public function validateRemoveReport() {
 -              $this->queue = $this->getSingleObject();
 -              if (!$this->queue->canEdit()) {
 -                      throw new PermissionDeniedException();
 -              }
 -              
 -              $this->readBoolean('markAsJustified', true);
 -      }
 -      
 -      /**
 -       * Removes this report by marking it as done without further processing.
 -       */
 -      public function removeReport() {
 -              $this->queue->markAsRejected((isset($this->parameters['markAsJustified']) ? $this->parameters['markAsJustified'] : false));
 -      }
 -      
 -      /**
 -       * Validates parameters to prepare a report.
 -       */
 -      public function validatePrepareReport() {
 -              WCF::getSession()->checkPermissions(['user.profile.canReportContent']);
 -              
 -              $this->readInteger('objectID');
 -              $this->readString('objectType');
 -              
 -              if (!ModerationQueueReportManager::getInstance()->isValid($this->parameters['objectType'])) {
 -                      throw new UserInputException('objectType');
 -              }
 -              
 -              // validate the combination of object type and object id
 -              if (!ModerationQueueReportManager::getInstance()->isValid($this->parameters['objectType'], $this->parameters['objectID'])) {
 -                      throw new UserInputException('objectID');
 -              }
 -              
 -              // validate if user may read the content (prevent information disclosure by reporting random ids)
 -              if (!ModerationQueueReportManager::getInstance()->canReport($this->parameters['objectType'], $this->parameters['objectID'])) {
 -                      throw new PermissionDeniedException();
 -              }
 -      }
 -      
 -      /**
 -       * Prepares a report.
 -       */
 -      public function prepareReport() {
 -              // content was already reported
 -              $alreadyReported = ModerationQueueReportManager::getInstance()->hasPendingReport($this->parameters['objectType'], $this->parameters['objectID']) ? 1 : 0;
 -              
 -              WCF::getTPL()->assign([
 -                      'alreadyReported' => $alreadyReported,
 -                      'object' => ModerationQueueReportManager::getInstance()->getReportedObject($this->parameters['objectType'], $this->parameters['objectID'])
 -              ]);
 -              
 -              return [
 -                      'alreadyReported' => $alreadyReported,
 -                      'template' => WCF::getTPL()->fetch('moderationReportDialog')
 -              ];
 -      }
 -      
 -      /**
 -       * Validates parameters for reporting.
 -       */
 -      public function validateReport() {
 -              WCF::getSession()->checkPermissions(['user.profile.canReportContent']);
 -              
 -              $this->readString('message');
 -              if (mb_strlen($this->parameters['message']) > 64000) {
 -                      // we allow only up to 64.000 characters (~1.5 below TEXT maximum)
 -                      $this->parameters['message'] = mb_substr($this->parameters['messages'], 0, 64000);
 -              }
 -              
 -              $this->validatePrepareReport();
 -      }
 -      
 -      /**
 -       * Reports an item.
 -       */
 -      public function report() {
 -              // if the specified content was already reported, e.g. a different user reported this
 -              // item meanwhile, silently ignore it. Just display a success and the user is happy :)
 -              if (!ModerationQueueReportManager::getInstance()->hasPendingReport($this->parameters['objectType'], $this->parameters['objectID'])) {
 -                      ModerationQueueReportManager::getInstance()->addReport(
 -                              $this->parameters['objectType'],
 -                              $this->parameters['objectID'],
 -                              $this->parameters['message']
 -                      );
 -              }
 -              
 -              return [
 -                      'reported' => 1
 -              ];
 -      }
 +class ModerationQueueReportAction extends ModerationQueueAction
 +{
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $allowGuestAccess = ['prepareReport', 'removeContent', 'removeReport', 'report'];
 +
 +    /**
 +     * moderation queue editor object
 +     * @var ModerationQueueEditor
 +     */
 +    public $queue;
 +
 +    /**
 +     * Validates parameters to delete reported content.
 +     */
 +    public function validateRemoveContent()
 +    {
 +        $this->validateRemoveReport();
 +
++        if (!ModerationQueueReportManager::getInstance()->canRemoveContent($this->queue->getDecoratedObject())) {
++            throw new PermissionDeniedException();
++        }
++
 +        $this->parameters['message'] = (isset($this->parameters['message']) ? StringUtil::trim($this->parameters['message']) : '');
 +    }
 +
 +    /**
 +     * Deletes reported content.
 +     */
 +    public function removeContent()
 +    {
 +        // mark content as deleted
 +        ModerationQueueReportManager::getInstance()->removeContent(
 +            $this->queue->getDecoratedObject(),
 +            $this->parameters['message']
 +        );
 +
 +        $this->queue->markAsConfirmed();
 +
 +        $this->unmarkItems();
 +    }
 +
 +    /**
 +     * Validates parameters to mark this report as done.
 +     */
 +    public function validateRemoveReport()
 +    {
 +        if (empty($this->objects)) {
 +            $this->readObjects();
 +
 +            if (empty($this->objects)) {
 +                throw new UserInputException('objectIDs');
 +            }
 +        }
 +
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            if (!$moderationQueueEditor->canEdit()) {
 +                throw new PermissionDeniedException();
 +            }
 +        }
 +
 +        if (isset($this->parameters['data']['markAsJustified'])) {
 +            $this->readBoolean('markAsJustified', true, 'data');
 +
 +            // Clipboard passes `markAsJustified` in the `data` array.
 +            $this->parameters['markAsJustified'] = $this->parameters['data']['markAsJustified'];
 +        } else {
 +            $this->readBoolean('markAsJustified', true);
 +        }
 +    }
 +
 +    /**
 +     * Removes this report by marking it as done without further processing.
 +     */
 +    public function removeReport()
 +    {
 +        WCF::getDB()->beginTransaction();
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            $moderationQueueEditor->markAsRejected($this->parameters['markAsJustified'] ?? false);
 +        }
 +        WCF::getDB()->commitTransaction();
 +
 +        $this->unmarkItems();
 +    }
 +
 +    /**
 +     * Validates parameters to prepare a report.
 +     */
 +    public function validatePrepareReport()
 +    {
 +        WCF::getSession()->checkPermissions(['user.profile.canReportContent']);
 +
 +        $this->readInteger('objectID');
 +        $this->readString('objectType');
 +
 +        if (!ModerationQueueReportManager::getInstance()->isValid($this->parameters['objectType'])) {
 +            throw new UserInputException('objectType');
 +        }
 +
 +        // validate the combination of object type and object id
 +        if (
 +            !ModerationQueueReportManager::getInstance()->isValid(
 +                $this->parameters['objectType'],
 +                $this->parameters['objectID']
 +            )
 +        ) {
 +            throw new UserInputException('objectID');
 +        }
 +
 +        // validate if user may read the content (prevent information disclosure by reporting random ids)
 +        if (
 +            !ModerationQueueReportManager::getInstance()->canReport(
 +                $this->parameters['objectType'],
 +                $this->parameters['objectID']
 +            )
 +        ) {
 +            throw new PermissionDeniedException();
 +        }
 +    }
 +
 +    /**
 +     * Prepares a report.
 +     */
 +    public function prepareReport()
 +    {
 +        // content was already reported
 +        $alreadyReported = ModerationQueueReportManager::getInstance()->hasPendingReport(
 +            $this->parameters['objectType'],
 +            $this->parameters['objectID']
 +        ) ? 1 : 0;
 +
 +        WCF::getTPL()->assign([
 +            'alreadyReported' => $alreadyReported,
 +            'object' => ModerationQueueReportManager::getInstance()->getReportedObject(
 +                $this->parameters['objectType'],
 +                $this->parameters['objectID']
 +            ),
 +        ]);
 +
 +        return [
 +            'alreadyReported' => $alreadyReported,
 +            'template' => WCF::getTPL()->fetch('moderationReportDialog'),
 +        ];
 +    }
 +
 +    /**
 +     * Validates parameters for reporting.
 +     */
 +    public function validateReport()
 +    {
 +        WCF::getSession()->checkPermissions(['user.profile.canReportContent']);
 +
 +        $this->readString('message');
 +        if (\mb_strlen($this->parameters['message']) > 64000) {
 +            // we allow only up to 64.000 characters (~1.5 below TEXT maximum)
 +            $this->parameters['message'] = \mb_substr($this->parameters['messages'], 0, 64000);
 +        }
 +
 +        $this->validatePrepareReport();
 +    }
 +
 +    /**
 +     * Reports an item.
 +     */
 +    public function report()
 +    {
 +        // if the specified content was already reported, e.g. a different user reported this
 +        // item meanwhile, silently ignore it. Just display a success and the user is happy :)
 +        if (
 +            !ModerationQueueReportManager::getInstance()->hasPendingReport(
 +                $this->parameters['objectType'],
 +                $this->parameters['objectID']
 +            )
 +        ) {
 +            ModerationQueueReportManager::getInstance()->addReport(
 +                $this->parameters['objectType'],
 +                $this->parameters['objectID'],
 +                $this->parameters['message']
 +            );
 +        }
 +
 +        return [
 +            'reported' => 1,
 +        ];
 +    }
 +
 +    /**
 +     * Validates the `changeJustifiedStatus` action.
 +     *
 +     * @since   5.4
 +     */
 +    public function validateChangeJustifiedStatus(): void
 +    {
 +        $this->queue = $this->getSingleObject();
 +        if (!$this->queue->canEdit() || !$this->queue->canChangeJustifiedStatus()) {
 +            throw new PermissionDeniedException();
 +        }
 +
 +        $this->readBoolean('markAsJustified', true);
 +    }
 +
 +    /**
 +     * Updates the `markAsJustified` status.
 +     */
 +    public function changeJustifiedStatus(): void
 +    {
 +        $additionalData = $this->queue->additionalData;
 +        if (!\is_array($additionalData)) {
 +            $additionalData = [];
 +        }
 +        $additionalData['markAsJustified'] = $this->parameters['markAsJustified'];
 +
 +        $this->queue->update([
 +            'additionalData' => \serialize($additionalData),
 +        ]);
 +    }
 +
 +    /**
 +     * Validates the `removeReportContent` action.
 +     *
 +     * @since   5.4
 +     */
 +    public function validateRemoveReportContent(): void
 +    {
 +        if (empty($this->objects)) {
 +            $this->readObjects();
 +
 +            if (empty($this->objects)) {
 +                throw new UserInputException('objectIDs');
 +            }
 +        }
 +
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            if (
 +                !$moderationQueueEditor->canEdit()
 +                || !ModerationQueueReportManager::getInstance()->canRemoveContent($moderationQueueEditor->getDecoratedObject())
 +            ) {
 +                throw new PermissionDeniedException();
 +            }
 +        }
 +
 +        $this->parameters['message'] = StringUtil::trim($this->parameters['message'] ?? '');
 +    }
 +
 +    /**
 +     * Deletes reported content via clipboard.
 +     *
 +     * @since   5.4
 +     */
 +    public function removeReportContent(): void
 +    {
 +        WCF::getDB()->beginTransaction();
 +        foreach ($this->getObjects() as $moderationQueueEditor) {
 +            ModerationQueueReportManager::getInstance()->removeContent(
 +                $moderationQueueEditor->getDecoratedObject(),
 +                $this->parameters['message']
 +            );
 +
 +            $moderationQueueEditor->markAsConfirmed();
 +        }
 +        WCF::getDB()->commitTransaction();
 +
 +        $this->unmarkItems();
 +    }
  }
index 510d83918caab665ecc4ead090bd7663d8377fcf,f2bd7fbf8fc356f13392d19451f6ac98ee1a610b..a911de26859a1ef19ececf020f51a15fa4ad6096
                > .codeBoxHeadline {
                        flex: 1 1 auto;
                        padding: 0 10px;
 -                      
 +
                        @include wcfFontHeadline;
+                       @include screen-sm-down {
+                               overflow: auto;
+                               white-space: nowrap;
+                       }
+               }
+               .icon {
+                       flex: 0 0 auto;
                }
        }
 -      
 +
        .codeBoxCode {
                position: relative;
                padding-left: 7ch;