Index: trunk/extensions/PreviewFunctions/PreviewFunctions.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | 'path' => __FILE__, |
34 | 34 | 'name' => 'PreviewFunctions', |
35 | 35 | 'descriptionmsg' => 'previewfunctions-desc', |
36 | | - 'version' => 1, |
| 36 | + 'version' => 2, |
37 | 37 | 'url' => 'https://mediawiki.org/wiki/Extension:PreviewFunctions', |
38 | 38 | 'author' => '[https://mediawiki.org/wiki/User:Bawolff Brian Wolff]', |
39 | 39 | ); |
Index: trunk/extensions/PreviewFunctions/PreviewFunctions.i18n.magic.php |
— | — | @@ -3,5 +3,4 @@ |
4 | 4 | |
5 | 5 | $magicWords['en'] = array( |
6 | 6 | 'ifpreview' => array( 0, 'ifpreview', 'onpreview' ), |
7 | | - 'previewwarning' => array( 0, 'addpreviewwarning' ), |
8 | 7 | ); |
Index: trunk/extensions/PreviewFunctions/PreviewFunctions_body.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | */ |
9 | 9 | public static function register( Parser $parser ) { |
10 | 10 | $parser->setFunctionHook( 'ifpreview', 'PreviewFunctions::ifPreview', Parser::SFH_OBJECT_ARGS ); |
11 | | - $parser->setFunctionHook( 'previewwarning', 'PreviewFunctions::addWarning' ); |
| 11 | + $parser->setHook( 'previewwarning', 'PreviewFunctions::addWarning' ); |
12 | 12 | return true; |
13 | 13 | } |
14 | 14 | |
— | — | @@ -21,32 +21,42 @@ |
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | | - public static function addWarning( $parser, $warning ) { |
| 25 | + /** |
| 26 | + * Syntax: <previewwarning>Warning here</previewwarning> |
| 27 | + * or: <previewwarning nodiv="true">Warning here</previewwarning> |
| 28 | + * or: {{#tag:previewwarning|warning here}} |
| 29 | + * |
| 30 | + * Tried to do this as a parserfunction, but just couldn't get |
| 31 | + * original wikitext back (even with PPFrame::RECOVER_ORIG ) |
| 32 | + * so doing a tag hook. |
| 33 | + * |
| 34 | + * This could also potentially record images/links used, but i think its |
| 35 | + * better that it doesn't (undecided on that). |
| 36 | + */ |
| 37 | + public static function addWarning( $warning, $args, $parser, $frame ) { |
26 | 38 | if ( $warning === '' ) return ''; |
27 | 39 | |
28 | | - // Not 100% sure if doing this right. |
29 | 40 | // Note, EditPage.php parses such warnings |
30 | 41 | // (but with a different parser object) |
31 | 42 | |
32 | | - // Even with something like PPFrame::RECOVER_ORIG - tag extensions are still expanded. |
33 | | - |
34 | | - // Not doing: |
35 | | - // $warning = $parser->mStripState->unstripGeneral( $warning ); |
36 | | - // Because double parses things that should be treated as html. |
37 | | - |
38 | | - // Based on a line in CoreParserFunctions::displaytitle. |
39 | | - // Can't just substitute a <nowiki>$1</nowiki> and then unstripNoWiki, since that doesn't work |
40 | | - // for other extensions that put nowiki content (Since some like $wgRawHtml's <html> |
41 | | - // would not like the tag escaping done by <nowiki>. |
42 | | - // I suppose I could look for the nowiki part of "UNIQ7d3e18c0572c78c3-nowiki-00000031-QINU" |
43 | | - // but thats super hacky. So just delete the strip items. |
| 43 | + // To make it work when using {{#tag:...}} syntax. (or i suppose fail better...) |
44 | 44 | $warning = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?' |
45 | 45 | . preg_quote( Parser::MARKER_SUFFIX, '/' ) . '/', |
46 | 46 | '', |
47 | 47 | $warning |
48 | 48 | ); |
49 | 49 | |
50 | | - $warning = Html::rawElement( 'div', array( 'class' => 'error mw-previewfunc-warning' ), $warning ); |
| 50 | + |
| 51 | + // Could do something complicated here to expand {{{1}}} but not anything else |
| 52 | + // (aka new parser instance and then do Parser::preprocess on it, i think. |
| 53 | + // Don't want to do Parser::recursivePreprocess as that does extensions too) |
| 54 | + // but not doing that (at least for now). |
| 55 | + |
| 56 | + |
| 57 | + if ( !isset( $args['nodiv'] ) ) { |
| 58 | + $warning = Html::rawElement( 'div', array( 'class' => 'error mw-previewfunc-warning' ), $warning ); |
| 59 | + } |
51 | 60 | $parser->getOutput()->addWarning( $warning ); |
| 61 | + return ''; |
52 | 62 | } |
53 | 63 | } |