Hello Wikimedia devlopers:
I was looking for a way to add a new custom tag to wikimedia. I found a second of code that looked promising:
# Create an HTML-style tag, e.g. <yourtag>special text</yourtag> # Callback will be called with the text within # Transform and return the text within function setHook( $tag, $callback ) { $oldVal = @$this->mTagHooks[$tag]; $this->mTagHooks[$tag] = $callback; return $oldVal; }
Unfortunately setHook isn't used anywhere so I have no example to work with and I don't know where the best place to insert the hook from. Anyone have any hints I could use?
Thanks
-John
Hacksprint wrote:
Unfortunately setHook isn't used anywhere so I have no example to work with and I don't know where the best place to insert the hook from. Anyone have any hints I could use?
We've got a couple of extensions in CVS: http://cvs.sourceforge.net/viewcvs.py/wikipedia/extensions/
EasyTimeline and WikiHiero are in use on Wikipedia so should be in a reasonably working state.
-- brion vibber (brion @ pobox.com)
Brion Vibber wrote:
Hacksprint wrote:
Unfortunately setHook isn't used anywhere so I have no example to work with and I don't know where the best place to insert the hook from. Anyone have any hints I could use?
We've got a couple of extensions in CVS: http://cvs.sourceforge.net/viewcvs.py/wikipedia/extensions/
EasyTimeline and WikiHiero are in use on Wikipedia so should be in a reasonably working state.
Just to add to that, MediaWiki extensions are switched on by including the PHP file from LocalSettings.php. When the file is included, it will register an extension function, and the extension function will be called back from Setup.php once the environment is fully initialised. Inside the extension function, you can do things like adding parser hooks and special pages.
-- Tim Starling
Tim Starling wrote:
Brion Vibber wrote:
Hacksprint wrote:
Unfortunately setHook isn't used anywhere so I have no example to work with and I don't know where the best place to insert the hook from. Anyone have any hints I could use?
We've got a couple of extensions in CVS: http://cvs.sourceforge.net/viewcvs.py/wikipedia/extensions/
EasyTimeline and WikiHiero are in use on Wikipedia so should be in a reasonably working state.
Just to add to that, MediaWiki extensions are switched on by including the PHP file from LocalSettings.php. When the file is included, it will register an extension function, and the extension function will be called back from Setup.php once the environment is fully initialised. Inside the extension function, you can do things like adding parser hooks and special pages.
-- Tim Starling
I added "include_once( "extensions/rblog.php" );" to my LocalSettings.php
Is this adequate for a minimal extension? I can't get it to do something useful with the <rblog> tag. Thanks
<?php
# Remote Blog extension # To use, include this file from your LocalSettings.php # To configure, set members of $wgRemoteBlogSettings after the inclusion
class RemoteBlogSettings { var $settings; }; $wgRemoteBlogSettings = new RemoteBlogSettings; $wgRemoteBlogSettings->settings="";
$wgExtensionFunctions[] = "wfRemoteBlogExtension";
function wfRemoteBlogExtension() { global $wgParser; $wgParser->setHook( "rblog", "ext_rblog_hook" ); }
function ext_rblog_hook( $rblog_src ) { return "Hello World" . $rblog_src; }
?>
My bad, I included the extension PHP file before DefaultSettings.php which was way too early. It all works now. Thanks to everyone who helped!
Hacksprint wrote:
Tim Starling wrote:
Brion Vibber wrote:
Hacksprint wrote:
Unfortunately setHook isn't used anywhere so I have no example to work with and I don't know where the best place to insert the hook from. Anyone have any hints I could use?
We've got a couple of extensions in CVS: http://cvs.sourceforge.net/viewcvs.py/wikipedia/extensions/
EasyTimeline and WikiHiero are in use on Wikipedia so should be in a reasonably working state.
Just to add to that, MediaWiki extensions are switched on by including the PHP file from LocalSettings.php. When the file is included, it will register an extension function, and the extension function will be called back from Setup.php once the environment is fully initialised. Inside the extension function, you can do things like adding parser hooks and special pages.
-- Tim Starling
I added "include_once( "extensions/rblog.php" );" to my LocalSettings.php
Is this adequate for a minimal extension? I can't get it to do something useful with the <rblog> tag. Thanks
<?php # Remote Blog extension # To use, include this file from your LocalSettings.php # To configure, set members of $wgRemoteBlogSettings after the inclusion class RemoteBlogSettings { var $settings; }; $wgRemoteBlogSettings = new RemoteBlogSettings; $wgRemoteBlogSettings->settings=""; $wgExtensionFunctions[] = "wfRemoteBlogExtension"; function wfRemoteBlogExtension() { global $wgParser; $wgParser->setHook( "rblog", "ext_rblog_hook" ); } function ext_rblog_hook( $rblog_src ) { return "Hello World" . $rblog_src; } ?>
Wikitech-l mailing list Wikitech-l@wikimedia.org http://mail.wikipedia.org/mailman/listinfo/wikitech-l
Is it true that callbacks set by setHook can only handle tags of the form:
<tag>content</tag>
And not tags of the form:
<tag attribute="value">content</tag>
Thanks
Hacksprint wrote:
Is it true that callbacks set by setHook can only handle tags of the form:
<tag>content</tag>
And not tags of the form:
<tag attribute="value">content</tag>
Thanks
That's correct. If you know your way around a regex you could probably change that, by fixing Parser.php and sending us the patch. I imagine you could pass an array of attributes to the hook function as a second parameter. You'd just have to change the regexes used to identify these tags.
-- Tim Starling
wikitech-l@lists.wikimedia.org