r25651 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25650‎ | r25651 | r25652 >
Date:23:07, 7 September 2007
Author:tstarling
Status:old
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -645,6 +645,7 @@
646646 $rcid = $wgRequest->getVal( 'rcid' );
647647 $rdfrom = $wgRequest->getVal( 'rdfrom' );
648648 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
 649+ $purge = $wgRequest->getVal( 'action' ) == 'purge';
649650
650651 $wgOut->setArticleFlag( true );
651652
@@ -668,7 +669,7 @@
669670 if ( !is_null( $diff ) ) {
670671 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
671672
672 - $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
 673+ $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge );
673674 // DifferenceEngine directly fetched the revision:
674675 $this->mRevIdFetched = $de->mNewid;
675676 $de->showDiffPage( $diffOnly );
@@ -960,7 +961,7 @@
961962 }
962963 } else {
963964 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
964 - $action = $this->mTitle->escapeLocalURL( 'action=purge' );
 965+ $action = htmlspecialchars( $_SERVER['REQUEST_URI'] );
965966 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
966967 $msg = str_replace( '$1',
967968 "<form method=\"post\" action=\"$action\">\n" .
Index: trunk/phase3/includes/DifferenceEngine.php
@@ -38,8 +38,9 @@
3939 * @param $old Integer: old ID we want to show and diff with.
4040 * @param $new String: either 'prev' or 'next'.
4141 * @param $rcid Integer: ??? FIXME (default 0)
 42+ * @param $refreshCache boolean If set, refreshes the diff cache
4243 */
43 - function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0 ) {
 44+ function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false ) {
4445 $this->mTitle = $titleObj;
4546 wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
4647
@@ -68,6 +69,7 @@
6970 $this->mNewid = intval($new);
7071 }
7172 $this->mRcidMarkPatrolled = intval($rcid); # force it to be an integer
 73+ $this->mRefreshCache = $refreshCache;
7274 }
7375
7476 function showDiffPage( $diffOnly = false ) {
@@ -324,8 +326,8 @@
325327 * Returns false if the diff could not be generated, otherwise returns true
326328 */
327329 function showDiff( $otitle, $ntitle ) {
328 - global $wgOut, $wgRequest;
329 - $diff = $this->getDiff( $otitle, $ntitle, $wgRequest->getVal( 'action' ) == 'purge' );
 330+ global $wgOut;
 331+ $diff = $this->getDiff( $otitle, $ntitle );
330332 if ( $diff === false ) {
331333 $wgOut->addWikitext( wfMsg( 'missingarticle', "<nowiki>(fixme, bug)</nowiki>" ) );
332334 return false;
@@ -352,11 +354,10 @@
353355 *
354356 * @param Title $otitle Old title
355357 * @param Title $ntitle New title
356 - * @param bool $skipCache Skip the diff cache for this request?
357358 * @return mixed
358359 */
359 - function getDiff( $otitle, $ntitle, $skipCache = false ) {
360 - $body = $this->getDiffBody( $skipCache );
 360+ function getDiff( $otitle, $ntitle ) {
 361+ $body = $this->getDiffBody();
361362 if ( $body === false ) {
362363 return false;
363364 } else {
@@ -368,27 +369,28 @@
369370 /**
370371 * Get the diff table body, without header
371372 *
372 - * @param bool $skipCache Skip cache for this request?
373373 * @return mixed
374374 */
375 - function getDiffBody( $skipCache = false ) {
 375+ function getDiffBody() {
376376 global $wgMemc;
377377 $fname = 'DifferenceEngine::getDiffBody';
378378 wfProfileIn( $fname );
379379
380380 // Cacheable?
381381 $key = false;
382 - if ( $this->mOldid && $this->mNewid && !$skipCache ) {
 382+ if ( $this->mOldid && $this->mNewid ) {
 383+ $key = wfMemcKey( 'diff', 'version', MW_DIFF_VERSION, 'oldid', $this->mOldid, 'newid', $this->mNewid );
383384 // Try cache
384 - $key = wfMemcKey( 'diff', 'version', MW_DIFF_VERSION, 'oldid', $this->mOldid, 'newid', $this->mNewid );
385 - $difftext = $wgMemc->get( $key );
386 - if ( $difftext ) {
387 - wfIncrStats( 'diff_cache_hit' );
388 - $difftext = $this->localiseLineNumbers( $difftext );
389 - $difftext .= "\n<!-- diff cache key $key -->\n";
390 - wfProfileOut( $fname );
391 - return $difftext;
392 - }
 385+ if ( !$this->mRefreshCache ) {
 386+ $difftext = $wgMemc->get( $key );
 387+ if ( $difftext ) {
 388+ wfIncrStats( 'diff_cache_hit' );
 389+ $difftext = $this->localiseLineNumbers( $difftext );
 390+ $difftext .= "\n<!-- diff cache key $key -->\n";
 391+ wfProfileOut( $fname );
 392+ return $difftext;
 393+ }
 394+ } // don't try to load but save the result
393395 }
394396
395397 #loadtext is permission safe, this just clears out the diff

Follow-up revisions

RevisionCommit summaryAuthorDate
r25754Merged revisions 25607-25751 via svnmerge from...david23:02, 10 September 2007

Status & tagging log