コード例 #1
0
ファイル: ApiReview.php プロジェクト: schwarer2006/wikia
 /**
  * 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');
         }
     }
 }
コード例 #2
0
 public static function AjaxReview()
 {
     global $wgUser, $wgOut, $wgRequest;
     $args = func_get_args();
     if (wfReadOnly()) {
         return '<err#>' . wfMsgExt('revreview-failed', 'parseinline') . wfMsgExt('revreview-submission-invalid', 'parseinline');
     }
     $tags = FlaggedRevs::getTags();
     // Make review interface object
     $form = new RevisionReviewForm($wgUser);
     $title = null;
     // target page
     $editToken = '';
     // edit token
     // Each ajax url argument is of the form param|val.
     // This means that there is no ugly order dependance.
     foreach ($args as $arg) {
         $set = explode('|', $arg, 2);
         if (count($set) != 2) {
             return '<err#>' . wfMsgExt('revreview-failed', 'parseinline') . wfMsgExt('revreview-submission-invalid', 'parseinline');
         }
         list($par, $val) = $set;
         switch ($par) {
             case "target":
                 $title = Title::newFromURL($val);
                 break;
             case "oldid":
                 $form->setOldId($val);
                 break;
             case "refid":
                 $form->setRefId($val);
                 break;
             case "validatedParams":
                 $form->setValidatedParams($val);
                 break;
             case "templateParams":
                 $form->setTemplateParams($val);
                 break;
             case "imageParams":
                 $form->setFileParams($val);
                 break;
             case "fileVersion":
                 $form->setFileVersion($val);
                 break;
             case "wpApprove":
                 $form->setApprove($val);
                 break;
             case "wpUnapprove":
                 $form->setUnapprove($val);
                 break;
             case "wpReject":
                 $form->setReject($val);
                 break;
             case "wpReason":
                 $form->setComment($val);
                 break;
             case "changetime":
                 $form->setLastChangeTime($val);
                 break;
             case "wpEditToken":
                 $editToken = $val;
                 break;
             default:
                 $p = preg_replace('/^wp/', '', $par);
                 // kill any "wp" prefix
                 if (in_array($p, $tags)) {
                     $form->setDim($p, $val);
                 }
                 break;
         }
     }
     # Valid target title?
     if (!$title) {
         return '<err#>' . wfMsgExt('notargettext', 'parseinline');
     }
     $form->setPage($title);
     $form->setSessionKey($wgRequest->getSessionData('wsFlaggedRevsKey'));
     $status = $form->ready();
     // all params loaded
     # Check session via user token
     if (!$wgUser->matchEditToken($editToken)) {
         return '<err#>' . wfMsgExt('sessionfailure', 'parseinline');
     }
     # Basic permission checks...
     $permErrors = $title->getUserPermissionsErrors('review', $wgUser, false);
     if (!$permErrors) {
         $permErrors = $title->getUserPermissionsErrors('edit', $wgUser, false);
     }
     if ($permErrors) {
         return '<err#>' . $wgOut->parse($wgOut->formatPermissionsErrorMessage($permErrors, 'review'));
     }
     # Try submission...
     $status = $form->submit();
     # Success...
     if ($status === true) {
         # Sent new lastChangeTime TS to client for later submissions...
         $changeTime = $form->getNewLastChangeTime();
         if ($form->getAction() === 'approve') {
             // approve
             return "<suc#><lct#{$changeTime}>";
         } elseif ($form->getAction() === 'unapprove') {
             // de-approve
             return "<suc#><lct#{$changeTime}>";
         } elseif ($form->getAction() === 'reject') {
             // revert
             return "<suc#><lct#{$changeTime}>";
         }
         # Failure...
     } else {
         return '<err#>' . wfMsgExt('revreview-failed', 'parse') . '<p>' . wfMsgHtml($status) . '</p>';
     }
 }