Add page purge limiter
[lhc/web/wiklou.git] / includes / actions / PurgeAction.php
index 4c5171c..7e77846 100644 (file)
@@ -1,8 +1,6 @@
 <?php
 /**
- * Formats credits for articles
- *
- * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
+ * User-requested page cache purging.
  *
  * 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
  *
  * @file
  * @ingroup Actions
- * @author <evan@wikitravel.org>
  */
 
+/**
+ * User-requested page cache purging.
+ *
+ * For users with 'purge', this will directly trigger the cache purging and
+ * for users without that right, it will show a confirmation form.
+ *
+ * @ingroup Actions
+ */
 class PurgeAction extends FormAction {
 
        private $redirectParams;
@@ -39,14 +44,6 @@ class PurgeAction extends FormAction {
                return '';
        }
 
-       /**
-        * Just get an empty form with a single submit button
-        * @return array
-        */
-       protected function getFormFields() {
-               return array();
-       }
-
        public function onSubmit( $data ) {
                return $this->page->doPurge();
        }
@@ -61,12 +58,19 @@ class PurgeAction extends FormAction {
                // This will throw exceptions if there's a problem
                $this->checkCanExecute( $this->getUser() );
 
-               if ( $this->getUser()->isAllowed( 'purge' ) ) {
+               $user = $this->getUser();
+
+               if ( $user->pingLimiter( 'purge' ) ) {
+                       // TODO: Display actionthrottledtext
+                       return;
+               }
+
+               if ( $user->isAllowed( 'purge' ) ) {
                        $this->redirectParams = wfArrayToCgi( array_diff_key(
                                $this->getRequest()->getQueryValues(),
                                array( 'title' => null, 'action' => null )
                        ) );
-                       if( $this->onSubmit( array() ) ) {
+                       if ( $this->onSubmit( array() ) ) {
                                $this->onSuccess();
                        }
                } else {
@@ -91,6 +95,6 @@ class PurgeAction extends FormAction {
        }
 
        public function onSuccess() {
-               $this->getOutput()->redirect( $this->getTitle()->getFullUrl( $this->redirectParams ) );
+               $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
        }
 }