r74152 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74151‎ | r74152 | r74153 >
Date:21:13, 2 October 2010
Author:platonides
Status:resolved
Tags:
Comment:
Always use doEdit().
Do not calculate the timestamp ourselves, but use ~~~~~ and let the parser do the magic.
Trimmed trailing whitespaces on i18n
Renamed article-comments-title-field to article-comments-title-string
Use getVal() everywhere, not $_POST
Check for URL sanity
Document what are some messages.

Fixes some issues of r73985 CR
Modified paths:
  • /trunk/extensions/ArticleComments/ArticleComments.i18n.php (modified) (history)
  • /trunk/extensions/ArticleComments/ArticleComments.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleComments/ArticleComments.php
@@ -288,29 +288,40 @@
289289 */
290290 function specialProcessComment() {
291291
292 - global $wgOut, $wgParser, $wgUser, $wgContLang;
 292+ global $wgOut, $wgParser, $wgUser, $wgContLang, $wgRequest;
293293
294294 # Retrieve submitted values
295 - $titleKey = $_POST['titleKey'];
296 - $titleNS = intval($_POST['titleNS']);
297 - $commenterName = $_POST['commenterName'];
298 - $commenterURL = isset($_POST['commenterURL']) ? $_POST['commenterURL'] : '';
299 - $comment = $_POST['comment'];
300 - global $wgRequest;
 295+ $titleText = $wgRequest->getVal( 'commentArticle' );
 296+ $commenterName = $wgRequest->getVal( 'commenterName' );
 297+ $commenterURL = trim( $wgRequest->getVal( 'commenterURL' ) );
 298+ $comment = $wgRequest->getVal( 'comment' );
301299
302 - $titleText = $wgRequest->getVal( 'commentArticle' );
 300+ // The default value is the same as not providing a URL
 301+ if ( $commenterURL == 'http://' ) {
 302+ $commenterURL = '';
 303+ }
 304+
303305 $title = Title::newFromText( $titleText );
304306
305307 # Perform validation checks on supplied fields
306308 $ac = 'article-comments-';
307309 $messages = array();
 310+
 311+ if ( !$wgRequest->wasPosted() )
 312+ $messages[] = wfMsgForContent( $ac.'not-posted' );
 313+
308314 if ( $titleText === '' || !$title) {
309315 $messages[] = wfMsgForContent(
310 - $ac.'invalid-field', wfMsgForContent($ac.'title-field'), $titleKey );
 316+ $ac.'invalid-field', wfMsgForContent($ac.'title-string'), $titleText );
311317 }
312318
313319 if (!$commenterName) $messages[] = wfMsgForContent(
314320 $ac.'required-field', wfMsgForContent($ac.'name-string'));
 321+
 322+ if ( !preg_match( "/^(" . wfUrlProtocols() . ')' . Parser::EXT_LINK_URL_CLASS . '+$/', $commenterURL ) )
 323+ $messages[] = wfMsgForContent(
 324+ $ac.'invalid-field', wfMsgForContent($ac.'url-string'), $commenterURL );
 325+
315326 if (!$comment) $messages[] = wfMsgForContent(
316327 $ac.'required-field', wfMsgForContent($ac.'comment-string'));
317328 if (!empty($messages)) {
@@ -397,8 +408,7 @@
398409 }
399410
400411 # Determine signature components
401 - $d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) . ' (' . date( 'T' ) . ')';
402 - if ($commenterURL && $commenterURL!='http://') $sigText = "[$commenterURL $commenterName]";
 412+ if ($commenterURL != '') $sigText = "[$commenterURL $commenterName]";
403413 else if ($wgUser->isLoggedIn()) $sigText = $wgParser->getUserSig( $wgUser );
404414 else $sigText = $commenterName;
405415
@@ -408,7 +418,7 @@
409419 wfMsgForContent($ac.'commenter-said', $commenterName),
410420 $comment,
411421 $sigText,
412 - $d
 422+ '~~~~~'
413423 );
414424
415425 $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' );
@@ -424,15 +434,9 @@
425435 $talkContent .= $commentText;
426436 }
427437
428 - # Update the talkArticle with the new comment
429 - $summary = wfMsgForContent($ac.'summary', $commenterName);
430 - if (method_exists($talkArticle, 'doEdit')) {
431 - $talkArticle->doEdit($talkContent, $summary);
432 - } else {
433 - $method = ($talkArticle->exists() ? 'updateArticle' : 'insertNewArticle' );
434 - $talkArticle->$method($talkContent, $summary, false, false);
435 - return;
436 - }
 438+ # Update the talkArticle with the new comment
 439+ $summary = wfMsgForContent($ac.'summary', $commenterName);
 440+ $talkArticle->doEdit($talkContent, $summary);
437441
438442 $wgOut->setPageTitle(wfMsgForContent($ac.'submission-succeeded'));
439443 $wgOut->addWikiText(wfMsgForContent($ac.'submission-success', $title->getPrefixedText()));
Index: trunk/extensions/ArticleComments/ArticleComments.i18n.php
@@ -9,12 +9,13 @@
1010 $messages = array();
1111
1212 $messages['en'] = array(
13 - 'article-comments-title-field' => 'Title',
 13+ 'article-comments-title-string' => 'title',
1414 'article-comments-name-string' => 'Name',
15 - 'article-comments-name-field' => 'Name (required): ',
16 - 'article-comments-url-field' => 'Website: ',
 15+ 'article-comments-name-field' => 'Name (required):',
 16+ 'article-comments-url-field' => 'Website:',
 17+ 'article-comments-url-string' => 'URL',
1718 'article-comments-comment-string' => 'Comment',
18 - 'article-comments-comment-field' => 'Comment: ',
 19+ 'article-comments-comment-field' => 'Comment:',
1920 'article-comments-submit-button' => 'Submit',
2021 'article-comments-leave-comment-link' => 'Leave a comment ...',
2122 'article-comments-invalid-field' => 'The $1 provided <nowiki>[$2]</nowiki> is invalid.',
@@ -35,3 +36,14 @@
3637 'processcomment' => 'Process Article Comment',
3738 );
3839
 40+$messages['qqq'] = array(
 41+ 'article-comments-required-field' => 'Shown as a list below article-comments-failure-reasons. With $1 being one of article-comments-*-string messages.',
 42+ 'article-comments-submission-failed' => 'Page title when there are errors in the comment submission',
 43+ '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.',
 44+ 'article-comments-new-comment' => 'Text to add in the new comment.
 45+* $1 - Expansion of article-comments-commenter-said.
 46+* $2 - Comment text.
 47+* $3 - Commenter name, possibly linking to its web.
 48+* $4 - Datetime.',
 49+);
 50+

Follow-up revisions

RevisionCommit summaryAuthorDate
r74157Fix to r74152: do not check the url when not provided....platonides21:38, 2 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73985Updated to work with MediaWiki 1.16+ (may also work with previous versions)...platonides21:36, 29 September 2010

Status & tagging log