Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | /* |
4 | 4 | * ArticleComments.php - A MediaWiki extension for adding comment sections to articles. |
5 | 5 | * @author Jim R. Wilson |
6 | | - * @version 0.4.2 |
| 6 | + * @version 0.4.3 |
7 | 7 | * @copyright Copyright (C) 2007 Jim R. Wilson |
8 | 8 | * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
9 | 9 | * ----------------------------------------------------------------------- |
— | — | @@ -22,6 +22,9 @@ |
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.4.3: |
| 27 | + * Added new insertion feature, comments will now be inserted before <!--COMMENTS_ABOVE--> if present |
| 28 | + * Or, after <!--COMMENTS_BELOW--> if present (the latter causes reverse chronological comment ordering). |
26 | 29 | * version 0.4.2: |
27 | 30 | * Updated default spam filtering code to check all fields against $wgSpamRegex, if specified. |
28 | 31 | * version 0.4.1: |
— | — | @@ -413,17 +416,28 @@ |
414 | 417 | if ($commenterURL && $commenterURL!='http://') $sigText = "[$commenterURL $commenterName]"; |
415 | 418 | else if ($wgUser->isLoggedIn()) $sigText = $wgParser->getUserSig( $wgUser ); |
416 | 419 | else $sigText = $commenterName; |
| 420 | + |
| 421 | + # Search for insertion point, or append most recent comment. |
| 422 | + $commentText = wfMsgForContent( |
| 423 | + $ac.'new-comment', |
| 424 | + wfMsgForContent($ac.'commenter-said', $commenterName), |
| 425 | + $comment, |
| 426 | + $sigText, |
| 427 | + $d |
| 428 | + ); |
| 429 | + $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
| 430 | + if ($posAbove===false) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
| 431 | + if ($posAbove!==false) { |
| 432 | + # Insert comments above HTML marker |
| 433 | + $talkContent = substr( $talkContent, 0, $posAbove ) . $commentText . substr( $talkContent, $posAbove ); |
| 434 | + } else if ($posBelow!==false) { |
| 435 | + # Insert comments below HTML marker |
| 436 | + $talkContent = substr( $talkContent, 0, $posBelow + 21 ) . $commentText . substr( $talkContent, $posBelow + 21 ); |
| 437 | + } else { |
| 438 | + # No marker found, append to bottom (default) |
| 439 | + $talkContent .= $commentText; |
| 440 | + } |
417 | 441 | |
418 | | - # Append most recent comment |
419 | | - $talkContent .= |
420 | | - wfMsgForContent( |
421 | | - $ac.'new-comment', |
422 | | - wfMsgForContent($ac.'commenter-said', $commenterName), |
423 | | - $comment, |
424 | | - $sigText, |
425 | | - $d |
426 | | - ); |
427 | | - |
428 | 442 | # Update the talkArticle with the new comment |
429 | 443 | $summary = wfMsgForContent($ac.'summary', $commenterName); |
430 | 444 | if (method_exists($talkArticle, 'doEdit')) { |