setSquidMaxage() globally if we can purge it, instead of in actions.
authorLiangent <liangent@gmail.com>
Mon, 4 Jun 2012 06:46:36 +0000 (14:46 +0800)
committerLiangent <liangent@gmail.com>
Mon, 4 Jun 2012 06:46:36 +0000 (14:46 +0800)
Change-Id: I404c994616eab0902a9e3650c97028e9bcfb22db

includes/Wiki.php
includes/actions/HistoryAction.php
includes/actions/ViewAction.php

index b20cb95..08e06ea 100644 (file)
@@ -462,6 +462,8 @@ class MediaWiki {
         * @param $page Page
         */
        private function performAction( Page $page ) {
+               global $wgUseSquid, $wgSquidMaxage;
+
                wfProfileIn( __METHOD__ );
 
                $request = $this->context->getRequest();
@@ -480,6 +482,15 @@ class MediaWiki {
 
                $action = Action::factory( $act, $page );
                if ( $action instanceof Action ) {
+                       # When it's a known action, let Squid cache things if we can purge them.
+                       # If the action is unknown, we don't know what may happen in an extension,
+                       # but not caching can be always safe.
+                       if ( $wgUseSquid &&
+                               in_array( $request->getFullRequestURL(), $title->getSquidURLs() )
+                       ) {
+                               $output->setSquidMaxage( $wgSquidMaxage );
+                       }
+
                        $action->show();
                        wfProfileOut( __METHOD__ );
                        return;
index 8e6bcd9..94bf50c 100644 (file)
@@ -87,7 +87,7 @@ class HistoryAction extends FormlessAction {
         * Print the history page for an article.
         */
        function onView() {
-               global $wgScript, $wgUseFileCache, $wgSquidMaxage;
+               global $wgScript, $wgUseFileCache;
 
                $out = $this->getOutput();
                $request = $this->getRequest();
@@ -101,10 +101,6 @@ class HistoryAction extends FormlessAction {
 
                wfProfileIn( __METHOD__ );
 
-               if ( $request->getFullRequestURL() == $this->getTitle()->getInternalURL( 'action=history' ) ) {
-                       $out->setSquidMaxage( $wgSquidMaxage );
-               }
-
                $this->preCacheMessages();
 
                # Fill in the file cache if not set already
index d43e5fb..d57585e 100644 (file)
@@ -34,13 +34,6 @@ class ViewAction extends FormlessAction {
        }
 
        public function show(){
-               global $wgSquidMaxage;
-
-               $request = $this->getRequest();
-               if ( $request->getFullRequestURL() == $this->getTitle()->getInternalURL() ) {
-                       $this->getOutput()->setSquidMaxage( $wgSquidMaxage );
-               }
-
                $this->page->view();
        }