Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | * ArticleComments.php - A MediaWiki extension for adding comment sections to articles. |
5 | 5 | * @author Jim R. Wilson |
6 | 6 | * @author Platonides |
7 | | - * @version 0.5.1 |
| 7 | + * @version 0.6 |
8 | 8 | * @copyright Copyright (C) 2007 Jim R. Wilson |
9 | 9 | * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
10 | 10 | * ----------------------------------------------------------------------- |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | * <comments /> |
24 | 24 | * Note: Typically this would be placed at the end of the article text. |
25 | 25 | * Version Notes: |
| 26 | + * version 0.6: |
| 27 | + * Added comments inside <comment> tags instead of article-comments-new-comment message. |
26 | 28 | * version 0.5.1: |
27 | 29 | * Removed the base64 pass |
28 | 30 | * version 0.5: |
— | — | @@ -83,7 +85,7 @@ |
84 | 86 | 'author' => 'Jim R. Wilson - wilson.jim.r <at> gmail.com', |
85 | 87 | 'url' => 'http://jimbojw.com/wiki/index.php?title=ArticleComments', |
86 | 88 | 'descriptionmsg' => 'article-comments-desc', |
87 | | - 'version' => '0.5.1' |
| 89 | + 'version' => '0.6' |
88 | 90 | ); |
89 | 91 | |
90 | 92 | # Add Extension Functions |
— | — | @@ -102,7 +104,8 @@ |
103 | 105 | $wgArticleCommentDefaults = array( |
104 | 106 | 'showurlfield' => true, # Provide an URL field ? |
105 | 107 | 'noscript' => false, # Set to true to not include any ArticleComments related JavaScript |
106 | | - 'hideform' => true # Should the comment field be hidden by default? |
| 108 | + 'hideform' => true, # Should the comment field be hidden by default? |
| 109 | + 'defaultMode' => 'normal', # Which mode should be preselected for comments? Values are: plain, normal and wiki |
107 | 110 | ); |
108 | 111 | |
109 | 112 | /** |
— | — | @@ -122,6 +125,7 @@ |
123 | 126 | # Sets up the ArticleComments Parser hook for <comments /> |
124 | 127 | function wfArticleCommentsParserSetup( &$parser ) { |
125 | 128 | $parser->setHook( 'comments', 'wfArticleCommentsParserHook' ); |
| 129 | + $parser->setHook( 'comment', 'wfArticleCommentsParserHookComment' ); |
126 | 130 | return true; |
127 | 131 | } |
128 | 132 | |
— | — | @@ -130,6 +134,64 @@ |
131 | 135 | return wfArticleCommentForm( $parser->mTitle, $params ); |
132 | 136 | } |
133 | 137 | |
| 138 | +function wfArticleCommentsParserHookComment( $text, $args, $parser, $frame ) { |
| 139 | + global $wgArticleCommentDefaults, $wgParser, $wgParserConf; |
| 140 | + |
| 141 | + if ( $parser === $wgParser ) # Workaround bug 25506 |
| 142 | + $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); |
| 143 | + |
| 144 | + if ( !isset( $args['name'] ) ) |
| 145 | + $args['name'] = wfMsgExt( 'article-comments-comment-missing-name-parameter', array( 'language' => $parser->getFunctionLang() ) ) ; |
| 146 | + |
| 147 | + if ( !isset( $args['url'] ) ) |
| 148 | + $args['url'] = ''; # This one can be empty |
| 149 | + |
| 150 | + if ( !isset( $args['date'] ) ) |
| 151 | + $args['date'] = wfMsgExt( 'article-comments-comment-missing-date-parameter', array( 'language' => $parser->getFunctionLang() ) ) ; |
| 152 | + else |
| 153 | + $args['date'] = $parser->getFunctionLang()->date( wfTimestamp( TS_MW, $args['date'] ) ); |
| 154 | + |
| 155 | + if ( !isset( $args['signature'] ) ) |
| 156 | + $args['signature'] = $args['url'] == '' ? $args['name'] : $parser->getOptions()->getSkin( $parser->getTitle() )->makeExternalLink( $args['url'], $args['name'] ); |
| 157 | + else // The signature is wikitext, so it may need parsing |
| 158 | + $args['signature'] = $parser->recursiveTagParse( $args['signature'], $frame ); |
| 159 | + |
| 160 | + if ( !isset( $args['mode'] ) ) |
| 161 | + $args['mode'] = $wgArticleCommentDefaults['defaultMode']; |
| 162 | + |
| 163 | + $args['mode'] = strtolower( $args['mode'] ); |
| 164 | + if ( $args['mode'] == 'plain' ) { |
| 165 | + // Don't perform any formatting |
| 166 | + |
| 167 | + $text = htmlspecialchars( $text ); |
| 168 | + |
| 169 | + // But make new line generate new paragraphs |
| 170 | + $text = str_replace( "\n", "</p><p>", $text ); |
| 171 | + |
| 172 | + return "<p>$text</p>"; |
| 173 | + } elseif ( $args['mode'] == 'normal' ) { |
| 174 | + // Convert some wikitext oddities to wiki markup |
| 175 | + |
| 176 | + # Need only a newline for new paragraph |
| 177 | + $text = str_replace( "\n", "\n\n", $text ); |
| 178 | + |
| 179 | + # Disable <pre> on space // TODO: Enable space indenting. |
| 180 | + $text = str_replace( "\n ", "\n ", $text ); |
| 181 | + |
| 182 | + } elseif ( $args['mode'] == 'wiki' ) { |
| 183 | + /* Full wikitext */ |
| 184 | + |
| 185 | + } else { |
| 186 | + return wfMsgExt( 'article-comments-comment-bad-mode', array( 'parsemag', 'language' => $parser->getFunctionLang() ) ) ; |
| 187 | + } |
| 188 | + |
| 189 | + # Parse the content, this is later kept as-is since we do a replaceafter there. |
| 190 | + $text = $parser->recursiveTagParse( $text, $frame ); |
| 191 | + |
| 192 | + return wfMsgExt( 'article-comments-comment-contents', array( 'parse', 'replaceafter', 'content' ), |
| 193 | + $args['name'], $args['url'], $args['signature'], $args['date'], $text ); |
| 194 | +} |
| 195 | + |
134 | 196 | /** |
135 | 197 | * Echos out a comment form depending on the page action and namespace. |
136 | 198 | * @param Title $title The title of the article on which the form will appear. |
— | — | @@ -298,7 +360,7 @@ |
299 | 361 | $messages[] = wfMsg( 'article-comments-invalid-field', wfMsgForContent( 'article-comments-title-string' ), $titleText ); |
300 | 362 | } |
301 | 363 | |
302 | | - if ( !$commenterName ) { |
| 364 | + if ( !$commenterName || strpos( $commenterName, "\n" ) !== false ) { |
303 | 365 | $messages[] = wfMsg( 'article-comments-required-field', wfMsgForContent( 'article-comments-name-string' ) ); |
304 | 366 | } |
305 | 367 | |
— | — | @@ -312,7 +374,7 @@ |
313 | 375 | |
314 | 376 | if ( !empty( $messages ) ) { |
315 | 377 | $wgOut->setPageTitle( wfMsg( 'article-comments-submission-failed' ) ); |
316 | | - $wikiText = "<div class='errorbox'>"; |
| 378 | + $wikiText = "<div class='errorbox'>\n"; |
317 | 379 | $wikiText .= wfMsg( 'article-comments-failure-reasons' ) . "\n\n"; |
318 | 380 | foreach ( $messages as $message ) { |
319 | 381 | $wikiText .= "* $message\n"; |
— | — | @@ -330,7 +392,7 @@ |
331 | 393 | # Check whether user is blocked from editing the talk page |
332 | 394 | if ( $wgUser->isBlockedFrom( $talkTitle ) ) { |
333 | 395 | $wgOut->setPageTitle( wfMsg( 'article-comments-submission-failed' ) ); |
334 | | - $wikiText = "<div class='errorbox'>"; |
| 396 | + $wikiText = "<div class='errorbox'>\n"; |
335 | 397 | $wikiText .= wfMsg( 'article-comments-failure-reasons' ) . "\n\n"; |
336 | 398 | $wikiText .= '* ' . wfMsg( 'article-comments-user-is-blocked', $talkTitle->getPrefixedText() ) . "\n"; |
337 | 399 | $wgOut->addWikiText( $wikiText . "</div>" ); |
— | — | @@ -393,20 +455,13 @@ |
394 | 456 | $talkContent = wfMsgForContent( 'article-comments-talk-page-starter', $title->getPrefixedText() ); |
395 | 457 | } |
396 | 458 | |
397 | | - # Determine signature components |
398 | | - if ( $commenterURL != '' ) $sigText = "[$commenterURL $commenterName]"; |
399 | | - else if ( $wgUser->isLoggedIn() ) $sigText = $wgParser->getUserSig( $wgUser ); |
400 | | - else $sigText = $commenterName; |
401 | | - |
402 | 459 | # Search for insertion point, or append most recent comment. |
403 | | - $commentText = wfMsgForContent( |
404 | | - 'article-comments-new-comment', |
405 | | - wfMsgForContent( 'article-comments-commenter-said', $commenterName ), |
406 | | - $comment, |
407 | | - $sigText, |
408 | | - '~~~~~' |
409 | | - ); |
410 | | - |
| 460 | + $commentText = wfMsgForContent( 'article-comments-new-comment-heading', $commenterName, $commenterURL, '~~~~', $comment ); |
| 461 | + $commentText .= '<comment date="' . htmlspecialchars( wfTimestamp( TS_ISO_8601 ) ) . '" name="' . htmlspecialchars( $commenterName ) . '"'; |
| 462 | + if ( $commenterURL != '' ) $commentText .= ' url="' . htmlspecialchars( $commenterURL ) . '"'; |
| 463 | + if ( $wgUser->isLoggedIn() ) $commentText .= ' signature="' . htmlspecialchars( $wgParser->getUserSig( $wgUser ) ) . '"'; |
| 464 | + $commentText .= ">\n" . str_replace( '</comment', '</comment', $comment ) . "\n</comment>"; |
| 465 | + |
411 | 466 | $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
412 | 467 | if ( $posAbove === false ) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
413 | 468 | if ( $posAbove !== false ) { |
Index: trunk/extensions/ArticleComments/ArticleComments.i18n.php |
— | — | @@ -32,7 +32,11 @@ |
33 | 33 | 'article-comments-submission-view-all' => 'You may view all comments on that article [[$1|here]]', |
34 | 34 | 'article-comments-prefilled-comment-text' => '', |
35 | 35 | 'article-comments-user-is-blocked' => 'Your user account is currently blocked from editing [[$1]].', |
36 | | - 'article-comments-new-comment' => "\n== \$1 ==\n\n<div class='commentBlock'>\n\$2\n\n--\$3 \$4\n</div>\n", |
| 36 | + 'article-comments-new-comment-heading' => "\n== {{int:article-comments-commenter-said|\$1}} ==\n\n", |
| 37 | + 'article-comments-comment-bad-mode' => '<div class="error">Invalid mode given for comment. Available ones are plain, normal and wiki.</div>', |
| 38 | + 'article-comments-comment-contents' => "<div class='commentBlock'><small>$4</small>$5--\$3</div>\n", |
| 39 | + 'article-comments-comment-missing-name-parameter' => 'Missing name', |
| 40 | + 'article-comments-comment-missing-date-parameter' => 'Missing comment date', |
37 | 41 | 'article-comments-no-spam' => 'At least one of the submitted fields was flagged as spam.', |
38 | 42 | 'processcomment' => 'Process article comment', |
39 | 43 | ); |
— | — | @@ -41,10 +45,20 @@ |
42 | 46 | 'article-comments-required-field' => 'Shown as a list below article-comments-failure-reasons. With $1 being one of article-comments-*-string messages.', |
43 | 47 | 'article-comments-submission-failed' => 'Page title when there are errors in the comment submission', |
44 | 48 | 'article-comments-invalid-field' => 'Shown as a list below article-comments-failure-reasons. With $1 being article-comments-title-string or article-comments-url-string messages, and $2 the wrong value.', |
45 | | - 'article-comments-new-comment' => 'Text to add in the new comment. |
46 | | -* $1 - Expansion of article-comments-commenter-said. |
47 | | -* $2 - Comment text. |
48 | | -* $3 - Commenter name, possibly linking to its web. |
49 | | -* $4 - Datetime.', |
| 49 | + 'article-comments-new-comment-heading' => 'Wiki text which will appear above the <comment> tags. |
| 50 | + |
| 51 | +Available variables: |
| 52 | +* $1 - Commenter name. |
| 53 | +* $2 - Commenter url (may be empty). |
| 54 | +* $3 - Datetime. |
| 55 | +* $4 - Comment text.', |
| 56 | + 'article-comments-comment-contents' => 'Way in which <comment> tags are parsed. |
| 57 | +Note it is importat not to place the $5 between new-lines in order to get new lines correctly converted into new paragraphs in normal mode (wfMsgExt can\'t place it inside a <p/>). |
| 58 | + |
| 59 | +* $1 - Commenter name. |
| 60 | +* $2 - Comment url. |
| 61 | +* $3 - User signature, if an URL is available, name linking to its web. |
| 62 | +* $4 - Parsed datetime. |
| 63 | +* $5 - Comment text.', |
50 | 64 | ); |
51 | 65 | |