r73139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73138‎ | r73139 | r73140 >
Date:18:36, 16 September 2010
Author:awjrichards
Status:resolved (Comments)
Tags:
Comment:
Updated to preserve query string in configured URLs
Modified paths:
  • /trunk/extensions/VariablePage/VariablePage.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VariablePage/VariablePage.body.php
@@ -28,10 +28,23 @@
2929 if ( strlen( $utm_campaign )) $query[ 'utm_campaign' ] = $utm_campaign;
3030 if ( strlen( $referrer )) $query[ 'referrer' ] = $referrer;
3131
32 - $tracking = '?' . wfArrayToCGI( $query );
 32+ // determine the URL to which we will redirect the user
 33+ $url = $this->determinePage( $wgVariablePagePossibilities );
3334
34 - $url = $this->determinePage( $wgVariablePagePossibilities );
35 - $wgOut->redirect( $url . $tracking );
 35+ // check if we have a pre-existing query string in the URL, merge it with our previously generated query
 36+ $query_start = strpos( $url, '?' );
 37+ if ( $query_start ) {
 38+ $query_str = substr( $url, $query_start + 1 );
 39+ $url = substr( $url, 0, $query_start );
 40+ foreach ( explode( "&", $query_str ) as $params ) {
 41+ list( $key, $value ) = explode( "=", $params );
 42+ $query_orig[ $key ] = $value;
 43+ }
 44+ $query = array_merge( $query, $query_orig );
 45+ }
 46+
 47+ $full_query = $wgRequest->appendQueryArray( $query, true );
 48+ $wgOut->redirect( $url . '?' . $full_query );
3649 }
3750
3851 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r73142Followup r73139, switched to using wfAppendQuery. Thanks for the tip, Catropeawjrichards19:15, 16 September 2010

Comments

#Comment by Tfinc (talk | contribs)   18:50, 16 September 2010

If you use parse_url() then you'll have to do a lot less index magic. Then you can simply refer to the bits as $url['query'] and then chop up as needed.

#Comment by Catrope (talk | contribs)   18:54, 16 September 2010

Even simpler: wfAppendQuery( $url, $query ), which returns $url . ('?' or '&', whichever is needed) . wfArrayToCGI( $query )

#Comment by Nikerabbit (talk | contribs)   18:54, 16 September 2010

How about wfCgiToArray()?

Status & tagging log