r46631 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46630‎ | r46631 | r46632 >
Date:01:59, 31 January 2009
Author:werdna
Status:deferred
Tags:
Comment:
Allow af_public_comments to be wikitext.
Relatedly, add parseInline function to OutputPage, to avoid duplicating the same awful regex in wfMsgExt.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)
  • /trunk/extensions/AbuseFilter/SpecialAbuseLog.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewList.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -645,6 +645,18 @@
646646 return $parserOutput->getText();
647647 }
648648
 649+ /** Parse wikitext, strip paragraphs, and return the HTML. */
 650+ public function parseInline( $text, $linestart = true, $interface = false ) {
 651+ $parsed = $this->parse( $text, $linestart, $interface );
 652+
 653+ $m = array();
 654+ if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
 655+ $parsed = $m[1];
 656+ }
 657+
 658+ return $parsed;
 659+ }
 660+
649661 /**
650662 * @param Article $article
651663 * @param User $user
Index: trunk/extensions/AbuseFilter/SpecialAbuseLog.php
@@ -180,13 +180,16 @@
181181 }
182182 $actions_taken = implode( ', ', $displayActions );
183183 }
 184+
 185+ global $wgOut;
 186+ $parsed_comments = $wgOut->parseInline( $row->af_public_comments );
184187
185188 if ($this->canSeeDetails()) {
186189 $detailsLink = $sk->makeKnownLinkObj( $this->getTitle( ), wfMsg( 'abusefilter-log-detailslink' ), 'details='.$row->afl_id );
187190
188 - $description = wfMsgExt( 'abusefilter-log-detailedentry', array( 'parseinline', 'replaceafter' ), array( $timestamp, $user, $row->afl_filter, $row->afl_action, $sk->makeKnownLinkObj( $title ), $actions_taken, $row->af_public_comments, $detailsLink ) );
 191+ $description = wfMsgExt( 'abusefilter-log-detailedentry', array( 'parseinline', 'replaceafter' ), array( $timestamp, $user, $row->afl_filter, $row->afl_action, $sk->makeKnownLinkObj( $title ), $actions_taken, $parsed_comments, $detailsLink ) );
189192 } else {
190 - $description = wfMsgExt( 'abusefilter-log-entry', array( 'parseinline', 'replaceafter' ), array( $timestamp, $user, $row->afl_action, $sk->makeKnownLinkObj( $title ), $actions_taken, $row->af_public_comments ) );
 193+ $description = wfMsgExt( 'abusefilter-log-entry', array( 'parseinline', 'replaceafter' ), array( $timestamp, $user, $row->afl_action, $sk->makeKnownLinkObj( $title ), $actions_taken, $parsed_comments ) );
191194 }
192195
193196 return $li ? Xml::tags( 'li', null, $description ) : $description;
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewList.php
@@ -168,7 +168,7 @@
169169 case 'af_id':
170170 return $sk->link( SpecialPage::getTitleFor( 'AbuseFilter', intval($value) ), intval($value) );
171171 case 'af_public_comments':
172 - return $sk->link( SpecialPage::getTitleFor( 'AbuseFilter', intval($row->af_id) ), $wgOut->parse( $value ) );
 172+ return $sk->link( SpecialPage::getTitleFor( 'AbuseFilter', intval($row->af_id) ), $wgOut->parseInline( $value ) );
173173 case 'af_actions':
174174 $actions = explode(',', $value);
175175 $displayActions = array();
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -253,6 +253,8 @@
254254
255255 foreach( $actionsByFilter as $filter => $actions ) {
256256 // Special-case handling for warnings.
 257+ global $wgOut;
 258+ $parsed_public_comments = $wgOut->parseInline( self::$filters[$filter]->af_public_comments );
257259
258260 if ( !empty( $actions['throttle'] ) ) {
259261 $parameters = $actions['throttle']['parameters'];
@@ -281,7 +283,7 @@
282284
283285 // Threaten them a little bit
284286 $msg = ( !empty($parameters[0]) && strlen($parameters[0]) ) ? $parameters[0] : 'abusefilter-warning';
285 - $messages[] = wfMsgNoTrans( $msg, self::$filters[$filter]->af_public_comments ) . "<br />\n";
 287+ $messages[] = wfMsgExt( $msg, 'parseinline', array( $parsed_public_comments) ) . "<br />\n";
286288
287289 $actionsTaken[$filter][] = 'warn';
288290
@@ -300,7 +302,7 @@
301303
302304 // Do the rest of the actions
303305 foreach( $actions as $action => $info ) {
304 - $newMsg = self::takeConsequenceAction( $action, $info['parameters'], $title, $vars, self::$filters[$filter]->af_public_comments );
 306+ $newMsg = self::takeConsequenceAction( $action, $info['parameters'], $title, $vars, self::$filters[$filter]->af_public_comments);
305307
306308 if ($newMsg)
307309 $messages[] = $newMsg;
@@ -365,10 +367,10 @@
366368 switch ($action) {
367369 case 'disallow':
368370 if (strlen($parameters[0])) {
369 - $display .= wfMsgNoTrans( $parameters[0], $rule_desc ) . "\n";
 371+ $display .= wfMsgExt( $parameters[0], 'parseinline', array($rule_desc) ) . "\n";
370372 } else {
371373 // Generic message.
372 - $display .= wfMsgNoTrans( 'abusefilter-disallowed', $rule_desc ) ."<br />\n";
 374+ $display .= wfMsgExt( 'abusefilter-disallowed', 'parseinline', array($rule_desc) ) ."<br />\n";
373375 }
374376 break;
375377
@@ -400,7 +402,7 @@
401403 $log->addEntry( 'block', Title::makeTitle( NS_USER, $wgUser->getName() ),
402404 wfMsgForContent( 'abusefilter-blockreason', $rule_desc ), $logParams, self::getFilterUser() );
403405
404 - $display .= wfMsgNoTrans( 'abusefilter-blocked-display', $rule_desc ) ."<br />\n";
 406+ $display .= wfMsgExt( 'abusefilter-blocked-display', 'parseinline', array($rule_desc) ) ."<br />\n";
405407 break;
406408 case 'rangeblock':
407409 global $wgUser;
@@ -436,7 +438,7 @@
437439 $log->addEntry( 'block', Title::makeTitle( NS_USER, $range ),
438440 wfMsgForContent( 'abusefilter-blockreason', $rule_desc ), $logParams, self::getFilterUser() );
439441
440 - $display .= wfMsgNoTrans( 'abusefilter-blocked-display', $rule_desc ) ."<br />\n";
 442+ $display .= wfMsgExt( 'abusefilter-blocked-display', 'parseinline', $rule_desc ) ."<br />\n";
441443 break;
442444 case 'degroup':
443445 global $wgUser;
@@ -448,7 +450,7 @@
449451 $wgUser->removeGroup( $group );
450452 }
451453
452 - $display .= wfMsgNoTrans( 'abusefilter-degrouped', $rule_desc ) ."<br />\n";
 454+ $display .= wfMsgExt( 'abusefilter-degrouped', 'parseinline', array($rule_desc) ) ."<br />\n";
453455
454456 // Don't log it if there aren't any groups being removed!
455457 if (!count($groups)) {
@@ -475,7 +477,7 @@
476478 $blockPeriod = (int)mt_rand( 3*86400, 7*86400 ); // Block for 3-7 days.
477479 $wgMemc->set( self::autoPromoteBlockKey( $wgUser ), true, $blockPeriod );
478480
479 - $display .= wfMsgNoTrans( 'abusefilter-autopromote-blocked', $rule_desc ) ."<br />\n";
 481+ $display .= wfMsgExt( 'abusefilter-autopromote-blocked', 'parseinline', array($rule_desc) ) ."<br />\n";
480482 }
481483 break;
482484
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -26,7 +26,10 @@
2727 $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle, $oldLinks );
2828
2929 if( $filter_result !== true ){
30 - $error = $filter_result;
 30+ global $wgOut;
 31+ $wgOut->addHTML( $filter_result );
 32+ $editor->showEditForm();
 33+ return false;
3134 }
3235 return true;
3336 }

Status & tagging log