r36756 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36755‎ | r36756 | r36757 >
Date:17:55, 27 June 2008
Author:dale
Status:old
Tags:
Comment:
updates for category autocomplete
Modified paths:
  • /branches/MetavidWiki-exp/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php (modified) (history)

Diff [purge]

Index: branches/MetavidWiki-exp/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php
@@ -644,31 +644,58 @@
645645 }
646646 /*again here is some possibly metavid congress archive specific stuff:*/
647647 function auto_complete_all($val){
 648+ global $wgContLang;
648649 //everything is db key based so swap space for underscore:
649650 $val = str_replace(' ','_',$val);
650651
 652+ $catNStxt = $wgContLang->getNsText(NS_CATEGORY);
 653+
651654 //make sure people know they can "search" too (formated by
652655 $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+ }
653662 //get people
654663 $person_out = MV_SpecialMediaSearch::auto_complete_person($val, 3);
655664 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";
657666 $out.=$person_out;
658667 }
659668 //get bills
660669 $bill_out = MV_SpecialMediaSearch::auto_complete_category('Bill', $val, 3);
661670 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";
663672 $out.=$bill_out;
664673 }
665 - //get intrests
 674+ //get interests
666675 $intrest_out = MV_SpecialMediaSearch::auto_complete_category('Interest_Group', $val, 3);
667676 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";
669678 $out.=$intrest_out;
670679 }
671680 return $out;
672681 }
 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+ }
673700 function auto_complete_category($category, $val, $result_limit='5'){
674701 $dbr =& wfGetDB(DB_SLAVE);
675702 $result = $dbr->select( 'categorylinks', 'cl_sortkey',
@@ -681,18 +708,7 @@
682709 if($dbr->numRows($result) == 0)return '';
683710 $out='';
684711 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);
697713 }
698714 return $out;
699715 }
@@ -736,19 +752,9 @@
737753 $img= wfFindFile($imgTitle);
738754 }
739755 //$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";
753759 //$out.="<li name=\"{$person_name}\"> $imgHTML $person_full_name</il>\n";
754760 }
755761 }
@@ -756,6 +762,19 @@
757763 //return people people in the Person Category
758764 return $out;
759765 }
 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+ }
760779 //return a json date obj
761780 //@@todo fix for big sites...(will start to be no fun if number of streams > 2000 )
762781 function getJsonDateObj($obj_name='mv_result'){

Status & tagging log