Index: trunk/extensions/ArticleComments/ArticleComments.php |
— | — | @@ -161,7 +161,7 @@ |
162 | 162 | |
163 | 163 | # Display the form |
164 | 164 | if (in_array($title->getNamespace(), $nsList)) { |
165 | | - $data .= wfArticleCommentForm($title, $params); |
| 165 | + $data .= wfArticleCommentForm( $title ); |
166 | 166 | } |
167 | 167 | |
168 | 168 | return true; |
— | — | @@ -173,47 +173,42 @@ |
174 | 174 | * @param Array $params A hash of parameters containing rendering options. |
175 | 175 | */ |
176 | 176 | function wfArticleCommentForm( $title, $params = array() ) { |
| 177 | + global $wgArticleCommentDefaults; |
177 | 178 | |
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; |
190 | 185 | $ac = 'article-comments-'; |
191 | | - $formAction = $wgScript.'?title='.$wgContLang->getNsText(NS_SPECIAL).':ProcessComment'; |
192 | 186 | |
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 | + |
214 | 211 | # 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'] ) { |
218 | 213 | return $content; |
219 | 214 | } |
220 | 215 | |
— | — | @@ -234,7 +229,7 @@ |
235 | 230 | # Prefill comment text if it has been specified by a system message |
236 | 231 | # Note: This is done dynamically with JavaScript since it would be annoying |
237 | 232 | # 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 |
239 | 234 | $pretext = wfMsgForContent($ac.'prefilled-comment-text'); |
240 | 235 | if ($pretext) { |
241 | 236 | $content .= |
— | — | @@ -301,13 +296,19 @@ |
302 | 297 | $commenterName = $_POST['commenterName']; |
303 | 298 | $commenterURL = isset($_POST['commenterURL']) ? $_POST['commenterURL'] : ''; |
304 | 299 | $comment = $_POST['comment']; |
| 300 | + global $wgRequest; |
| 301 | + |
| 302 | + $titleText = $wgRequest->getVal( 'commentArticle' ); |
| 303 | + $title = Title::newFromText( $titleText ); |
305 | 304 | |
306 | 305 | # Perform validation checks on supplied fields |
307 | 306 | $ac = 'article-comments-'; |
308 | 307 | $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 | + |
312 | 313 | if (!$commenterName) $messages[] = wfMsgForContent( |
313 | 314 | $ac.'required-field', wfMsgForContent($ac.'name-string')); |
314 | 315 | if (!$comment) $messages[] = wfMsgForContent( |
— | — | @@ -324,13 +325,10 @@ |
325 | 326 | } |
326 | 327 | |
327 | 328 | # 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 ); |
331 | 330 | |
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 ); |
335 | 333 | |
336 | 334 | # Check whether user is blocked from editing the talk page |
337 | 335 | if ($wgUser->isBlockedFrom($talkTitle)) { |
— | — | @@ -344,7 +342,7 @@ |
345 | 343 | |
346 | 344 | # Retrieve article content |
347 | 345 | $articleContent = ''; |
348 | | - if ( $article->exists() ) { |
| 346 | + if ( $title->exists() ) { |
349 | 347 | $articleContent = $article->getContent(); |
350 | 348 | } |
351 | 349 | |