r47336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47335‎ | r47336 | r47337 >
Date:19:37, 16 February 2009
Author:aaron
Status:ok
Tags:
Comment:
* Tweaked asterisk handling in summaries
* Added shortenSummary() function
* Escaped $ literal for regexp and removed var matching
Modified paths:
  • /trunk/extensions/CodeReview/CodeReleaseNotes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReleaseNotes.php
@@ -83,24 +83,8 @@
8484 $summary = htmlspecialchars($row->cr_message);
8585 # Add this commit summary if needed
8686 if( $this->isRelevant( $summary ) ) {
87 - # Asterixs often used as point-by-point bullets
88 - $summary = str_replace('*','',$summary);
89 - $blurbs = explode("\n",$summary);
90 - $blurbs = array_map( 'trim', $blurbs ); # Clean up items
91 - $blurbs = array_filter( $blurbs ); # Filter out any garbage
9287 # Keep it short if possible...
93 - if( count($blurbs) > 2 ) {
94 - $summary = "";
95 - foreach( $blurbs as $blurb ) {
96 - if( $this->isRelevant( $blurb ) ) {
97 - $summary .= trim($blurb) . "\n";
98 - }
99 - }
100 - # Small enough as is...
101 - } else {
102 - $summary = implode("\n",$blurbs);
103 - }
104 - $summary = trim($summary);
 88+ $summary = $this->shortenSummary( $summary );
10589 # Anything left? (this can happen with some heuristics)
10690 if( $summary ) {
10791 $summary = str_replace( "\n", "<br/>", $summary ); // Newlines -> <br/>
@@ -115,10 +99,42 @@
116100 $wgOut->addHTML( '</ul>' );
117101 }
118102
 103+ private function shortenSummary( $summary, $first = true ) {
 104+ # Asterixs often used as point-by-point bullets
 105+ if( strpos($summary,'*') !== false ) {
 106+ $blurbs = explode('*',$summary);
 107+ # Double newlines separate importance generally
 108+ } else if( strpos($summary,"\n\n") !== false ) {
 109+ $blurbs = explode("\n\n",$summary);
 110+ } else {
 111+ return trim( $summary );
 112+ }
 113+ $blurbs = array_map( 'trim', $blurbs ); # Clean up items
 114+ $blurbs = array_filter( $blurbs ); # Filter out any garbage
 115+ # Keep it short if possible...
 116+ if( count($blurbs) > 1 ) {
 117+ $summary = array();
 118+ foreach( $blurbs as $blurb ) {
 119+ # Always show the first bit
 120+ if( $first && count($summary) == 0 ) {
 121+ $summary[] = $this->shortenSummary($blurb,true);
 122+ # Is this bit important? Does it mention a revision?
 123+ } else if( $this->isRelevant( $blurb ) || preg_match('/\br(\d+)\b/',$blurb) ) {
 124+ $bit = $this->shortenSummary($blurb,false);
 125+ if( $bit ) $summary[] = $bit;
 126+ }
 127+ }
 128+ $summary = implode("\n",$summary);
 129+ } else {
 130+ $summary = implode("\n",$blurbs);
 131+ }
 132+ return $summary;
 133+ }
 134+
119135 // Quick relevance tests (these *should* be over-inclusive a little if anything)
120136 private function isRelevant( $summary ) {
121 - # Fixed a bug? Mentioned a config var?
122 - if( preg_match( '/\b(bug #?(\d+)|$wg[0-9a-z]{3,50})\b/i', $summary ) )
 137+ # Fixed a bug? Mentioned a config var? Mentioned a rev?
 138+ if( preg_match( '/\b(bug #?(\d+)|\$[we]g[0-9a-z]{3,50})\b/i', $summary ) )
123139 return true;
124140 # Sanity check: summary cannot be *too* short to be useful
125141 $words = str_word_count($summary);
@@ -126,8 +142,7 @@
127143 return false;
128144 # All caps words (like "BREAKING CHANGE"/magic words)?
129145 # Literals like "'autoconfirmed'"/'"user contributions"'?
130 - # PHP vars like "$conf" mentioned?
131 - if( preg_match( '/\b([A-Z]{8,20}|[\'"]\w+[\'"]|$[0-9a-zA-Z]{3,50})\b/', $summary ) )
 146+ if( preg_match( '/\b([A-Z]{8,30}|[\'"]\w+[\'"])\b/', $summary ) )
132147 return true;
133148 # Random keywords
134149 if( preg_match( '/\b(wiki|HTML\d|CSS\d|UTF-?8|(Apache|PHP|CGI|Java|Perl|Python|\w+SQL) ?\d?\.?\d?)\b/i', $summary ) )

Status & tagging log