jenkins-bot has submitted this change and it was merged.

Change subject: Make an empty "?action=" parameter default to "view"
......................................................................


Make an empty "?action=" parameter default to "view"

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
---
M includes/actions/Action.php
M tests/phpunit/includes/actions/ActionTest.php
2 files changed, 24 insertions(+), 9 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/actions/Action.php b/includes/actions/Action.php
index 839d7b2..4208b3b 100644
--- a/includes/actions/Action.php
+++ b/includes/actions/Action.php
@@ -147,7 +147,7 @@
                // 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';
                }
 
diff --git a/tests/phpunit/includes/actions/ActionTest.php 
b/tests/phpunit/includes/actions/ActionTest.php
index 4a30292..75c5b50 100644
--- a/tests/phpunit/includes/actions/ActionTest.php
+++ b/tests/phpunit/includes/actions/ActionTest.php
@@ -56,8 +56,6 @@
                        // Null and non-existing values
                        [ 'null', null ],
                        [ 'undeclared', null ],
-                       [ '', null ],
-                       [ false, null ],
                ];
        }
 
@@ -137,22 +135,39 @@
                $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 );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/166572
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I07847600bb24ae078276acf98e6eb244039414d7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to