Wikipedia api - parsing wiki text by disabling preview mode

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

Wikipedia api - parsing wiki text by disabling preview mode

Kenan Erdogan
Hi,

I am using Wikipedia api to convert wiki text into html.

Everything works fine except that in the output there are also warning messages which are normally seen in preview mode. To exclude them, I set  'preview' parameter to False in the query but warning messages are still in the html output.

Here is an exmaple query: https://en.wikipedia.org/w/api.php?action=parse&format=json&preview=False&text=[[foo]]+{{Infobox%20writer%20|%20name%20%20%20%20%20%20%20%20%20=%20Test|%20ethnicity%20%20%20%20=%20[[test]]}}

Is there any idea how to get html output without preview warning messages.

Thanks a lot,
Kenan
-- 
GESIS - Leibniz Institute for the Social Sciences
Computational Social Science (CSS)
Team Social Analytics and Services
M.Sc. Kenan Erdogan

Unter Sachsenhausen 6-8, 50667 Cologne, Germany
Tel: + 49 (0) 221-47694-211

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

Re: Wikipedia api - parsing wiki text by disabling preview mode

Gabriel Wicke-3
The general issue of inline warnings & the need for a saner warning mechanism is discussed at https://phabricator.wikimedia.org/T141970. It seems likely that some code in the infobox you are referencing looks at the REVISION* value, and emits the inline warning if no revision is set.

The easiest way to get rid of the warning would be to heed the warning's advice about the unknown "ethnicity" parameter.

On Wed, Jul 26, 2017 at 8:41 AM, Kenan Erdogan <[hidden email]> wrote:
Hi,

I am using Wikipedia api to convert wiki text into html.

Everything works fine except that in the output there are also warning messages which are normally seen in preview mode. To exclude them, I set  'preview' parameter to False in the query but warning messages are still in the html output.

Here is an exmaple query: https://en.wikipedia.org/w/api.php?action=parse&format=json&preview=False&text=[[foo]]+{{Infobox%20writer%20|%20name%20%20%20%20%20%20%20%20%20=%20Test|%20ethnicity%20%20%20%20=%20[[test]]}}

Is there any idea how to get html output without preview warning messages.

Thanks a lot,
Kenan
-- 
GESIS - Leibniz Institute for the Social Sciences
Computational Social Science (CSS)
Team Social Analytics and Services
M.Sc. Kenan Erdogan

Unter Sachsenhausen 6-8, 50667 Cologne, Germany
Tel: <a href="tel:+49%20221%2047694211" value="+4922147694211" target="_blank">+ 49 (0) 221-47694-211

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




--
Gabriel Wicke
Principal Engineer, Wikimedia Foundation

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

Re: Wikipedia api - parsing wiki text by disabling preview mode

Bartosz Dziewoński
In reply to this post by Kenan Erdogan
The problem here is that the technique used for this (checking is
{{REVISIONID}} expands to nothing) really checks for "is this not a
saved revision", rather than "is this a preview". In my opinion the
entire thing is a bad idea and a huge hack and just asking for
problems, like you just discovered. An example using this technique
is Template:If preview [1].

You might be able to work around this by using TemplateSandbox [2]
features to "replace" problematic templates/modules by ones that do
nothing, or "return false". For example, this works for your query by
overriding Module:Check for unknown parameters to do nothing [3]:

https://en.wikipedia.org/w/api.php?action=parse&format=json&preview=False&text=[[foo]]+{{Infobox%20writer%20|%20name%20%20%20%20%20%20%20%20%20=%20Test|%20ethnicity%20%20%20%20=%20[[test]]}}&templatesandboxtitle=Module%3ACheck+for+unknown+parameters&templatesandboxtext=local+p+%3D+%7B%7D%0Afunction+p.check+(frame)%0A%09return+%27%27%0Aend%0Areturn+p
(http://tinyurl.com/ycwgyljq)

But this is obviously inconvenient, since you need to manually find out
where the output comes from, and would eventually need to implement this
for many templates/modules.

[1] https://en.wikipedia.org/wiki/Template:If_preview
[2] https://www.mediawiki.org/wiki/Extension:TemplateSandbox
[3] https://en.wikipedia.org/wiki/Module:Check_for_unknown_parameters

--
Bartosz Dziewoński

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

Re: Wikipedia api - parsing wiki text by disabling preview mode

Bartosz Dziewoński
In reply to this post by Kenan Erdogan
As a side note, I noticed now that your example query has
a "&preview=False" parameter in it – this actually won't do
what you expect. Any value given for boolean parameters,
including "false", "0", "", etc., means true. If you mean
false, you have to not pass the parameter at all.
(Not that it changes anything in this case.)

--
Bartosz Dziewoński

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

Re: Wikipedia api - parsing wiki text by disabling preview mode

Gergo Tisza
In reply to this post by Kenan Erdogan
On Wed, Jul 26, 2017 at 5:41 PM, Kenan Erdogan <[hidden email]> wrote:
Here is an exmaple query: https://en.wikipedia.org/w/api.php?action=parse&format=json&preview=False&text=[[foo]]+{{Infobox%20writer%20|%20name%20%20%20%20%20%20%20%20%20=%20Test|%20ethnicity%20%20%20%20=%20[[test]]}}

Note that preview=False will actually set the preview parameter to true. See the API doc about datatypes:
https://en.wikipedia.org/w/api.php?action=help&modules=main#main.2Fdatatypes

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