Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Platonides |
7 | 7 | * @version 0.5 |
8 | 8 | * @copyright Copyright (C) 2007 Jim R. Wilson |
9 | | - * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
| 9 | + * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
10 | 10 | * ----------------------------------------------------------------------- |
11 | 11 | * Description: |
12 | 12 | * This is a MediaWiki (http://www.mediawiki.org/) extension which adds support |
— | — | @@ -49,38 +49,38 @@ |
50 | 50 | * Initial release. |
51 | 51 | * ----------------------------------------------------------------------- |
52 | 52 | * Copyright (c) 2007 Jim R. Wilson |
53 | | - * |
54 | | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
55 | | - * of this software and associated documentation files (the "Software"), to deal |
56 | | - * in the Software without restriction, including without limitation the rights to |
57 | | - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
58 | | - * the Software, and to permit persons to whom the Software is furnished to do |
| 53 | + * |
| 54 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 55 | + * of this software and associated documentation files (the "Software"), to deal |
| 56 | + * in the Software without restriction, including without limitation the rights to |
| 57 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 58 | + * the Software, and to permit persons to whom the Software is furnished to do |
59 | 59 | * so, subject to the following conditions: |
60 | | - * |
61 | | - * The above copyright notice and this permission notice shall be included in all |
| 60 | + * |
| 61 | + * The above copyright notice and this permission notice shall be included in all |
62 | 62 | * copies or substantial portions of the Software. |
63 | | - * |
64 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
65 | | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
66 | | - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
67 | | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
68 | | - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
69 | | - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
70 | | - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
71 | | - * OTHER DEALINGS IN THE SOFTWARE. |
| 63 | + * |
| 64 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 65 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 66 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 67 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 68 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 69 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 70 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 71 | + * OTHER DEALINGS IN THE SOFTWARE. |
72 | 72 | * ----------------------------------------------------------------------- |
73 | 73 | */ |
74 | | - |
| 74 | + |
75 | 75 | # Confirm MW environment |
76 | | -if (!defined('MEDIAWIKI')) die(); |
| 76 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
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 |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | |
130 | 130 | # Hide content from the Parser using base64 to avoid mangling. |
131 | 131 | # Note: Content will be decoded after Tidy has finished its processing of the page. |
132 | | - return '<pre>@ENCODED@'.base64_encode($commentForm).'@ENCODED@</pre>'; |
| 132 | + return '<pre>@ENCODED@' . base64_encode( $commentForm ) . '@ENCODED@</pre>'; |
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
— | — | @@ -139,15 +139,15 @@ |
140 | 140 | function wfArticleCommentsAfterContent( $data, $skin ) { |
141 | 141 | |
142 | 142 | global $wgRequest, $wgArticleCommentsNSDisplayList; |
143 | | - |
| 143 | + |
144 | 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' |
| 145 | + if ( $wgRequest->getVal( 'action' ) && |
| 146 | + $wgRequest->getVal( 'action' ) != 'view' && |
| 147 | + $wgRequest->getVal( 'action' ) != 'purge' |
148 | 148 | ) return true; |
149 | | - |
| 149 | + |
150 | 150 | # Short-circuit if displaylist is undefined, empty or null |
151 | | - if ($wgArticleCommentsNSDisplayList == null) |
| 151 | + if ( $wgArticleCommentsNSDisplayList == null ) |
152 | 152 | return true; |
153 | 153 | |
154 | 154 | $title = $skin->getTitle(); |
— | — | @@ -157,13 +157,13 @@ |
158 | 158 | |
159 | 159 | # Ensure that the namespace list is an actual list |
160 | 160 | $nsList = $wgArticleCommentsNSDisplayList; |
161 | | - if (!is_array($nsList)) $nsList = array($nsList); |
162 | | - |
| 161 | + if ( !is_array( $nsList ) ) $nsList = array( $nsList ); |
| 162 | + |
163 | 163 | # Display the form |
164 | | - if (in_array($title->getNamespace(), $nsList)) { |
| 164 | + if ( in_array( $title->getNamespace(), $nsList ) ) { |
165 | 165 | $data .= wfArticleCommentForm( $title ); |
166 | 166 | } |
167 | | - |
| 167 | + |
168 | 168 | return true; |
169 | 169 | } |
170 | 170 | |
— | — | @@ -175,10 +175,10 @@ |
176 | 176 | function wfArticleCommentForm( $title, $params = array() ) { |
177 | 177 | global $wgArticleCommentDefaults; |
178 | 178 | |
179 | | - # Merge in global defaults if specified |
| 179 | + # Merge in global defaults if specified |
180 | 180 | $tmp = $wgArticleCommentDefaults; |
181 | 181 | foreach ( $params as $k => $v ) { |
182 | | - $tmp[strtolower($k)] = (bool)strcasecmp( $v, "false" ); |
| 182 | + $tmp[strtolower( $k )] = (bool)strcasecmp( $v, "false" ); |
183 | 183 | } |
184 | 184 | $params = $tmp; |
185 | 185 | $ac = 'article-comments-'; |
— | — | @@ -190,21 +190,21 @@ |
191 | 191 | $content .= '<p>'; |
192 | 192 | $content .= Html::hidden( 'commentArticle', $title->getPrefixedDBkey() ); |
193 | 193 | |
194 | | - $content .= '<label for="commenterName">' . wfMsgExt($ac.'name-field', array( 'parseinline', 'content' ) ) . Html::element('br') . '</label>'; |
195 | | - $content .= Html::input( 'commenterName', '', 'text', array( 'id'=>'commenterName' ) ); |
| 194 | + $content .= '<label for="commenterName">' . wfMsgExt( $ac . 'name-field', array( 'parseinline', 'content' ) ) . Html::element( 'br' ) . '</label>'; |
| 195 | + $content .= Html::input( 'commenterName', '', 'text', array( 'id' => 'commenterName' ) ); |
196 | 196 | $content .= '</p>'; |
197 | 197 | |
198 | 198 | if ( $params['showurlfield'] ) { |
199 | | - $content .= '<p><label for="commenterURL">' . wfMsgExt($ac.'url-field', array( 'parseinline', 'content' ) ) . Html::element('br') . '</label>'; |
200 | | - $content .= Html::input( 'commenterURL', 'http://', 'text', array( 'id'=>'commenterURL' ) ); |
| 199 | + $content .= '<p><label for="commenterURL">' . wfMsgExt( $ac . 'url-field', array( 'parseinline', 'content' ) ) . Html::element( 'br' ) . '</label>'; |
| 200 | + $content .= Html::input( 'commenterURL', 'http://', 'text', array( 'id' => 'commenterURL' ) ); |
201 | 201 | $content .= '</p>'; |
202 | 202 | } |
203 | | - |
204 | | - $content .= '<p><label for="comment">'.wfMsgExt($ac.'comment-field', array( 'parseinline', 'content' ) ) . Html::element('br') . '</label>'; |
205 | | - |
| 203 | + |
| 204 | + $content .= '<p><label for="comment">' . wfMsgExt( $ac . 'comment-field', array( 'parseinline', 'content' ) ) . Html::element( 'br' ) . '</label>'; |
| 205 | + |
206 | 206 | $content .= '<textarea id="comment" name="comment" style="width:30em" rows="5">' . '</textarea></p>'; |
207 | 207 | |
208 | | - $content .= '<p>' . Html::input( 'comment-submit', wfMsgForContent( $ac.'submit-button' ), 'submit' ) . '</p>'; |
| 208 | + $content .= '<p>' . Html::input( 'comment-submit', wfMsgForContent( $ac . 'submit-button' ), 'submit' ) . '</p>'; |
209 | 209 | $content .= '</form></div>'; |
210 | 210 | |
211 | 211 | # Short-circuit if noScript has been set to anything other than false |
— | — | @@ -216,51 +216,51 @@ |
217 | 217 | $content .= "<script type='text/javascript'>//<![CDATA[\n(function(){\n"; |
218 | 218 | |
219 | 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"; |
| 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 | 230 | # Prefill comment text if it has been specified by a system message |
231 | 231 | # Note: This is done dynamically with JavaScript since it would be annoying |
232 | 232 | # for JS-disabled browsers to have the prefilled text (since they'd have |
233 | 233 | # to manually delete it) and would break parser output caching |
234 | | - $pretext = wfMsgForContent($ac.'prefilled-comment-text'); |
235 | | - if ($pretext) { |
| 234 | + $pretext = wfMsgForContent( $ac . 'prefilled-comment-text' ); |
| 235 | + if ( $pretext ) { |
236 | 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"; |
| 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 | 249 | } |
250 | 250 | |
251 | 251 | # Hides the commentForm until the "Make a comment" link is clicked |
252 | 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"; |
| 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 | 265 | } |
266 | 266 | |
267 | 267 | $content .= "})();\n//]]></script>"; |
— | — | @@ -274,7 +274,7 @@ |
275 | 275 | * @param String $text Article/Output text (passed by reference) |
276 | 276 | * @return Boolean Always tru to give other hooking methods a chance to run. |
277 | 277 | */ |
278 | | -function wfProcessEncodedContent($out, $text) { |
| 278 | +function wfProcessEncodedContent( $out, $text ) { |
279 | 279 | $text = preg_replace( |
280 | 280 | '/<pre>\n@ENCODED@([0-9a-zA-Z\\+\\/]+=*)@ENCODED@\n<\\/pre>/e', |
281 | 281 | 'base64_decode("$1")', |
— | — | @@ -295,7 +295,7 @@ |
296 | 296 | $commenterName = $wgRequest->getVal( 'commenterName' ); |
297 | 297 | $commenterURL = trim( $wgRequest->getVal( 'commenterURL' ) ); |
298 | 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://' ) { |
302 | 302 | $commenterURL = ''; |
— | — | @@ -308,30 +308,30 @@ |
309 | 309 | $messages = array(); |
310 | 310 | |
311 | 311 | if ( !$wgRequest->wasPosted() ) |
312 | | - $messages[] = wfMsgForContent( $ac.'not-posted' ); |
| 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 | | - |
319 | | - if (!$commenterName) $messages[] = wfMsgForContent( |
320 | | - $ac.'required-field', wfMsgForContent($ac.'name-string')); |
321 | 318 | |
| 319 | + if ( !$commenterName ) $messages[] = wfMsgForContent( |
| 320 | + $ac . 'required-field', wfMsgForContent( $ac . 'name-string' ) ); |
| 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')); |
| 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 | 330 | $wikiText = "<div class='errorbox'>"; |
331 | | - $wikiText .= wfMsgForContent($ac.'failure-reasons')."\n\n"; |
332 | | - foreach ($messages as $message) { |
| 331 | + $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
| 332 | + foreach ( $messages as $message ) { |
333 | 333 | $wikiText .= "* $message\n"; |
334 | 334 | } |
335 | | - $wgOut->addWikiText($wikiText . "</div>"); |
| 335 | + $wgOut->addWikiText( $wikiText . "</div>" ); |
336 | 336 | return; |
337 | 337 | } |
338 | 338 | |
— | — | @@ -342,12 +342,12 @@ |
343 | 343 | $talkArticle = new Article( $talkTitle ); |
344 | 344 | |
345 | 345 | # Check whether user is blocked from editing the talk page |
346 | | - if ($wgUser->isBlockedFrom($talkTitle)) { |
347 | | - $wgOut->setPageTitle(wfMsgForContent($ac.'submission-failed')); |
| 346 | + if ( $wgUser->isBlockedFrom( $talkTitle ) ) { |
| 347 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
348 | 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>"); |
| 349 | + $wikiText .= wfMsgForContent( $ac . 'failure-reasons' ) . "\n\n"; |
| 350 | + $wikiText .= '* ' . wfMsgForContent( $ac . 'user-is-blocked', $talkTitle->getPrefixedText() ) . "\n"; |
| 351 | + $wgOut->addWikiText( $wikiText . "</div>" ); |
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
— | — | @@ -362,26 +362,26 @@ |
363 | 363 | if ( $talkTitle->exists() ) { |
364 | 364 | $talkContent = $talkArticle->getContent(); |
365 | 365 | } |
366 | | - |
367 | | - |
| 366 | + |
| 367 | + |
368 | 368 | # Check if talk NS is in the Namespace display list |
369 | 369 | # Note: if so, then there's no need to confirm that <comments /> appears in the article or talk page. |
370 | 370 | global $wgArticleCommentsNSDisplayList; |
371 | 371 | $skipCheck = ( |
372 | | - is_array($wgArticleCommentsNSDisplayList) ? |
373 | | - in_array($talkTitle->getNamespace(),$wgArticleCommentsNSDisplayList): |
| 372 | + is_array( $wgArticleCommentsNSDisplayList ) ? |
| 373 | + in_array( $talkTitle->getNamespace(), $wgArticleCommentsNSDisplayList ): |
374 | 374 | false |
375 | 375 | ); |
376 | 376 | |
377 | 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 |
| 378 | + if ( !$skipCheck && |
| 379 | + preg_match( '/<comments( +[^>]*)?\\/>/', $articleContent ) === 0 && |
| 380 | + preg_match( '/<comments( +[^>]*)?\\/>/', $talkContent ) === 0 |
381 | 381 | ) { |
382 | | - $wgOut->setPageTitle(wfMsgForContent($ac.'submission-failed')); |
| 382 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
383 | 383 | $wgOut->addWikiText( |
384 | | - "<div class='errorbox'>". |
385 | | - wfMsgForContent($ac.'no-comments', $title->getPrefixedText()). |
| 384 | + "<div class='errorbox'>" . |
| 385 | + wfMsgForContent( $ac . 'no-comments', $title->getPrefixedText() ) . |
386 | 386 | "</div>" |
387 | 387 | ); |
388 | 388 | return; |
— | — | @@ -392,55 +392,55 @@ |
393 | 393 | wfRunHooks( 'ArticleCommentsSpamCheck', array( $comment , $commenterName, $commenterURL, &$isspam ) ); |
394 | 394 | |
395 | 395 | # If it's spam - it's gone! |
396 | | - if ($isspam) { |
397 | | - $wgOut->setPageTitle(wfMsgForContent($ac.'submission-failed')); |
| 396 | + if ( $isspam ) { |
| 397 | + $wgOut->setPageTitle( wfMsgForContent( $ac . 'submission-failed' ) ); |
398 | 398 | $wgOut->addWikiText( |
399 | | - "<div class='errorbox'>". |
400 | | - wfMsgForContent($ac.'no-spam'). |
| 399 | + "<div class='errorbox'>" . |
| 400 | + wfMsgForContent( $ac . 'no-spam' ) . |
401 | 401 | "</div>" |
402 | 402 | ); |
403 | 403 | return; |
404 | 404 | } |
405 | | - |
| 405 | + |
406 | 406 | # Initialize the talk page's content. |
407 | 407 | if ( $talkContent == '' ) { |
408 | | - $talkContent = wfMsgForContent($ac.'talk-page-starter', $title->getPrefixedText() ); |
| 408 | + $talkContent = wfMsgForContent( $ac . 'talk-page-starter', $title->getPrefixedText() ); |
409 | 409 | } |
410 | | - |
| 410 | + |
411 | 411 | # Determine signature components |
412 | | - if ($commenterURL != '') $sigText = "[$commenterURL $commenterName]"; |
413 | | - else if ($wgUser->isLoggedIn()) $sigText = $wgParser->getUserSig( $wgUser ); |
| 412 | + if ( $commenterURL != '' ) $sigText = "[$commenterURL $commenterName]"; |
| 413 | + else if ( $wgUser->isLoggedIn() ) $sigText = $wgParser->getUserSig( $wgUser ); |
414 | 414 | else $sigText = $commenterName; |
415 | | - |
| 415 | + |
416 | 416 | # Search for insertion point, or append most recent comment. |
417 | 417 | $commentText = wfMsgForContent( |
418 | | - $ac.'new-comment', |
419 | | - wfMsgForContent($ac.'commenter-said', $commenterName), |
| 418 | + $ac . 'new-comment', |
| 419 | + wfMsgForContent( $ac . 'commenter-said', $commenterName ), |
420 | 420 | $comment, |
421 | 421 | $sigText, |
422 | 422 | '~~~~~' |
423 | 423 | ); |
424 | | - |
| 424 | + |
425 | 425 | $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' ); |
426 | | - if ($posAbove===false) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
427 | | - if ($posAbove!==false) { |
| 426 | + if ( $posAbove === false ) $posBelow = stripos( $talkContent, '<!--COMMENTS_BELOW-->' ); |
| 427 | + if ( $posAbove !== false ) { |
428 | 428 | # Insert comments above HTML marker |
429 | 429 | $talkContent = substr( $talkContent, 0, $posAbove ) . $commentText . substr( $talkContent, $posAbove ); |
430 | | - } else if ($posBelow!==false) { |
| 430 | + } else if ( $posBelow !== false ) { |
431 | 431 | # Insert comments below HTML marker |
432 | 432 | $talkContent = substr( $talkContent, 0, $posBelow + 21 ) . $commentText . substr( $talkContent, $posBelow + 21 ); |
433 | 433 | } else { |
434 | 434 | # No marker found, append to bottom (default) |
435 | 435 | $talkContent .= $commentText; |
436 | 436 | } |
437 | | - |
| 437 | + |
438 | 438 | # Update the talkArticle with the new comment |
439 | | - $summary = wfMsgForContent($ac.'summary', $commenterName); |
440 | | - $talkArticle->doEdit($talkContent, $summary); |
| 439 | + $summary = wfMsgForContent( $ac . 'summary', $commenterName ); |
| 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 | /** |
— | — | @@ -452,16 +452,16 @@ |
453 | 453 | * @param Boolean $isspam Whether the comment is spam (passed by reference) |
454 | 454 | * @return Boolean Always true to indicate other hooking methods may continue to check for spam. |
455 | 455 | */ |
456 | | -function defaultArticleCommentSpamCheck($comment, $commenterName, $commenterURL, $isspam) { |
| 456 | +function defaultArticleCommentSpamCheck( $comment, $commenterName, $commenterURL, $isspam ) { |
457 | 457 | |
458 | 458 | # Short-circuit if spam has already been determined |
459 | | - if ($isspam) return true; |
460 | | - $fields = array($comment, $commenterName, $commenterURL); |
461 | | - |
| 459 | + if ( $isspam ) return true; |
| 460 | + $fields = array( $comment, $commenterName, $commenterURL ); |
| 461 | + |
462 | 462 | # Run everything through $wgSpamRegex if it has been specified |
463 | 463 | global $wgSpamRegex; |
464 | | - if ($wgSpamRegex) { |
465 | | - foreach ($fields as $field) { |
| 464 | + if ( $wgSpamRegex ) { |
| 465 | + foreach ( $fields as $field ) { |
466 | 466 | if ( preg_match( $wgSpamRegex, $field ) ) return $isspam = true; |
467 | 467 | } |
468 | 468 | } |
— | — | @@ -471,23 +471,23 @@ |
472 | 472 | '%\\[url=(https?|ftp)://%smi', |
473 | 473 | '%<a\\s+[^>]*href\\s*=\\s*[\'"]?\\s*(https?|ftp)://%smi' |
474 | 474 | ); |
475 | | - foreach ($spampatterns as $sp) { |
476 | | - foreach (array($comment, $commenterName, $commenterURL) as $field) { |
477 | | - if ( preg_match($sp, $field) ) return $isspam = true; |
| 475 | + foreach ( $spampatterns as $sp ) { |
| 476 | + foreach ( array( $comment, $commenterName, $commenterURL ) as $field ) { |
| 477 | + if ( preg_match( $sp, $field ) ) return $isspam = true; |
478 | 478 | } |
479 | 479 | } |
480 | | - |
| 480 | + |
481 | 481 | # Check for bad input for commenterName (seems to be a popular spam location) |
482 | 482 | $spampatterns = array( |
483 | 483 | '%<a\\s+%smi', |
484 | 484 | '%(https?|ftp)://%smi', |
485 | 485 | '%(\\n|\\r)%smi' |
486 | 486 | ); |
487 | | - foreach ($spampatterns as $sp) if ( preg_match($sp, $commenterName) ) return $isspam = true; |
488 | | - |
| 487 | + foreach ( $spampatterns as $sp ) if ( preg_match( $sp, $commenterName ) ) return $isspam = true; |
| 488 | + |
489 | 489 | # Fail for length violations |
490 | | - if ( strlen($commenterName)>255 || strlen($commenterURL)>300 ) return $isspam = true; |
491 | | - |
| 490 | + if ( strlen( $commenterName ) > 255 || strlen( $commenterURL ) > 300 ) return $isspam = true; |
| 491 | + |
492 | 492 | # We made it this far, leave $isspam alone and give other implementors a chance. |
493 | 493 | return true; |
494 | 494 | } |