}
$offset = $endMatches[0][1] + strlen( $endMatches[0][0] );
}
- if ( ! $found ) {
+ if ( !$found ) {
// couldn't find appropriate closing tag, skip
$this->splitAndAdd( $textExt, $count, substr( $text, $start, strlen( $matches[0][0] ) ) );
$start += strlen( $matches[0][0] );
$succ = true;
// check if first text contains all terms
foreach ( $terms as $term ) {
- if ( ! preg_match( "/$patPre" . $term . "$patPost/ui", $firstText ) ) {
+ if ( !preg_match( "/$patPre" . $term . "$patPost/ui", $firstText ) ) {
$succ = false;
break;
}
$offsets[$first] = 0;
}
}
- if ( ! $snippets ) {
+ if ( !$snippets ) {
// match whole query on text
$this->process( $pat1, $textExt, $left, $contextchars, $snippets, $offsets );
// match whole query on templates/tables/images
$processed = array();
foreach ( $terms as $term ) {
- if ( ! isset( $processed[$term] ) ) {
+ if ( !isset( $processed[$term] ) ) {
$pat3 = "/$patPre(" . $term . ")$patPost/ui"; // highlight word
$extract = preg_replace( $pat3,
"\\1<span class='searchmatch'>\\2</span>\\3", $extract );
/**
* Split text into lines and add it to extracts array
*
- * @param array $extracts index -> $line
+ * @param array $extracts Index -> $line
* @param int $count
* @param string $text
*/
/**
* Basic wikitext removal
* @protected
+ * @param string $text
* @return mixed
*/
function removeWiki( $text ) {
}
++$lineno;
$m = array();
- if ( ! preg_match( $pat1, $line, $m ) ) {
+ if ( !preg_match( $pat1, $line, $m ) ) {
continue;
}
--$contextlines;
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
+ * @return string
+ */
+ 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 = htmlspecialchars( substr( trim( $match[0] ), 0, $contextlines * $contextchars ) ); // trim and limit to max number of chars
+ return str_replace( "\n", '<br>', $text );
+ }
}