Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -1,8 +1,9 @@ |
2 | | -<?php //{{MediaWikiExtension}}<source lang="php"> |
| 2 | +<?php |
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.4 |
| 6 | + * @author Platonides |
| 7 | + * @version 0.5 |
7 | 8 | * @copyright Copyright (C) 2007 Jim R. Wilson |
8 | 9 | * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
9 | 10 | * ----------------------------------------------------------------------- |
— | — | @@ -10,8 +11,7 @@ |
11 | 12 | * This is a MediaWiki (http://www.mediawiki.org/) extension which adds support |
12 | 13 | * for comment sections within article pages, or directly into all pages. |
13 | 14 | * Requirements: |
14 | | - * MediaWiki 1.6.x, 1.8.x, 1.9.x or higher |
15 | | - * PHP 4.x, 5.x or higher |
| 15 | + * MediaWiki 1.16.x or higher |
16 | 16 | * Installation: |
17 | 17 | * 1. Drop this script (ArticleComments.php) in $IP/extensions |
18 | 18 | * Note: $IP is your MediaWiki install dir. |
— | — | @@ -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.5: |
| 27 | + * Updated to work with MediaWiki 1.16+ |
26 | 28 | * version 0.4.3: |
27 | 29 | * Added new insertion feature, comments will now be inserted before <!--COMMENTS_ABOVE--> if present |
28 | 30 | * Or, after <!--COMMENTS_BELOW--> if present (the latter causes reverse chronological comment ordering). |
— | — | @@ -78,22 +80,52 @@ |
79 | 81 | 'author'=>'Jim R. Wilson - wilson.jim.r <at> gmail.com', |
80 | 82 | 'url'=>'http://jimbojw.com/wiki/index.php?title=ArticleComments', |
81 | 83 | 'description'=>'Enables comment sections on article pages.', |
82 | | - 'version'=>'0.4.1' |
| 84 | + 'version'=>'0.5' |
83 | 85 | ); |
84 | 86 | |
85 | 87 | # Add Extension Functions |
86 | | -$wgExtensionFunctions[] = 'wfArticleCommentsParserSetup'; |
| 88 | +$wgExtensionMessagesFiles['ArticleComments'] = dirname( __FILE__ ) . "/ArticleComments.i18n.php"; |
87 | 89 | |
| 90 | + |
| 91 | +# Attach Hooks |
| 92 | +$wgHooks['ParserFirstCallInit'][] = 'wfArticleCommentsParserSetup'; |
| 93 | +$wgHooks['SkinAfterContent'][] = 'wfArticleCommentsAfterContent'; |
| 94 | +$wgHooks['ParserAfterTidy'][] = 'wfProcessEncodedContent'; |
| 95 | +$wgHooks['ArticleCommentsSpamCheck'][] = 'defaultArticleCommentSpamCheck'; |
| 96 | + |
| 97 | +/** |
| 98 | + * Comment options |
| 99 | + * May be overriden as parameters to the <comment> tag |
| 100 | + */ |
| 101 | +$wgArticleCommentDefaults = array( |
| 102 | + 'showurlfield' => true, # Provide an URL field ? |
| 103 | + 'noscript' => false, # Set to true to not include any ArticleComments related JavaScript |
| 104 | + 'hideform' => true # Should the comment field be hidden by default? |
| 105 | + ); |
| 106 | + |
| 107 | +/** |
| 108 | + * List of namespaces on which a comment field is automatically added. |
| 109 | + * Eg. $wgArticleCommentsNSDisplayList[] = NS_MAIN; |
| 110 | + */ |
| 111 | +$wgArticleCommentsNSDisplayList = array(); |
| 112 | + |
| 113 | +# Sets up special page to handle comment submission |
| 114 | +$wgExtensionFunctions[] = 'setupSpecialProcessComment'; |
| 115 | + |
| 116 | +function setupSpecialProcessComment() { |
| 117 | + SpecialPage::addPage( new SpecialPage( 'ProcessComment', '', true, 'specialProcessComment', false ) ); |
| 118 | +} |
| 119 | + |
88 | 120 | # Sets up the ArticleComments Parser hook for <comments /> |
89 | | -function wfArticleCommentsParserSetup() { |
90 | | - global $wgParser; |
91 | | - $wgParser->setHook( 'comments', 'wfArticleCommentsParserHook' ); |
| 121 | +function wfArticleCommentsParserSetup( &$parser ) { |
| 122 | + $parser->setHook( 'comments', 'wfArticleCommentsParserHook' ); |
| 123 | + return true; |
92 | 124 | } |
93 | | -function wfArticleCommentsParserHook( $text, $params = array(), $parser ) { |
94 | 125 | |
| 126 | +function wfArticleCommentsParserHook( $text, $params = array(), $parser ) { |
95 | 127 | # Generate a comment form for display |
96 | 128 | $commentForm = wfArticleCommentForm( $parser->mTitle, $params ); |
97 | | - |
| 129 | + |
98 | 130 | # Hide content from the Parser using base64 to avoid mangling. |
99 | 131 | # Note: Content will be decoded after Tidy has finished its processing of the page. |
100 | 132 | return '<pre>@ENCODED@'.base64_encode($commentForm).'@ENCODED@</pre>'; |
— | — | @@ -104,7 +136,7 @@ |
105 | 137 | * @param Title $title The title of the article on which the form will appear. |
106 | 138 | * @param Array $params A hash of parameters containing rendering options. |
107 | 139 | */ |
108 | | -function displayArticleCommentForm( $title = null, $params = array() ) { |
| 140 | +function wfArticleCommentsAfterContent( $data, $skin ) { |
109 | 141 | |
110 | 142 | global $wgRequest, $wgArticleCommentsNSDisplayList; |
111 | 143 | |
— | — | @@ -112,16 +144,16 @@ |
113 | 145 | if ($wgRequest->getVal('action') && |
114 | 146 | $wgRequest->getVal('action')!='view' && |
115 | 147 | $wgRequest->getVal('action')!='purge' |
116 | | - ) return; |
| 148 | + ) return true; |
117 | 149 | |
118 | | - # Short-circuit if displayl ist is undefined or null |
119 | | - if ($wgArticleCommentsNSDisplayList==null) return; |
| 150 | + # Short-circuit if displaylist is undefined, empty or null |
| 151 | + if ($wgArticleCommentsNSDisplayList == null) |
| 152 | + return true; |
120 | 153 | |
121 | | - # Use wgTitle if title is not specified |
122 | | - if ($title==null) { |
123 | | - global $wgTitle; |
124 | | - $title = $wgTitle; |
125 | | - } |
| 154 | + $title = $skin->getTitle(); |
| 155 | + if ( !$title->exists() ) { |
| 156 | + return true; |
| 157 | + } |
126 | 158 | |
127 | 159 | # Ensure that the namespace list is an actual list |
128 | 160 | $nsList = $wgArticleCommentsNSDisplayList; |
— | — | @@ -129,20 +161,20 @@ |
130 | 162 | |
131 | 163 | # Display the form |
132 | 164 | if (in_array($title->getNamespace(), $nsList)) { |
133 | | - echo(wfArticleCommentForm($title, $params)); |
| 165 | + $data .= wfArticleCommentForm($title, $params); |
134 | 166 | } |
135 | 167 | |
| 168 | + return true; |
136 | 169 | } |
137 | 170 | |
138 | 171 | /** |
139 | | - * Generates and returns an ArticleComment form. |
| 172 | + * Generates and returns an ArticleComment form html. |
140 | 173 | * @param Title $title The title of the article on which the form will appear. |
141 | 174 | * @param Array $params A hash of parameters containing rendering options. |
142 | 175 | */ |
143 | | -function wfArticleCommentForm( $title = null, $params = array() ) { |
| 176 | +function wfArticleCommentForm( $title, $params = array() ) { |
144 | 177 | |
145 | | - global $wgScript, $wgArticleCommentDefaults, $wgContentLang, $wgContLang; |
146 | | - $wcl = ($wgContentLang ? $wgContentLang : $wgContLang); |
| 178 | + global $wgScript, $wgArticleCommentDefaults, $wgContLang; |
147 | 179 | |
148 | 180 | # Merge in global defaults if specified |
149 | 181 | if (is_array($wgArticleCommentDefaults) && |
— | — | @@ -154,34 +186,28 @@ |
155 | 187 | $params = array_merge($tmp, $params); |
156 | 188 | } |
157 | 189 | |
158 | | - # Use wgTitle if title is not specified |
159 | | - if ($title==null) { |
160 | | - global $wgTitle; |
161 | | - $title = $wgTitle; |
162 | | - } |
163 | | - |
164 | 190 | $ac = 'article-comments-'; |
165 | | - $formAction = $wgScript.'?title='.$wcl->getNsText(NS_SPECIAL).':ProcessComment'; |
| 191 | + $formAction = $wgScript.'?title='.$wgContLang->getNsText(NS_SPECIAL).':ProcessComment'; |
166 | 192 | |
167 | 193 | # Build out the comment form. |
168 | 194 | $content = |
169 | 195 | '<div id="commentForm">'. |
170 | | - '<form method="post" action="'.$formAction.'">'. |
| 196 | + '<form method="post" action="'. htmlspecialchars( $formAction ) .'">'. |
171 | 197 | '<input type="hidden" id="titleKey" name="titleKey" '. |
172 | | - 'value="'.$title->getDBKey().'" />'. |
| 198 | + 'value="'. htmlspecialchars( $title->getDBKey() ) . '" />'. |
173 | 199 | '<input type="hidden" id="titleNS" name="titleNS" '. |
174 | | - 'value="'.$title->getNamespace().'" />'. |
175 | | - '<p>'.wfMsgForContent($ac.'name-field').'<br />'. |
| 200 | + 'value="'. htmlspecialchars( $title->getNamespace() ) .'" />'. |
| 201 | + '<p>'.wfMsgExt($ac.'name-field', array( 'parseinline', 'content' ) ).'<br />'. |
176 | 202 | '<input type="text" id="commenterName" name="commenterName" /></p>'. |
177 | 203 | ($params['showurlfield']=='false' || $params['showurlfield']===false?'': |
178 | | - '<p>'.wfMsgForContent($ac.'url-field').'<br />'. |
| 204 | + '<p>'.wfMsgExt($ac.'url-field', array( 'parseinline', 'content' ) ).'<br />'. |
179 | 205 | '<input type="text" id="commenterURL" name="commenterURL" value="http://" /></p>' |
180 | 206 | ). |
181 | | - '<p>'.wfMsgForContent($ac.'comment-field').'<br />'. |
| 207 | + '<p>'.wfMsgExt($ac.'comment-field', array( 'parseinline', 'content' ) ).'<br />'. |
182 | 208 | '<textarea id="comment" name="comment" style="width:30em" rows="5">'. |
183 | 209 | '</textarea></p>'. |
184 | 210 | '<p><input id="submit" type="submit" '. |
185 | | - 'value="'.wfMsgForContent($ac.'submit-button').'" /></p>'. |
| 211 | + 'value="'.htmlspecialchars( wfMsgForContent($ac.'submit-button') ) .'" /></p>'. |
186 | 212 | '</form></div>'; |
187 | 213 | |
188 | 214 | # Short-circuit if noScript has been set to anything other than false |
— | — | @@ -246,10 +272,6 @@ |
247 | 273 | return $content; |
248 | 274 | } |
249 | 275 | |
250 | | -# Attach Hooks |
251 | | -$wgHooks['ParserAfterTidy'][] = 'wfProcessEncodedContent'; |
252 | | -$wgHooks['ArticleCommentsSpamCheck'][] = 'defaultArticleCommentSpamCheck'; |
253 | | - |
254 | 276 | /** |
255 | 277 | * Processes HTML comments with encoded content. |
256 | 278 | * Usage: $wgHooks['OutputPageBeforeHTML'][] = 'wfProcessEncodedContent'; |
— | — | @@ -259,54 +281,19 @@ |
260 | 282 | */ |
261 | 283 | function wfProcessEncodedContent($out, $text) { |
262 | 284 | $text = preg_replace( |
263 | | - '/<pre>@ENCODED@([0-9a-zA-Z\\+\\/]+=*)@ENCODED@<\\/pre>/e', |
| 285 | + '/<pre>\n@ENCODED@([0-9a-zA-Z\\+\\/]+=*)@ENCODED@\n<\\/pre>/e', |
264 | 286 | 'base64_decode("$1")', |
265 | 287 | $text |
266 | 288 | ); |
267 | 289 | return true; |
268 | 290 | } |
269 | 291 | |
270 | | -# Sets up special page to handle comment submission |
271 | | -$wgExtensionFunctions[] = 'setupSpecialProcessComment'; |
272 | | -function setupSpecialProcessComment() { |
273 | | - global $IP, $wgMessageCache; |
274 | | - require_once($IP.'/includes/SpecialPage.php'); |
275 | | - SpecialPage::addPage(new SpecialPage('ProcessComment', '', true, 'specialProcessComment', false)); |
276 | | - |
277 | | - # Messages used in this extension |
278 | | - $wgMessageCache->addMessage('article-comments-title-field', 'Title'); |
279 | | - $wgMessageCache->addMessage('article-comments-name-string', 'Name'); |
280 | | - $wgMessageCache->addMessage('article-comments-name-field', 'Name (required): '); |
281 | | - $wgMessageCache->addMessage('article-comments-url-field', 'Website: '); |
282 | | - $wgMessageCache->addMessage('article-comments-comment-string', 'Comment'); |
283 | | - $wgMessageCache->addMessage('article-comments-comment-field', 'Comment: '); |
284 | | - $wgMessageCache->addMessage('article-comments-submit-button', 'Submit'); |
285 | | - $wgMessageCache->addMessage('article-comments-leave-comment-link', 'Leave a comment ...'); |
286 | | - $wgMessageCache->addMessage('article-comments-invalid-field', 'The $1 provided <nowiki>[$2]</nowiki> is invalid.'); |
287 | | - $wgMessageCache->addMessage('article-comments-required-field', '$1 field is required.'); |
288 | | - $wgMessageCache->addMessage('article-comments-submission-failed', 'Comment Submission Failed'); |
289 | | - $wgMessageCache->addMessage('article-comments-failure-reasons', 'Sorry, your comment submission failed for the following reason(s):'); |
290 | | - $wgMessageCache->addMessage('article-comments-no-comments', 'Sorry, the article "[[$1]]" is not accepting comments at this time.'); |
291 | | - $wgMessageCache->addMessage('article-comments-talk-page-starter', "<noinclude>Comments on [[$1]]\n<comments />\n----- __NOEDITSECTION__</noinclude>\n"); |
292 | | - $wgMessageCache->addMessage('article-comments-commenter-said', '$1 said ...'); |
293 | | - $wgMessageCache->addMessage('article-comments-summary', 'Comment provided by $1 - via ArticleComments extension'); |
294 | | - $wgMessageCache->addMessage('article-comments-submission-succeeded', 'Comment submission succeeded'); |
295 | | - $wgMessageCache->addMessage('article-comments-submission-success', 'You have successfully submitted a comment for [[$1]]'); |
296 | | - $wgMessageCache->addMessage('article-comments-submission-view-all', 'You may view all comments on that article [[$1|here]]'); |
297 | | - $wgMessageCache->addMessage('article-comments-prefilled-comment-text', ''); |
298 | | - $wgMessageCache->addMessage('article-comments-user-is-blocked', 'Your user account is currently blocked from editing [[$1]].'); |
299 | | - $wgMessageCache->addMessage('article-comments-new-comment', "\n== \$1 ==\n\n<div class='commentBlock'>\n\$2\n\n--\$3 \$4\n</div>\n"); |
300 | | - $wgMessageCache->addMessage('article-comments-no-spam', "At least one of the submitted fields was flagged as spam."); |
301 | | - $wgMessageCache->addMessage('processcomment', 'Process Article Comment'); |
302 | | -} |
303 | | - |
304 | 292 | /** |
305 | 293 | * Special page for comment processing. |
306 | 294 | */ |
307 | 295 | function specialProcessComment() { |
308 | 296 | |
309 | | - global $wgOut, $wgParser, $wgUser, $wgContentLang, $wgContLang; |
310 | | - $wcl = ($wgContentLang ? $wgContentLang : $wgContLang); |
| 297 | + global $wgOut, $wgParser, $wgUser, $wgContLang; |
311 | 298 | |
312 | 299 | # Retrieve submitted values |
313 | 300 | $titleKey = $_POST['titleKey']; |
— | — | @@ -412,7 +399,7 @@ |
413 | 400 | } |
414 | 401 | |
415 | 402 | # Determine signature components |
416 | | - $d = $wcl->timeanddate( date( 'YmdHis' ), false, false) . ' (' . date( 'T' ) . ')'; |
| 403 | + $d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) . ' (' . date( 'T' ) . ')'; |
417 | 404 | if ($commenterURL && $commenterURL!='http://') $sigText = "[$commenterURL $commenterName]"; |
418 | 405 | else if ($wgUser->isLoggedIn()) $sigText = $wgParser->getUserSig( $wgUser ); |
419 | 406 | else $sigText = $commenterName; |
— | — | @@ -425,6 +412,7 @@ |
426 | 413 | $sigText, |
427 | 414 | $d |
428 | 415 | ); |
| 416 | + |
429 | 417 | $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
430 | 418 | if ($posAbove===false) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
431 | 419 | if ($posAbove!==false) { |
— | — | @@ -501,5 +489,3 @@ |
502 | 490 | # We made it this far, leave $isspam alone and give other implementors a chance. |
503 | 491 | return true; |
504 | 492 | } |
505 | | - |
506 | | -//</source> |
Index: trunk/extensions/ArticleComments/ArticleComments.i18n.php |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for ArticleComments extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +$messages['en'] = array( |
| 13 | + 'article-comments-title-field' => 'Title', |
| 14 | + 'article-comments-name-string' => 'Name', |
| 15 | + 'article-comments-name-field' => 'Name (required): ', |
| 16 | + 'article-comments-url-field' => 'Website: ', |
| 17 | + 'article-comments-comment-string' => 'Comment', |
| 18 | + 'article-comments-comment-field' => 'Comment: ', |
| 19 | + 'article-comments-submit-button' => 'Submit', |
| 20 | + 'article-comments-leave-comment-link' => 'Leave a comment ...', |
| 21 | + 'article-comments-invalid-field' => 'The $1 provided <nowiki>[$2]</nowiki> is invalid.', |
| 22 | + 'article-comments-required-field' => '$1 field is required.', |
| 23 | + 'article-comments-submission-failed' => 'Comment Submission Failed', |
| 24 | + 'article-comments-failure-reasons' => 'Sorry, your comment submission failed for the following reason(s):', |
| 25 | + 'article-comments-no-comments' => 'Sorry, the article "[[$1]]" is not accepting comments at this time.', |
| 26 | + 'article-comments-talk-page-starter' => "<noinclude>Comments on [[$1]]\n<comments />\n----- __NOEDITSECTION__</noinclude>\n", |
| 27 | + 'article-comments-commenter-said' => '$1 said ...', |
| 28 | + 'article-comments-summary' => 'Comment provided by $1 - via ArticleComments extension', |
| 29 | + 'article-comments-submission-succeeded' => 'Comment submission succeeded', |
| 30 | + 'article-comments-submission-success' => 'You have successfully submitted a comment for [[$1]]', |
| 31 | + 'article-comments-submission-view-all' => 'You may view all comments on that article [[$1|here]]', |
| 32 | + 'article-comments-prefilled-comment-text' => '', |
| 33 | + 'article-comments-user-is-blocked' => 'Your user account is currently blocked from editing [[$1]].', |
| 34 | + 'article-comments-new-comment' => "\n== \$1 ==\n\n<div class='commentBlock'>\n\$2\n\n--\$3 \$4\n</div>\n", |
| 35 | + 'article-comments-no-spam' => 'At least one of the submitted fields was flagged as spam.', |
| 36 | + 'processcomment' => 'Process Article Comment', |
| 37 | +); |
| 38 | + |
Property changes on: trunk/extensions/ArticleComments/ArticleComments.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 39 | + native |