X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdiff%2FDifferenceEngine.php;h=4ee066e9e3575c953afaf274d2a9f6961e155d1b;hb=9e0e8abd7eac4c16b22a0ff7c8381f0f7ecccf64;hp=d03a5bee736b81122265b2d8d9e63b127c96f5c0;hpb=4f741418fcb0a85f1ccfa3a72e5faa34259b8e53;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index d03a5bee73..4ee066e9e3 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -48,7 +48,6 @@ class DifferenceEngine extends ContextSource { * @var Title */ var $mOldPage, $mNewPage; - var $mRcidMarkPatrolled; /** * @var Revision @@ -80,8 +79,8 @@ class DifferenceEngine extends ContextSource { * Constructor * @param $context IContextSource context to use, anything else will be ignored * @param $old Integer old ID we want to show and diff with. - * @param string $new either 'prev' or 'next'. - * @param $rcid Integer ??? FIXME (default 0) + * @param $new String either 'prev' or 'next'. + * @param $rcid Integer Deprecated, no longer used! * @param $refreshCache boolean If set, refreshes the diff cache * @param $unhide boolean If set, allow viewing deleted revs */ @@ -96,7 +95,6 @@ class DifferenceEngine extends ContextSource { $this->mOldid = $old; $this->mNewid = $new; - $this->mRcidMarkPatrolled = intval( $rcid ); # force it to be an integer $this->mRefreshCache = $refreshCache; $this->unhide = $unhide; } @@ -223,33 +221,6 @@ class DifferenceEngine extends ContextSource { throw new PermissionsError( 'read', $permErrors ); } - # If external diffs are enabled both globally and for the user, - # we'll use the application/x-external-editor interface to call - # an external diff tool like kompare, kdiff3, etc. - if ( ExternalEdit::useExternalEngine( $this->getContext(), 'diff' ) ) { - //TODO: come up with a good solution for non-text content here. - // at least, the content format needs to be passed to the client somehow. - // Currently, action=raw will just fail for non-text content. - - $urls = array( - 'File' => array( 'Extension' => 'wiki', 'URL' => - # This should be mOldPage, but it may not be set, see below. - $this->mNewPage->getCanonicalURL( array( - 'action' => 'raw', 'oldid' => $this->mOldid ) ) - ), - 'File2' => array( 'Extension' => 'wiki', 'URL' => - $this->mNewPage->getCanonicalURL( array( - 'action' => 'raw', 'oldid' => $this->mNewid ) ) - ), - ); - - $externalEditor = new ExternalEdit( $this->getContext(), $urls ); - $externalEditor->execute(); - - wfProfileOut( __METHOD__ ); - return; - } - $rollback = ''; $undoLink = ''; @@ -392,8 +363,9 @@ class DifferenceEngine extends ContextSource { if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) { $deleted = true; // new revisions text is hidden - if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) + if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) { $suppressed = true; // also suppressed + } } # If the diff cannot be shown due to a deleted revision, then output @@ -438,43 +410,47 @@ class DifferenceEngine extends ContextSource { * @return String */ protected function markPatrolledLink() { - global $wgUseRCPatrol; + global $wgUseRCPatrol, $wgRCMaxAge, $wgEnableAPI, $wgEnableWriteAPI; + $cache = wfGetMainCache(); if ( $this->mMarkPatrolledLink === null ) { // Prepare a change patrol link, if applicable - if ( $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $this->getUser() ) ) { - // 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; + if ( + // Is patrolling enabled and the user allowed to? + $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $this->getUser() ) && + // Only do this if the revision isn't more than 6 hours older + // than the Max RC age (6h because the RC might not be cleaned out regularly) + RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 ) && + // Maybe the result is cached + !$cache->get( wfMemcKey( 'NotPatrollableRevId', $this->mNewid ) ) + ) { + // Look for an unpatrolled change corresponding to this diff + + $db = wfGetDB( DB_SLAVE ); + $change = RecentChange::newFromConds( + array( + 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ), + 'rc_this_oldid' => $this->mNewid, + 'rc_patrolled' => 0 + ), + __METHOD__, + array( 'USE INDEX' => 'rc_timestamp' ) + ); + + if ( $change ) { + $rcid = $change->getAttribute( 'rc_id' ); } else { - // Look for an unpatrolled change corresponding to this diff - $db = wfGetDB( DB_SLAVE ); - $change = RecentChange::newFromConds( - array( - // 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; - } + // None found + $rcid = 0; } // Build the link if ( $rcid ) { $this->getOutput()->preventClickjacking(); - $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' ); + if ( $wgEnableAPI && $wgEnableWriteAPI + && $this->getUser()->isAllowed( 'writeapi' ) + ) { + $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' ); + } $token = $this->getUser()->getEditToken( $rcid ); $this->mMarkPatrolledLink = ' [' . Linker::linkKnown( @@ -488,6 +464,7 @@ class DifferenceEngine extends ContextSource { ) ) . ']'; } else { + $cache->set( wfMemcKey( 'NotPatrollableRevId', $this->mNewid ), '1', $wgRCMaxAge ); $this->mMarkPatrolledLink = ''; } } else { @@ -531,7 +508,7 @@ class DifferenceEngine extends ContextSource { if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) { // Stolen from Article::view --AG 2007-10-11 // Give hooks a chance to customise the output - // @TODO: standardize this crap into one function + // @todo standardize this crap into one function if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { // NOTE: deprecated hook, B/C only // use the content object's own rendering @@ -540,9 +517,9 @@ class DifferenceEngine extends ContextSource { $txt = $po ? $po->getText() : ''; $out->addHTML( $txt ); } - } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { + } elseif ( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { // Handled by extension - } elseif( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { + } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { // NOTE: deprecated hook, B/C only // Handled by extension } else { @@ -571,7 +548,7 @@ class DifferenceEngine extends ContextSource { # Show categories etc. $out->addParserOutputNoText( $parserOutput ); } - } else if ( $parserOutput ) { + } elseif ( $parserOutput ) { $out->addParserOutput( $parserOutput ); } } @@ -888,7 +865,9 @@ class DifferenceEngine extends ContextSource { } function localiseLineNumbersCb( $matches ) { - if ( $matches[1] === '1' && $this->mReducedLineNumbers ) return ''; + if ( $matches[1] === '1' && $this->mReducedLineNumbers ) { + return ''; + } return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped(); }