Index: trunk/extensions/CodeReview/CodeReleaseNotes.php |
— | — | @@ -83,24 +83,8 @@ |
84 | 84 | $summary = htmlspecialchars($row->cr_message); |
85 | 85 | # Add this commit summary if needed |
86 | 86 | 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 |
92 | 87 | # 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 ); |
105 | 89 | # Anything left? (this can happen with some heuristics) |
106 | 90 | if( $summary ) { |
107 | 91 | $summary = str_replace( "\n", "<br/>", $summary ); // Newlines -> <br/> |
— | — | @@ -115,10 +99,42 @@ |
116 | 100 | $wgOut->addHTML( '</ul>' ); |
117 | 101 | } |
118 | 102 | |
| 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 | + |
119 | 135 | // Quick relevance tests (these *should* be over-inclusive a little if anything) |
120 | 136 | 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 ) ) |
123 | 139 | return true; |
124 | 140 | # Sanity check: summary cannot be *too* short to be useful |
125 | 141 | $words = str_word_count($summary); |
— | — | @@ -126,8 +142,7 @@ |
127 | 143 | return false; |
128 | 144 | # All caps words (like "BREAKING CHANGE"/magic words)? |
129 | 145 | # 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 ) ) |
132 | 147 | return true; |
133 | 148 | # Random keywords |
134 | 149 | if( preg_match( '/\b(wiki|HTML\d|CSS\d|UTF-?8|(Apache|PHP|CGI|Java|Perl|Python|\w+SQL) ?\d?\.?\d?)\b/i', $summary ) ) |