r12500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12499‎ | r12500 | r12501 >
Date:04:59, 8 January 2006
Author:vibber
Status:old
Tags:
Comment:
Fixups to the abstract extraction: images, tables, unicode
Modified paths:
  • /trunk/extensions/ActiveAbstract/AbstractFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ActiveAbstract/AbstractFilter.php
@@ -107,6 +107,11 @@
108108 * @access private
109109 */
110110 function _stripMarkup( $text ) {
 111+ global $wgContLang;
 112+
 113+ $text = substr( $text, 0, 4096 ); // don't bother with long text...
 114+
 115+ $image = preg_quote( $wgContLang->getNsText( NS_IMAGE ), '#' );
111116 $text = str_replace( "'''", "", $text );
112117 $text = str_replace( "''", "", $text );
113118 $text = preg_replace( '#<!--.*?-->#s', '', $text ); // HTML-style comments
@@ -114,7 +119,20 @@
115120 $text = preg_replace( '#\\[[a-z]+:.*? (.*?)\\]#s', '$1', $text ); // URL links
116121 $text = preg_replace( '#\\{\\{\\{.*?\\}\\}\\}#s', '', $text ); // template parameters
117122 $text = preg_replace( '#\\{\\{.*?\\}\\}#s', '', $text ); // template calls
 123+ $text = preg_replace( '#\\{\\|.*?\\|\\}#s', '', $text ); // tables
 124+ $text = preg_replace( "#
 125+ \\[\\[
 126+ :?$image\\s*:
 127+ (
 128+ [^][]*
 129+ \[\[
 130+ [^][]*
 131+ \]\]
 132+ )*
 133+ [^][]*
 134+ \\]\\]#six", '', $text ); // images
118135 $text = preg_replace( '#\\[\\[([^|\\]]*\\|)?(.*?)\\]\\]#s', '$2', $text ); // links
 136+ $text = preg_replace( '#^:.*$#m', '', $text ); // indented lines near start are usually disambigs or notices
119137 $text = Sanitizer::decodeCharReferences( $text );
120138 return trim( $text );
121139 }
@@ -136,12 +154,14 @@
137155 $endgroup = implode( '', array_map( 'preg_quote', $endchars ) );
138156 $end = "[$endgroup]";
139157 $sentence = ".*?$end+";
140 - $firsttwo = "/^($sentence$sentence)/";
 158+ $firsttwo = "/^($sentence$sentence)/u";
141159
142160 if( preg_match( $firsttwo, $text, $matches ) ) {
143161 return $matches[1];
144162 } else {
145 - return $text;
 163+ // Just return the first line
 164+ $lines = explode( "\n", $text );
 165+ return trim( $lines[0] );
146166 }
147167 }
148168

Status & tagging log