Example #1
0
 /**
  * This function does essentially the same as RevisionReview::AjaxReview,
  * except that it generates the template and image parameters itself.
  */
 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     // Check basic permissions
     if (!$wgUser->isAllowed('review')) {
         $this->dieUsage("You don't have the right to review revisions.", 'permissiondenied');
     } elseif ($wgUser->isBlocked(false)) {
         $this->dieUsageMsg(array('blockedtext'));
     }
     // Get target rev and title
     $revid = (int) $params['revid'];
     $rev = Revision::newFromId($revid);
     if (!$rev) {
         $this->dieUsage("Cannot find a revision with the specified ID.", 'notarget');
     }
     $title = $rev->getTitle();
     // Construct submit form...
     $form = new RevisionReviewForm($wgUser);
     $form->setPage($title);
     $form->setOldId($revid);
     $form->setApprove(empty($params['unapprove']));
     $form->setUnapprove(!empty($params['unapprove']));
     if (isset($params['comment'])) {
         $form->setComment($params['comment']);
     }
     // The flagging parameters have the form 'flag_$name'.
     // Extract them and put the values into $form->dims
     foreach (FlaggedRevs::getTags() as $tag) {
         $form->setDim($tag, (int) $params['flag_' . $tag]);
     }
     if ($form->getAction() === 'approve') {
         $article = new FlaggableWikiPage($title);
         // Get the file version used for File: pages
         $file = $article->getFile();
         if ($file) {
             $fileVer = array('time' => $file->getTimestamp(), 'sha1' => $file->getSha1());
         } else {
             $fileVer = null;
         }
         // Now get the template and image parameters needed
         list($templateIds, $fileTimeKeys) = FRInclusionCache::getRevIncludes($article, $rev, $wgUser);
         // Get version parameters for review submission (flat strings)
         list($templateParams, $imageParams, $fileParam) = RevisionReviewForm::getIncludeParams($templateIds, $fileTimeKeys, $fileVer);
         // Set the version parameters...
         $form->setTemplateParams($templateParams);
         $form->setFileParams($imageParams);
         $form->setFileVersion($fileParam);
         $form->bypassValidationKey();
         // always OK; uses current templates/files
     }
     $status = $form->ready();
     // all params set
     # Try to do the actual review
     $status = $form->submit();
     # Approve/de-approve success
     if ($status === true) {
         $this->getResult()->addValue(null, $this->getModuleName(), array('result' => 'Success'));
         # Approve-specific failures
     } elseif ($form->getAction() === 'approve') {
         if ($status === 'review_denied') {
             $this->dieUsage("You don't have the necessary rights to set the specified flags.", 'permissiondenied');
         } elseif ($status === 'review_too_low') {
             $this->dieUsage("Either all or none of the flags have to be set to zero.", 'mixedapproval');
         } elseif ($status === 'review_bad_key') {
             $this->dieUsage("You don't have the necessary rights to set the specified flags.", 'permissiondenied');
         } elseif ($status === 'review_bad_tags') {
             $this->dieUsage("The specified flags are not valid.", 'invalidtags');
         } elseif ($status === 'review_bad_oldid') {
             $this->dieUsage("No revision with the specified ID.", 'notarget');
         } else {
             // FIXME: review_param_missing? better msg?
             $this->dieUsageMsg(array('unknownerror', ''));
         }
         # De-approve specific failure
     } elseif ($form->getAction() === 'unapprove') {
         if ($status === 'review_denied') {
             $this->dieUsage("You don't have the necessary rights to remove the flags.", 'permissiondenied');
         } elseif ($status === 'review_not_flagged') {
             $this->dieUsage("No flagged revision with the specified ID.", 'notarget');
         } else {
             // FIXME: review_param_missing? better msg?
             $this->dieUsageMsg(array('unknownerror', ''));
         }
         # Generic failures
     } else {
         if ($status === 'review_page_unreviewable') {
             $this->dieUsage("Provided page is not reviewable.", 'notreviewable');
         } elseif ($status === 'review_page_notexists') {
             $this->dieUsage("Provided page does not exist.", 'notarget');
         }
     }
 }