Florianschmidtwelzow has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370370 )

Change subject: Let InputBox redirect veaction=edit when prefix param is set
......................................................................

Let InputBox redirect veaction=edit when prefix param is set

This will allow users to use InputBox with useve and the prefix
parameter, like they already can for source edit mode (action =
edit).

Also: Add tests for the redirect code.

Bug: T172631
Change-Id: I6bf246cdd58dbd17863819a9becfacf231b1a2e9
---
M InputBox.hooks.php
A tests/phpunit/InputBox.hooksTest.php
2 files changed, 67 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/InputBox 
refs/changes/70/370370/1

diff --git a/InputBox.hooks.php b/InputBox.hooks.php
index 50636fa..a19fd83 100644
--- a/InputBox.hooks.php
+++ b/InputBox.hooks.php
@@ -66,7 +66,8 @@
                $request,
                $wiki
        ) {
-               if ( $wiki->getAction( $request ) !== 'edit' ) {
+               $veaction = $request->getVal( 'veaction' );
+               if ( !in_array( 'edit', [ $wiki->getAction(), $veaction ] ) ) {
                        // not our problem
                        return true;
                }
diff --git a/tests/phpunit/InputBox.hooksTest.php 
b/tests/phpunit/InputBox.hooksTest.php
new file mode 100644
index 0000000..96ad3ba
--- /dev/null
+++ b/tests/phpunit/InputBox.hooksTest.php
@@ -0,0 +1,65 @@
+<?php
+
+class InputBoxHooksTest extends MediaWikiTestCase {
+       /**
+        * @dataProvider redirectDataProvider
+        * @param $requestParams
+        * @param $expected
+        */
+       public function testNoRedirectVeActionNoPrefix( $requestParams, 
$expected ) {
+               $context = new RequestContext();
+               $title = new Title( 'whatever' );
+               if ( isset( $requestParams['title'] ) ) {
+                       $title = new Title( $requestParams['title'] );
+               }
+               $context->setWikiPage( new WikiPage( $title ) );
+               $request = new FauxRequest( $requestParams );
+               $context->setRequest( $request );
+               $bogusOutputPage = $context->getOutput();
+               $wiki = new MediaWiki( $context );
+               InputBoxHooks::onMediaWikiPerformAction( $bogusOutputPage, 
null, null, null, $request,
+                       $wiki );
+               $this->assertEquals(
+                       $expected,
+                       $bogusOutputPage->getRedirect() );
+       }
+
+       public static function redirectDataProvider() {
+               return [
+                       // testNoRedirectVeActionNoPrefix
+                       [ [
+                               'veaction' => 'edit',
+                               'title' => 'toEdit',
+                       ], '' ],
+                       // testNoRedirectVeActionNoEdit
+                       [ [
+                               'veaction' => 'whatever',
+                               'prefix' => 'TestPrefix/',
+                               'title' => 'toEdit',
+                       ], '' ],
+                       // testRedirectVeActionEdit
+                       [ [
+                               'veaction' => 'edit',
+                               'prefix' => 'TestPrefix/',
+                               'title' => 'toEdit',
+                       ], 
'/w/index.php?veaction=edit&title=TestPrefix%2FtoEdit' ],
+                       // testNoRedirectNoPrefix
+                       [ [
+                               'action' => 'edit',
+                               'title' => 'toEdit',
+                       ], '' ],
+                       // testNoRedirectNoEditAction
+                       [ [
+                               'action' => 'view',
+                               'prefix' => 'TestPrefix/',
+                               'title' => 'toEdit',
+                       ], '' ],
+                       // testRedirectEditActionPrefix
+                       [ [
+                               'action' => 'edit',
+                               'prefix' => 'TestPrefix/',
+                               'title' => 'toEdit',
+                       ], '/w/index.php?action=edit&title=TestPrefix%2FtoEdit' 
]
+               ];
+       }
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6bf246cdd58dbd17863819a9becfacf231b1a2e9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/InputBox
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to