/** * Generates a brief review form for a page * @return array (html string, error string or true) */ public function getHtml() { global $wgLang; $revId = $this->rev->getId(); if ($this->rev->isDeleted(Revision::DELETED_TEXT)) { return array('', 'review_bad_oldid'); # The revision must be valid and public } $article = $this->article; // convenience $srev = $article->getStableRev(); # See if the version being displayed is flagged... if ($revId == $article->getStable()) { $frev = $srev; // avoid query } else { $frev = FlaggedRevision::newFromTitle($article->getTitle(), $revId); } $oldFlags = $frev ? $frev->getTags() : FlaggedRevs::quickTags(FR_CHECKED); // basic tags $reviewTime = $frev ? $frev->getTimestamp() : ''; // last review of rev $priorRevId = $this->refRev ? $this->refRev->getId() : 0; # If we are reviewing updates to a page, start off with the stable revision's # flags. Otherwise, we just fill them in with the selected revision's flags. # @TODO: do we want to carry over info for other diffs? if ($srev && $srev->getRevId() == $priorRevId) { // diff-to-stable $flags = $srev->getTags(); # Check if user is allowed to renew the stable version. # If not, then get the flags for the new revision itself. if (!FlaggedRevs::userCanSetFlags($this->user, $oldFlags)) { $flags = $oldFlags; } # Re-review button is need for template/file only review case $reviewIncludes = $srev->getRevId() == $revId && !$article->stableVersionIsSynced(); } else { // views $flags = $oldFlags; $reviewIncludes = false; // re-review button not needed } # Disable form for unprivileged users $disabled = array(); if (!$article->getTitle()->quickUserCan('review') || !FlaggedRevs::userCanSetFlags($this->user, $flags)) { $disabled = array('disabled' => 'disabled'); } # Begin form... $reviewTitle = SpecialPage::getTitleFor('RevisionReview'); $action = $reviewTitle->getLocalUrl('action=submit'); $params = array('method' => 'post', 'action' => $action, 'id' => 'mw-fr-reviewform'); $form = Xml::openElement('form', $params) . "\n"; $form .= Xml::openElement('fieldset', array('class' => 'flaggedrevs_reviewform noprint')) . "\n"; # Add appropriate legend text $legendMsg = $frev ? 'revreview-reflag' : 'revreview-flag'; $form .= Xml::openElement('legend', array('id' => 'mw-fr-reviewformlegend')); $form .= "<strong>" . wfMessage($legendMsg)->escaped() . "</strong>"; $form .= Xml::closeElement('legend') . "\n"; # Show explanatory text $form .= $this->topNotice; # Check if anyone is reviewing this already and # show a conflict warning message as needed... if ($priorRevId) { list($u, $ts) = FRUserActivity::getUserReviewingDiff($priorRevId, $this->rev->getId()); } else { list($u, $ts) = FRUserActivity::getUserReviewingPage($this->rev->getPage()); } $form .= Xml::openElement('p'); // Page under review (and not by this user)... if ($u !== null && $u != $this->user->getName()) { $form .= '<span class="fr-under-review">'; $msg = $priorRevId ? 'revreview-poss-conflict-c' : 'revreview-poss-conflict-p'; $form .= wfMessage($msg, $u, $wgLang->date($ts, true), $wgLang->time($ts, true))->parse(); $form .= "</span>"; // Page not under review or under review by this user... } elseif (!$frev) { // rev not already reviewed $form .= '<span id="mw-fr-reviewing-status" style="display:none;"></span>'; // JS widget } $form .= Xml::closeElement('p') . "\n"; # Start rating controls $css = $disabled ? 'fr-rating-controls-disabled' : 'fr-rating-controls'; $form .= Xml::openElement('p', array('class' => $css, 'id' => 'fr-rating-controls')) . "\n"; # Add main checkboxes/selects $form .= Xml::openElement('span', array('id' => 'mw-fr-ratingselects', 'class' => 'fr-rating-options')) . "\n"; $form .= self::ratingInputs($this->user, $flags, (bool) $disabled, (bool) $frev) . "\n"; $form .= Xml::closeElement('span') . "\n"; # Don't put buttons & comment field on the same line as tag inputs. if (!$disabled && !FlaggedRevs::binaryFlagging()) { // $disabled => no comment/buttons $form .= "<br />"; } # Start comment & buttons $form .= Xml::openElement('span', array('id' => 'mw-fr-confirmreview')) . "\n"; # Hide comment input if needed if (!$disabled) { $form .= Xml::inputLabel(wfMessage('revreview-log')->text(), 'wpReason', 'mw-fr-commentbox', 40, '', array('maxlength' => 255, 'class' => 'fr-comment-box')); } # Add the submit buttons... $rejectId = $this->rejectRefRevId(); // determine if there will be reject button $form .= self::submitButtons($rejectId, $frev, (bool) $disabled, $reviewIncludes); # Show stability log if there is anything interesting... if ($article->isPageLocked()) { $form .= ' ' . FlaggedRevsXML::logToggle('revreview-log-toggle-show'); } # End comment & buttons $form .= Xml::closeElement('span') . "\n"; # ..add the actual stability log body here if ($article->isPageLocked()) { $form .= FlaggedRevsXML::stabilityLogExcerpt($article); } # End rating controls $form .= Xml::closeElement('p') . "\n"; # Show explanatory text $form .= $this->bottomNotice; # Get the file version used for File: pages as needed $fileKey = $this->getFileVersion(); # Get template/file version info as needed list($templateIDs, $imageSHA1Keys) = $this->getIncludeVersions(); # Convert these into flat string params list($templateParams, $imageParams, $fileVersion) = RevisionReviewForm::getIncludeParams($templateIDs, $imageSHA1Keys, $fileKey); # Hidden params $form .= Html::hidden('title', $reviewTitle->getPrefixedText()) . "\n"; $form .= Html::hidden('target', $article->getTitle()->getPrefixedDBKey()) . "\n"; $form .= Html::hidden('refid', $priorRevId, array('id' => 'mw-fr-input-refid')) . "\n"; $form .= Html::hidden('oldid', $revId, array('id' => 'mw-fr-input-oldid')) . "\n"; $form .= Html::hidden('wpEditToken', $this->user->getEditToken()) . "\n"; $form .= Html::hidden('changetime', $reviewTime, array('id' => 'mw-fr-input-changetime')) . "\n"; // id for JS $form .= Html::hidden('userreviewing', (int) ($u === $this->user->getName()), array('id' => 'mw-fr-user-reviewing')) . "\n"; // id for JS # Add review parameters $form .= Html::hidden('templateParams', $templateParams) . "\n"; $form .= Html::hidden('imageParams', $imageParams) . "\n"; $form .= Html::hidden('fileVersion', $fileVersion) . "\n"; # Special token to discourage fiddling... $key = $this->request->getSessionData('wsFlaggedRevsKey'); $checkCode = RevisionReviewForm::validationKey($templateParams, $imageParams, $fileVersion, $revId, $key); $form .= Html::hidden('validatedParams', $checkCode) . "\n"; $form .= Xml::closeElement('fieldset') . "\n"; $form .= Xml::closeElement('form') . "\n"; return array($form, true); }