Hello.
Is it possible to add dynamic contents to the pages of WikiMedia? For example to include some statistics from an underlying .xml file?
Arvalux.
On Mon, 11 Oct 2004 20:30:49 +0200, Arvalux arvalux@yahoo.de wrote:
Hello.
Is it possible to add dynamic contents to the pages of WikiMedia? For example to include some statistics from an underlying .xml file?
Arvalux.
AFAIK, there is no flexible tool for doing this developed as yet. There are a few magic variables, such as {{SITENAME}} and {{NUMBEROFARTICLES}} which when inserted in wiki-text will be replaced on demand by the software, but for a more complex case, it might be worth developing an 'extension' with similar syntax to the <math> markup.
For instance, you could define <xml>data.xml: title</xml> to get the <title> element out of a file called "data.xml". (This is a rather dumb example, but the point is the software has "hooks" for interfacing with 'external' code in this way).
Arvalux wrote:
Is it possible to add dynamic contents to the pages of WikiMedia? For example to include some statistics from an underlying .xml file?
You can register an extension (currently an euphemism;-) as it was done for <math>. For your extenstion foo, the wiki text <foo>bar</foo> will then pass "bar" to a PHP function of your choice. You can also access the global $wgTitle or the like to include a file associated with the article title, or something.
Magnus
-----Ursprüngliche Nachricht----- Von: wikitech-l-bounces@wikimedia.org [mailto:wikitech-l-bounces@wikimedia.org] Im Auftrag von Magnus Manske Gesendet: Montag, 11. Oktober 2004 22:02 An: Wikimedia developers Betreff: Re: [Wikitech-l] dynamic contents in WikiMedia pages?
Arvalux wrote:
Is it possible to add dynamic contents to the pages of WikiMedia? For example to include some statistics from an underlying .xml file?
You can register an extension (currently an euphemism;-) as it was done for <math>. For your extenstion foo, the wiki text <foo>bar</foo> will then pass "bar" to a PHP function of your choice. You can also access the global $wgTitle or the like to include a file associated with the article title, or something.
Magnus
--------------------------------------------
Yeeeeeeeehhaaaaaaa! :-)
I've added following lines at the end of Setup.php:
function ParsePHPTag($Content) { ob_start(); eval($Content); $Result = ob_get_contents(); ob_end_clean(); return($Result); }
$wgParser->setHook('php','ParsePHPTag');
and I've added the following to a regular site, edited by click 'edit':
<php> echo date('Y-m-d H:i:s'); </php>
Whats the result?
2004-10-12 01:11:23
It does its work! Yeeepiee! :-) Now WikiMedia is my favorite UECMS - User Editable CMS ;-)
Of course, I'll remove my changes from the native WikiMedia files and put them in separate files.
Thanks for help!
Arvalux.
((I'm ask if I hold any copyright to anything of the presented solution in this mail or that this email is an annotation for. -- No, I do not hold any copyright, feel free to use this soolution. You can send me a mail of what you've done with it or how you extended it, especially if you can solve the problem described at the end.))
Annotations for the php-solution in my last email.
The *problem* was:
Is it possible to add dynamic contents to the pages of WikiMedia? For example to include some statistics from an underlying .xml file?
The *help* was (thanks Magnus):
You can use the same way of implementation, for example the <math>-tag uses. Like "math" you can register an extention "php" and a php function to handle the contents enclosed by <php>- and </php>-tags.
My *solution* is:
When searching for file content "math" you get many files... studying the code leads me to Parser.php, then it leads me to setHook(...) - thats the function. Then I searched for "new Parser", where the parser is created, that leads to Setup.php. For test purposes I wrote my code directly at the end of Setup.php. I think it's better to put it in a separate file just leaving a link in the Setup.php. At least when updating the MediaWiki software it minimizes the reimplementation.
My code at the end of Setup.php is:
function ParsePHPTag($Content) { ob_start(); eval($Content); $Result = ob_get_contents(); ob_end_clean(); return($Result); } $wgParser->setHook('php','ParsePHPTag');
And I've added somewhere as content in a regular WikiMedia site ([[PHP_Test]]):
<php> // output the date in format yyyy-mm-dd, hh:nn:ss echo date('Y-m-d, H:i:s'); </php>
The result is:
2004-10-12 01:11:23
(Ok, seems to work) Clicking refresh the result is:
2004-10-12 01:11:23
Hm, what goes wrong here? I guess it has something to do with the cache. When loading the page's 'code' it is always the same, hence it seems to me this is the criteria if the page is rendered or not - simply following a rule "same code results in same output". In other words: when the rendered output of a page is in cache and the cached timestamp matches the timestamp of the page (or its 'code') to be load the page will not rendered again.
I tried to find out how to #prevent a page from being cached, # force a reload of a page, # clear a certain page from cache, # clear the cache, or something like that. But I myself have to ask for help. (Look for an email "influence the cache".)
Arvalux.
wikitech-l@lists.wikimedia.org