r74000 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73999‎ | r74000 | r74001 >
Date:22:50, 29 September 2010
Author:platonides
Status:deferred
Tags:
Comment:
Use Html functions.
Pass the prefixed text, not text + namespace and check that the Title exists.
Modified paths:
  • /trunk/extensions/ArticleComments/ArticleComments.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleComments/ArticleComments.php
@@ -161,7 +161,7 @@
162162
163163 # Display the form
164164 if (in_array($title->getNamespace(), $nsList)) {
165 - $data .= wfArticleCommentForm($title, $params);
 165+ $data .= wfArticleCommentForm( $title );
166166 }
167167
168168 return true;
@@ -173,47 +173,42 @@
174174 * @param Array $params A hash of parameters containing rendering options.
175175 */
176176 function wfArticleCommentForm( $title, $params = array() ) {
 177+ global $wgArticleCommentDefaults;
177178
178 - global $wgScript, $wgArticleCommentDefaults, $wgContLang;
179 -
180 - # Merge in global defaults if specified
181 - if (is_array($wgArticleCommentDefaults) &&
182 - !empty($wgArticleCommentDefaults)) {
183 - $tmp = array();
184 - foreach ($wgArticleCommentDefaults as $k=>$v) {
185 - $tmp[strtolower($k)] = $v;
186 - }
187 - $params = array_merge($tmp, $params);
188 - }
189 -
 179+ # Merge in global defaults if specified
 180+ $tmp = $wgArticleCommentDefaults;
 181+ foreach ( $params as $k => $v ) {
 182+ $tmp[strtolower($k)] = (bool)strcasecmp( $v, "false" );
 183+ }
 184+ $params = $tmp;
190185 $ac = 'article-comments-';
191 - $formAction = $wgScript.'?title='.$wgContLang->getNsText(NS_SPECIAL).':ProcessComment';
192186
193 - # Build out the comment form.
194 - $content =
195 - '<div id="commentForm">'.
196 - '<form method="post" action="'. htmlspecialchars( $formAction ) .'">'.
197 - '<input type="hidden" id="titleKey" name="titleKey" '.
198 - 'value="'. htmlspecialchars( $title->getDBKey() ) . '" />'.
199 - '<input type="hidden" id="titleNS" name="titleNS" '.
200 - 'value="'. htmlspecialchars( $title->getNamespace() ) .'" />'.
201 - '<p>'.wfMsgExt($ac.'name-field', array( 'parseinline', 'content' ) ).'<br />'.
202 - '<input type="text" id="commenterName" name="commenterName" /></p>'.
203 - ($params['showurlfield']=='false' || $params['showurlfield']===false?'':
204 - '<p>'.wfMsgExt($ac.'url-field', array( 'parseinline', 'content' ) ).'<br />'.
205 - '<input type="text" id="commenterURL" name="commenterURL" value="http://" /></p>'
206 - ).
207 - '<p>'.wfMsgExt($ac.'comment-field', array( 'parseinline', 'content' ) ).'<br />'.
208 - '<textarea id="comment" name="comment" style="width:30em" rows="5">'.
209 - '</textarea></p>'.
210 - '<p><input id="submit" type="submit" '.
211 - 'value="'.htmlspecialchars( wfMsgForContent($ac.'submit-button') ) .'" /></p>'.
212 - '</form></div>';
213 -
 187+ # Build out the comment form.
 188+ $content = '<div id="commentForm">';
 189+ $content .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => SpecialPage::getTitleFor( 'ProcessComment' )->getLocalURL() ) );
 190+
 191+ $content .= '<p>';
 192+ $content .= Html::hidden( 'commentArticle', $title->getPrefixedDBkey() );
 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' ) );
 196+ $content .= '</p>';
 197+
 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' ) );
 201+ $content .= '</p>';
 202+ }
 203+
 204+ $content .= '<p><label for="comment">'.wfMsgExt($ac.'comment-field', array( 'parseinline', 'content' ) ) . Html::element('br') . '</label>';
 205+
 206+ $content .= '<textarea id="comment" name="comment" style="width:30em" rows="5">' . '</textarea></p>';
 207+
 208+ $content .= '<p>' . Html::input( 'comment-submit', wfMsgForContent( $ac.'submit-button' ), 'submit' ) . '</p>';
 209+ $content .= '</form></div>';
 210+
214211 # Short-circuit if noScript has been set to anything other than false
215 - if (isset($params['noscript']) &&
216 - $params['noscript']!=='false' &&
217 - $params['noscript']) {
 212+ if ( $params['noscript'] ) {
218213 return $content;
219214 }
220215
@@ -234,7 +229,7 @@
235230 # Prefill comment text if it has been specified by a system message
236231 # Note: This is done dynamically with JavaScript since it would be annoying
237232 # for JS-disabled browsers to have the prefilled text (since they'd have
238 - # to manually delete it).
 233+ # to manually delete it) and would break parser output caching
239234 $pretext = wfMsgForContent($ac.'prefilled-comment-text');
240235 if ($pretext) {
241236 $content .=
@@ -301,13 +296,19 @@
302297 $commenterName = $_POST['commenterName'];
303298 $commenterURL = isset($_POST['commenterURL']) ? $_POST['commenterURL'] : '';
304299 $comment = $_POST['comment'];
 300+ global $wgRequest;
 301+
 302+ $titleText = $wgRequest->getVal( 'commentArticle' );
 303+ $title = Title::newFromText( $titleText );
305304
306305 # Perform validation checks on supplied fields
307306 $ac = 'article-comments-';
308307 $messages = array();
309 - if (!$titleKey) $messages[] = wfMsgForContent(
310 - $ac.'invalid-field', wfMsgForContent($ac.'title-field'), $titleKey
311 - );
 308+ if ( $titleText === '' || !$title) {
 309+ $messages[] = wfMsgForContent(
 310+ $ac.'invalid-field', wfMsgForContent($ac.'title-field'), $titleKey );
 311+ }
 312+
312313 if (!$commenterName) $messages[] = wfMsgForContent(
313314 $ac.'required-field', wfMsgForContent($ac.'name-string'));
314315 if (!$comment) $messages[] = wfMsgForContent(
@@ -324,13 +325,10 @@
325326 }
326327
327328 # Setup title and talkTitle object
328 - $title = Title::newFromDBkey($titleKey);
329 - $title->mNamespace = $titleNS - ($titleNS % 2);
330 - $article = new Article($title);
 329+ $article = new Article( $title );
331330
332 - $talkTitle = Title::newFromDBkey($titleKey);
333 - $talkTitle->mNamespace = $titleNS + 1 - ($titleNS % 2);
334 - $talkArticle = new Article($talkTitle);
 331+ $talkTitle = $title->getTalkPage();
 332+ $talkArticle = new Article( $talkTitle );
335333
336334 # Check whether user is blocked from editing the talk page
337335 if ($wgUser->isBlockedFrom($talkTitle)) {
@@ -344,7 +342,7 @@
345343
346344 # Retrieve article content
347345 $articleContent = '';
348 - if ( $article->exists() ) {
 346+ if ( $title->exists() ) {
349347 $articleContent = $article->getContent();
350348 }
351349

Status & tagging log