public function highlightText( $text, $terms, $contextlines, $contextchars ) {
global $wgContLang, $wgSearchHighlightBoundaries;
- $fname = __METHOD__;
-
if ( $text == '' ) {
return '';
}
$spat .= '/';
$textExt = array(); // text extracts
$otherExt = array(); // other extracts
- wfProfileIn( "$fname-split" );
$start = 0;
$textLen = strlen( $text );
$count = 0; // sequence number to maintain ordering
$all = $textExt + $otherExt; // these have disjunct key sets
- wfProfileOut( "$fname-split" );
-
// prepare regexps
foreach ( $terms as $index => $term ) {
// manually do upper/lowercase stuff for utf-8 since PHP won't do it
$pat1 = "/(" . $phrase . ")/ui";
$pat2 = "/$patPre(" . $anyterm . ")$patPost/ui";
- wfProfileIn( "$fname-extract" );
-
$left = $contextlines;
$snippets = array();
}
}
- wfProfileOut( "$fname-extract" );
-
return $extract;
}
* @return mixed
*/
function removeWiki( $text ) {
- $fname = __METHOD__;
- wfProfileIn( $fname );
-
- // $text = preg_replace( "/'{2,5}/", "", $text );
- // $text = preg_replace( "/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text );
- // $text = preg_replace( "/\[\[([^]|]+)\]\]/", "\\1", $text );
- // $text = preg_replace( "/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text );
- // $text = preg_replace( "/\\{\\|(.*?)\\|\\}/", "", $text );
- // $text = preg_replace( "/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text );
$text = preg_replace( "/\\{\\{([^|]+?)\\}\\}/", "", $text );
$text = preg_replace( "/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text );
$text = preg_replace( "/\\[\\[([^|]+?)\\]\\]/", "\\1", $text );
array( $this, 'linkReplace' ),
$text
);
- // $text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text);
$text = preg_replace( "/<\/?[^>]+>/", "", $text );
$text = preg_replace( "/'''''/", "", $text );
$text = preg_replace( "/('''|<\/?[iIuUbB]>)/", "", $text );
$text = preg_replace( "/''/", "", $text );
- wfProfileOut( $fname );
return $text;
}
*/
public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
global $wgContLang;
- $fname = __METHOD__;
$lines = explode( "\n", $text );
$lineno = 0;
$extract = "";
- wfProfileIn( "$fname-extract" );
foreach ( $lines as $line ) {
if ( 0 == $contextlines ) {
break;
$extract .= "${line}\n";
}
- wfProfileOut( "$fname-extract" );
return $extract;
}
* Returns the first few lines of the text
*
* @param string $text
- * @param int $contextlines max number of returned lines
- * @param int $contextchars average number of characters per line
+ * @param int $contextlines Max number of returned lines
+ * @param int $contextchars Average number of characters per line
* @return string
*/
- public function highlightNone( $text, $contextlines, $contextchars) {
+ public function highlightNone( $text, $contextlines, $contextchars ) {
$match = array();
$text = ltrim( $text ) . "\n"; // make sure the preg_match may find the last line
- $text = str_replace( "\n\n", "\n", $text); // remove empty lines
- preg_match( "/^(.*\n){0,$contextlines}/", $text , $match);
+ $text = str_replace( "\n\n", "\n", $text ); // remove empty lines
+ preg_match( "/^(.*\n){0,$contextlines}/", $text, $match );
$text = htmlspecialchars( substr( trim( $match[0] ), 0, $contextlines * $contextchars ) ); // trim and limit to max number of chars
return str_replace( "\n", '<br>', $text );
}