aboutsummaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorBrion Vibber <brion@users.mediawiki.org>2003-05-16 11:19:06 +0000
committerBrion Vibber <brion@users.mediawiki.org>2003-05-16 11:19:06 +0000
commit0dbedf1c7b340a2e5db96e02c6e0e883ab1b6a12 (patch)
tree4e495fc494fa6de09da486ea8574f1649a91329d /includes
parent92ea39aa9f6aa2ea72579828d0f1a720b4457bef (diff)
downloadmediawikicore-0dbedf1c7b340a2e5db96e02c6e0e883ab1b6a12.tar.gz
mediawikicore-0dbedf1c7b340a2e5db96e02c6e0e883ab1b6a12.zip
Cache slow special pages allpages, lonelypages, longpages, shortpages, watnedpages
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/1319
Diffstat (limited to 'includes')
-rw-r--r--includes/LogPage.php41
-rw-r--r--includes/SpecialAllpages.php18
-rw-r--r--includes/SpecialLonelypages.php11
-rw-r--r--includes/SpecialLongpages.php11
-rw-r--r--includes/SpecialShortpages.php12
-rw-r--r--includes/SpecialWantedpages.php18
6 files changed, 91 insertions, 20 deletions
diff --git a/includes/LogPage.php b/includes/LogPage.php
index eca14cb48f03..45d2d3512de2 100644
--- a/includes/LogPage.php
+++ b/includes/LogPage.php
@@ -9,7 +9,7 @@ class LogPage {
{
# For now, assume title is correct dbkey
# and log pages always go in Wikipedia namespace
- $this->mTitle = $title;
+ $this->mTitle = str_replace( " ", "_", $title );
$this->mId = 0;
$this->mUpdateRecentChanges = true ;
$this->mContentLoaded = false;
@@ -18,7 +18,7 @@ class LogPage {
function getContent( $defaulttext = "<ul>\n</ul>" )
{
- $sql = "SELECT cur_id,cur_text FROM cur " .
+ $sql = "SELECT cur_id,cur_text,cur_timestamp FROM cur " .
"WHERE cur_namespace=" . Namespace::getWikipedia() . " AND " .
"cur_title='" . wfStrencode($this->mTitle ) . "'";
$res = wfQuery( $sql, "LogPage::getContent" );
@@ -27,24 +27,36 @@ class LogPage {
$s = wfFetchObject( $res );
$this->mId = $s->cur_id;
$this->mContent = $s->cur_text;
+ $this->mTimestamp = $s->cur_timestamp;
} else {
$this->mId = 0;
$this->mContent = $defaulttext;
+ $this->mTimestamp = wfTimestampNow();
}
$this->mContentLoaded = true; # Well, sort of
return $this->mContent;
}
+
+ function getTimestamp()
+ {
+ if( !$this->mContentLoaded ) {
+ $this->getContent();
+ }
+ return $this->mTimestamp;
+ }
function saveContent()
{
+ if( wfReadOnly() ) return;
+
global $wgUser;
$fname = "LogPage::saveContent";
$uid = $wgUser->getID();
$ut = wfStrencode( $wgUser->getName() );
if( !$this->mContentLoaded ) return false;
- $now = date( "YmdHis" );
+ $this->mTimestamp = $now = wfTimestampNow();
$won = wfInvertTimestamp( $now );
if($this->mId == 0) {
$sql = "INSERT INTO cur (cur_timestamp,cur_user,cur_user_text,
@@ -113,6 +125,29 @@ class LogPage {
return $this->saveContent();
}
+
+ function replaceContent( $text, $comment = "" )
+ {
+ $this->mContent = $text;
+ $this->mComment = $comment;
+ $this->mTimestamp = wfTimestampNow();
+ return $this->saveContent();
+ }
+
+ function showAsDisabledPage( $rawhtml = true )
+ {
+ global $wgLang, $wgOut;
+ $wgOut->checkLastModified( $this->getTimestamp() );
+ $func = ( $rawhtml ? "addHTML" : "addWikiText" );
+ $wgOut->$func(
+ "<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
+ "<p>" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "</p>\n\n" .
+ "<hr />\n\n" .
+ $this->getContent()
+ );
+ return;
+
+ }
}
?>
diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php
index a3b7aafb5d71..bbd5fdc1ff28 100644
--- a/includes/SpecialAllpages.php
+++ b/includes/SpecialAllpages.php
@@ -14,9 +14,20 @@ function wfSpecialAllpages()
function indexShowToplevel()
{
- global $wgOut, $indexMaxperpage;
+ global $wgOut, $indexMaxperpage, $wgLang;
$fname = "indexShowToplevel";
- # FIXME: This may be slow; we may need to cache it
+
+ # Cache
+ $vsp = $wgLang->getValidSpecialPages();
+ $log = new LogPage( $vsp["Allpages"] );
+ $log->mUpdateRecentChanges = false;
+
+ global $wgMiserMode;
+ if ( $wgMiserMode ) {
+ $log->showAsDisabledPage();
+ return;
+ }
+
# $fromwhere = "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0";
$fromwhere = "FROM cur WHERE cur_namespace=0";
@@ -58,6 +69,9 @@ function indexShowToplevel()
$outpoint = $s->cur_title;
$out .= indexShowline( $inpoint, $outpoint );
$out .= "</table>\n";
+
+ # Saving cache
+ $log->replaceContent( $out );
$wgOut->addHtml( $out );
}
diff --git a/includes/SpecialLonelypages.php b/includes/SpecialLonelypages.php
index b62b48225a1a..ab7f937cb078 100644
--- a/includes/SpecialLonelypages.php
+++ b/includes/SpecialLonelypages.php
@@ -6,9 +6,14 @@ function wfSpecialLonelypages()
global $limit, $offset; # From query string
$fname = "wfSpecialLonelypages";
+ # Cache
+ $vsp = $wgLang->getValidSpecialPages();
+ $log = new LogPage( $vsp["Lonelypages"] );
+ $log->mUpdateRecentChanges = false;
+
global $wgMiserMode;
if ( $wgMiserMode ) {
- $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
+ $log->showAsDisabledPage();
return;
}
@@ -41,6 +46,10 @@ function wfSpecialLonelypages()
$s .= "</ol>";
$wgOut->addHTML( $s );
$wgOut->addHTML( "<p>{$sl}\n" );
+
+ # Saving cache
+ if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
+ $log->replaceContent( $s );
}
?>
diff --git a/includes/SpecialLongpages.php b/includes/SpecialLongpages.php
index 3807abdb2d8c..e45e22c79a38 100644
--- a/includes/SpecialLongpages.php
+++ b/includes/SpecialLongpages.php
@@ -6,9 +6,14 @@ function wfSpecialLongpages()
global $limit, $offset; # From query string
$fname = "wfSpecialLongpages";
+ # Cache
+ $vsp = $wgLang->getValidSpecialPages();
+ $log = new LogPage( $vsp["Longpages"] );
+ $log->mUpdateRecentChanges = false;
+
global $wgMiserMode;
if ( $wgMiserMode ) {
- $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
+ $log->showAsDisabledPage();
return;
}
@@ -42,6 +47,10 @@ function wfSpecialLongpages()
$s .= "</ol>";
$wgOut->addHTML( $s );
$wgOut->addHTML( "<p>{$sl}\n" );
+
+ # Saving cache
+ if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
+ $log->replaceContent( $s );
}
?>
diff --git a/includes/SpecialShortpages.php b/includes/SpecialShortpages.php
index 57efef409bdf..76e18ed5e7ae 100644
--- a/includes/SpecialShortpages.php
+++ b/includes/SpecialShortpages.php
@@ -6,9 +6,14 @@ function wfSpecialShortpages()
global $limit, $offset; # From query string
$fname = "wfSpecialShortpages";
+ # Cache
+ $vsp = $wgLang->getValidSpecialPages();
+ $log = new LogPage( $vsp["Shortpages"] );
+ $log->mUpdateRecentChanges = false;
+
global $wgMiserMode;
if ( $wgMiserMode ) {
- $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
+ $log->showAsDisabledPage();
return;
}
@@ -41,6 +46,11 @@ function wfSpecialShortpages()
$s .= "</ol>";
$wgOut->addHTML( $s );
$wgOut->addHTML( "<p>{$sl}\n" );
+
+
+ # Saving cache
+ if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
+ $log->replaceContent( $s );
}
?>
diff --git a/includes/SpecialWantedpages.php b/includes/SpecialWantedpages.php
index 3f84ce333af5..7f125f8bb828 100644
--- a/includes/SpecialWantedpages.php
+++ b/includes/SpecialWantedpages.php
@@ -1,6 +1,6 @@
<?
-global $IP;
-include_once ( "$IP/LogPage.php" ) ;
+
+include_once ( "LogPage.php" ) ;
function wfSpecialWantedpages()
{
@@ -10,17 +10,13 @@ function wfSpecialWantedpages()
# Cache
$vsp = $wgLang->getValidSpecialPages() ;
- $mw = $vsp["Wantedpages"] ;
- $mw = str_replace ( " " , "_" , $mw ) ; # DBKEY
- $log = new LogPage ( $mw ) ;
- $log->mUpdateRecentChanges = false ;
+ $log = new LogPage( $vsp["Wantedpages"] );
+ $log->mUpdateRecentChanges = false;
$wgOut->setRobotpolicy( "noindex,nofollow" );
global $wgMiserMode;
if ( $wgMiserMode ) {
- $s = "=== " . wfMsg( "perfdisabled" ) . " ===\n" ;
- $s .= $log->getContent() ;
- $wgOut->addWikiText ( $s ) ;
+ $log->showAsDisabledPage();
return;
}
@@ -66,9 +62,7 @@ function wfSpecialWantedpages()
# Saving cache
if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
- $log->mContent = $cache ;
- $log->mContentLoaded = true ;
- $log->saveContent() ;
+ $log->replaceContent( $s );
}
?>