Quantcast

Retrieve a wiki article with URL query parameters?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Retrieve a wiki article with URL query parameters?

Daniel Barrett
Can the MediaWiki API retrieve the HTML of a wiki page, if that page changes its rendering based on the URL query string?

For example, if I have an article “Foo” with the URL:

        http://wiki.example.com/wiki/Foo

and it renders *different* HTML if I pass the query parameter “bar”:

        http://wiki.example.com/wiki/Foo?bar=1

can the MediaWiki API pass along "bar=1" and retrieve the HTML produced by the second URL?

I know I can retrieve “Foo” using action=’parse’, prop=’text’, page=’Foo’. But I can’t find any way to pass a URL query parameter along with the call and have it take effect.

Thanks for any assistance,
DanB

_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Retrieve a wiki article with URL query parameters?

Daniel Barrett
I asked:
>Can the MediaWiki API retrieve the HTML of a wiki page, if that page changes its rendering based on the URL query string?

Never mind, I got it working. Just add those URL query parameters to the WebRequest object that's being used:

        RequestContext::getMain()->getRequest()->setVal('bar', 1');

Then pass the WebRequest object to the DerivativeRequest (first parameter). Works great!

DanB
_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Retrieve a wiki article with URL query parameters?

Gergo Tisza
On Fri, Nov 4, 2016 at 12:15 PM, Daniel Barrett <[hidden email]> wrote:
Never mind, I got it working. Just add those URL query parameters to the WebRequest object that's being used:

        RequestContext::getMain()->getRequest()->setVal('bar', 1');

Then pass the WebRequest object to the DerivativeRequest (first parameter). Works great!

RequestContext::getMain()->getRequest() describes the current request, so you'll probably want to create a DerivativeRequest from that and then only change the parameters in the DerivativeRequest.

_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Retrieve a wiki article with URL query parameters?

Chad
On Fri, Nov 4, 2016 at 3:53 PM Gergo Tisza <[hidden email]> wrote:
On Fri, Nov 4, 2016 at 12:15 PM, Daniel Barrett <[hidden email]> wrote:
Never mind, I got it working. Just add those URL query parameters to the WebRequest object that's being used:

        RequestContext::getMain()->getRequest()->setVal('bar', 1');

Then pass the WebRequest object to the DerivativeRequest (first parameter). Works great!

RequestContext::getMain()->getRequest() describes the current request, so you'll probably want to create a DerivativeRequest from that and then only change the parameters in the DerivativeRequest.


If you're doing this from within a parser function or hook (which is what it
sounds like), you'll want to make sure you disable the cache for the given
pages it's used on from within your callback function. Otherwise results
will get wonky :)

$parser->disableCache();

-Chad

_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Retrieve a wiki article with URL query parameters?

Chad


On Fri, Nov 4, 2016 at 9:09 PM Chad <[hidden email]> wrote:
On Fri, Nov 4, 2016 at 3:53 PM Gergo Tisza <[hidden email]> wrote:
On Fri, Nov 4, 2016 at 12:15 PM, Daniel Barrett <[hidden email]> wrote:
Never mind, I got it working. Just add those URL query parameters to the WebRequest object that's being used:

        RequestContext::getMain()->getRequest()->setVal('bar', 1');

Then pass the WebRequest object to the DerivativeRequest (first parameter). Works great!

RequestContext::getMain()->getRequest() describes the current request, so you'll probably want to create a DerivativeRequest from that and then only change the parameters in the DerivativeRequest.


If you're doing this from within a parser function or hook (which is what it
sounds like), you'll want to make sure you disable the cache for the given
pages it's used on from within your callback function. Otherwise results
will get wonky :)

$parser->disableCache();

-Chad

Gah, pressed send a little quickly. I also wanted to add:

A caveat though: I would be a little suspicious of code that involves
putting request parameters into the page output. Need to handle
both proper escaping *as well as* the case when you're being parsed
from a non-web request (like a jobqueue job).

-Chad 

_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Loading...