function add_embed_search()
 {
     global $wgOut;
     //grab a de-encapsulated search
     $mvSearch = new MV_SpecialMediaSearch();
     $mvSearch->setUpFilters();
     //do the search
     $mvSearch->doSearch();
     $wgOut->addHTML($mvSearch->dynamicSearchControl());
     $wgOut->addHTML($mvSearch->getResultsHTML());
 }
	function get_search_feed() {
		global $wgSitename, $wgOut;
		// set up search obj:
		$sms = new MV_SpecialMediaSearch();
		// setup filters:
		$sms->setUpFilters();
		// do the search:
		$sms->doSearch();
		// get the search page title:
		$msTitle = Title::MakeTitle( NS_SPECIAL, 'MediaSearch' );

		$this->feed = new mvRSSFeed(
		$wgSitename . ' - ' . wfMsg( 'mediasearch' ) . ' : ' . strip_tags( $sms->getFilterDesc() ), // title
		strip_tags( $sms->getFilterDesc() ), // description
		$msTitle->getFullUrl() . '?' . $sms->get_httpd_filters_query() // link
		);

		$this->feed->outHeader( $this->output_xml_header );
		$MV_Overlay = new MV_Overlay();
		// for each search result:
		foreach ( $sms->results as $inx => & $mvd ) {
			// get Stream title for mvd match:
			$mvTitle = new MV_Title( $mvd->wiki_title );
			$stremTitle = Title::MakeTitle( MV_NS_STREAM, $mvTitle->getStreamName() . '/' . $mvTitle->getTimeRequest() );
			$this->feed->outPutItem( $mvTitle, $MV_Overlay->getMVDhtml( $mvd, $absolute_links = true ) );
		}
		$this->feed->outFooter();
	}
 function getTopSearches()
 {
     $dbr = wfGetDB(DB_READ);
     $o = '';
     $options = array();
     /*$result = $dbr->select('mv_search_digest', '`query_key`, COUNT(1) as `hit_count`', "`time` >= '$start_time' ",
     	 __METHOD__,
     	 array('GROUP BY' => 'query_key', 'ORDER BY `hit_count` ASC',
     	 'LIMIT 0,'.$this->params['num_results']) );*/
     /*$sql="SELECT `mv_search_digest`.`query_key`, COUNT(1) as `hit_count`, `mv_query_key_lookup`.`filters`
     	 FROM `mv_search_digest`
     	 LEFT JOIN `mv_query_key_lookup` ON (`mv_search_digest`.`query_key` = `mv_query_key_lookup`.`query_key`)
     	 WHERE `time` >= '{$this->getStartTime()}' GROUP BY `mv_search_digest`.`query_key`
     	 LIMIT 0, {$this->params[num_results]}";*/
     // $from_tables
     $vars = array($dbr->tableName('mv_search_digest') . '.query_key', 'COUNT(1) as `hit_count`', $dbr->tableName('mv_query_key_lookup') . '.filters');
     $from_tables = $dbr->tableName('mv_search_digest') . ' JOIN' . $dbr->tableName('mv_query_key_lookup') . ' ON ( ' . $dbr->tableName('mv_search_digest') . '.query_key = ' . $dbr->tableName('mv_query_key_lookup') . '.query_key ' . ' ) ';
     $conds = '`time` >= ' . $dbr->addQuotes($this->getStartTime());
     $options['GROUP BY'] = $dbr->tableName('mv_search_digest') . '.query_key';
     $options['ORDER BY'] = '`hit_count`  DESC';
     $options['LIMIT'] = $this->params['num_results'];
     $result = $dbr->select($from_tables, $vars, $conds, __METHOD__, $options);
     if ($dbr->numRows($result) == 0) {
         return '';
     } else {
         // @@todo probably should try to abstract out formating..
         // but will need to wait until we have a few more test cases to do a productive abstraction
         if ($this->params['format'] == 'ul_list') {
             $class_attr = $this->params['class'] != '' ? ' class="' . htmlspecialchars($this->params['class']) . '"' : '';
             $o .= '<ul' . $class_attr . '>';
         }
         $mvms = new MV_SpecialMediaSearch();
         $sTitle = Title::MakeTitle(NS_SPECIAL, 'MediaSearch');
         while ($row = $dbr->fetchObject($result)) {
             $title_desc = htmlspecialchars($row->hit_count) . ' ' . wfMsg('mv_date_' . $this->params['time_range']);
             $mvms->loadFiltersFromSerialized($row->filters);
             $o .= '<li><a title="' . $title_desc . '" href="' . $sTitle->escapeLocalURL($mvms->get_httpd_filters_query() . '&tl=1') . '">' . $mvms->getFilterDesc($query_key = true) . '</li>';
         }
         if ($this->params['format'] == 'ul_list') {
             $o .= '</ul>';
         }
     }
     return $o;
 }
 function get_tool_html($tool_id, $ns = '', $title_str = '')
 {
     global $wgUser;
     if ($title_str == '') {
         $title_str = $this->mv_interface->article->mvTitle->getStreamName();
     }
     if ($ns == '') {
         $ns = MV_NS_STREAM;
     }
     switch ($tool_id) {
         case 'stream_page':
             global $wgOut, $wgParser;
             // render the wiki page for this stream
             $title = Title::newFromText($title_str, $ns);
             $curRevision = Revision::newFromTitle($title);
             // @@todo in the future a deleted Stream means
             // remove stuff from stream table,mvd etc and return "missing Stream"
             if ($curRevision == null) {
                 $wgOut->addWikiText(wfMsg('noarticletext'));
                 $this->innerHTML = $wgOut->getHTML();
             } else {
                 $sk =& $wgUser->getSkin();
                 // empty out the categories
                 $wgOut->mCategoryLinks = array();
                 // run via parser to add in Category info:
                 $parserOptions = ParserOptions::newFromUser($wgUser);
                 $parserOptions->setEditSection(false);
                 $parserOptions->setTidy(true);
                 $parserOutput = $wgParser->parse($curRevision->getText(), $title, $parserOptions);
                 $wgOut->addCategoryLinks($parserOutput->getCategories());
                 $wgOut->addHTML($parserOutput->mText);
                 $wgOut->addHTML($sk->getCategories());
                 // empty out the categories
                 $wgOut->mCategoryLinks = array();
                 // $wgOut->addWikiTextWithTitle( $curRevision->getText(), $tile) ;
                 $this->innerHTML = $wgOut->getHTML();
             }
             break;
         case 'mang_layers':
             $this->innerHTML = $this->get_mang_layers_page($title_str);
             break;
         case 'search':
             $title = Title::newFromText($title_str, MV_NS_STREAM);
             // render search box
             $this->innerHTML = '<h3>Search Stream: ' . htmlspecialchars($title_str) . '</h3>';
             $MvSearch = new MV_SpecialMediaSearch();
             $MvSearch->setupFilters('stream', array('stream_name' => $title->getDBkey()));
             $this->innerHTML .= $MvSearch->dynamicSearchControl();
             break;
         case 'navigate':
             // render full stream navigation
             $this->innerHTML = $this->get_nav_page($title_str);
             break;
         case 'export':
             $this->innerHTML = $this->get_export_page($title_str);
             break;
         case 'embed':
             // display embed code:
             $this->innerHTML = 'embed page';
             break;
         case 'overlay':
             // display overlay options
             $this->innerHTML = 'overlay page';
             break;
         case 'menu':
             $this->innerHTML = $this->getToolsListing();
             break;
         default:
             $this->status = 'error';
             $this->innerHTML = wfMsg('mv_tool_missing', $tool_id);
             break;
     }
     return $this->return_obj();
 }
function mv_date_obj()
{
    // returns the date object for existing stream set
    // @@todo this is very cacheable since it only changes when a streams change date or a new stream is added.
    return MV_SpecialMediaSearch::getJsonDateObj();
}
 function auto_complete_person($val, $result_limit = '5', $format = 'ac_line', &$match_count = '', &$person_ary = array())
 {
     $dbr =& wfGetDB(DB_SLAVE);
     //first check the nick names:
     $nick_rows = MV_SpecialMediaSearch::getViaNickname($val, $result_limit);
     foreach ($nick_rows as $person) {
         $person_ary[$person] = true;
     }
     $result = $dbr->select('categorylinks', 'cl_sortkey', array('cl_to' => 'Person', '`cl_sortkey` LIKE \'%' . mysql_escape_string($val) . '%\' COLLATE latin1_swedish_ci'), __METHOD__, array('LIMIT' => $result_limit));
     $out = '';
     while ($row = $dbr->fetchObject($result)) {
         $person_name = $row->cl_sortkey;
         $person_ary[$person_name] = true;
     }
     if (count($person_ary) == 0) {
         return '';
     }
     foreach ($person_ary as $person_name => $na) {
         // make sure the person page exists:
         $personTitle = Title::makeTitle(NS_MAIN, $person_name);
         if ($personTitle->exists()) {
             // dont try and get person full name from semantic table if available
             $person_full_name = $person_name;
             // format and output the line:
             $out .= MV_SpecialMediaSearch::format_ac_line($person_full_name, $val, '', MV_SpecialMediaSearch::getPersonImageURL($person_name), $format);
         }
     }
     // $out.='</ul>';
     // return people people in the Person Category
     return $out;
 }
 function auto_complete_all($val)
 {
     //everything is db key based so swap space for underscore:
     $val = str_replace(' ', '_', $val);
     //make sure people know they can "search" too (formated by
     $out = 'do_search|' . wfMsg('mv_search_transcripts_for') . ' <B>$1</B>|no_image' . "\n";
     //get people
     $person_out = MV_SpecialMediaSearch::auto_complete_person($val, 3);
     if ($person_out != '') {
         $out .= 'Category:Person|<h2>People:</h2> |no_image' . "\n";
         $out .= $person_out;
     }
     //get bills
     $bill_out = MV_SpecialMediaSearch::auto_complete_category('Bill', $val, 3);
     if ($bill_out != '') {
         $out .= 'Category:Bill|<h2>Bills:</h2>|no_image' . "\n";
         $out .= $bill_out;
     }
     //get intrests
     $intrest_out = MV_SpecialMediaSearch::auto_complete_category('Interest_Group', $val, 3);
     if ($intrest_out != '') {
         $out .= 'Category:Interest Group|<h2>Interest Group:</h2>|no_image' . "\n";
         $out .= $intrest_out;
     }
     return $out;
 }