/** * We have our own delete() function, since Article.php's implementation is split in two phases * * @param Article $article - Article object to work on * @param string $token - Delete token (same as edit token) * @param string $reason - Reason for the deletion. Autogenerated if NULL * @return Title::getUserPermissionsErrors()-like array */ public static function delete(&$article, $token, &$reason = NULL) { global $wgUser; // Check permissions $errors = $article->mTitle->getUserPermissionsErrors('delete', $wgUser); if (!empty($errors)) { return $errors; } if (wfReadOnly()) { return array(array('readonlytext')); } if ($wgUser->isBlocked()) { return array(array('blocked')); } // Check token if (!$wgUser->matchEditToken($token)) { return array(array('sessionfailure')); } // Auto-generate a summary, if necessary if (is_null($reason)) { $reason = $article->generateReason($hasHistory); if ($reason === false) { return array(array('cannotdelete')); } } // Luckily, Article.php provides a reusable delete function that does the hard work for us if ($article->doDeleteArticle($reason)) { return array(); } return array(array('cannotdelete', $article->mTitle->getPrefixedText())); }
/** * We have our own delete() function, since Article.php's implementation is split in two phases * * @param Article $article - Article object to work on * @param string $token - Delete token (same as edit token) * @param string $reason - Reason for the deletion. Autogenerated if NULL * @return Title::getUserPermissionsErrors()-like array */ public static function delete(&$article, $token, &$reason = null) { global $wgUser; if ($article->isBigDeletion() && !$wgUser->isAllowed('bigdelete')) { global $wgDeleteRevisionsLimit; return array(array('delete-toobig', $wgDeleteRevisionsLimit)); } $title = $article->getTitle(); $errors = self::getPermissionsError($title, $token); if (count($errors)) { return $errors; } // Auto-generate a summary, if necessary if (is_null($reason)) { // Need to pass a throwaway variable because generateReason expects // a reference $hasHistory = false; $reason = $article->generateReason($hasHistory); if ($reason === false) { return array(array('cannotdelete')); } } $error = ''; if (!wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, $error))) { $this->dieUsageMsg(array('hookaborted', $error)); } // Luckily, Article.php provides a reusable delete function that does the hard work for us if ($article->doDeleteArticle($reason)) { wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $article->getId())); return array(); } return array(array('cannotdelete', $article->mTitle->getPrefixedText())); }
/** * We have our own delete() function, since Article.php's implementation is split in two phases * * @param Article $article - Article object to work on * @param string $token - Delete token (same as edit token) * @param string $reason - Reason for the deletion. Autogenerated if NULL * @return Title::getUserPermissionsErrors()-like array */ public static function delete(&$article, $token, $suppress, &$reason = NULL) { global $wgUser; $title = $article->getTitle(); $errors = self::getPermissionsError($title, $token, $suppress); if (count($errors)) { return $errors; } // Auto-generate a summary, if necessary if (is_null($reason)) { # Need to pass a throwaway variable because generateReason expects # a reference $hasHistory = false; $reason = $article->generateReason($hasHistory); if ($reason === false) { return array(array('cannotdelete')); } } if (!wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason))) { return array(array('hookaborted')); } // Luckily, Article.php provides a reusable delete function that does the hard work for us if ($article->doDeleteArticle($reason, $suppress)) { wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $article->getId())); return array(); } return array(array('cannotdelete', $article->mTitle->getPrefixedText())); }