From 3a57f51b05addc650179879acb54362dea49070d Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 7 Sep 2007 23:07:07 +0000 Subject: [PATCH] Fixed the diff cache purge feature: * Made it work with the anon-only confirmation form. * Fixed data flow issue (removed reference to $wgRequest in DifferenceEngine.php) * Made it actually purge rather than just skip the cache one time --- includes/Article.php | 5 +++-- includes/DifferenceEngine.php | 38 ++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 7ba55c548b..5167fd7d9d 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -645,6 +645,7 @@ class Article { $rcid = $wgRequest->getVal( 'rcid' ); $rdfrom = $wgRequest->getVal( 'rdfrom' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); + $purge = $wgRequest->getVal( 'action' ) == 'purge'; $wgOut->setArticleFlag( true ); @@ -668,7 +669,7 @@ class Article { if ( !is_null( $diff ) ) { $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid ); + $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge ); // DifferenceEngine directly fetched the revision: $this->mRevIdFetched = $de->mNewid; $de->showDiffPage( $diffOnly ); @@ -960,7 +961,7 @@ class Article { } } else { $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) ); - $action = $this->mTitle->escapeLocalURL( 'action=purge' ); + $action = htmlspecialchars( $_SERVER['REQUEST_URI'] ); $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) ); $msg = str_replace( '$1', "
\n" . diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 99bb4798a7..e88234269c 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -38,8 +38,9 @@ class DifferenceEngine { * @param $old Integer: old ID we want to show and diff with. * @param $new String: either 'prev' or 'next'. * @param $rcid Integer: ??? FIXME (default 0) + * @param $refreshCache boolean If set, refreshes the diff cache */ - function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0 ) { + function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false ) { $this->mTitle = $titleObj; wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n"); @@ -68,6 +69,7 @@ class DifferenceEngine { $this->mNewid = intval($new); } $this->mRcidMarkPatrolled = intval($rcid); # force it to be an integer + $this->mRefreshCache = $refreshCache; } function showDiffPage( $diffOnly = false ) { @@ -324,8 +326,8 @@ CONTROL; * Returns false if the diff could not be generated, otherwise returns true */ function showDiff( $otitle, $ntitle ) { - global $wgOut, $wgRequest; - $diff = $this->getDiff( $otitle, $ntitle, $wgRequest->getVal( 'action' ) == 'purge' ); + global $wgOut; + $diff = $this->getDiff( $otitle, $ntitle ); if ( $diff === false ) { $wgOut->addWikitext( wfMsg( 'missingarticle', "(fixme, bug)" ) ); return false; @@ -352,11 +354,10 @@ CONTROL; * * @param Title $otitle Old title * @param Title $ntitle New title - * @param bool $skipCache Skip the diff cache for this request? * @return mixed */ - function getDiff( $otitle, $ntitle, $skipCache = false ) { - $body = $this->getDiffBody( $skipCache ); + function getDiff( $otitle, $ntitle ) { + $body = $this->getDiffBody(); if ( $body === false ) { return false; } else { @@ -368,27 +369,28 @@ CONTROL; /** * Get the diff table body, without header * - * @param bool $skipCache Skip cache for this request? * @return mixed */ - function getDiffBody( $skipCache = false ) { + function getDiffBody() { global $wgMemc; $fname = 'DifferenceEngine::getDiffBody'; wfProfileIn( $fname ); // Cacheable? $key = false; - if ( $this->mOldid && $this->mNewid && !$skipCache ) { - // Try cache + if ( $this->mOldid && $this->mNewid ) { $key = wfMemcKey( 'diff', 'version', MW_DIFF_VERSION, 'oldid', $this->mOldid, 'newid', $this->mNewid ); - $difftext = $wgMemc->get( $key ); - if ( $difftext ) { - wfIncrStats( 'diff_cache_hit' ); - $difftext = $this->localiseLineNumbers( $difftext ); - $difftext .= "\n\n"; - wfProfileOut( $fname ); - return $difftext; - } + // Try cache + if ( !$this->mRefreshCache ) { + $difftext = $wgMemc->get( $key ); + if ( $difftext ) { + wfIncrStats( 'diff_cache_hit' ); + $difftext = $this->localiseLineNumbers( $difftext ); + $difftext .= "\n\n"; + wfProfileOut( $fname ); + return $difftext; + } + } // don't try to load but save the result } #loadtext is permission safe, this just clears out the diff -- 2.20.1