[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make rebuildFileCache cover ?action=history

2016-09-20 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Make rebuildFileCache cover ?action=history
..


Make rebuildFileCache cover ?action=history

Also simplified the logic slightly

Change-Id: I6145d52b6b701735fa4bd8e41e07fb2bf6fdcee3
---
M includes/MediaWiki.php
M includes/actions/HistoryAction.php
M includes/cache/FileCacheBase.php
M includes/cache/HTMLFileCache.php
M includes/page/Article.php
M maintenance/rebuildFileCache.php
6 files changed, 71 insertions(+), 49 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index 2fce08c..8cf009f 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -529,11 +529,12 @@
}
} catch ( Exception $e ) {
$context = $this->context;
+   $action = $context->getRequest()->getVal( 'action', 
'view' );
if (
$e instanceof DBConnectionError &&
$context->hasTitle() &&
$context->getTitle()->canExist() &&
-   $context->getRequest()->getVal( 'action', 
'view' ) === 'view' &&
+   in_array( $action, [ 'view', 'history' ], true 
) &&
HTMLFileCache::useFileCache( $this->context, 
HTMLFileCache::MODE_OUTAGE )
) {
// Try to use any (even stale) file during 
outages...
diff --git a/includes/actions/HistoryAction.php 
b/includes/actions/HistoryAction.php
index 41378fb..f3ef3b3 100644
--- a/includes/actions/HistoryAction.php
+++ b/includes/actions/HistoryAction.php
@@ -105,8 +105,7 @@
$config = $this->context->getConfig();
 
# Fill in the file cache if not set already
-   $useFileCache = $config->get( 'UseFileCache' );
-   if ( $useFileCache && HTMLFileCache::useFileCache( 
$this->getContext() ) ) {
+   if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
$cache = new HTMLFileCache( $this->getTitle(), 
'history' );
if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
ob_start( [ &$cache, 'saveToFileCache' ] );
diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php
index 360420b..e25f882 100644
--- a/includes/cache/FileCacheBase.php
+++ b/includes/cache/FileCacheBase.php
@@ -157,12 +157,6 @@
 * @return string Compressed text
 */
public function saveText( $text ) {
-   global $wgUseFileCache;
-
-   if ( !$wgUseFileCache ) {
-   return false;
-   }
-
if ( $this->useGzip() ) {
$text = gzencode( $text );
}
diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php
index 71011e0..a85639f 100644
--- a/includes/cache/HTMLFileCache.php
+++ b/includes/cache/HTMLFileCache.php
@@ -21,6 +21,8 @@
  * @ingroup Cache
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Page view caching in the file system.
  * The only cacheable actions are "view" and "history". Also special pages
@@ -31,6 +33,7 @@
 class HTMLFileCache extends FileCacheBase {
const MODE_NORMAL = 0; // normal cache mode
const MODE_OUTAGE = 1; // fallback cache for DB outages
+   const MODE_REBUILD = 2; // background cache rebuild mode
 
/**
 * Construct an HTMLFileCache object from a Title and an action
@@ -52,6 +55,7 @@
 */
public function __construct( $title, $action ) {
parent::__construct();
+
$allowedTypes = self::cacheablePageActions();
if ( !in_array( $action, $allowedTypes ) ) {
throw new MWException( 'Invalid file cache type given.' 
);
@@ -96,16 +100,15 @@
/**
 * Check if pages can be cached for this request/user
 * @param IContextSource $context
-* @param integer $mode One of the HTMLFileCache::MODE_* constants
+* @param integer $mode One of the HTMLFileCache::MODE_* constants 
(since 1.28)
 * @return bool
 */
public static function useFileCache( IContextSource $context, $mode = 
self::MODE_NORMAL ) {
-   global $wgUseFileCache, $wgDebugToolbar, $wgContLang;
+   $config = MediaWikiServices::getInstance()->getMainConfig();
 
-   if ( !$wgUseFileCache ) {
+   if ( !$config->get( 'UseFileCache' ) && $mode !== 
self::MODE_REBUILD ) {
return false;
-   }
-   if ( $wgDebugToolbar ) {
+   } elseif ( 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make rebuildFileCache cover ?action=history

2016-09-14 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310697

Change subject: Make rebuildFileCache cover ?action=history
..

Make rebuildFileCache cover ?action=history

Also simplified the logic slightly

Change-Id: I6145d52b6b701735fa4bd8e41e07fb2bf6fdcee3
---
M includes/MediaWiki.php
M includes/actions/HistoryAction.php
M includes/cache/HTMLFileCache.php
M includes/page/Article.php
M maintenance/rebuildFileCache.php
5 files changed, 64 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/97/310697/1

diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index af096cc..ce1888c 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -528,11 +528,12 @@
}
} catch ( Exception $e ) {
$context = $this->context;
+   $action = $context->getRequest()->getVal( 'action', 
'view' );
if (
$e instanceof DBConnectionError &&
$context->hasTitle() &&
$context->getTitle()->canExist() &&
-   $context->getRequest()->getVal( 'action', 
'view' ) === 'view' &&
+   in_array( $action, [ 'view', 'history' ] , true 
) &&
HTMLFileCache::useFileCache( $this->context, 
HTMLFileCache::MODE_OUTAGE )
) {
// Try to use any (even stale) file during 
outages...
diff --git a/includes/actions/HistoryAction.php 
b/includes/actions/HistoryAction.php
index 41378fb..f3ef3b3 100644
--- a/includes/actions/HistoryAction.php
+++ b/includes/actions/HistoryAction.php
@@ -105,8 +105,7 @@
$config = $this->context->getConfig();
 
# Fill in the file cache if not set already
-   $useFileCache = $config->get( 'UseFileCache' );
-   if ( $useFileCache && HTMLFileCache::useFileCache( 
$this->getContext() ) ) {
+   if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
$cache = new HTMLFileCache( $this->getTitle(), 
'history' );
if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
ob_start( [ &$cache, 'saveToFileCache' ] );
diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php
index 285e152..787e2d8 100644
--- a/includes/cache/HTMLFileCache.php
+++ b/includes/cache/HTMLFileCache.php
@@ -21,6 +21,8 @@
  * @ingroup Cache
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Page view caching in the file system.
  * The only cacheable actions are "view" and "history". Also special pages
@@ -31,6 +33,7 @@
 class HTMLFileCache extends FileCacheBase {
const MODE_NORMAL = 0; // normal cache mode
const MODE_OUTAGE = 1; // fallback cache for DB outages
+   const MODE_SCRIPT = 2; // background cache rebuild mode
 
/**
 * Construct an HTMLFileCache object from a Title and an action
@@ -52,6 +55,7 @@
 */
public function __construct( $title, $action ) {
parent::__construct();
+
$allowedTypes = self::cacheablePageActions();
if ( !in_array( $action, $allowedTypes ) ) {
throw new MWException( 'Invalid file cache type given.' 
);
@@ -96,16 +100,15 @@
/**
 * Check if pages can be cached for this request/user
 * @param IContextSource $context
-* @param integer $mode One of the HTMLFileCache::MODE_* constants
+* @param integer $mode One of the HTMLFileCache::MODE_* constants 
(since 1.28)
 * @return bool
 */
public static function useFileCache( IContextSource $context, $mode = 
self::MODE_NORMAL ) {
-   global $wgUseFileCache, $wgDebugToolbar, $wgContLang;
+   $config = MediaWikiServices::getInstance()->getMainConfig();
 
-   if ( !$wgUseFileCache ) {
+   if ( !$config->get( 'UseFileCache' ) && $mode !== 
self::MODE_SCRIPT ) {
return false;
-   }
-   if ( $wgDebugToolbar ) {
+   } elseif ( $config->get( 'DebugToolbar' ) ) {
wfDebug( "HTML file cache skipped. \$wgDebugToolbar 
on\n" );
 
return false;
@@ -133,7 +136,7 @@
$ulang = $context->getLanguage();
 
// Check that there are no other sources of variation
-   if ( $user->getId() || !$ulang->equals( $wgContLang ) ) {
+   if ( $user->getId() || $ulang->getCode() !== $config->get( 
'LanguageCode' ) ) {
return false;
}
 
@@ -153,15 +156,15 @@
 * @return void
 */
public function