Merge "ResourceLoaderFileModule: Do not separately cache .less files"
[lhc/web/wiklou.git] / includes / actions / PurgeAction.php
index e212fbf..ed0bff7 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 {
 
-       public function getName(){
-               return 'purge';
-       }
+       private $redirectParams;
 
-       public function getRestriction(){
-               return null;
+       public function getName() {
+               return 'purge';
        }
 
-       public function requiresUnblock(){
+       public function requiresUnblock() {
                return false;
        }
 
-       public function getDescription(){
+       public function getDescription() {
                return '';
        }
 
@@ -45,49 +48,54 @@ class PurgeAction extends FormAction {
         * Just get an empty form with a single submit button
         * @return array
         */
-       protected function getFormFields(){
+       protected function getFormFields() {
                return array();
        }
 
-       public function onSubmit( $data ){
-               $this->page->doPurge();
-               return true;
+       public function onSubmit( $data ) {
+               return $this->page->doPurge();
        }
 
        /**
-        * purge is slightly wierd because it can be either formed or formless depending
+        * purge is slightly weird because it can be either formed or formless depending
         * on user permissions
         */
-       public function show(){
+       public function show() {
                $this->setHeaders();
 
                // This will throw exceptions if there's a problem
                $this->checkCanExecute( $this->getUser() );
 
-               if( $this->getUser()->isAllowed( 'purge' ) ){
-                       $this->onSubmit( array() );
-                       $this->onSuccess();
+               if ( $this->getUser()->isAllowed( 'purge' ) ) {
+                       $this->redirectParams = wfArrayToCgi( array_diff_key(
+                               $this->getRequest()->getQueryValues(),
+                               array( 'title' => null, 'action' => null )
+                       ) );
+                       if ( $this->onSubmit( array() ) ) {
+                               $this->onSuccess();
+                       }
                } else {
+                       $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
                        $form = $this->getForm();
-                       if( $form->show() ){
+                       if ( $form->show() ) {
                                $this->onSuccess();
                        }
                }
        }
 
-       protected function alterForm( HTMLForm $form ){
-               $form->setSubmitText( wfMsg( 'confirm_purge_button' ) );
+       protected function alterForm( HTMLForm $form ) {
+               $form->setSubmitTextMsg( 'confirm_purge_button' );
        }
 
-       protected function preText(){
-               return wfMessage( 'confirm-purge-top' )->parse();
+       protected function preText() {
+               return $this->msg( 'confirm-purge-top' )->parse();
        }
 
-       protected function postText(){
-               return wfMessage( 'confirm-purge-bottom' )->parse();
+       protected function postText() {
+               return $this->msg( 'confirm-purge-bottom' )->parse();
        }
 
-       public function onSuccess(){
-               $this->getOutput()->redirect( $this->getTitle() );
+       public function onSuccess() {
+               $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
        }
 }