X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/74c929b24b048c9f1e31e17db757ae4195cd7673..dc9cc5d707f5a612938cc9371614cc41c328fda2:/includes/diff/DifferenceEngine.php diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index b30ff190..aa48f9f3 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -27,7 +27,10 @@ class DifferenceEngine { var $mOldRev, $mNewRev; var $mRevisionsLoaded = false; // Have the revisions been loaded var $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2? + var $mCacheHit = false; // Was the diff fetched from cache? var $htmldiff; + + protected $unhide = false; /**#@-*/ /** @@ -38,23 +41,20 @@ class DifferenceEngine { * @param $rcid Integer: ??? FIXME (default 0) * @param $refreshCache boolean If set, refreshes the diff cache * @param $htmldiff boolean If set, output using HTMLDiff instead of raw wikicode diff + * @param $unhide boolean If set, allow viewing deleted revs */ - function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false , $htmldiff = false) { + function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false , $htmldiff = false, $unhide = false ) { $this->mTitle = $titleObj; wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n"); if ( 'prev' === $new ) { # Show diff between revision $old and the previous one. # Get previous one from DB. - # $this->mNewid = intval($old); - $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid ); - } elseif ( 'next' === $new ) { - # Show diff between revision $old and the previous one. - # Get previous one from DB. - # + # Show diff between revision $old and the next one. + # Get next one from DB. $this->mOldid = intval($old); $this->mNewid = $this->mTitle->getNextRevisionID( $this->mOldid ); if ( false === $this->mNewid ) { @@ -62,19 +62,32 @@ class DifferenceEngine { # revision is cur, which is "0". $this->mNewid = 0; } - } else { $this->mOldid = intval($old); $this->mNewid = intval($new); + wfRunHooks( 'NewDifferenceEngine', array(&$titleObj, &$this->mOldid, &$this->mNewid, $old, $new) ); } $this->mRcidMarkPatrolled = intval($rcid); # force it to be an integer $this->mRefreshCache = $refreshCache; $this->htmldiff = $htmldiff; + $this->unhide = $unhide; } function getTitle() { return $this->mTitle; } + + function wasCacheHit() { + return $this->mCacheHit; + } + + function getOldid() { + return $this->mOldid; + } + + function getNewid() { + return $this->mNewid; + } function showDiffPage( $diffOnly = false ) { global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol, $wgEnableHtmlDiff; @@ -111,7 +124,7 @@ CONTROL; } $wgOut->setArticleFlag( false ); - if ( ! $this->loadRevisionData() ) { + if ( !$this->loadRevisionData() ) { $t = $this->mTitle->getPrefixedText(); $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ), $this->mOldid, $this->mNewid ); $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) ); @@ -171,22 +184,26 @@ CONTROL; // If we've been given an explicit change identifier, use it; saves time if( $this->mRcidMarkPatrolled ) { $rcid = $this->mRcidMarkPatrolled; + $rc = RecentChange::newFromId( $rcid ); + // Already patrolled? + $rcid = is_object($rc) && !$rc->getAttribute('rc_patrolled') ? $rcid : 0; } else { // Look for an unpatrolled change corresponding to this diff $db = wfGetDB( DB_SLAVE ); $change = RecentChange::newFromConds( - array( - // Add redundant user,timestamp condition so we can use the existing index - 'rc_user_text' => $this->mNewRev->getUserText( Revision::FOR_THIS_USER ), - 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ), - 'rc_this_oldid' => $this->mNewid, - 'rc_last_oldid' => $this->mOldid, - 'rc_patrolled' => 0 - ), - __METHOD__ + array( + // Add redundant user,timestamp condition so we can use the existing index + 'rc_user_text' => $this->mNewRev->getRawUserText(), + 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ), + 'rc_this_oldid' => $this->mNewid, + 'rc_last_oldid' => $this->mOldid, + 'rc_patrolled' => 0 + ), + __METHOD__ ); if( $change instanceof RecentChange ) { $rcid = $change->mAttribs['rc_id']; + $this->mRcidMarkPatrolled = $rcid; } else { // None found $rcid = 0; @@ -194,11 +211,8 @@ CONTROL; } // Build the link if( $rcid ) { - $patrol = ' [' . $sk->makeKnownLinkObj( - $this->mTitle, - wfMsgHtml( 'markaspatrolleddiff' ), - "action=markpatrolled&rcid={$rcid}" - ) . ']'; + $patrol = ' [' . $sk->makeKnownLinkObj( $this->mTitle, + wfMsgHtml( 'markaspatrolleddiff' ), "action=markpatrolled&rcid={$rcid}" ) . ']'; } else { $patrol = ''; } @@ -206,81 +220,100 @@ CONTROL; $patrol = ''; } + $diffOnlyArg = ''; + # Carry over 'diffonly' param via navigation links + if( $diffOnly != $wgUser->getBoolOption('diffonly') ) { + $diffOnlyArg = '&diffonly='.$diffOnly; + } $htmldiffarg = $this->htmlDiffArgument(); + # Make "previous revision link" $prevlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'previousdiff' ), - 'diff=prev&oldid='.$this->mOldid.$htmldiffarg, '', '', 'id="differences-prevlink"' ); - if ( $this->mNewRev->isCurrent() ) { + "diff=prev&oldid={$this->mOldid}{$htmldiffarg}{$diffOnlyArg}", '', '', 'id="differences-prevlink"' ); + # Make "next revision link" + if( $this->mNewRev->isCurrent() ) { $nextlink = ' '; } else { $nextlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'nextdiff' ), - 'diff=next&oldid='.$this->mNewid.$htmldiffarg, '', '', 'id="differences-nextlink"' ); + "diff=next&oldid={$this->mNewid}{$htmldiffarg}{$diffOnlyArg}", '', '', 'id="differences-nextlink"' ); } $oldminor = ''; $newminor = ''; - if ($this->mOldRev->mMinorEdit == 1) { + if( $this->mOldRev->isMinor() ) { $oldminor = Xml::span( wfMsg( 'minoreditletter' ), 'minor' ) . ' '; } - - if ($this->mNewRev->mMinorEdit == 1) { + if( $this->mNewRev->isMinor() ) { $newminor = Xml::span( wfMsg( 'minoreditletter' ), 'minor' ) . ' '; } $rdel = ''; $ldel = ''; if( $wgUser->isAllowed( 'deleterevision' ) ) { - $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); if( !$this->mOldRev->userCan( Revision::DELETED_RESTRICTED ) ) { // If revision was hidden from sysops - $ldel = wfMsgHtml( 'rev-delundel' ); + $ldel = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml( 'rev-delundel' ).')' ); } else { - $ldel = $sk->makeKnownLinkObj( $revdel, - wfMsgHtml( 'rev-delundel' ), - 'target=' . urlencode( $this->mOldRev->mTitle->getPrefixedDbkey() ) . - '&oldid=' . urlencode( $this->mOldRev->getId() ) ); - // Bolden oversighted content - if( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) - $ldel = "$ldel"; + $query = array( 'target' => $this->mOldRev->mTitle->getPrefixedDbkey(), + 'oldid' => $this->mOldRev->getId() + ); + $ldel = $sk->revDeleteLink( $query, $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ); } - $ldel = " ($ldel) "; + $ldel = " $ldel "; // We don't currently handle well changing the top revision's settings if( $this->mNewRev->isCurrent() ) { - // If revision was hidden from sysops - $rdel = wfMsgHtml( 'rev-delundel' ); + $rdel = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml( 'rev-delundel' ).')' ); } else if( !$this->mNewRev->userCan( Revision::DELETED_RESTRICTED ) ) { // If revision was hidden from sysops - $rdel = wfMsgHtml( 'rev-delundel' ); + $rdel = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml( 'rev-delundel' ).')' ); } else { - $rdel = $sk->makeKnownLinkObj( $revdel, - wfMsgHtml( 'rev-delundel' ), - 'target=' . urlencode( $this->mNewRev->mTitle->getPrefixedDbkey() ) . - '&oldid=' . urlencode( $this->mNewRev->getId() ) ); - // Bolden oversighted content - if( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) - $rdel = "$rdel"; + $query = array( 'target' => $this->mNewRev->mTitle->getPrefixedDbkey(), + 'oldid' => $this->mNewRev->getId() + ); + $rdel = $sk->revDeleteLink( $query, $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ); } - $rdel = " ($rdel) "; + $rdel = " $rdel "; } $oldHeader = '
and don't parse @@ -326,12 +358,22 @@ CONTROL; $wgOut->addHTML( htmlspecialchars( $this->mNewtext ) ); $wgOut->addHTML( "\n\n" ); } - } else - $wgOut->addWikiTextTidy( $this->mNewtext ); + } else { + $wgOut->addWikiTextTidy( $this->mNewtext ); + } - if( !$this->mNewRev->isCurrent() ) { + if( is_object( $this->mNewRev ) && !$this->mNewRev->isCurrent() ) { $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting ); } + # Add redundant patrol link on bottom... + if( $this->mRcidMarkPatrolled && $this->mTitle->quickUserCan('patrol') ) { + $sk = $wgUser->getSkin(); + $wgOut->addHTML( + "