User:Barre/MediaWiki/Extensions/kw include file

From KitwarePublic
Jump to navigationJump to search

<kw_bread_crumbs>prefix=» |small=1|bgcolor=F9F9F9|trim_prefix=User:|on_top_hack=1</kw_bread_crumbs> <kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwIncludeFile.php?content-type=text%2Fplain&root=kwGridWeb%7Cpre=0%7Cwiki_markup=1%7Ccollapse_par=1%7Cpreg_match=/.*\/\*\s*(==.*?)^\*\//sm</kw_include_file>

Examples

First let's include a small file:

<kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/README.txt?root=kwGrid</kw_include_file>

...is rendered as: <kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/README.txt?root=kwGrid</kw_include_file>

Now for something more complex: note that the whole documentation above this section is included straight from the extension code itself ! Here is how it is done:

<kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwIncludeFile.php?content-type=text%2Fplain&root=kwGridWeb|pre=0|wiki_markup=1|collapse_par=1|preg_match=/.*\/\*\s*(==.*?)^\*\//sm</kw_include_file>

The hairy URL is followed by several options. The pre=0 parameter means that we do not want the text to be inserted verbatim inside PRE.../PRE tags. The wiki_markup=1 parameter specifies that the text is to be interpreted as Wiki markup. The (optional) collapse_par=1 parameter helps the Wiki engine by collapsing lines into paragraphs. The preg_match parameter specificies a regular expression that is used to extract only the documentation portion of the remote file: nothing fancy here, we are just looking for the string starting with == right inside a PHP comment /* ... */.

You can also include the contents of a wiki page (in that example, the User:Barre page):

<kw_include_file>url=http://public.kitware.com/Wiki?title=User:Barre&action=raw|pre=0|wiki_markup=1</kw_include_file>

<kw_include_file>url=http://public.kitware.com/Wiki?title=User:Barre&action=raw%7Cpre=0%7Cwiki_markup=1</kw_include_file>