API talk:Parsing wikitext

From MediaWiki.org
Jump to navigation Jump to search

Minor issues with expandtemplates[edit]

Hi,

I just want to report two issues with expandtemplates :

  • expandtemplates seems to work for only one level of templates (templates inside templates are not expanded)
  • expandtemplates doesn't take into account <includeonly> or <noinclude>

For example, on the French Wikipedia, expandtemplates for {{e}} gives <includeonly>{{exp|e}}</includeonly><noinclude> {{/Documentation}} </noinclude>

Possibly you should report this to http://bugzilla.wikimedia.org/, so the issues can be properly tracked and fixed. -- Tbleher 10:16, 22 January 2008 (UTC)
Ok, done. There's the same problem for Special:ExpandTemplates. --NicoV 14:54, 22 January 2008 (UTC)
Seems to be fixed --NicoV 17:54, 23 January 2008 (UTC)

error with parse...[edit]

i am getting the following return...

<?xml version="1.0"?>
<api>
  <error code="params" info="The page parameter cannot be used together with the text and title parameters" xml:space="preserve">

my query string looks like this...

/api.php?action=parse&page=Houdini

i am using mw 1.15.1 i get nothing of value from the mw debug log and i have verified that my rewrite rules are not adding the title parameter. any thoughts? 67.97.209.36 14:25, 18 November 2009 (UTC)

if i change my query string to this...
/api.php?action=parse&text={{Houdini}}
i get the expected result.
67.97.209.36 16:46, 18 November 2009 (UTC)

I'm seeing the same problems. I think we should write it up as a bug. --Duke33 01:58, 14 January 2010 (UTC)

I took the liberty of writing it up:bugzilla:22684 --Duke33 17:16, 1 March 2010 (UTC)

Parsing into printable text ?[edit]

Hi,

Is there a way to parse a wiki text to get a simplified text (without HTML, external and internal replaced by their text, ...) ?

My need is the following :

  • The project Check Wikipedia uses a configuration file for each wiki (for example: en)
  • It's used among other things to generate pages in Wiki format (for example: en)
  • In the configuration file, you can see for example a description of error n°1: error_001_desc_script=This article has no bold title like <nowiki>'''Title'''</nowiki>, so it contains Wiki text.
  • I am writing a Java program (WikiCleaner) to help fixing the errors reported by this tool. I'd like to display this text in my program as a simple text: This article has no bold title like '''Title'''.

Thanks, NicoV --16:33, 28 March 2010 (UTC)

Error with DPL[edit]

DPL and DPL in templates are not expanded. e.g. these fail

  • api.php?action=query&prop=revisions&titles=yourtitle&rvprop=content&rvexpandtemplates
  • api.php?action=expandtemplates&text={{TemplateWithDPL}}

Hamishwillee 00:02, 19 July 2010 (UTC)

Simple template output wrapped in paragraph tags[edit]

Suppose I have Template:Foo, which contains this wikitext:

This calls the hello world template: {{hello world}}.

Template:Hello world contains this text:

Hello, world!

I would expect the text output to look like this:

This calls the hello world template: Hello, world!

This is my API call:

http://example.com/w/api.php?action=parse&pst=1&disablepp=1&format=json&redirects=1&text=%7B%7BFoo%7D%7D

The problem[edit]

The json returned wraps the output in paragraph tags for some reason, which I don't want.

array(1) {
  ["parse"]=>
  array(12) {
    ["title"]=>
    string(3) "API"
    ["text"]=>
    array(1) {
      ["*"]=>
      string(59) "<p>This calls the hello world template: Hello, world!.
</p>"
    }
    ["langlinks"]=>
    array(0) {
    }
    ["categories"]=>
    array(0) {
    }
    ["links"]=>
    array(0) {
    }
    ["templates"]=>
    array(0) {
    }
    ["images"]=>
    array(0) {
    }
    ["externallinks"]=>
    array(0) {
    }
    ["sections"]=>
    array(0) {
    }
    ["displaytitle"]=>
    string(3) "API"
    ["iwlinks"]=>
    array(0) {
    }
    ["properties"]=>
    array(0) {
    }
  }
}
  • Templates that contain tables do not wrap their output in paragraph (

    ) tags.

  • When the templates are used on a normal wiki page, no such paragraph tag wrapping occurs

"byteoffset" is a misnomer[edit]

In the "sections" array returned by this API call, the field named "byteoffset" holds the offset of the section within the wikitext markup. Contrary to its name, the offset is measured in code points, not bytes. (Note: non-BMP characters count as one. Beware of UTF-16, especially in JavaScript, where "💩".length === 2.) Keφr 22:11, 10 March 2014 (UTC)

action=parse should give a basetimestamp/starttimestamp when given an oldid[edit]

Say, I want to use action=parse to take the wikitext and some of the more "advanced" parser output, like the section list or the XML tree. If I want to transform the wikitext and save it back, with edit conflict resolution, I need a starttimestamp and/or basetimestamp. Without having it here, I have to round-trip the server twice. Kludgy. Keφr 11:11, 11 March 2014 (UTC)

Argument "disablepp" does not work[edit]

Hi, I hope that I am doing something wrong. Here's my query:

http://de.wikipedia.org/w/api.php?action=parse&format=json&prop=text%7Csections%7Crevid&page=Diskussion:Die%20unendliche%20Geschichte&disablepp=true

As you can see in the output, there is still a comment with preprocessor stuff:

<-- \nNewPP limit report\nParsed by mw1092\nCPU time usage: 0.364 seconds\nReal time usage: 0.482 seconds\nPreprocessor visited node count: 934/1000000\nPreprocessor generated node count: 2144/1500000\nPost\u2010expand include size: 12867/2048000 bytes\nTemplate argument size: 1558/2048000 bytes\nHighest expansion depth: 7/40\nExpensive parser function count: 2/500\n-->

--2A02:8071:B486:2300:2210:7AFF:FEF8:7EEE 21:52, 9 October 2014 (UTC)

You're right. This is a known bug, as reported here and here. – RobinHood70 talk 08:35, 10 October 2014 (UTC)

Request Header Or Cookie Too Large[edit]

Hi, how do I avoid "400 Bad Request - Request Header Or Cookie Too Large"?

or "414 Request-URI Too Long"?

I'm trying to parse the content of this, I would like to make a few automated changes to the source and then to sow it in a html page. אור שפירא (talk) 07:10, 22 July 2015 (UTC)

Are you using GET requests or POST requests ? Try using POST requests (for GET requests, parameters are in the URI; for POST requests, they are outside the URI). --NicoV (talk) 07:15, 22 July 2015 (UTC)

Import wikitext from parsertree[edit]

I wanted to edit wikitext automatically and easily, so I tried to edit it with parsetree. But I couldn't find a way to get wikitext from parsetree. Can't I convert parsetree to wikitext with api? --Gustmd7410 (talk) 23:40, 3 June 2018 (UTC)