I'm looking for a way to return parsed wikitext without [edit] links or any other text that mediawiki returns only while logged in. In other words, I want action=parse to return parsed wikitext as if a logged in user was not logged in. Is this possible?
Thanks, Jim
2010/4/2 Jim Safley jimsafley@gmail.com:
I'm looking for a way to return parsed wikitext without [edit] links or any other text that mediawiki returns only while logged in. In other words, I want action=parse to return parsed wikitext as if a logged in user was not logged in. Is this possible?
Is it an option to just log out, then use action=parse? Why go through the trouble of impersonating a logged-out user when you can just log out?
I guess this doesn't really work if you're like a JS gadget, though.
Roan Kattouw (Catrope)
Hi,
The "log in" process involves (as usual for almost all sites) sending the server a username and password etc, and getting back a cookie or cookies, which are then sent with each request. Browsers do this automatically, they don't "know" that there is a login, they just send back whatever cookies they have been given.
If, as Catrope says, you are in js or something, with no control over the HTTP request, you can't do much about that except logging out (you might be able to save and restore the cookies?). But if you are doing the HTTP request, just leave out the cookies, and you will look "logged out" to the server.
For example, code to read the API (or index.php) might look like this: (from Interwicket)
import urllib from StringIO import StringIO from gzip import GzipFile
class MyURLopener(urllib.FancyURLopener): version="Interwicket/1.0"
# [...]
try: uo = MyURLopener() uo.addheader('Cookie', logindata or '') uo.addheader('Accept-Encoding', 'gzip') f = uo.open(url) text = f.read() try: if 'gzip' in f.info()['Content-Encoding']: text = GzipFile(fileobj=StringIO(text)).read() else: pass except KeyError: pass text = unicode(text, 'UTF-8' , errors = 'ignore') except Exception, e: with plock: print "(%s: exception reading API: %s)" % (currentThread().name, repr(e)) text = ''
If you set logindata = None, rather than the login cookies, you'll get the result for a logged out user. (or leave out that line)
Robert
Thank you all for your helpful input. If anonymous editing is enabled (as it is by default) the [edit] links are always present in the parsed wikitext. Is there a way to remove them if even if no cookies exist?
Jim
2010/4/3 Jim Safley jimsafley@gmail.com:
Thank you all for your helpful input. If anonymous editing is enabled (as it is by default) the [edit] links are always present in the parsed wikitext. Is there a way to remove them if even if no cookies exist?
There's a hack:
http://en.wikipedia.org/w/api.php?action=parse&text=__NOEDITSECTION__%7B...
Roan Kattouw (Catrope)
There's a hack:
http://en.wikipedia.org/w/api.php?action=parse&text=__NOEDITSECTION__%7B...
Thank you. That works perfectly, but how does it work? It's undocumented.
On 04/05/2010 05:13 PM, Jim Safley wrote:
There's a hack:
http://en.wikipedia.org/w/api.php?action=parse&text=__NOEDITSECTION__%7B...
Thank you. That works perfectly, but how does it work? It's undocumented.
It uses the documented "parse" method of the API [1], coupled with the __NOEDITSECTION__ tag [2], and transclusion of a page in any namespace [3].
[1] http://www.mediawiki.org/wiki/API:Expanding_templates_and_rendering [2] http://www.mediawiki.org/wiki/Help:Magic_words [3] http://www.mediawiki.org/wiki/Help:Templates
Conrad
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Jim Safley wrote:
There's a hack:
http://en.wikipedia.org/w/api.php?action=parse&text=__NOEDITSECTION__%7B...
Thank you. That works perfectly, but how does it work? It's undocumented.
action=parse is documented. It parses any wikitext you ask for. __NOEDITSECTION__ is a magic word that disables edit sections on the current page. {{:Foo}} is a template call to make the contents of page Foo appear on current page.
mediawiki-api@lists.wikimedia.org