Make an empty "?action=" parameter default to "view"
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Tue, 14 Oct 2014 14:31:43 +0000 (16:31 +0200)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Tue, 17 May 2016 16:36:39 +0000 (18:36 +0200)
When no action is given, e.g. in
https://en.wikipedia.org/wiki/URL
the action defaults to "view". Just like you called
https://en.wikipedia.org/wiki/URL?action=view

But when the action is empty, e.g.
https://en.wikipedia.org/wiki/URL?action=
you get an error message telling you that "the action specified"
can not be "recognized". Wait, I did not "specified" an action.
That's why I left the parameter empty. From the users point of
view I expect the empty string to behave like null/undefined.

This is a resubmit of I331924d without the problematic bits.

Change-Id: I07847600bb24ae078276acf98e6eb244039414d7

includes/actions/Action.php
tests/phpunit/includes/actions/ActionTest.php

index 839d7b2..4208b3b 100644 (file)
@@ -147,7 +147,7 @@ abstract class Action {
                // Trying to get a WikiPage for NS_SPECIAL etc. will result
                // in WikiPage::factory throwing "Invalid or virtual namespace -1 given."
                // For SpecialPages et al, default to action=view.
-               if ( !$context->canUseWikiPage() ) {
+               if ( $actionName === '' || !$context->canUseWikiPage() ) {
                        return 'view';
                }
 
index 4a30292..75c5b50 100644 (file)
@@ -56,8 +56,6 @@ class ActionTest extends MediaWikiTestCase {
                        // Null and non-existing values
                        [ 'null', null ],
                        [ 'undeclared', null ],
-                       [ '', null ],
-                       [ false, null ],
                ];
        }
 
@@ -137,22 +135,39 @@ class ActionTest extends MediaWikiTestCase {
                $this->assertType( $expected ?: 'null', $action );
        }
 
-       public function testNull_doesNotExist() {
-               $exists = Action::exists( null );
+       public function emptyActionProvider() {
+               return [
+                       [ null ],
+                       [ false ],
+                       [ '' ],
+               ];
+       }
+
+       /**
+        * @dataProvider emptyActionProvider
+        */
+       public function testEmptyAction_doesNotExist( $requestedAction ) {
+               $exists = Action::exists( $requestedAction );
 
                $this->assertFalse( $exists );
        }
 
-       public function testNull_defaultsToView() {
-               $context = $this->getContext( null );
+       /**
+        * @dataProvider emptyActionProvider
+        */
+       public function testEmptyAction_defaultsToView( $requestedAction ) {
+               $context = $this->getContext( $requestedAction );
                $actionName = Action::getActionName( $context );
 
                $this->assertEquals( 'view', $actionName );
        }
 
-       public function testNull_canNotBeInstantiated() {
+       /**
+        * @dataProvider emptyActionProvider
+        */
+       public function testEmptyAction_canNotBeInstantiated( $requestedAction ) {
                $page = $this->getPage();
-               $action = Action::factory( null, $page );
+               $action = Action::factory( $requestedAction, $page );
 
                $this->assertNull( $action );
        }