Fixed the diff cache purge feature:
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 7 Sep 2007 23:07:07 +0000 (23:07 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 7 Sep 2007 23:07:07 +0000 (23:07 +0000)
* 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
includes/DifferenceEngine.php

index 7ba55c5..5167fd7 100644 (file)
@@ -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',
                                "<form method=\"post\" action=\"$action\">\n" .
index 99bb479..e882342 100644 (file)
@@ -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', "<nowiki>(fixme, bug)</nowiki>" ) );
                        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<!-- diff cache key $key -->\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<!-- diff cache key $key -->\n";
+                                       wfProfileOut( $fname );
+                                       return $difftext;
+                               }
+                       } // don't try to load but save the result
                }
 
                #loadtext is permission safe, this just clears out the diff