Example #1
0
 /**
  * We have our own delete() function, since Article.php's implementation is split in two phases
  *
  * @param $page WikiPage object to work on
  * @param $user User doing the action
  * @param $token String: delete token (same as edit token)
  * @param $reason String: reason for the deletion. Autogenerated if NULL
  * @return Title::getUserPermissionsErrors()-like array
  */
 public static function delete(Page $page, User $user, $token, &$reason = null)
 {
     $title = $page->getTitle();
     $errors = self::getPermissionsError($title, $user, $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 = $page->getAutoDeleteReason($hasHistory);
         if ($reason === false) {
             return array(array('cannotdelete', $title->getPrefixedText()));
         }
     }
     $error = '';
     // Luckily, Article.php provides a reusable delete function that does the hard work for us
     if ($page->doDeleteArticle($reason, false, 0, true, $error)) {
         return array();
     } else {
         return array(array('cannotdelete', $title->getPrefixedText()));
     }
 }