User:Barre/MediaWiki/Extensions: Difference between revisions
No edit summary |
(Noted that links to extensions give error message) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{User:Barre/Template/Header}} | |||
[http://www.mediawiki.org/ MediaWiki], the software that runs this Wiki site, allows developers to [http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension write their own extensions] to the Wiki markup. An extension defines an HTML/XML-style tag which can be used in the Wiki editor like any other markup. If you want to write your own extensions, check those [[#Resources|resources]]. | |||
So here it goes... <-- '''The links below give an error message: "Fatal error: Call to undefined function: setshowtoc() in /mounts/raid/projects/KitwareWeb/mediawiki-1.5.7-namic/extensions/kwIncludeFile.php on line 303"/''' --[[User:JohnMcDonnell|JohnMcDonnell]] 10:46, 9 May 2006 (EDT) | |||
* <tt>[[User:Barre/Extensions/kw_bread_crumbs|kw_bread_crumbs]]</tt><br><kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwBreadCrumbs.php?content-type=text%2Fplain&root=kwGridWeb|pre=0|collapse_par=1|preg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> | |||
* <tt>[[User:Barre/Extensions/kw_include_file|kw_include_file]]</tt><br><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|collapse_par=1|preg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> | |||
* <tt>[[User:Barre/Extensions/kw_site_map|kw_site_map]]</tt><br><kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwSiteMap.php?content-type=text%2Fplain&root=kwGridWeb|pre=0|collapse_par=1|preg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> | |||
* <tt>[[User:Barre/Extensions/kw_article_time_stamp|kw_article_time_stamp]]</tt><br><kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwArticleTimeStamp.php?content-type=text%2Fplain&root=kwGridWeb|pre=0|collapse_par=1|preg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> | |||
===Resources=== | |||
* [http://wikipedia.sourceforge.net/docs/html MediaWiki generated documentation] | |||
* [http://meta.wikimedia.org/wiki/Help:Contents#For_MediaWiki_hackers Help For Mediawiki Hackers] | |||
* [http://meta.wikimedia.org/wiki/Database_layout Database Layout] and [http://cvs.sourceforge.net/viewcvs.py/wikipedia/phase3/docs/schema.doc?view=markup Schema] | |||
* [http://wise-nano.org/w/Programming_notes Programming notes] (Chris Phoenix, CRN) | |||
* [http://mail.wikimedia.org/ Wikimedia mailing lists] | |||
===Cache Problem=== | |||
As of MediaWiki 1.3 and 1.4, the extension feature is limited by the caching mechanism. If your extension is used to display dynamic contents and therefore needs to be re-executed each time the page is accessed, you will notice pretty early on that it does not work as expected. The problem is that MediaWiki caches the contents of the page the first time it is rendered, and serves that cached output until the corresponding page is modified again. Several parameters are considered when the decision is made to use the cached output instead of re-rendering the page, and most of them deal with comparing the creation time of the cache against the creation time of the page (cur_timestamp/cur_touched is the SQL database). If the cache is older than the page, it is re-rendered. | |||
The code below uses that knowledge to 'touch' the page and invalidate its cache. It is indeed slightly identical to the code in the Title::invalidateCache() method. Sadly invalidateCache() can not be used in an extension: even though it sets cur_touched to 'now', at the time we would be calling this method we would still be in the process of creating and rendering the page itself and the page would be cached anyway once we would be done with our extension. At the end of the day the cache would always end up newer than cur_touched, defeating the whole purpose of calling invalidateCache(). The trick here is to set cur_touched in the future, something not too intrusive, say 'now' + 120 seconds, provided that we expect the whole page (and our extension code) to be executed and rendered within 120 seconds. That way, cur_touched remains 'fresher' than the cache, and the next time the page is accessed, the cache creation time will appear to be older than cur_touched, forcing the page to be re-rendered, and forcing cur_touched to be, again, set in the future and appear fresher than the new cache, etc. | |||
$ts = mktime(); | |||
$now = gmdate("YmdHis", $ts + 120); | |||
$ns = $wgTitle->getNamespace(); | |||
$ti = wfStrencode($wgTitle->getDBkey()); | |||
$sql = "UPDATE cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; | |||
wfQuery($sql, DB_WRITE, ""); |
Latest revision as of 14:46, 9 May 2006
<kw_bread_crumbs>prefix=» |small=1|bgcolor=F9F9F9|trim_prefix=User:|on_top_hack=1</kw_bread_crumbs> MediaWiki, the software that runs this Wiki site, allows developers to write their own extensions to the Wiki markup. An extension defines an HTML/XML-style tag which can be used in the Wiki editor like any other markup. If you want to write your own extensions, check those resources.
So here it goes... <-- The links below give an error message: "Fatal error: Call to undefined function: setshowtoc() in /mounts/raid/projects/KitwareWeb/mediawiki-1.5.7-namic/extensions/kwIncludeFile.php on line 303"/ --JohnMcDonnell 10:46, 9 May 2006 (EDT)
- kw_bread_crumbs
<kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwBreadCrumbs.php?content-type=text%2Fplain&root=kwGridWeb%7Cpre=0%7Ccollapse_par=1%7Cpreg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> - kw_include_file
<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%7Ccollapse_par=1%7Cpreg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> - kw_site_map
<kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwSiteMap.php?content-type=text%2Fplain&root=kwGridWeb%7Cpre=0%7Ccollapse_par=1%7Cpreg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file> - kw_article_time_stamp
<kw_include_file>url=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/scripts/media-wiki-extensions/kwArticleTimeStamp.php?content-type=text%2Fplain&root=kwGridWeb%7Cpre=0%7Ccollapse_par=1%7Cpreg_match=/\/\*\s*=*Description=*\s*(.*?)\n\n/sm</kw_include_file>
Resources
- MediaWiki generated documentation
- Help For Mediawiki Hackers
- Database Layout and Schema
- Programming notes (Chris Phoenix, CRN)
- Wikimedia mailing lists
Cache Problem
As of MediaWiki 1.3 and 1.4, the extension feature is limited by the caching mechanism. If your extension is used to display dynamic contents and therefore needs to be re-executed each time the page is accessed, you will notice pretty early on that it does not work as expected. The problem is that MediaWiki caches the contents of the page the first time it is rendered, and serves that cached output until the corresponding page is modified again. Several parameters are considered when the decision is made to use the cached output instead of re-rendering the page, and most of them deal with comparing the creation time of the cache against the creation time of the page (cur_timestamp/cur_touched is the SQL database). If the cache is older than the page, it is re-rendered.
The code below uses that knowledge to 'touch' the page and invalidate its cache. It is indeed slightly identical to the code in the Title::invalidateCache() method. Sadly invalidateCache() can not be used in an extension: even though it sets cur_touched to 'now', at the time we would be calling this method we would still be in the process of creating and rendering the page itself and the page would be cached anyway once we would be done with our extension. At the end of the day the cache would always end up newer than cur_touched, defeating the whole purpose of calling invalidateCache(). The trick here is to set cur_touched in the future, something not too intrusive, say 'now' + 120 seconds, provided that we expect the whole page (and our extension code) to be executed and rendered within 120 seconds. That way, cur_touched remains 'fresher' than the cache, and the next time the page is accessed, the cache creation time will appear to be older than cur_touched, forcing the page to be re-rendered, and forcing cur_touched to be, again, set in the future and appear fresher than the new cache, etc.
$ts = mktime(); $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace(); $ti = wfStrencode($wgTitle->getDBkey()); $sql = "UPDATE cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; wfQuery($sql, DB_WRITE, "");