Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / actions / SpecialPageAction.php
index 3c8a21e..e59b6d6 100644 (file)
  * An action that just passes the request to the relevant special page
  *
  * @ingroup Actions
- * @since 1.26
+ * @since 1.25
  */
 class SpecialPageAction extends FormlessAction {
-
        /**
         * @var array A mapping of action names to special page names.
         */
-       public static $actionToSpecialPageMapping = array(
+       public static $actionToSpecialPageMapping = [
                'revisiondelete' => 'Revisiondelete',
                'editchangetags' => 'EditTags',
-       );
+       ];
 
        public function getName() {
                $request = $this->getRequest();
@@ -49,6 +48,7 @@ class SpecialPageAction extends FormlessAction {
                if ( isset( self::$actionToSpecialPageMapping[$actionName] ) ) {
                        return $actionName;
                }
+
                return 'nosuchaction';
        }
 
@@ -65,15 +65,33 @@ class SpecialPageAction extends FormlessAction {
        }
 
        public function show() {
-               $action = self::getName();
-               if ( $action === 'nosuchaction' ) {
-                       throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
+               $special = $this->getSpecialPage();
+               if ( !$special ) {
+                       throw new ErrorPageError(
+                               $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
                }
 
-               // map actions to (whitelisted) special pages
-               $special = SpecialPageFactory::getPage( self::$actionToSpecialPageMapping[$action] );
                $special->setContext( $this->getContext() );
                $special->getContext()->setTitle( $special->getPageTitle() );
                $special->run( '' );
        }
+
+       public function doesWrites() {
+               $special = $this->getSpecialPage();
+
+               return $special ? $special->doesWrites() : false;
+       }
+
+       /**
+        * @return SpecialPage|null
+        */
+       protected function getSpecialPage() {
+               $action = $this->getName();
+               if ( $action === 'nosuchaction' ) {
+                       return null;
+               }
+
+               // map actions to (whitelisted) special pages
+               return SpecialPageFactory::getPage( self::$actionToSpecialPageMapping[$action] );
+       }
 }