Index: branches/MetavidWiki-exp/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php |
— | — | @@ -644,31 +644,58 @@ |
645 | 645 | } |
646 | 646 | /*again here is some possibly metavid congress archive specific stuff:*/ |
647 | 647 | function auto_complete_all($val){ |
| 648 | + global $wgContLang; |
648 | 649 | //everything is db key based so swap space for underscore: |
649 | 650 | $val = str_replace(' ','_',$val); |
650 | 651 | |
| 652 | + $catNStxt = $wgContLang->getNsText(NS_CATEGORY); |
| 653 | + |
651 | 654 | //make sure people know they can "search" too (formated by |
652 | 655 | $out='do_search|'.wfMsg('mv_search_transcripts_for','<B>$1</B>').'|no_image'."\n"; |
| 656 | + //get keywords |
| 657 | + $category_out = MV_SpecialMediaSearch::auto_complete_search_categories($val, 3); |
| 658 | + if($category_out!=''){ |
| 659 | + $out.=$catNStxt.':Categories|<h6>'.wfMsg('mv_category_matches').'</h6>|no_image'."\n"; |
| 660 | + $out.=$category_out; |
| 661 | + } |
653 | 662 | //get people |
654 | 663 | $person_out = MV_SpecialMediaSearch::auto_complete_person($val, 3); |
655 | 664 | if($person_out!=''){ |
656 | | - $out.='Category:Person|<h6>'.wfMsg('mv_people_matches').'</h6>|no_image'."\n"; |
| 665 | + $out.=$catNStxt.':Person|<h6>'.wfMsg('mv_people_matches').'</h6>|no_image'."\n"; |
657 | 666 | $out.=$person_out; |
658 | 667 | } |
659 | 668 | //get bills |
660 | 669 | $bill_out = MV_SpecialMediaSearch::auto_complete_category('Bill', $val, 3); |
661 | 670 | if($bill_out!=''){ |
662 | | - $out.='Category:Bill|<h6>'.wfMsg('mv_bill_matches').'</h6>|no_image'."\n"; |
| 671 | + $out.=$catNStxt.':Bill|<h6>'.wfMsg('mv_bill_matches').'</h6>|no_image'."\n"; |
663 | 672 | $out.=$bill_out; |
664 | 673 | } |
665 | | - //get intrests |
| 674 | + //get interests |
666 | 675 | $intrest_out = MV_SpecialMediaSearch::auto_complete_category('Interest_Group', $val, 3); |
667 | 676 | if($intrest_out!=''){ |
668 | | - $out.='Category:Interest Group|<h6>'.wfMsg('mv_interest_group_matches').'</h6>|no_image'."\n"; |
| 677 | + $out.=$catNStxt.':Interest Group|<h6>'.wfMsg('mv_interest_group_matches').'</h6>|no_image'."\n"; |
669 | 678 | $out.=$intrest_out; |
670 | 679 | } |
671 | 680 | return $out; |
672 | 681 | } |
| 682 | + function auto_complete_search_categories($val, $result_limit='5'){ |
| 683 | + global $wgContLang; |
| 684 | + $dbr =& wfGetDB(DB_SLAVE); |
| 685 | + $result = $dbr->select( 'page', 'page_title', |
| 686 | + array('page_namespace'=>NS_CATEGORY, |
| 687 | + '`page_title` LIKE \'%'.mysql_escape_string($val).'%\' COLLATE latin1_general_ci'), |
| 688 | + __METHOD__, |
| 689 | + array('LIMIT'=>$result_limit)); |
| 690 | + print $dbr->lastQuery(); |
| 691 | + |
| 692 | + if($dbr->numRows($result) == 0)return ''; |
| 693 | + $out=''; |
| 694 | + $catNStxt = $wgContLang->getNsText(NS_CATEGORY); |
| 695 | + while($row = $dbr->fetchObject($result)){ |
| 696 | + $out.=MV_SpecialMediaSearch::format_ac_line($row->page_title, $val, $catNStxt.':'); |
| 697 | + } |
| 698 | + return $out; |
| 699 | + } |
673 | 700 | function auto_complete_category($category, $val, $result_limit='5'){ |
674 | 701 | $dbr =& wfGetDB(DB_SLAVE); |
675 | 702 | $result = $dbr->select( 'categorylinks', 'cl_sortkey', |
— | — | @@ -681,18 +708,7 @@ |
682 | 709 | if($dbr->numRows($result) == 0)return ''; |
683 | 710 | $out=''; |
684 | 711 | while($row = $dbr->fetchObject($result)){ |
685 | | - $page_title = $row->cl_sortkey; |
686 | | - //bold matching part of title: |
687 | | - $bs = stripos($page_title, $val); |
688 | | - if($bs!==false){ |
689 | | - $page_title_bold = substr($page_title, 0, $bs) . |
690 | | - '<b>'.substr($page_title, $bs, strlen($val)) . |
691 | | - '</b>' . substr($page_title, $bs+strlen($val)); |
692 | | - }else{ |
693 | | - $page_title_bold = $page_title; |
694 | | - } |
695 | | - //$page_title_bold = str_ireplace($val, '<b>'.$val.'</b>',$page_title); |
696 | | - $out.=$page_title.'|'.$page_title_bold.'|no_image'."\n"; |
| 712 | + $out.=MV_SpecialMediaSearch::format_ac_line($row->cl_sortkey, $val); |
697 | 713 | } |
698 | 714 | return $out; |
699 | 715 | } |
— | — | @@ -736,19 +752,9 @@ |
737 | 753 | $img= wfFindFile($imgTitle); |
738 | 754 | } |
739 | 755 | //$imgHTML="<img src=\"{$img->getURL()}\" width=\"44\">"; |
740 | | - //bold the part of the selected title |
741 | | - $sval = str_replace('_', ' ', $val); |
742 | | - //$person_name_bold = str_ireplace($val, '<b>'.$val.'</b>', $person_full_name); |
743 | | - $bs = stripos($person_full_name, $sval); |
744 | | - //print $person_full_name . ' serch for: ' . $val . "<br>"; |
745 | | - if($bs!==false){ |
746 | | - $person_name_bold = substr($person_full_name, 0, $bs) . |
747 | | - '<b>'.substr($person_full_name, $bs, strlen($val)) . |
748 | | - '</b>' . substr($person_full_name, $bs+strlen($val)); |
749 | | - }else{ |
750 | | - $person_name_bold = $person_full_name; |
751 | | - } |
752 | | - $out.= $person_name.'|'.$person_name_bold .'|'.$img->getURL() . "\n"; |
| 756 | + //bold the part of the selected title |
| 757 | + $out.=MV_SpecialMediaSearch::format_ac_line($person_full_name, $val, '', $img->getURL()); |
| 758 | + //$out.= $person_name.'|'.$person_name_bold .'|'.$img->getURL() . "\n"; |
753 | 759 | //$out.="<li name=\"{$person_name}\"> $imgHTML $person_full_name</il>\n"; |
754 | 760 | } |
755 | 761 | } |
— | — | @@ -756,6 +762,19 @@ |
757 | 763 | //return people people in the Person Category |
758 | 764 | return $out; |
759 | 765 | } |
| 766 | + function format_ac_line(&$page_title, &$val, $prefix='', $img_link='no_image'){ |
| 767 | + //bold matching part of title: |
| 768 | + $bs = stripos($page_title, str_replace('_',' ',$val) ); |
| 769 | + if($bs!==false){ |
| 770 | + $page_title_bold = substr($page_title, 0, $bs) . |
| 771 | + '<b>'.substr($page_title, $bs, strlen($val)) . |
| 772 | + '</b>' . substr($page_title, $bs+strlen($val)); |
| 773 | + }else{ |
| 774 | + $page_title_bold = $page_title; |
| 775 | + } |
| 776 | + //$page_title_bold = str_ireplace($val, '<b>'.$val.'</b>',$page_title); |
| 777 | + return $prefix.$page_title.'|'.$page_title_bold.'|'.$img_link."\n"; |
| 778 | + } |
760 | 779 | //return a json date obj |
761 | 780 | //@@todo fix for big sites...(will start to be no fun if number of streams > 2000 ) |
762 | 781 | function getJsonDateObj($obj_name='mv_result'){ |