use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
+use wcf\system\exception\ValidateActionException;
use wcf\system\WCF;
use wcf\util\ClassUtil;
use wcf\util\JSON;
throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->__getTraceAsString());
}
else if ($e instanceof UserInputException) {
- throw new AJAXException($e->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString());
+ // repackage as ValidationActionException
+ $exception = new ValidateActionException($e->getField(), $e->getType(), $e->getVariables());
+ throw new AJAXException($exception->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString(), array(
+ 'errorMessage' => $exception->getMessage(),
+ 'fieldName' => $exception->getFieldName()
+ ));
+ }
+ else if ($e instanceof ValidateActionException) {
+ throw new AJAXException($exception->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString(), array(
+ 'errorMessage' => $exception->getMessage(),
+ 'fieldName' => $exception->getFieldName()
+ ));
}
else {
throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString());
<?php
namespace wcf\data;
use wcf\system\event\EventHandler;
+use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
-use wcf\system\exception\ValidateActionException;
use wcf\system\WCF;
use wcf\util\ClassUtil;
use wcf\util\StringUtil;
public function validateAction() {
// validate if user is logged in
if (!WCF::getUser()->userID && !in_array($this->getActionName(), $this->allowGuestAccess)) {
- throw new ValidateActionException("Please login before executing this action");
+ throw new IllegalLinkException();
}
// validate action name
if (!method_exists($this, $this->getActionName())) {
- throw new ValidateActionException("unknown action '".$this->getActionName()."'");
+ throw new SystemException("unknown action '".$this->getActionName()."'");
}
$actionName = 'validate'.StringUtil::firstCharToUpperCase($this->getActionName());
if (!method_exists($this, $actionName)) {
- throw new ValidateActionException("validation of action '".$this->getActionName()."' failed");
+ throw new PermissionDeniedException();
}
// execute action
public function validateCreate() {
// validate permissions
if (is_array($this->permissionsCreate) && !empty($this->permissionsCreate)) {
- try {
- WCF::getSession()->checkPermissions($this->permissionsCreate);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsCreate);
}
else {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
public function validateDelete() {
// validate permissions
if (is_array($this->permissionsDelete) && !empty($this->permissionsDelete)) {
- try {
- WCF::getSession()->checkPermissions($this->permissionsDelete);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsDelete);
}
else {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
// read objects
$this->readObjects();
if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+ throw new UserInputException('objectIDs');
}
}
}
public function validateUpdate() {
// validate permissions
if (is_array($this->permissionsUpdate) && !empty($this->permissionsUpdate)) {
- try {
- WCF::getSession()->checkPermissions($this->permissionsUpdate);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsUpdate);
}
else {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
// read objects
$this->readObjects();
if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+ throw new UserInputException('objectIDs');
}
}
}
use wcf\system\category\CategoryHandler;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\SystemException;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\UserInputException;
use wcf\system\user\collapsible\content\UserCollapsibleContentHandler;
use wcf\system\WCF;
public function validateCreate() {
// validate permissions
if (!empty($this->permissionsCreate)) {
- try {
- WCF::getSession()->checkPermissions($this->permissionsCreate);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsCreate);
}
if (!isset($this->parameters['data']['objectTypeID'])) {
- throw new ValidateActionException("Missing 'objectTypeID' data parameter");
+ throw new UserInputException('objectTypeID');
}
$objectType = CategoryHandler::getInstance()->getObjectType($this->parameters['data']['objectTypeID']);
if ($objectType === null) {
- throw new ValidateActionException("Unknown category object type with id '".$this->parameters['data']['objectTypeID']."'");
+ throw new UserInputException('objectTypeID', 'notValid');
}
if (!$objectType->getProcessor()->canAddCategory()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
WCF::getSession()->checkPermissions($this->permissionsDelete);
}
catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
$this->readObjects();
if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+ throw new UserInputException('objectIDs');
}
}
foreach ($this->objects as $categoryEditor) {
if (!$categoryEditor->getCategoryType()->canDeleteCategory()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
public function validateUpdate() {
// validate permissions
if (!empty($this->permissionsUpdate)) {
- try {
- WCF::getSession()->checkPermissions($this->permissionsUpdate);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsUpdate);
}
// read objects
if (empty($this->objects)) {
$this->readObjects();
- }
-
- if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+
+ if (empty($this->objects)) {
+ throw new UserInputException('objectIDs');
+ }
}
foreach ($this->objects as $categoryEditor) {
if (!$categoryEditor->getCategoryType()->canEditCategory()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
WCF::getSession()->checkPermissions($this->permissionsUpdate);
}
catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
// validate 'structure' parameter
- if (!isset($this->parameters['data']['structure'])) {
- throw new ValidateActionException("Missing 'structure' parameter");
- }
- if (!is_array($this->parameters['data']['structure'])) {
- throw new ValidateActionException("'structure' parameter is no array");
+ if (!isset($this->parameters['data']['structure']) || !is_array($this->parameters['data']['structure'])) {
+ throw new UserInputException('structure');
}
// validate given category ids
// validate category
$category = CategoryHandler::getInstance()->getCategory($parentCategoryID);
if ($category === null) {
- throw new ValidateActionException("Unknown category with id '".$parentCategoryID."'");
+ throw new UserInputException('structure');
}
$this->objects[$category->categoryID] = new $this->className($category);
// validate permissions
if (!$category->getCategoryType()->canEditCategory()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
// validate category
$category = CategoryHandler::getInstance()->getCategory($categoryID);
if ($category === null) {
- throw new ValidateActionException("Unknown category with id '".$categoryID."'");
+ throw new UserInputException('structure');
}
$this->objects[$category->categoryID] = new $this->className($category);
// validate permissions
if (!$category->getCategoryType()->canEditCategory()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
use wcf\system\cronjob\CronjobScheduler;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
use wcf\util\DateUtil;
foreach ($this->objects as $cronjob) {
if (!$cronjob->isDeletable()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
foreach ($this->objects as $cronjob) {
if (!$cronjob->isEditable()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
foreach ($this->objects as $cronjob) {
if (!$cronjob->canBeDisabled()) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
}
namespace wcf\data\language;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/**
* Validates permission to set a language as default.
*/
public function validateSetAsDefault() {
- try {
- WCF::getSession()->checkPermissions($this->permissionsUpdate);
- }
- catch (PermissionDeniedException $e) {
- throw new ValidateActionException('Insufficient permissions');
- }
+ WCF::getSession()->checkPermissions($this->permissionsUpdate);
// read objects
if (empty($this->objects)) {
$this->readObjects();
if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+ throw new UserInputException('objectIDs');
}
}
}
<?php
namespace wcf\data\package;
use wcf\data\AbstractDatabaseObjectAction;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/**
*/
public function validateGetPluginList() {
if (!isset($this->parameters['activePage']) || !intval($this->parameters['activePage'])) {
- throw new ValidateActionException("Missing or invalid parameter 'activePage'");
+ throw new UserInputException('activePage');
}
}
namespace wcf\data\package\installation\queue;
use wcf\data\package\Package;
use wcf\data\AbstractDatabaseObjectAction;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/**
$this->package = new Package($this->packageID);
if (!$this->package->packageID) {
- throw new ValidateActionException('Invalid package id');
+ throw new UserInputException('packageID');
}
if (!isset($this->parameters['action']) || !in_array($this->parameters['action'], array('install', 'update', 'uninstall', 'rollback'))) {
- throw new ValidateActionException('Invalid or missing action');
+ throw new UserInputException('action');
}
}
use wcf\system\clipboard\ClipboardHandler;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\ValidateActionException;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\StringUtil;
*/
public function validateCreate() {
if (!isset($this->parameters['data']['password'])) {
- throw new ValidateActionException("Missing parameter 'password'");
+ throw new UserInputException('password');
}
}
// list might be empty because only our own user id was given
if (empty($userIDs)) {
- throw new ValidateActionException("Invalid object id");
+ throw new UserInputException('objectIDs');
}
// validate groups
}
if (!UserGroup::isAccessibleGroup($groupIDs)) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
$this->readObjects();
if (empty($this->objects)) {
- throw new ValidateActionException('Invalid object id');
+ throw new UserInputException('objectIDs');
}
}
if (count($this->objects) == 1 && ($this->objects[0]->userID == WCF::getUser()->userID)) {
$count = count($this->parameters);
if ($count > 1 || ($count == 1 && !isset($this->parameters['options']))) {
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
- throw new ValidateActionException('Insufficient permissions');
+ throw new PermissionDeniedException();
}
}
*/
public function validateGetSearchResultList() {
if (!isset($this->parameters['data']['searchString'])) {
- throw new ValidateActionException("Missing parameter 'searchString'");
+ throw new UserInputException('searchString');
}
if (!isset($this->parameters['data']['includeUserGroups'])) {
- throw new ValidateActionException("Missing parameter 'includeUserGroups'");
+ throw new UserInputException('includeUserGroups');
}
if (isset($this->parameters['data']['excludedSearchValues']) && !is_array($this->parameters['data']['excludedSearchValues'])) {
- throw new ValidateActionException("Invalid parameter 'excludedSearchValues' given");
+ throw new UserInputException('excludedSearchValues');
}
}
* @param string $message
* @param boolean $isDoomsday
* @param string $stacktrace
+ * @param array<mixed> $returnValues
*/
- public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null) {
+ public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array()) {
if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
if (WCF::debugModeIsEnabled()) {
}
$responseData['code'] = $errorType;
+ $responseData['returnValues'] = $returnValues;
+
$statusHeader = '';
switch ($errorType) {
case self::MISSING_PARAMETERS:
*/
protected $type = null;
+ /**
+ * variables for AJAX error handling
+ * @var array
+ */
+ protected $variables = array();
+
/**
* Creates a new UserInputException.
*
* @param string $field affected formular field
* @param string $type kind of this error
+ * @param array $variables additional variables for AJAX error handling
*/
- public function __construct($field = '', $type = 'empty') {
+ public function __construct($field = '', $type = 'empty', array $variables = array()) {
$this->field = $field;
$this->type = $type;
+ $this->variables = $variables;
$this->message = 'Parameter '.$field.' is missing or invalid';
parent::__construct();
public function getType() {
return $this->type;
}
+
+ /**
+ * Returns additional variables for AJAX error handling.
+ *
+ * @return array
+ */
+ public function getVariables() {
+ return $this->variables;
+ }
}
<?php
namespace wcf\system\exception;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
/**
* Simple exception for AJAX-driven requests.
* @category Community Framework
*/
class ValidateActionException extends \Exception {
+ /**
+ * error message
+ * @var string
+ */
+ protected $errorMessage = '';
+
+ /**
+ * erroneous field name
+ * @var string
+ */
+ protected $fieldName = '';
+
/**
* @see \Exception::__construct()
*/
- public function __construct($message) {
- $this->message = $message;
+ public function __construct($fieldName, $errorMessage = 'empty', array $variables = array()) {
+ $this->errorMessage = $errorMessage;
+ if (StringUtil::indexOf($this->errorMessage, '.') === false) {
+ $this->errorMessage = WCF::getLanguage()->get('wcf.global.form.error.'.$this->errorMessage);
+ }
+ else {
+ $this->errorMessage = WCF::getLanguage()->getDynamicVariable($this->errorMessage, $variables);
+ }
+
+ $this->fieldName = $fieldName;
+ $this->message = WCF::getLanguage()->getDynamicVariable('wcf.global.error.invalidParameter', array('fieldName' => $this->fieldName));
+ }
+
+ /**
+ * Returns error message.
+ *
+ * @return string
+ */
+ public function getErrorMessage() {
+ return $this->errorMessage;
+ }
+
+ /**
+ * Returns erroneous field name.
+ *
+ * @return string
+ */
+ public function getFieldName() {
+ return $this->fieldName;
}
/**