Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -76,11 +76,11 @@ |
77 | 77 | |
78 | 78 | # Credits |
79 | 79 | $wgExtensionCredits['other'][] = array( |
80 | | - 'name' => 'ArticleComments', |
81 | | - 'author' => 'Jim R. Wilson - wilson.jim.r <at> gmail.com', |
82 | | - 'url' => 'http://jimbojw.com/wiki/index.php?title=ArticleComments', |
83 | | - 'description' => 'Enables comment sections on article pages.', |
84 | | - 'version' => '0.5' |
| 80 | + 'name' => 'ArticleComments', |
| 81 | + 'author' => 'Jim R. Wilson - wilson.jim.r <at> gmail.com', |
| 82 | + 'url' => 'http://jimbojw.com/wiki/index.php?title=ArticleComments', |
| 83 | + 'description' => 'Enables comment sections on article pages.', |
| 84 | + 'version' => '0.5' |
85 | 85 | ); |
86 | 86 | |
87 | 87 | # Add Extension Functions |
— | — | @@ -113,22 +113,22 @@ |
114 | 114 | $wgExtensionFunctions[] = 'setupSpecialProcessComment'; |
115 | 115 | |
116 | 116 | function setupSpecialProcessComment() { |
117 | | - SpecialPage::addPage( new SpecialPage( 'ProcessComment', '', true, 'specialProcessComment', false ) ); |
| 117 | + SpecialPage::addPage( new SpecialPage( 'ProcessComment', '', true, 'specialProcessComment', false ) ); |
118 | 118 | } |
119 | 119 | |
120 | 120 | # Sets up the ArticleComments Parser hook for <comments /> |
121 | 121 | function wfArticleCommentsParserSetup( &$parser ) { |
122 | | - $parser->setHook( 'comments', 'wfArticleCommentsParserHook' ); |
123 | | - return true; |
| 122 | + $parser->setHook( 'comments', 'wfArticleCommentsParserHook' ); |
| 123 | + return true; |
124 | 124 | } |
125 | 125 | |
126 | 126 | function wfArticleCommentsParserHook( $text, $params = array(), $parser ) { |
127 | | - # Generate a comment form for display |
128 | | - $commentForm = wfArticleCommentForm( $parser->mTitle, $params ); |
| 127 | + # Generate a comment form for display |
| 128 | + $commentForm = wfArticleCommentForm( $parser->mTitle, $params ); |
129 | 129 | |
130 | | - # Hide content from the Parser using base64 to avoid mangling. |
131 | | - # Note: Content will be decoded after Tidy has finished its processing of the page. |
132 | | - return '<pre>@ENCODED@' . base64_encode( $commentForm ) . '@ENCODED@</pre>'; |
| 130 | + # Hide content from the Parser using base64 to avoid mangling. |
| 131 | + # Note: Content will be decoded after Tidy has finished its processing of the page. |
| 132 | + return '<pre>@ENCODED@' . base64_encode( $commentForm ) . '@ENCODED@</pre>'; |
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
— | — | @@ -138,33 +138,33 @@ |
139 | 139 | */ |
140 | 140 | function wfArticleCommentsAfterContent( $data, $skin ) { |
141 | 141 | |
142 | | - global $wgRequest, $wgArticleCommentsNSDisplayList; |
| 142 | + global $wgRequest, $wgArticleCommentsNSDisplayList; |
143 | 143 | |
144 | | - # Short circuit for anything other than action=view or action=purge |
145 | | - if ( $wgRequest->getVal( 'action' ) && |
146 | | - $wgRequest->getVal( 'action' ) != 'view' && |
147 | | - $wgRequest->getVal( 'action' ) != 'purge' |
148 | | - ) return true; |
| 144 | + # Short circuit for anything other than action=view or action=purge |
| 145 | + if ( $wgRequest->getVal( 'action' ) && |
| 146 | + $wgRequest->getVal( 'action' ) != 'view' && |
| 147 | + $wgRequest->getVal( 'action' ) != 'purge' |
| 148 | + ) return true; |
149 | 149 | |
150 | | - # Short-circuit if displaylist is undefined, empty or null |
151 | | - if ( $wgArticleCommentsNSDisplayList == null ) |
| 150 | + # Short-circuit if displaylist is undefined, empty or null |
| 151 | + if ( $wgArticleCommentsNSDisplayList == null ) |
152 | 152 | return true; |
153 | 153 | |
154 | 154 | $title = $skin->getTitle(); |
155 | | - if ( !$title->exists() ) { |
| 155 | + if ( !$title->exists() ) { |
156 | 156 | return true; |
157 | 157 | } |
158 | 158 | |
159 | | - # Ensure that the namespace list is an actual list |
160 | | - $nsList = $wgArticleCommentsNSDisplayList; |
161 | | - if ( !is_array( $nsList ) ) $nsList = array( $nsList ); |
| 159 | + # Ensure that the namespace list is an actual list |
| 160 | + $nsList = $wgArticleCommentsNSDisplayList; |
| 161 | + if ( !is_array( $nsList ) ) $nsList = array( $nsList ); |
162 | 162 | |
163 | | - # Display the form |
164 | | - if ( in_array( $title->getNamespace(), $nsList ) ) { |
165 | | - $data .= wfArticleCommentForm( $title ); |
166 | | - } |
| 163 | + # Display the form |
| 164 | + if ( in_array( $title->getNamespace(), $nsList ) ) { |
| 165 | + $data .= wfArticleCommentForm( $title ); |
| 166 | + } |
167 | 167 | |
168 | | - return true; |
| 168 | + return true; |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
— | — | @@ -181,7 +181,7 @@ |
182 | 182 | $tmp[strtolower( $k )] = (bool)strcasecmp( $v, "false" ); |
183 | 183 | } |
184 | 184 | $params = $tmp; |
185 | | - $ac = 'article-comments-'; |
| 185 | + $ac = 'article-comments-'; |
186 | 186 | |
187 | 187 | # Build out the comment form. |
188 | 188 | $content = '<div id="commentForm">'; |
— | — | @@ -207,64 +207,64 @@ |
208 | 208 | $content .= '<p>' . Html::input( 'comment-submit', wfMsgForContent( $ac . 'submit-button' ), 'submit' ) . '</p>'; |
209 | 209 | $content .= '</form></div>'; |
210 | 210 | |
211 | | - # Short-circuit if noScript has been set to anything other than false |
212 | | - if ( $params['noscript'] ) { |
213 | | - return $content; |
214 | | - } |
| 211 | + # Short-circuit if noScript has been set to anything other than false |
| 212 | + if ( $params['noscript'] ) { |
| 213 | + return $content; |
| 214 | + } |
215 | 215 | |
216 | | - # Inline JavaScript to make form behavior more rich (must degrade well in JS-disabled browsers) |
217 | | - $content .= "<script type='text/javascript'>//<![CDATA[\n(function(){\n"; |
| 216 | + # Inline JavaScript to make form behavior more rich (must degrade well in JS-disabled browsers) |
| 217 | + $content .= "<script type='text/javascript'>//<![CDATA[\n(function(){\n"; |
218 | 218 | |
219 | | - # Prefill the name field if the user is logged in. |
220 | | - $content .= |
221 | | - 'var prefillUserName = function(){' . "\n" . |
222 | | - 'var ptu=document.getElementById("pt-userpage");' . "\n" . |
223 | | - 'if (ptu) document.getElementById("commenterName").value=' . |
224 | | - 'ptu.getElementsByTagName("a")[0].innerHTML;};' . "\n" . |
225 | | - 'if (window.addEventListener) window.addEventListener' . |
226 | | - '("load",prefillUserName,false);' . "\n" . |
227 | | - 'else if (window.attachEvent) window.attachEvent' . |
228 | | - '("onload",prefillUserName);' . "\n"; |
| 219 | + # Prefill the name field if the user is logged in. |
| 220 | + $content .= |
| 221 | + 'var prefillUserName = function(){' . "\n" . |
| 222 | + 'var ptu=document.getElementById("pt-userpage");' . "\n" . |
| 223 | + 'if (ptu) document.getElementById("commenterName").value=' . |
| 224 | + 'ptu.getElementsByTagName("a")[0].innerHTML;};' . "\n" . |
| 225 | + 'if (window.addEventListener) window.addEventListener' . |
| 226 | + '("load",prefillUserName,false);' . "\n" . |
| 227 | + 'else if (window.attachEvent) window.attachEvent' . |
| 228 | + '("onload",prefillUserName);' . "\n"; |
229 | 229 | |
230 | | - # Prefill comment text if it has been specified by a system message |
231 | | - # Note: This is done dynamically with JavaScript since it would be annoying |
232 | | - # for JS-disabled browsers to have the prefilled text (since they'd have |
233 | | - # to manually delete it) and would break parser output caching |
234 | | - $pretext = wfMsgForContent( $ac . 'prefilled-comment-text' ); |
235 | | - if ( $pretext ) { |
236 | | - $content .= |
237 | | - 'var comment = document.getElementById("comment");' . "\n" . |
238 | | - 'comment._everFocused=false;' . "\n" . |
239 | | - 'comment.innerHTML="' . htmlspecialchars( $pretext ) . '";' . "\n" . |
240 | | - 'var clearCommentOnFirstFocus = function() {' . "\n" . |
241 | | - 'var c=document.getElementById("comment");' . "\n" . |
242 | | - 'if (!c._everFocused) {' . "\n" . |
243 | | - 'c._everFocused=true;' . "\n" . |
244 | | - 'c.value="";}}' . "\n" . |
245 | | - 'if (comment.addEventListener) comment.addEventListener' . |
246 | | - '("focus",clearCommentOnFirstFocus,false);' . "\n" . |
247 | | - 'else if (comment.attachEvent) comment.attachEvent' . |
248 | | - '("onfocus",clearCommentOnFirstFocus);' . "\n"; |
249 | | - } |
| 230 | + # Prefill comment text if it has been specified by a system message |
| 231 | + # Note: This is done dynamically with JavaScript since it would be annoying |
| 232 | + # for JS-disabled browsers to have the prefilled text (since they'd have |
| 233 | + # to manually delete it) and would break parser output caching |
| 234 | + $pretext = wfMsgForContent( $ac . 'prefilled-comment-text' ); |
| 235 | + if ( $pretext ) { |
| 236 | + $content .= |
| 237 | + 'var comment = document.getElementById("comment");' . "\n" . |
| 238 | + 'comment._everFocused=false;' . "\n" . |
| 239 | + 'comment.innerHTML="' . htmlspecialchars( $pretext ) . '";' . "\n" . |
| 240 | + 'var clearCommentOnFirstFocus = function() {' . "\n" . |
| 241 | + 'var c=document.getElementById("comment");' . "\n" . |
| 242 | + 'if (!c._everFocused) {' . "\n" . |
| 243 | + 'c._everFocused=true;' . "\n" . |
| 244 | + 'c.value="";}}' . "\n" . |
| 245 | + 'if (comment.addEventListener) comment.addEventListener' . |
| 246 | + '("focus",clearCommentOnFirstFocus,false);' . "\n" . |
| 247 | + 'else if (comment.attachEvent) comment.attachEvent' . |
| 248 | + '("onfocus",clearCommentOnFirstFocus);' . "\n"; |
| 249 | + } |
250 | 250 | |
251 | | - # Hides the commentForm until the "Make a comment" link is clicked |
252 | | - # Note: To disable, set $wgArticleCommentDefaults['hideForm']=false in LocalSettings.php |
253 | | - if ( !isset( $params['hideform'] ) || |
254 | | - ( $params['hideform'] != 'false' && |
255 | | - !$params['hideform'] === false ) ) { |
256 | | - $content .= |
257 | | - 'var cf=document.getElementById("commentForm");' . "\n" . |
258 | | - 'cf.style.display="none";' . "\n" . |
259 | | - 'var p=document.createElement("p");' . "\n" . |
260 | | - 'p.innerHTML="<a href=\'javascript:void(0)\' onclick=\'' . |
261 | | - 'document.getElementById(\\"commentForm\\").style.display=\\"block\\";' . |
262 | | - 'this.style.display=\\"none\\";false' . |
263 | | - '\'>' . wfMsgForContent( $ac . 'leave-comment-link' ) . '</a>";' . "\n" . |
264 | | - 'cf.parentNode.insertBefore(p,cf);' . "\n"; |
265 | | - } |
| 251 | + # Hides the commentForm until the "Make a comment" link is clicked |
| 252 | + # Note: To disable, set $wgArticleCommentDefaults['hideForm']=false in LocalSettings.php |
| 253 | + if ( !isset( $params['hideform'] ) || |
| 254 | + ( $params['hideform'] != 'false' && |
| 255 | + !$params['hideform'] === false ) ) { |
| 256 | + $content .= |
| 257 | + 'var cf=document.getElementById("commentForm");' . "\n" . |
| 258 | + 'cf.style.display="none";' . "\n" . |
| 259 | + 'var p=document.createElement("p");' . "\n" . |
| 260 | + 'p.innerHTML="<a href=\'javascript:void(0)\' onclick=\'' . |
| 261 | + 'document.getElementById(\\"commentForm\\").style.display=\\"block\\";' . |
| 262 | + 'this.style.display=\\"none\\";false' . |
| 263 | + '\'>' . wfMsgForContent( $ac . 'leave-comment-link' ) . '</a>";' . "\n" . |
| 264 | + 'cf.parentNode.insertBefore(p,cf);' . "\n"; |
| 265 | + } |
266 | 266 | |
267 | | - $content .= "})();\n//]]></script>"; |
268 | | - return $content; |
| 267 | + $content .= "})();\n//]]></script>"; |
| 268 | + return $content; |
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
— | — | @@ -275,12 +275,12 @@ |
276 | 276 | * @return Boolean Always tru to give other hooking methods a chance to run. |
277 | 277 | */ |
278 | 278 | function wfProcessEncodedContent( $out, $text ) { |
279 | | - $text = preg_replace( |
280 | | - '/<pre>\n@ENCODED@([0-9a-zA-Z\\+\\/]+=*)@ENCODED@\n<\\/pre>/e', |
281 | | - 'base64_decode("$1")', |
282 | | - $text |
283 | | - ); |
284 | | - return true; |
| 279 | + $text = preg_replace( |
| 280 | + '/<pre>\n@ENCODED@([0-9a-zA-Z\\+\\/]+=*)@ENCODED@\n<\\/pre>/e', |
| 281 | + 'base64_decode("$1")', |
| 282 | + $text |
| 283 | + ); |
| 284 | + return true; |
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
— | — | @@ -288,13 +288,13 @@ |
289 | 289 | */ |
290 | 290 | function specialProcessComment() { |
291 | 291 | |
292 | | - global $wgOut, $wgParser, $wgUser, $wgContLang, $wgRequest; |
| 292 | + global $wgOut, $wgParser, $wgUser, $wgContLang, $wgRequest; |
293 | 293 | |
294 | | - # Retrieve submitted values |
295 | | - $titleText = $wgRequest->getVal( 'commentArticle' ); |
296 | | - $commenterName = $wgRequest->getVal( 'commenterName' ); |
297 | | - $commenterURL = trim( $wgRequest->getVal( 'commenterURL' ) ); |
298 | | - $comment = $wgRequest->getVal( 'comment' ); |
| 294 | + # Retrieve submitted values |
| 295 | + $titleText = $wgRequest->getVal( 'commentArticle' ); |
| 296 | + $commenterName = $wgRequest->getVal( 'commenterName' ); |
| 297 | + $commenterURL = trim( $wgRequest->getVal( 'commenterURL' ) ); |
| 298 | + $comment = $wgRequest->getVal( 'comment' ); |
299 | 299 | |
300 | 300 | // The default value is the same as not providing a URL |
301 | 301 | if ( $commenterURL == 'http://' ) { |
— | — | @@ -303,144 +303,144 @@ |
304 | 304 | |
305 | 305 | $title = Title::newFromText( $titleText ); |
306 | 306 | |
307 | | - # Perform validation checks on supplied fields |
308 | | - $ac = 'article-comments-'; |
309 | | - $messages = array(); |
| 307 | + # Perform validation checks on supplied fields |
| 308 | + $ac = 'article-comments-'; |
| 309 | + $messages = array(); |
310 | 310 | |
311 | 311 | if ( !$wgRequest->wasPosted() ) |
312 | 312 | $messages[] = wfMsgForContent( $ac . 'not-posted' ); |
313 | 313 | |
314 | | - if ( $titleText === '' || !$title ) { |
| 314 | + if ( $titleText === '' || !$title ) { |
315 | 315 | $messages[] = wfMsgForContent( |
316 | | - $ac . 'invalid-field', wfMsgForContent( $ac . 'title-string' ), $titleText ); |
| 316 | + $ac . 'invalid-field', wfMsgForContent( $ac . 'title-string' ), $titleText ); |
317 | 317 | } |
318 | 318 | |
319 | | - if ( !$commenterName ) $messages[] = wfMsgForContent( |
320 | | - $ac . 'required-field', wfMsgForContent( $ac . 'name-string' ) ); |
| 319 | + if ( !$commenterName ) $messages[] = wfMsgForContent( |
| 320 | + $ac . 'required-field', wfMsgForContent( $ac . 'name-string' ) ); |
321 | 321 | |
322 | 322 | if ( !preg_match( "/^(" . wfUrlProtocols() . ')' . Parser::EXT_LINK_URL_CLASS . '+$/', $commenterURL ) ) |
323 | 323 | $messages[] = wfMsgForContent( |
324 | | - $ac . 'invalid-field', wfMsgForContent( $ac . 'url-string' ), $commenterURL ); |
| 324 | + $ac . 'invalid-field', wfMsgForContent( $ac . 'url-string' ), $commenterURL ); |
325 | 325 | |
326 | | - if ( !$comment ) $messages[] = wfMsgForContent( |
327 | | - $ac . 'required-field', wfMsgForContent( $ac . 'comment-string' ) ); |
328 | | - if ( !empty( $messages ) ) { |
329 | | - $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
330 | | - $wikiText = "<div class='errorbox'>"; |
331 | | - $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
332 | | - foreach ( $messages as $message ) { |
333 | | - $wikiText .= "* $message\n"; |
334 | | - } |
335 | | - $wgOut->addWikiText( $wikiText . "</div>" ); |
336 | | - return; |
337 | | - } |
| 326 | + if ( !$comment ) $messages[] = wfMsgForContent( |
| 327 | + $ac . 'required-field', wfMsgForContent( $ac . 'comment-string' ) ); |
| 328 | + if ( !empty( $messages ) ) { |
| 329 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
| 330 | + $wikiText = "<div class='errorbox'>"; |
| 331 | + $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
| 332 | + foreach ( $messages as $message ) { |
| 333 | + $wikiText .= "* $message\n"; |
| 334 | + } |
| 335 | + $wgOut->addWikiText( $wikiText . "</div>" ); |
| 336 | + return; |
| 337 | + } |
338 | 338 | |
339 | | - # Setup title and talkTitle object |
340 | | - $article = new Article( $title ); |
| 339 | + # Setup title and talkTitle object |
| 340 | + $article = new Article( $title ); |
341 | 341 | |
342 | | - $talkTitle = $title->getTalkPage(); |
343 | | - $talkArticle = new Article( $talkTitle ); |
| 342 | + $talkTitle = $title->getTalkPage(); |
| 343 | + $talkArticle = new Article( $talkTitle ); |
344 | 344 | |
345 | | - # Check whether user is blocked from editing the talk page |
346 | | - if ( $wgUser->isBlockedFrom( $talkTitle ) ) { |
347 | | - $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
348 | | - $wikiText = "<div class='errorbox'>"; |
349 | | - $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
350 | | - $wikiText .= '* ' . wfMsgForContent( $ac . 'user-is-blocked', $talkTitle->getPrefixedText() ) . "\n"; |
351 | | - $wgOut->addWikiText( $wikiText . "</div>" ); |
352 | | - return; |
353 | | - } |
| 345 | + # Check whether user is blocked from editing the talk page |
| 346 | + if ( $wgUser->isBlockedFrom( $talkTitle ) ) { |
| 347 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
| 348 | + $wikiText = "<div class='errorbox'>"; |
| 349 | + $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
| 350 | + $wikiText .= '* ' . wfMsgForContent( $ac . 'user-is-blocked', $talkTitle->getPrefixedText() ) . "\n"; |
| 351 | + $wgOut->addWikiText( $wikiText . "</div>" ); |
| 352 | + return; |
| 353 | + } |
354 | 354 | |
355 | | - # Retrieve article content |
356 | | - $articleContent = ''; |
357 | | - if ( $title->exists() ) { |
358 | | - $articleContent = $article->getContent(); |
359 | | - } |
| 355 | + # Retrieve article content |
| 356 | + $articleContent = ''; |
| 357 | + if ( $title->exists() ) { |
| 358 | + $articleContent = $article->getContent(); |
| 359 | + } |
360 | 360 | |
361 | | - # Retrieve existing talk content |
362 | | - $talkContent = ''; |
363 | | - if ( $talkTitle->exists() ) { |
364 | | - $talkContent = $talkArticle->getContent(); |
365 | | - } |
| 361 | + # Retrieve existing talk content |
| 362 | + $talkContent = ''; |
| 363 | + if ( $talkTitle->exists() ) { |
| 364 | + $talkContent = $talkArticle->getContent(); |
| 365 | + } |
366 | 366 | |
367 | 367 | |
368 | | - # Check if talk NS is in the Namespace display list |
369 | | - # Note: if so, then there's no need to confirm that <comments /> appears in the article or talk page. |
370 | | - global $wgArticleCommentsNSDisplayList; |
371 | | - $skipCheck = ( |
372 | | - is_array( $wgArticleCommentsNSDisplayList ) ? |
373 | | - in_array( $talkTitle->getNamespace(), $wgArticleCommentsNSDisplayList ): |
374 | | - false |
375 | | - ); |
| 368 | + # Check if talk NS is in the Namespace display list |
| 369 | + # Note: if so, then there's no need to confirm that <comments /> appears in the article or talk page. |
| 370 | + global $wgArticleCommentsNSDisplayList; |
| 371 | + $skipCheck = ( |
| 372 | + is_array( $wgArticleCommentsNSDisplayList ) ? |
| 373 | + in_array( $talkTitle->getNamespace(), $wgArticleCommentsNSDisplayList ): |
| 374 | + false |
| 375 | + ); |
376 | 376 | |
377 | | - # Check whether the article or its talk page contains a <comments /> flag |
378 | | - if ( !$skipCheck && |
379 | | - preg_match( '/<comments( +[^>]*)?\\/>/', $articleContent ) === 0 && |
380 | | - preg_match( '/<comments( +[^>]*)?\\/>/', $talkContent ) === 0 |
381 | | - ) { |
382 | | - $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
383 | | - $wgOut->addWikiText( |
384 | | - "<div class='errorbox'>" . |
385 | | - wfMsgForContent( $ac . 'no-comments', $title->getPrefixedText() ) . |
386 | | - "</div>" |
387 | | - ); |
388 | | - return; |
389 | | - } |
| 377 | + # Check whether the article or its talk page contains a <comments /> flag |
| 378 | + if ( !$skipCheck && |
| 379 | + preg_match( '/<comments( +[^>]*)?\\/>/', $articleContent ) === 0 && |
| 380 | + preg_match( '/<comments( +[^>]*)?\\/>/', $talkContent ) === 0 |
| 381 | + ) { |
| 382 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
| 383 | + $wgOut->addWikiText( |
| 384 | + "<div class='errorbox'>" . |
| 385 | + wfMsgForContent( $ac . 'no-comments', $title->getPrefixedText() ) . |
| 386 | + "</div>" |
| 387 | + ); |
| 388 | + return; |
| 389 | + } |
390 | 390 | |
391 | | - # Run spam checks |
392 | | - $isspam = false; |
| 391 | + # Run spam checks |
| 392 | + $isspam = false; |
393 | 393 | wfRunHooks( 'ArticleCommentsSpamCheck', array( $comment , $commenterName, $commenterURL, &$isspam ) ); |
394 | 394 | |
395 | | - # If it's spam - it's gone! |
396 | | - if ( $isspam ) { |
397 | | - $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
398 | | - $wgOut->addWikiText( |
399 | | - "<div class='errorbox'>" . |
400 | | - wfMsgForContent( $ac . 'no-spam' ) . |
401 | | - "</div>" |
402 | | - ); |
403 | | - return; |
404 | | - } |
| 395 | + # If it's spam - it's gone! |
| 396 | + if ( $isspam ) { |
| 397 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
| 398 | + $wgOut->addWikiText( |
| 399 | + "<div class='errorbox'>" . |
| 400 | + wfMsgForContent( $ac . 'no-spam' ) . |
| 401 | + "</div>" |
| 402 | + ); |
| 403 | + return; |
| 404 | + } |
405 | 405 | |
406 | | - # Initialize the talk page's content. |
407 | | - if ( $talkContent == '' ) { |
408 | | - $talkContent = wfMsgForContent( $ac . 'talk-page-starter', $title->getPrefixedText() ); |
409 | | - } |
| 406 | + # Initialize the talk page's content. |
| 407 | + if ( $talkContent == '' ) { |
| 408 | + $talkContent = wfMsgForContent( $ac . 'talk-page-starter', $title->getPrefixedText() ); |
| 409 | + } |
410 | 410 | |
411 | | - # Determine signature components |
412 | | - if ( $commenterURL != '' ) $sigText = "[$commenterURL $commenterName]"; |
413 | | - else if ( $wgUser->isLoggedIn() ) $sigText = $wgParser->getUserSig( $wgUser ); |
414 | | - else $sigText = $commenterName; |
| 411 | + # Determine signature components |
| 412 | + if ( $commenterURL != '' ) $sigText = "[$commenterURL $commenterName]"; |
| 413 | + else if ( $wgUser->isLoggedIn() ) $sigText = $wgParser->getUserSig( $wgUser ); |
| 414 | + else $sigText = $commenterName; |
415 | 415 | |
416 | | - # Search for insertion point, or append most recent comment. |
417 | | - $commentText = wfMsgForContent( |
418 | | - $ac . 'new-comment', |
419 | | - wfMsgForContent( $ac . 'commenter-said', $commenterName ), |
420 | | - $comment, |
421 | | - $sigText, |
422 | | - '~~~~~' |
423 | | - ); |
| 416 | + # Search for insertion point, or append most recent comment. |
| 417 | + $commentText = wfMsgForContent( |
| 418 | + $ac . 'new-comment', |
| 419 | + wfMsgForContent( $ac . 'commenter-said', $commenterName ), |
| 420 | + $comment, |
| 421 | + $sigText, |
| 422 | + '~~~~~' |
| 423 | + ); |
424 | 424 | |
425 | | - $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
426 | | - if ( $posAbove === false ) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
427 | | - if ( $posAbove !== false ) { |
428 | | - # Insert comments above HTML marker |
429 | | - $talkContent = substr( $talkContent, 0, $posAbove ) . $commentText . substr( $talkContent, $posAbove ); |
430 | | - } else if ( $posBelow !== false ) { |
431 | | - # Insert comments below HTML marker |
432 | | - $talkContent = substr( $talkContent, 0, $posBelow + 21 ) . $commentText . substr( $talkContent, $posBelow + 21 ); |
433 | | - } else { |
434 | | - # No marker found, append to bottom (default) |
435 | | - $talkContent .= $commentText; |
436 | | - } |
| 425 | + $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
| 426 | + if ( $posAbove === false ) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
| 427 | + if ( $posAbove !== false ) { |
| 428 | + # Insert comments above HTML marker |
| 429 | + $talkContent = substr( $talkContent, 0, $posAbove ) . $commentText . substr( $talkContent, $posAbove ); |
| 430 | + } else if ( $posBelow !== false ) { |
| 431 | + # Insert comments below HTML marker |
| 432 | + $talkContent = substr( $talkContent, 0, $posBelow + 21 ) . $commentText . substr( $talkContent, $posBelow + 21 ); |
| 433 | + } else { |
| 434 | + # No marker found, append to bottom (default) |
| 435 | + $talkContent .= $commentText; |
| 436 | + } |
437 | 437 | |
438 | 438 | # Update the talkArticle with the new comment |
439 | 439 | $summary = wfMsgForContent( $ac . 'summary', $commenterName ); |
440 | 440 | $talkArticle->doEdit( $talkContent, $summary ); |
441 | 441 | |
442 | | - $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-succeeded' ) ); |
443 | | - $wgOut->addWikiText( wfMsgForContent( $ac . 'submission-success', $title->getPrefixedText() ) ); |
444 | | - $wgOut->addWikiText( wfMsgForContent( $ac . 'submission-view-all', $talkTitle->getPrefixedText() ) ); |
| 442 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-succeeded' ) ); |
| 443 | + $wgOut->addWikiText( wfMsgForContent( $ac . 'submission-success', $title->getPrefixedText() ) ); |
| 444 | + $wgOut->addWikiText( wfMsgForContent( $ac . 'submission-view-all', $talkTitle->getPrefixedText() ) ); |
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
— | — | @@ -454,40 +454,40 @@ |
455 | 455 | */ |
456 | 456 | function defaultArticleCommentSpamCheck( $comment, $commenterName, $commenterURL, $isspam ) { |
457 | 457 | |
458 | | - # Short-circuit if spam has already been determined |
459 | | - if ( $isspam ) return true; |
460 | | - $fields = array( $comment, $commenterName, $commenterURL ); |
| 458 | + # Short-circuit if spam has already been determined |
| 459 | + if ( $isspam ) return true; |
| 460 | + $fields = array( $comment, $commenterName, $commenterURL ); |
461 | 461 | |
462 | | - # Run everything through $wgSpamRegex if it has been specified |
463 | | - global $wgSpamRegex; |
464 | | - if ( $wgSpamRegex ) { |
465 | | - foreach ( $fields as $field ) { |
466 | | - if ( preg_match( $wgSpamRegex, $field ) ) return $isspam = true; |
467 | | - } |
468 | | - } |
| 462 | + # Run everything through $wgSpamRegex if it has been specified |
| 463 | + global $wgSpamRegex; |
| 464 | + if ( $wgSpamRegex ) { |
| 465 | + foreach ( $fields as $field ) { |
| 466 | + if ( preg_match( $wgSpamRegex, $field ) ) return $isspam = true; |
| 467 | + } |
| 468 | + } |
469 | 469 | |
470 | | - # Rudimentary spam protection |
471 | | - $spampatterns = array( |
472 | | - '%\\[url=(https?|ftp)://%smi', |
473 | | - '%<a\\s+[^>]*href\\s*=\\s*[\'"]?\\s*(https?|ftp)://%smi' |
474 | | - ); |
475 | | - foreach ( $spampatterns as $sp ) { |
476 | | - foreach ( array( $comment, $commenterName, $commenterURL ) as $field ) { |
477 | | - if ( preg_match( $sp, $field ) ) return $isspam = true; |
478 | | - } |
479 | | - } |
| 470 | + # Rudimentary spam protection |
| 471 | + $spampatterns = array( |
| 472 | + '%\\[url=(https?|ftp)://%smi', |
| 473 | + '%<a\\s+[^>]*href\\s*=\\s*[\'"]?\\s*(https?|ftp)://%smi' |
| 474 | + ); |
| 475 | + foreach ( $spampatterns as $sp ) { |
| 476 | + foreach ( array( $comment, $commenterName, $commenterURL ) as $field ) { |
| 477 | + if ( preg_match( $sp, $field ) ) return $isspam = true; |
| 478 | + } |
| 479 | + } |
480 | 480 | |
481 | | - # Check for bad input for commenterName (seems to be a popular spam location) |
482 | | - $spampatterns = array( |
483 | | - '%<a\\s+%smi', |
484 | | - '%(https?|ftp)://%smi', |
485 | | - '%(\\n|\\r)%smi' |
486 | | - ); |
487 | | - foreach ( $spampatterns as $sp ) if ( preg_match( $sp, $commenterName ) ) return $isspam = true; |
| 481 | + # Check for bad input for commenterName (seems to be a popular spam location) |
| 482 | + $spampatterns = array( |
| 483 | + '%<a\\s+%smi', |
| 484 | + '%(https?|ftp)://%smi', |
| 485 | + '%(\\n|\\r)%smi' |
| 486 | + ); |
| 487 | + foreach ( $spampatterns as $sp ) if ( preg_match( $sp, $commenterName ) ) return $isspam = true; |
488 | 488 | |
489 | | - # Fail for length violations |
490 | | - if ( strlen( $commenterName ) > 255 || strlen( $commenterURL ) > 300 ) return $isspam = true; |
| 489 | + # Fail for length violations |
| 490 | + if ( strlen( $commenterName ) > 255 || strlen( $commenterURL ) > 300 ) return $isspam = true; |
491 | 491 | |
492 | | - # We made it this far, leave $isspam alone and give other implementors a chance. |
493 | | - return true; |
| 492 | + # We made it this far, leave $isspam alone and give other implementors a chance. |
| 493 | + return true; |
494 | 494 | } |
Index: trunk/extensions/ArticleComments/ArticleComments.i18n.php |
— | — | @@ -9,31 +9,31 @@ |
10 | 10 | $messages = array(); |
11 | 11 | |
12 | 12 | $messages['en'] = array( |
13 | | - 'article-comments-title-string' => 'title', |
14 | | - 'article-comments-name-string' => 'Name', |
15 | | - 'article-comments-name-field' => 'Name (required):', |
16 | | - 'article-comments-url-field' => 'Website:', |
17 | | - 'article-comments-url-string' => 'URL', |
18 | | - 'article-comments-comment-string' => 'Comment', |
19 | | - 'article-comments-comment-field' => 'Comment:', |
20 | | - 'article-comments-submit-button' => 'Submit', |
21 | | - 'article-comments-leave-comment-link' => 'Leave a comment ...', |
22 | | - 'article-comments-invalid-field' => 'The $1 provided <nowiki>[$2]</nowiki> is invalid.', |
23 | | - 'article-comments-required-field' => '$1 field is required.', |
24 | | - 'article-comments-submission-failed' => 'Comment Submission Failed', |
25 | | - 'article-comments-failure-reasons' => 'Sorry, your comment submission failed for the following reason(s):', |
26 | | - 'article-comments-no-comments' => 'Sorry, the article "[[$1]]" is not accepting comments at this time.', |
27 | | - 'article-comments-talk-page-starter' => "<noinclude>Comments on [[$1]]\n<comments />\n----- __NOEDITSECTION__</noinclude>\n", |
28 | | - 'article-comments-commenter-said' => '$1 said ...', |
29 | | - 'article-comments-summary' => 'Comment provided by $1 - via ArticleComments extension', |
30 | | - 'article-comments-submission-succeeded' => 'Comment submission succeeded', |
31 | | - 'article-comments-submission-success' => 'You have successfully submitted a comment for [[$1]]', |
32 | | - 'article-comments-submission-view-all' => 'You may view all comments on that article [[$1|here]]', |
33 | | - 'article-comments-prefilled-comment-text' => '', |
34 | | - 'article-comments-user-is-blocked' => 'Your user account is currently blocked from editing [[$1]].', |
35 | | - 'article-comments-new-comment' => "\n== \$1 ==\n\n<div class='commentBlock'>\n\$2\n\n--\$3 \$4\n</div>\n", |
36 | | - 'article-comments-no-spam' => 'At least one of the submitted fields was flagged as spam.', |
37 | | - 'processcomment' => 'Process Article Comment', |
| 13 | + 'article-comments-title-string' => 'title', |
| 14 | + 'article-comments-name-string' => 'Name', |
| 15 | + 'article-comments-name-field' => 'Name (required):', |
| 16 | + 'article-comments-url-field' => 'Website:', |
| 17 | + 'article-comments-url-string' => 'URL', |
| 18 | + 'article-comments-comment-string' => 'Comment', |
| 19 | + 'article-comments-comment-field' => 'Comment:', |
| 20 | + 'article-comments-submit-button' => 'Submit', |
| 21 | + 'article-comments-leave-comment-link' => 'Leave a comment ...', |
| 22 | + 'article-comments-invalid-field' => 'The $1 provided <nowiki>[$2]</nowiki> is invalid.', |
| 23 | + 'article-comments-required-field' => '$1 field is required.', |
| 24 | + 'article-comments-submission-failed' => 'Comment Submission Failed', |
| 25 | + 'article-comments-failure-reasons' => 'Sorry, your comment submission failed for the following reason(s):', |
| 26 | + 'article-comments-no-comments' => 'Sorry, the article "[[$1]]" is not accepting comments at this time.', |
| 27 | + 'article-comments-talk-page-starter' => "<noinclude>Comments on [[$1]]\n<comments />\n----- __NOEDITSECTION__</noinclude>\n", |
| 28 | + 'article-comments-commenter-said' => '$1 said ...', |
| 29 | + 'article-comments-summary' => 'Comment provided by $1 - via ArticleComments extension', |
| 30 | + 'article-comments-submission-succeeded' => 'Comment submission succeeded', |
| 31 | + 'article-comments-submission-success' => 'You have successfully submitted a comment for [[$1]]', |
| 32 | + 'article-comments-submission-view-all' => 'You may view all comments on that article [[$1|here]]', |
| 33 | + 'article-comments-prefilled-comment-text' => '', |
| 34 | + 'article-comments-user-is-blocked' => 'Your user account is currently blocked from editing [[$1]].', |
| 35 | + 'article-comments-new-comment' => "\n== \$1 ==\n\n<div class='commentBlock'>\n\$2\n\n--\$3 \$4\n</div>\n", |
| 36 | + 'article-comments-no-spam' => 'At least one of the submitted fields was flagged as spam.', |
| 37 | + 'processcomment' => 'Process Article Comment', |
38 | 38 | ); |
39 | 39 | |
40 | 40 | $messages['qqq'] = array( |