public function testLoadRevisionData() { $cases = $this->getLoadRevisionDataCases(); foreach ($cases as $case) { list($expectedOld, $expectedNew, $old, $new, $message) = $case; $diffEngine = new DifferenceEngine($this->context, $old, $new, 2, true, false); $diffEngine->loadRevisionData(); $this->assertEquals($diffEngine->getOldid(), $expectedOld, $message); $this->assertEquals($diffEngine->getNewid(), $expectedNew, $message); } }
function execute($par) { global $wgRequest, $wgOut; $t = Title::newFromText($wgRequest->getVal('target')); $wgOut->setArticleBodyOnly(true); if ($wgRequest->getVal('action') == 'permalink') { $result = array(); $result['title'] = $t; $result['rchi'] = $wgRequest->getVal('rchi'); $result['rclo'] = $wgRequest->getVal('rclow'); $result['rcid'] = $wgRequest->getVal('rcid'); $result['old'] = $wgRequest->getVal('old'); $result['new'] = $wgRequest->getVal('new'); $result['vandal'] = $wgRequest->getVal('vandal'); $result['rc_cur_id'] = $t->getArticleID(); $result = RCPatrolData::getListofEditors($result); $wgOut->addHTML("<div id='articletitle' style='display:none;'><a href='{$t->getLocalURL()}'>{$t->getFullText()}</a></div>"); $oldTitle = $this->getContext()->getTitle(); $this->getContext()->setTitle($result['title']); $d = new DifferenceEngine($this->getContext(), RCPatrol::cleanOldId($wgRequest->getVal('old')), $wgRequest->getVal('new'), $wgRequest->getVal('rcid')); $d->loadRevisionData(); $this->getContext()->setTitle($oldTitle); $wgOut->addHTML("<div id='rc_header' class='tool_header'>"); $wgOut->addHTML('<a href="#" id="rcpatrol_keys">Get Shortcuts</a>'); $wgOut->addHTML(RCPatrol::getButtons($result, $d->mNewRev)); $wgOut->addHTML("</div>"); $wgOut->addHTML('<div id="rcpatrol_info" style="display:none;">' . wfMessage('rcpatrol_keys')->text() . '</div>'); $d->showDiffPage(); $wgOut->disable(); $response['html'] = $wgOut->getHTML(); print_r(json_encode($response)); return; } $a = new Article($t); if (!$wgRequest->getVal('grabnext')) { if (class_exists('RCTest') && RCTest::isEnabled() && $wgRequest->getVal('rctest')) { // Don't do anything if it's a test } elseif (!$wgRequest->getVal('skip') && $wgRequest->getVal('action') == 'markpatrolled') { $this->markRevisionsPatrolled($a); } elseif ($wgRequest->getVal('skip')) { // skip the article for now RCPatrol::skipArticle($t->getArticleID()); } } $wgOut->clearHTML(); $wgOut->redirect(''); $result = RCPatrol::getNextArticleToPatrol($wgRequest->getVal('rcid')); $response = array(); if ($result) { $rcTest = null; $testHtml = ""; if (class_exists('RCTest') && RCTest::isEnabled()) { $rcTest = new RCTest(); $testHtml = $rcTest->getTestHtml(); /* Uncomment to debug rctest $response['testtime'] = $rcTest->isTestTime() ? 1 : 0; $response['totpatrol'] = $rcTest->getTotalPatrols(); $response['adjpatrol'] = $rcTest->getAdjustedPatrolCount(); global $wgCookiePrefix; $response['testcookie'] = $_COOKIE[$wgCookiePrefix . '_rct_a']; */ } $t = $result['title']; $wgOut->addHTML("<div id='bodycontents2'>"); $titleText = RCTestStub::getTitleText($result, $rcTest); $wgOut->addHTML("<div id='articletitle' style='display:none;'>{$titleText}</div>"); // Initialize the RCTest object. This is use to inject // tests into the RC Patrol queue. $d = RCTestStub::getDifferenceEngine($this->getContext(), $result, $rcTest); $d->loadRevisionData(); $wgOut->addHTML("<div id='rc_header' class='tool_header'>"); $wgOut->addHTML('<a href="#" id="rcpatrol_keys">Get Shortcuts</a>'); $wgOut->addHTML(RCPatrol::getButtons($result, $d->mNewRev, $rcTest)); $wgOut->addHTML("</div>"); $wgOut->addHTML('<div id="rcpatrol_info" style="display:none;">' . wfMessage('rcpatrol_keys')->text() . '</div>'); $d->showDiffPage(); $wgOut->addHtml($testHtml); $wgOut->addHTML("</div>"); $response['unpatrolled'] = self::getUnpatrolledCount(); } else { $wgOut->addWikiMsg('markedaspatrolledtext'); $response['unpatrolled'] = self::getUnpatrolledCount(); } $wgOut->disable(); header('Vary: Cookie'); $response['html'] = $wgOut->getHTML(); print_r(json_encode($response)); return; }
static function getMarkPatrolledLink() { global $wgRequest, $wgUser; // Append a [Mark as Patrolled] link in certain cases $markPatrolledLink = ''; $rcid = $wgRequest->getInt('rcid'); $fromRC = $wgRequest->getInt('fromrc'); if ($wgUser && $rcid > 0 && $fromRC && $wgUser->isAllowed('patrol')) { $rc = RecentChange::newFromId($rcid); if ($rc) { $oldRevId = $rc->getAttribute('rc_last_oldid'); $newRevId = $rc->getAttribute('rc_this_oldid'); $diff = new DifferenceEngine(null, $oldRevId, $newRevId); if ($diff->loadRevisionData()) { $markPatrolledLink = $diff->markPatrolledLink(); } else { throw new MWException("wikiHow internal error: we know there is an rcid ({$rcid}) and newrevid ({$newRevId}), but couldn't find the revision"); } } } return $markPatrolledLink; }
function getNextToPatrolHTML() { global $wgOut; if (!$this->mResult) { // nothing to patrol return null; } // construct the HTML to reply // load the page $t = $this->mTitle; // Title::newFromID($this->mResult->qc_page); if (!$t) { $this->deleteBad($this->mResult->qc_page); return "<!--{$this->mResult->qc_page}-->error creating title, oops, please <a href='#' onclick='window.location.reload()'>refresh</a>"; } // get current revsion $r = Revision::newFromTitle($t); if (!$r) { return "Error creating revision"; } $d = new DifferenceEngine($t, $this->mResult->qc_old_rev_id, $this->mResult->qc_rev_id); $d->loadRevisionData(); // interesting $html = ""; $changedby = self::getChangedBy("Edits patrolled by: "); $wgOut->clearHTML(); $d->showDiffPage(true); $html = "<div id='qc_box'>" . $changedby . $html . $wgOut->getHTML() . "</div>"; $wgOut->clearHTML(); $html .= "<div id='quickeditlink'></div>"; $popts = $wgOut->parserOptions(); $popts->setTidy(true); $html .= WikihowArticleHTML::processArticleHTML($wgOut->parse($r->getText(), $t, $popts), array('no-ads' => 1, 'ns' => $t->getNamespace())); $html .= "<input type='hidden' name='qc_id' value='{$this->mResult->qc_id}'/>"; $html .= "<div id='numqcusers'>{$this->mUsers}</div>"; return $html; }