Extension:SearchFeed

Installation

 * 1) Place SearchFeed.i18n.php ,SearchFeed.php and SearchFeed_body.php extension files in the extensions/SearchFeed directory.
 * 2) Save the file in the extensions directory of mediawiki folder.
 * 3) Add to LocalSettings.php the line require_once ("extensions/SearchFeed/SearchFeed.php")

The extension need the following three file.

SearchFeed.i18n.php
 array( 'searchfeed' => 'SearchFeed', ) ); ?>

SearchFeed.php


SearchFeed_body.php
getVal( 'feed', 'rss' );

if( !isset( $wgFeedClasses[$feedFormat] ) ) { wfHttpError( 500, "Internal Server Error", "Unsupported feed type." ); return false; }

$feedTitle = $wgSitename. ' - ' . ' [' . $wgContLanguageCode. ']';				$feed = new $wgFeedClasses[$feedFormat](					$feedTitle,					htmlspecialchars( '' ),					$wgTitle->getFullUrl );

$term = $wgRequest->getText('term',''); $limit = $wgRequest->getText('limit','50');

$feed->outHeader;

$offset = 0; $namespaces = array_keys(SearchEngine::searchableNamespaces); $popts = new ParserOptions; $popts->setEditSection(false); $popts->setAllowSpecialInclusion(false); //				$popts->setInterwikiMagic(true); $popts->setAllowExternalImages(true); $popts->setTidy(true);

$search = SearchEngine::create; $search->setLimitOffset( $limit, $offset ); $search->setNamespaces( $namespaces ); $search->showRedirects = true; //$this->searchRedirects

$textMatches = $search->searchText( $term );

while($result = $textMatches->next) { $title = $result->getTitle;

$revision = Revision::newFromTitle( $title ); $wikitext = $revision->getRawText;

$lines = explode( "\n", $wikitext );

$contextlines = $wgUser->getOption( 'contextlines', 5 ); $contextchars = $wgUser->getOption( 'contextchars', 120 );

$max = intval( $contextchars ) + 1; $pat1 = "/(.*)($term)(.{0,$max})/i";

$lineno = 0;

$extract = ''; foreach ( $lines as $line ) { if ( 0 == $contextlines ) { break; }						++$lineno; $m = array; if ( ! preg_match( $pat1, $line, $m ) ) { continue; }						--$contextlines; $pre = $wgContLang->truncate( $m[1], -$contextchars, '...' );

if ( count( $m ) < 3 ) { $post = ''; } else { $post = $wgContLang->truncate( $m[3], $contextchars, '...' ); }

$found = $m[2];

$line = htmlspecialchars( $pre . $found . $post ); //						$pat2 = '/(' . $terms . ")/i"; //						$line = preg_replace( $pat2, "\\1", $line );

if(!empty($line)) $extract .= "\n{$line}\n"; }

//					$lc = SearchEngine::legalSearchChars. '&#;'; //					$extract = preg_replace( "/[^{$lc}]+/", " ", $extract ); //					$extract = preg_replace( "/''[']*/", " ", $extract );

$parserOutput = $wgParser->parse( $extract, $title, $popts,						1, true, $revision->getId); $text = $parserOutput->getText;

$text = strip_tags($text, " "); //					$text = preg_replace( "/\/i" ,' ', $text); //					$text = preg_replace( "/\(.*?)\<\/a\>/i" ,"\\1", $text);

$talkpage = $title->getTalkPage; $item = new FeedItem(						$title->getPrefixedText,						$text,						$title->getFullURL,						$revision->getTimestamp,						$revision->getRawUserText,						$talkpage->getFullURL						); $feed->outItem( $item ); }

$feed->outFooter;

exit; }

function loadMessages { static $messagesLoaded = false; global $wgMessageCache; if ( $messagesLoaded ) return; $messagesLoaded = true;

require( dirname( __FILE__ ) . '/SearchFeed.i18n.php' ); #echo $allMessages; prints>> Array foreach ( $allMessages as $lang => $langMessages ) {

$wgMessageCache->addMessages( $langMessages,$lang);

}               return; } } ?>