Make destination URL of a page save configurable
authorEbrahim Byagowi <ebrahim@gnu.org>
Wed, 27 Jan 2016 23:31:31 +0000 (23:31 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 18 Feb 2016 14:15:12 +0000 (14:15 +0000)
With this, if a gadget put a hidden input named "wpExtraQueryRedirect",
can guide MediaWiki to keep that extra query parameter even after the
save of the page.

Bug: T124986
Change-Id: Ie45d6d80e83298e4c349f1e2dedd4eaa66b7697a

includes/EditPage.php

index 5ebb44a..82fcdcf 100644 (file)
@@ -1420,6 +1420,11 @@ class EditPage {
                        }
                }
 
+               // "wpExtraQueryRedirect" is a hidden input to modify
+               // after save URL and is not used by actual edit form
+               $request = RequestContext::getMain()->getRequest();
+               $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
+
                switch ( $status->value ) {
                        case self::AS_HOOK_ERROR_EXPECTED:
                        case self::AS_CONTENT_TOO_BIG:
@@ -1443,6 +1448,13 @@ class EditPage {
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
                                $query = $resultDetails['redirect'] ? 'redirect=no' : '';
+                               if ( $extraQueryRedirect ) {
+                                       if ( $query === '' ) {
+                                               $query = $extraQueryRedirect;
+                                       } else {
+                                               $query = $query . '&' . $extraQueryRedirect;
+                                       }
+                               }
                                $anchor = isset( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : '';
                                $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
                                return false;
@@ -1464,6 +1476,14 @@ class EditPage {
                                                $extraQuery = 'redirect=no&' . $extraQuery;
                                        }
                                }
+                               if ( $extraQueryRedirect ) {
+                                       if ( $extraQuery === '' ) {
+                                               $extraQuery = $extraQueryRedirect;
+                                       } else {
+                                               $extraQuery = $extraQuery . '&' . $extraQueryRedirect;
+                                       }
+                               }
+
                                $wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
                                return false;