http://www.mediawiki.org/wiki/Special:Code/MediaWiki/74152

Revision: 74152
Author:   platonides
Date:     2010-10-02 21:13:32 +0000 (Sat, 02 Oct 2010)

Log Message:
-----------
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
    trunk/extensions/ArticleComments/ArticleComments.php

Modified: trunk/extensions/ArticleComments/ArticleComments.i18n.php
===================================================================
--- trunk/extensions/ArticleComments/ArticleComments.i18n.php   2010-10-02 
21:09:23 UTC (rev 74151)
+++ trunk/extensions/ArticleComments/ArticleComments.i18n.php   2010-10-02 
21:13:32 UTC (rev 74152)
@@ -9,12 +9,13 @@
 $messages = array();
 
 $messages['en'] = array(
-    'article-comments-title-field' => 'Title',
+    'article-comments-title-string' => 'title',
     'article-comments-name-string' => 'Name',
-    'article-comments-name-field' => 'Name (required): ',
-    'article-comments-url-field' => 'Website: ',
+    'article-comments-name-field' => 'Name (required):',
+    'article-comments-url-field' => 'Website:',
+    'article-comments-url-string' => 'URL',
     'article-comments-comment-string' => 'Comment',
-    'article-comments-comment-field' => 'Comment: ',
+    'article-comments-comment-field' => 'Comment:',
     'article-comments-submit-button' => 'Submit',
     'article-comments-leave-comment-link' => 'Leave a comment ...',
     'article-comments-invalid-field' => 'The $1 provided <nowiki>[$2]</nowiki> 
is invalid.',
@@ -35,3 +36,14 @@
     'processcomment' => 'Process Article Comment',
 );
 
+$messages['qqq'] = array(
+       'article-comments-required-field' => 'Shown as a list below 
article-comments-failure-reasons. With $1 being one of 
article-comments-*-string messages.',
+       'article-comments-submission-failed' => 'Page title when there are 
errors in the comment submission',
+       '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.',
+       'article-comments-new-comment' => 'Text to add in the new comment.
+* $1 - Expansion of article-comments-commenter-said.
+* $2 - Comment text.
+* $3 - Commenter name, possibly linking to its web.
+* $4 - Datetime.',
+);
+

Modified: trunk/extensions/ArticleComments/ArticleComments.php
===================================================================
--- trunk/extensions/ArticleComments/ArticleComments.php        2010-10-02 
21:09:23 UTC (rev 74151)
+++ trunk/extensions/ArticleComments/ArticleComments.php        2010-10-02 
21:13:32 UTC (rev 74152)
@@ -288,29 +288,40 @@
 */
 function specialProcessComment() {
 
-    global $wgOut, $wgParser, $wgUser, $wgContLang;
+    global $wgOut, $wgParser, $wgUser, $wgContLang, $wgRequest;
 
     # Retrieve submitted values
-    $titleKey = $_POST['titleKey'];
-    $titleNS = intval($_POST['titleNS']);
-    $commenterName = $_POST['commenterName'];
-    $commenterURL = isset($_POST['commenterURL']) ? $_POST['commenterURL'] : 
'';
-    $comment = $_POST['comment'];
-    global $wgRequest;
+    $titleText = $wgRequest->getVal( 'commentArticle' );
+    $commenterName = $wgRequest->getVal( 'commenterName' );
+    $commenterURL = trim( $wgRequest->getVal( 'commenterURL' ) );
+    $comment = $wgRequest->getVal( 'comment' );
     
-    $titleText = $wgRequest->getVal( 'commentArticle' );
+       // The default value is the same as not providing a URL
+       if ( $commenterURL == 'http://' ) {
+               $commenterURL = '';
+       }
+
        $title = Title::newFromText( $titleText );
 
     # Perform validation checks on supplied fields
     $ac = 'article-comments-';
     $messages = array();
+
+       if ( !$wgRequest->wasPosted() )
+               $messages[] = wfMsgForContent( $ac.'not-posted' );
+
     if ( $titleText === '' || !$title) {
                $messages[] = wfMsgForContent(
-        $ac.'invalid-field', wfMsgForContent($ac.'title-field'), $titleKey );
+        $ac.'invalid-field', wfMsgForContent($ac.'title-string'), $titleText );
        }
        
     if (!$commenterName) $messages[] = wfMsgForContent(
         $ac.'required-field', wfMsgForContent($ac.'name-string'));
+
+       if ( !preg_match( "/^(" . wfUrlProtocols() . ')' . 
Parser::EXT_LINK_URL_CLASS . '+$/', $commenterURL ) )
+               $messages[] = wfMsgForContent(
+        $ac.'invalid-field', wfMsgForContent($ac.'url-string'), $commenterURL 
);
+
     if (!$comment) $messages[] = wfMsgForContent(
         $ac.'required-field', wfMsgForContent($ac.'comment-string'));
     if (!empty($messages)) {
@@ -397,8 +408,7 @@
     }
     
     # Determine signature components
-    $d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) . ' (' . 
date( 'T' ) . ')';
-    if ($commenterURL && $commenterURL!='http://') $sigText = "[$commenterURL 
$commenterName]";
+    if ($commenterURL != '') $sigText = "[$commenterURL $commenterName]";
     else if ($wgUser->isLoggedIn()) $sigText = $wgParser->getUserSig( $wgUser 
);
     else $sigText = $commenterName;
     
@@ -408,7 +418,7 @@
         wfMsgForContent($ac.'commenter-said', $commenterName),
         $comment,
         $sigText,
-        $d
+        '~~~~~'
     );
     
     $posAbove = stripos( $talkContent, '<!--COMMENTS_ABOVE-->' );
@@ -424,15 +434,9 @@
         $talkContent .= $commentText;
     }
  
-    # Update the talkArticle with the new comment
-    $summary = wfMsgForContent($ac.'summary', $commenterName);
-    if (method_exists($talkArticle, 'doEdit')) {
-        $talkArticle->doEdit($talkContent, $summary);
-    } else {
-        $method = ($talkArticle->exists() ? 'updateArticle' : 
'insertNewArticle' );
-        $talkArticle->$method($talkContent, $summary, false, false);
-        return;
-    }
+       # Update the talkArticle with the new comment
+       $summary = wfMsgForContent($ac.'summary', $commenterName);
+       $talkArticle->doEdit($talkContent, $summary);
 
     $wgOut->setPageTitle(wfMsgForContent($ac.'submission-succeeded'));
     $wgOut->addWikiText(wfMsgForContent($ac.'submission-success', 
$title->getPrefixedText()));



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to