Make ApiEditPage use Article::newFromWikiPage() and add user to context
[lhc/web/wiklou.git] / includes / actions / CachedAction.php
index 5a2264a..d21f9ae 100644 (file)
@@ -4,7 +4,7 @@
  * Abstract action class with scaffolding for caching HTML and other values
  * in a single blob.
  *
- * Before using any of the cahing functionality, call startCache.
+ * Before using any of the caching functionality, call startCache.
  * After the last call to either getCachedValue or addCachedHTML, call saveCache.
  *
  * To get a cached value or compute it, use getCachedValue like this:
  * computations here. This function should returns the HTML to be cached.
  * It should not add anything to the PageOutput object!
  *
- * @since 1.20
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * @file CachedAction.php
- * @ingroup Action
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
- * @licence GNU GPL v2 or later
+ * @file
+ * @ingroup Action
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ * @since 1.20
  */
 abstract class CachedAction extends FormlessAction implements ICacheHelper {
 
        /**
-        * CacheHelper object to which we foreward the non-SpecialPage specific caching work.
+        * CacheHelper object to which we forward the non-SpecialPage specific caching work.
         * Initialized in startCache.
         *
         * @since 1.20
@@ -36,6 +48,14 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         */
        protected $cacheHelper;
 
+       /**
+        * If the cache is enabled or not.
+        *
+        * @since 1.20
+        * @var boolean
+        */
+       protected $cacheEnabled = true;
+
        /**
         * Sets if the cache should be enabled or not.
         *
@@ -52,12 +72,13 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param integer|null $cacheExpiry Sets the cache expirty, either ttl in seconds or unix timestamp.
+        * @param integer|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
         * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
         */
        public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
-               $this->cacheHelper = new CacheHelper( $this->get );
+               $this->cacheHelper = new CacheHelper();
 
+               $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
                $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
 
                $keyArgs = $this->getCacheKey();
@@ -69,7 +90,7 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
                $this->cacheHelper->setCacheKey( $keyArgs );
 
                if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
-                       $this->cacheHelper->purge();
+                       $this->cacheHelper->rebuildOnDemand();
                }
 
                $this->cacheHelper->startCache( $cacheExpiry, $cacheEnabled );
@@ -120,14 +141,14 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
        }
 
        /**
-        * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry..
+        * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
         *
         * @since 1.20
         *
         * @param integer $cacheExpiry
         */
-       public function setExpirey( $cacheExpiry ) {
-               $this->cacheHelper->setExpirey( $cacheExpiry );
+       public function setExpiry( $cacheExpiry ) {
+               $this->cacheHelper->setExpiry( $cacheExpiry );
        }
 
        /**
@@ -158,4 +179,4 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
                }
        }
 
-}
\ No newline at end of file
+}