Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / includes / search / SearchHighlighter.php
index 57cdaf4..c3c3a8f 100644 (file)
@@ -447,6 +447,7 @@ class SearchHighlighter {
        /**
         * Basic wikitext removal
         * @protected
+        * @param string $text
         * @return mixed
         */
        function removeWiki( $text ) {
@@ -482,6 +483,7 @@ class SearchHighlighter {
         * the target is category or image, leave it
         *
         * @param array $matches
+        * @return string
         */
        function linkReplace( $matches ) {
                $colon = strpos( $matches[1], ':' );
@@ -553,4 +555,21 @@ class SearchHighlighter {
 
                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 );
+       }
 }