From 121bb4f03eb71f37c0294327648bdd0a00679a4d Mon Sep 17 00:00:00 2001 From: Platonides Date: Tue, 3 Aug 2010 22:32:09 +0000 Subject: [PATCH] http://www.mediawiki.org/wiki/User:Catrope/Stub_threshold shows us people setting it to insanely large values trying to disable it. r70433 addressed the UI. Here we proxy its access via a new method getStubThreshold() that disables it if a page of such size cannot be created (by an user), so we can serve them parser cached articles again. --- includes/Article.php | 8 ++++---- includes/Linker.php | 4 ++-- includes/User.php | 22 ++++++++++++++++++++-- includes/parser/LinkHolderArray.php | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 51b12702e2..3812658514 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -891,7 +891,7 @@ class Article { # Should the parser cache be used? $useParserCache = $this->useParserCache( $oldid ); wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" ); - if ( $wgUser->getOption( 'stubthreshold' ) ) { + if ( $wgUser->getStubThreshold() ) { wfIncrStats( 'pcache_miss_stub' ); } @@ -1450,7 +1450,7 @@ class Article { global $wgUser, $wgEnableParserCache; return $wgEnableParserCache - && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 + && $wgUser->getStubThreshold() == 0 && $this->exists() && empty( $oldid ) && !$this->mTitle->isCssOrJsPage() @@ -4589,13 +4589,13 @@ class Article { // Should the parser cache be used? $useParserCache = $wgEnableParserCache && - intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 && + $wgUser->getStubThreshold() == 0 && $this->exists() && $oldid === null; wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" ); - if ( $wgUser->getOption( 'stubthreshold' ) ) { + if ( $wgUser->getStubThreshold() ) { wfIncrStats( 'pcache_miss_stub' ); } diff --git a/includes/Linker.php b/includes/Linker.php index db9202ad4a..a8d9c8b828 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -267,7 +267,7 @@ class Linker { } if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387) - $colour = $this->getLinkColour( $target, $wgUser->getOption( 'stubthreshold' ) ); + $colour = $this->getLinkColour( $target, $wgUser->getStubThreshold() ); if ( $colour !== '' ) { $classes[] = $colour; # mw-redirect or stub } @@ -337,7 +337,7 @@ class Linker { global $wgUser; wfDeprecated( __METHOD__ ); - $threshold = intval( $wgUser->getOption( 'stubthreshold' ) ); + $threshold = $wgUser->getStubThreshold(); $colour = ( $size < $threshold ) ? 'stub' : ''; // FIXME: replace deprecated makeColouredLinkObj by link() return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); diff --git a/includes/User.php b/includes/User.php index 0ed1716b7d..d376da27a1 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2078,6 +2078,20 @@ class User { return $this->mDatePreference; } + /** + * Get the user preferred stub threshold + */ + function getStubThreshold() { + global $wgMaxArticleSize; # Maximum article size, in Kb + $threshold = intval( $this->getOption( 'stubthreshold' ) ); + if ( $threshold > $wgMaxArticleSize * 1024 ) { + # If they have set an impossible value, disable the preference + # so we can use the parser cache again. + $threshold = 0; + } + return $threshold; + } + /** * Get the permissions this user has. * @return \type{\arrayof{\string}} Array of permission names @@ -2686,10 +2700,11 @@ class User { } // stubthreshold is only included below for completeness, - // it will always be 0 when this function is called by parsercache. + // since it disables the parser cache, its value will always + // be 0 when this function is called by parsercache. $confstr = $this->getOption( 'math' ); - $confstr .= '!' . $this->getOption( 'stubthreshold' ); + $confstr .= '!' . $this->getStubThreshold(); if ( $wgUseDynamicDates ) { $confstr .= '!' . $this->getDatePreference(); } @@ -2700,6 +2715,9 @@ class User { $extra = $wgContLang->getExtraHashOptions(); $confstr .= $extra; + // Since the skin could be overloading link(), it should be + // included here but in practice, none of our skins do that. + $confstr .= $wgRenderHashAppend; // Give a chance for extensions to modify the hash, if they have diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index b1732f0a64..5379d17ee3 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -99,7 +99,7 @@ class LinkHolderArray { function getStubThreshold() { global $wgUser; if ( !isset( $this->stubThreshold ) ) { - $this->stubThreshold = $wgUser->getOption('stubthreshold'); + $this->stubThreshold = $wgUser->getStubThreshold(); } return $this->stubThreshold; } -- 2.20.1