Extension talk:UrlGetParameters

Latest comment: 3 years ago by Megajoule in topic Call to undefined method Parser::disableCache()

parameters passed by POST method

edit

In some cases, parameters may be passed by POST method. Under that situation, this code would not work properly.

In order to solve this issue, we can use the $wgRequest->data array instead of _GET one. The $wgRequest->data array is the concatenation of _POST and _GET one.

The affected function is urlGetParameters_Render and the code would be patched as

function urlGetParameters_Render( &$parser ) {
    // {{#urlget:paramname|defaultvalue}}

    // Get the parameters that were passed to this function
    $params = func_get_args();
    array_shift( $params );

    global $wgRequest;
    if(array_key_exists($params[0],$wgRequest->data)
                return $wgRequest->data[$params[0]];

        if(count($params)>1)
                return $params[1];

        return "";
}
edit

Could you please show how to create a link that would call a page with such parameters? My attempt caused MediaWiki to create RedLinks, because it decided that the target page didn't exist...

>> You can use Extension:AllowGetParamsInWikilinks

>> If you need POST parameters, you should use a form

Cache issues

edit

If you use this extension, you may have cache issues thus not getting the desired result. You can disable the cache when calling this extension.

The affected function is urlGetParameters_Render and the code would be re-patched (using the previous suggestion) as

function urlGetParameters_Render( &$parser ) {
    // {{#urlget:paramname|defaultvalue}}

    // Get the parameters that were passed to this function
    $params = func_get_args();
    array_shift( $params );

    $parser->disableCache();

    global $wgRequest;
    if(array_key_exists($params[0],$wgRequest->data)
                return $wgRequest->data[$params[0]];

        if(count($params)>1)
                return $params[1];

        return "";
}

Problem solved after installing Winter

edit

I had problems getting a paramter using

<span class="plainlinks">[{{fullurl:{{FULLPAGENAME}}|parameter=value}} link]</span>

Test after click: {{#urlget:parameter}}

After installing Winter it worked by adding {{#nocache}}. Just wanted leave that note for others. Cheers, very useful extension :) --Subfader 14:51, 28 May 2009 (UTC)Reply

NoCache

edit

First of all, can't this be fixed so that you don't need to disable cache for the page using UrlGetParameters???
Extension:Winter is a very bad recommendation. Not only that it's a 76 KB monster, it also can f*** up other parser functions. Installing WInter just to use {{#nocache}} is not worth it. I would recommend Extension:MagicNoCache (not tested) or Extension:Variables with 3 simple lines you can add {{NOCACHE}} or what ever name you prefer:

               	case MAG_NOCACHE:
			$parser->disableCache(); # Mark this content as uncacheable
			break;

--Subfader 23:11, 3 June 2009 (UTC)Reply

Just a note.. Winter does not "fuck up" parser functions. Both of them can be used on the same page, they just might have unexpected results when you use them together. Another note, Winter provides access to the URL GET parameters, so if you have installed Winter, you don't actually need to install this extension. But I do agree with Subfader in one aspect: Winter is not necessarily the best solution if you simply need to disable caching since it is an entire scripting language. --Frantik 07:38, 24 September 2009 (UTC)Reply

get full url?

edit

WOuld be ace if you'd be able to get the fullurl with all parameters. --Subfader 20:01, 15 July 2009 (UTC)Reply

Yes, that would be an easy workaround for a start! Why can't you get the URL with all parameters? Might be helpful in wikis where it takes the admins a while to install this extension (helpful, indeed! thanks for implementing!) --Achimbode 11:52, 25 March 2011 (UTC)Reply

Error when installed?

edit

Using:-

  • MediaWiki: 1.5.2
  • PHP: 5.2.5 (isapi)
  • MySQL: 4.0.26-nt

I get an error:-

Fatal error: Call to undefined method Parser::setFunctionHook() in C:\Inetpub\wwwroot\wiki\extensions\UrlGetParameters\UrlGetParameters.php on line 15

Can anyone throw any light on why this is?

Southcot 10:22, 30 July 2009 (UTC)Reply

Your MediaWiki version is extremely outdated, consider an upgrade --Subfader 10:32, 30 July 2009 (UTC)Reply

Yep just realised that <redface>my quick look at the extension requirements read 1.10 as being 1.1.</redface>. Thanks for answering this. Was looking for a kick to get the upgrade done anyway.

Southcot 13:11, 30 July 2009 (UTC)Reply

Performance

edit

I ran into an interesting performance issue that may help people using this extension.

The bottom line is - use #vardefine if you need to evaluate the content of a #urlget many times on a single page (from the Variable extension - http://www.mediawiki.org/wiki/Extension:VariablesExtension ).

I was able to cut down access times of a wiki page from 15s to 3s doing something like :

{{#vardefine:urlparam|{{#urlget:letter|number}}}}
== {{#var:urlparam}} ==

{{#ifeq: {{#var:urlparam}} | number|
{{#ask:[[Category:Definition]][[Has page name::<A]]}}
|
{{#ask:[[Category:Definition]][[Has page name::~{{#var:urlparam}}*]]}}
}}

This example displays the result of a semantic mediawiki query based on the choice of a starting letter for a glossary.

Calls to #var are far more efficient than repeating calls to #urlget.

- Laurent Alquier

Avoid Injection Issues

edit

To avoid code injection using this extension, wouldn't it be better if the returned value was urlencoded to remove any command sequences? For example:

	if( array_key_exists( $params[0], $_GET ) ){
		return rawurlencode($_GET[$params[0]]);
	} elseif ( count( $params ) > 1 ){
		return rawurlencode($params[1]);
	} else {
		return '';
	}

Doesn't work with MW 1.16 beta 3

edit

Hi. I'm using version 1.0.0 of this extension and I get the following error with MW 1.16 beta 3:

Fatal error: Cannot access protected property WebRequest::$data in 
/localhost/wiki/extensions/URLGetParameters/URLGetParameters.php on line 33

Any suggestions?
Many thanks
mitchelln 15:11, 23 July 2010 (UTC)Reply

Fixed! Using the code suggested in above "Avoid Injection Issues" section by the anonymous person. Thanks whoever you are!
Full fix:
function urlGetParameters_Render( &$parser ) {
    // {{#urlget:paramname|defaultvalue}}
 
    // Get the parameters that were passed to this function
    $params = func_get_args();
    array_shift( $params );
 
    $parser->disableCache();
 
    global $wgRequest;
	if( array_key_exists( $params[0], $_GET ) ){
		return rawurlencode($_GET[$params[0]]);
	} elseif ( count( $params ) > 1 ){
		return rawurlencode($params[1]);
	} else {
		return '';
	}
 
        if(count($params)>1)
                return $params[1];
 
        return "";
}
mitchelln 17:10, 23 July 2010 (UTC)Reply

This sorted it for me too thanks for posting.

Southcot 09:19, 16 March 2011 (UTC)Reply


Have noticed that this fix does screw up the display of the default value if it contains formatting such as <span> etc. Better to have it working at some level though.

Southcot 09:40, 16 March 2011 (UTC)Reply

Getting error messages

edit

Hello, I get error messages when trying this om MW 1.16. Anyone else having problems? rotsee 16:39, 3 March 2011 (UTC)Reply

Isn't there a [] missing at line 10? rotsee 16:45, 3 March 2011 (UTC)Reply
Yes, indeed - somehow some bugs got into the code by the time it got into SVN. I believe I just fixed them. Yaron Koren 05:21, 4 March 2011 (UTC)Reply

Is this safe?

edit

I wonder if return rawurlencode( $_GET[$params[0]] ) is really safe? I think it should use $wgRequest, no? I switched it to rawurlencode() so I can work with the parameters in the wiki page for templates etc. --Subfader (talk) 21:24, 11 March 2012 (UTC)Reply

Default value doesn't work anymore

edit

{{#urlget:foo|0}} doesn't return "0" if the pamter "foo" is empty. Any idea what could cause this?

Better Solution for Caching

edit

I think i have a better solution that addresses the issue with caching. Instead of just outright disabling the cache, I would recommend doing something like this:

if (isset($params)) { $parser->disableCache(); }

That should only disable the cache when the parameters are set (IE - when the pf is being called). It shouldn't disable the cache for your entire wiki. Thought that I'd pass this along. If someone wants to incorporate it into the code, feel free. --Duke33 (talk) 01:47, 9 May 2013 (UTC)Reply

Should it still be marked as stable ?

edit

The link provided to download lead to a 404. In the wikimedia code review, I find "abandoned" status. So It seems it's maintained anymore...

Use the download links in the infobox. I've never had any trouble using this extension, so I'd consider this stable. Cavila 13:19, 2 October 2017 (UTC)Reply
Yes, the "abandoned" there just refers to a patch, not to the extension. Yaron Koren (talk) 16:15, 2 October 2017 (UTC)Reply

Call to undefined method Parser::disableCache()

edit

MediaWiki 1.35.1, UrlGetParameters 1.5.0

Problem preventing the page from displaying!

Call to undefined method Parser::disableCache()

Problem solved by replacing the call to disableCache() in lines 41, 47, 54, 58 in extensions/MyVariables/MyVariablesHooks.php with this:

//$parser->disableCache();
$parser->getOutput()->updateCacheExpiry(0);

--Megajoule (talk) 07:57, 31 December 2020 (UTC)Reply

fbclid

edit

Might there be some way to use this extension to remove the fbclid parameter, which gets added when you post a link on facebook?

Return to "UrlGetParameters" page.