Extension talk:BBCodeSyntax/Archive 1
Contents |
[edit] To Do...
- Add URL support.
- Clean up SPAN tags.
- Figure out implementation of IMG tag.
- Get HTML sizes working for FONT.
- Change GREEDY matches to LAZY matches. See below.
- Actually get v0.2 ready for posting.
- Optimize with arrays (per Pawelabrams suggestion)
- Make sure to post process and strip HTML from the inputted BBCode (as advised under "Do not trust the user")
- Acutally work on the extension.
--KaizenNeko 07:38, 31 July 2009 (UTC)
[edit] [v0.1] Nested BBCode Parsing Bug
Identical tags that are nested in other tags are not parsed.
- I actually found a solution to this and will be issuing an update later on.
- Basically the fix involves using LAZY matches instead of GREEDY ones.
--NekoOuterverse 15:25, 11 February 2008 (UTC)
[edit] Other BBCodes from HTML
Maybe add abbr, pre, table(s) similar tags to v0.3? --NekoOuterverse 14:24, 2 July 2008 (UTC)
[edit] This looks quite slow
This could be done using 5-6 preg_replaces and 2 str_replaces. I'll post a code snippet soon. Pawelabrams (mail me on gmail, same nick ;p ), 86.63.134.78 21:02, 24 March 2009 (UTC)
- Yup, I knew I had something like that somewhere... Re-made one, currently 5 tags supported: Pawelabrams, 86.63.134.78 21:02, 24 March 2009 (UTC)
<?php // Confirm MediaWiki environment if (!defined('MEDIAWIKI')) die(); // Credits $wgExtensionCredits['other'][] = array( 'name'=>'BBCodeSyntax', 'author'=>'Paul Deveau <nekoouterverse@black-blade.net>', 'url'=>'http://www.mediawiki.org/wiki/Extension:BBCodeSyntax', 'description'=>'Adds support for BBCode syntax as used by many popular bulletin board software packages, along with a few I use on my site often.', 'version'=>'0.1' ); // Attach Hook $wgHooks['ParserAfterTidy'][] = 'wfBBCodeSyntax'; function wfBBCodeSyntax(&$parser, &$text) { // noparse - Render raw BBCode without being parsed $holdNP = $text; preg_match('%\[noparse\](.+)\[/noparse\]%i', $holdNP, $matches); $workNP = $matches[1]; $workNP = preg_replace('/\[/i', '[', $workNP); $workNP = preg_replace('/\]/i', ']', $workNP); $text = preg_replace('%\[noparse\](.+)\[/noparse\]%i', $workNP, $text); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is' ); $replace = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$1</a>', '<a href="$1">$2</a>' ); $text = preg_replace ($search, $replace, $text); return true; }
- My knowledge at the time was (and still is) pretty basic of Regex & PHP. I'll make sure to implement arrays if I update this thing again.
[edit] Do not trust the user
Script doesn't verify if the values are correct or not. In the BGCOLOR code you just insert in the style attribute one could insert anything.. like
[bgcolor=" ><script language="javascript">alert(1);</script>red]background[/bgcolor]
It's not that hard to add code to check for some color constants.
- Basically I need to add in a post processor that strips HTML tags from being inserted.
[edit] Joining in the project...
Well, I've decided to join in the BBCode for MediaWiki project and improve the extension with my knowledge of PHP! Techjar 14:56, 13 August 2009 (UTC)
[edit] Suggestion for [url] tag
Hi, i resolved the [url] tag problem (and [img]), with a conversion from bbcode to wiki (and not to html), with the ParserBeforeStrip hook.
$out = preg_replace("/\\[url\\](.+?)\[\/url\]/is",'[\1 \1]', $out); $out = preg_replace("/\\[url=(.+?)\\](.+?)\[\/url\]/is",'[\1 \2]', $out); $out = preg_replace("/\\[img\\](.+?)\[\/img\]/is",'\1', $out);