/** * Load revision metadata for the specified articles. If newid is 0, then compare * the old article in oldid to the current article; if oldid is 0, then * compare the current article to the immediately previous one (ignoring the * value of newid). * * If oldid is false, leave the corresponding revision object set * to false. This is impossible via ordinary user input, and is provided for * API convenience. * * @return bool */ public function loadRevisionData() { if ($this->mRevisionsLoaded) { return true; } // Whether it succeeds or fails, we don't want to try again $this->mRevisionsLoaded = true; $this->loadRevisionIds(); // Load the new revision object if ($this->mNewid) { $this->mNewRev = Revision::newFromId($this->mNewid); } else { $this->mNewRev = Revision::newFromTitle($this->getTitle(), false, Revision::READ_NORMAL); } if (!$this->mNewRev instanceof Revision) { return false; } // Update the new revision ID in case it was 0 (makes life easier doing UI stuff) $this->mNewid = $this->mNewRev->getId(); $this->mNewPage = $this->mNewRev->getTitle(); // Load the old revision object $this->mOldRev = false; if ($this->mOldid) { $this->mOldRev = Revision::newFromId($this->mOldid); } elseif ($this->mOldid === 0) { $rev = $this->mNewRev->getPrevious(); if ($rev) { $this->mOldid = $rev->getId(); $this->mOldRev = $rev; } else { // No previous revision; mark to show as first-version only. $this->mOldid = false; $this->mOldRev = false; } } /* elseif ( $this->mOldid === false ) leave mOldRev false; */ if (is_null($this->mOldRev)) { return false; } if ($this->mOldRev) { $this->mOldPage = $this->mOldRev->getTitle(); } // Load tags information for both revisions $dbr = wfGetDB(DB_SLAVE); if ($this->mOldid !== false) { $this->mOldTags = $dbr->selectField('tag_summary', 'ts_tags', array('ts_rev_id' => $this->mOldid), __METHOD__); } else { $this->mOldTags = false; } $this->mNewTags = $dbr->selectField('tag_summary', 'ts_tags', array('ts_rev_id' => $this->mNewid), __METHOD__); return true; }
/** * (non-PHPdoc) * @see includes/ChangesList#insertRollback($s, $rc) */ public function insertRollback(&$s, &$rc) { global $wgUser; parent::insertRollback($s, $rc); if (!$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id']) { if ($wgUser->isAllowed('edit')) { $rev = new Revision(array('id' => $rc->mAttribs['rc_this_oldid'], 'user' => $rc->mAttribs['rc_user'], 'user_text' => $rc->mAttribs['rc_user_text'], 'deleted' => $rc->mAttribs['rc_deleted'])); $undoAfter = $rev->getPrevious(); $undoLink = $this->generateUndoLink($this->skin, $rc->getTitle(), $rev, $undoAfter); if (isset($undoLink)) { $s .= ' ' . $undoLink; } } } }
/** * Render the inline difference between two revisions * using InlineDiffEngine */ function showDiff() { $ctx = MobileContext::singleton(); $prevId = $this->prevRev ? $this->prevRev->getId() : 0; $unhide = (bool) $this->getRequest()->getVal('unhide'); $contentHandler = $this->rev->getContentHandler(); $de = $contentHandler->createDifferenceEngine($this->getContext(), $prevId, $this->revId); // HACK: if (get_class($de) == 'DifferenceEngine') { $de = new $this->diffClass($this->getContext(), $prevId, $this->revId, 0, false, $unhide); } else { $de->showDiffPage(); return; } $this->mDiffEngine = $de; $diff = $de->getDiffBody(); if (!$prevId) { $audience = $unhide ? Revision::FOR_THIS_USER : Revision::FOR_PUBLIC; $diff = '<ins>' . nl2br(htmlspecialchars($this->rev->getText($audience))) . '</ins>'; } $warnings = $de->getWarningMessageText(); if ($warnings) { $warnings = MobileUI::warningBox($warnings); } $this->getOutput()->addHtml($warnings . '<div id="mw-mf-minidiff">' . $diff . '</div>'); $prev = $this->rev->getPrevious(); $next = $this->rev->getNext(); if ($prev || $next) { $history = Html::openElement('ul', array('class' => 'hlist revision-history-links')); if ($prev) { $history .= Html::openElement('li') . Html::element('a', array('href' => SpecialPage::getTitleFor('MobileDiff', $prev->getId())->getLocalUrl()), $this->msg('previousdiff')) . Html::closeElement('li'); } if ($next) { $history .= Html::openElement('li') . Html::element('a', array('href' => SpecialPage::getTitleFor('MobileDiff', $next->getId())->getLocalUrl()), $this->msg('nextdiff')) . Html::closeElement('li'); } $history .= Html::closeElement('ul'); $this->getOutput()->addHtml($history); } }
/** * DiffViewHeader hook handler * @see https://www.mediawiki.org/wiki/Manual:Hooks/DiffViewHeader * * Redirect Diff page to mobile version if appropriate * * @param DifferenceEngine $diff DifferenceEngine object that's calling * @param Revision $oldRev Revision object of the "old" revision (may be null/invalid) * @param Revision $newRev Revision object of the "new" revision * @return bool */ public static function onDiffViewHeader($diff, $oldRev, $newRev) { $context = MobileContext::singleton(); // Only do redirects to MobileDiff if user is in mobile view and it's not a special page if ($context->shouldDisplayMobileView() && !$diff->getContext()->getTitle()->isSpecialPage()) { $output = $context->getOutput(); $newRevId = $newRev->getId(); // The MobileDiff page currently only supports showing a single revision, so // only redirect to MobileDiff if we are sure this isn't a multi-revision diff. if ($oldRev) { // Get the revision immediately before the new revision $prevRev = $newRev->getPrevious(); if ($prevRev) { $prevRevId = $prevRev->getId(); $oldRevId = $oldRev->getId(); if ($prevRevId === $oldRevId) { $output->redirect(SpecialPage::getTitleFor('MobileDiff', $newRevId)->getFullURL()); } } } else { $output->redirect(SpecialPage::getTitleFor('MobileDiff', $newRevId)->getFullURL()); } } return true; }
/** * Get the text that needs to be saved in order to undo all revisions * between $undo and $undoafter. Revisions must belong to the same page, * must exist and must not be deleted * @param $undo Revision * @param $undoafter Revision Must be an earlier revision than $undo * @return mixed string on success, false on failure * @deprecated since 1.21: use ContentHandler::getUndoContent() instead. */ public function getUndoText( Revision $undo, Revision $undoafter = null ) { ContentHandler::deprecated( __METHOD__, '1.21' ); $this->loadLastEdit(); if ( $this->mLastRevision ) { if ( is_null( $undoafter ) ) { $undoafter = $undo->getPrevious(); } $handler = $this->getContentHandler(); $undone = $handler->getUndoContent( $this->mLastRevision, $undo, $undoafter ); if ( !$undone ) { return false; } else { return ContentHandler::getContentText( $undone ); } } return false; }
/** * @desc Retrives categories list from previous revision's text and if there is "CSS Updates" category returns true * * @param Revision $rev * * @return bool */ private static function prevRevisionHasCssUpdatesCat(Revision $rev) { return ($prevRev = $rev->getPrevious(true)) instanceof Revision && in_array(SpecialCssModel::UPDATES_CATEGORY, self::getCategoriesFromWikitext($prevRev->getRawText())); }
/** * Add or update the new messages flag * @param string $field 'user_ip' for anonymous users, 'user_id' otherwise * @param string|int $id User's IP address for anonymous users, User ID otherwise * @param Revision|null $curRev New, as yet unseen revision of the user talk page. Ignored if null. * @return bool True if successful, false otherwise */ protected function updateNewtalk($field, $id, $curRev = null) { // Get timestamp of the talk page revision prior to the current one $prevRev = $curRev ? $curRev->getPrevious() : false; $ts = $prevRev ? $prevRev->getTimestamp() : null; // Mark the user as having new messages since this revision $dbw = wfGetDB(DB_MASTER); $dbw->insert('user_newtalk', array($field => $id, 'user_last_timestamp' => $dbw->timestampOrNull($ts)), __METHOD__, 'IGNORE'); if ($dbw->affectedRows()) { wfDebug(__METHOD__ . ": set on ({$field}, {$id})\n"); return true; } else { wfDebug(__METHOD__ . " already set ({$field}, {$id})\n"); return false; } }