r41951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41950‎ | r41951 | r41952 >
Date:22:10, 10 October 2008
Author:dale
Status:old
Tags:
Comment:
lose matching, nickname lookup for autocomplete
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialExport.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php
@@ -670,10 +670,12 @@
671671 //try the $sulightData array
672672 if(isset($sulightData[ $dbKey ])){
673673 $page_body.= $name . '=' . $sulightData[ $dbKey ]."| \n";
674 - }else{
675 - if ( trim( $person->$dbKey ) != '' ) {
676 - if ( $dbKey == 'state' ) $person->state = $states_ary[$person->state];
677 - $page_body .= "{$name}={$person->$dbKey}| \n";
 674+ }else{
 675+ if( isset($person->$dbKey) ){
 676+ if ( trim( $person->$dbKey ) != '' ) {
 677+ if ( $dbKey == 'state' ) $person->state = $states_ary[$person->state];
 678+ $page_body .= "{$name}={$person->$dbKey}| \n";
 679+ }
678680 }
679681 }
680682 }
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialExport.php
@@ -356,7 +356,7 @@
357357 <' . $ns . 'clip id="mvd_' . htmlentities( $mvd->id ) . '" start="npt:' . htmlentities( seconds2ntp( $mvd->start_time ) ) . '" end="npt:' . htmlentities( seconds2ntp( $mvd->end_time ) ) . '">
358358 <' . $ns . 'img src="' . htmlentities( $streamTitle->getFullStreamImageURL( null, seconds2ntp( $mvd->start_time ) ) ) . '"/>';
359359 // output all metadata @@todo we should generalize the semantic properties.
360 - $tracks[$mvd->mvd_type] .= ( isset( $mvd->Speech_by ) && trim( $mvd->Speech_by ) != '' ) ? '<meta name="Speech_by" content="' . htmlentities ( htmlspecialchars( $mvd->Speech_by ) ) . '"/>':'';
 360+ $tracks[$mvd->mvd_type] .= ( isset( $mvd->Speech_by ) && trim( $mvd->Speech_by ) != '' ) ? '<meta name="Speech_by" content="' . htmlentities ( $mvd->Speech_by ) . '"/>':'';
361361 $tracks[$mvd->mvd_type] .= ( isset( $mvd->Bill ) && trim( $mvd->Bill ) != '' ) ? '<meta name="Bill" content="' . htmlentities( $mvd->Bill ) . '"/>':'';
362362
363363 // add in categories as "keywords"
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php
@@ -1107,6 +1107,10 @@
11081108 }
11091109 function auto_complete_category( $category, $val, $result_limit = '5', $format = 'ac_line', & $match_count = '' ) {
11101110 $dbr = & wfGetDB( DB_SLAVE );
 1111+ //do value pre-proccessing if bill type:
 1112+ if($category=='Bill')
 1113+ $val = MV_SpecialMediaSearch::bill_formater( $val );
 1114+
11111115 $result = $dbr->select( 'categorylinks', 'cl_sortkey', array (
11121116 'cl_to' => $category,
11131117 '`cl_sortkey` LIKE \'%' . mysql_escape_string( $val
@@ -1123,37 +1127,39 @@
11241128 $out .= MV_SpecialMediaSearch :: format_ac_line( $row->cl_sortkey, $val, '', 'no_image', $format );
11251129 }
11261130 return $out;
1127 - }
 1131+ }
11281132 /*@@todo cache result for given values*/
11291133 function auto_complete_person( $val, $result_limit = '5', $format = 'ac_line', & $match_count = '', & $person_ary = array() ) {
11301134 $dbr = & wfGetDB( DB_SLAVE );
 1135+
 1136+ //first check the nick names:
 1137+ $nick_rows = MV_SpecialMediaSearch::getViaNickname($val, $result_limit);
 1138+ foreach($nick_rows as $person){
 1139+ $person_ary[$person]=true;
 1140+ }
 1141+
11311142 $result = $dbr->select( 'categorylinks', 'cl_sortkey', array (
11321143 'cl_to' => 'Person',
11331144 '`cl_sortkey` LIKE \'%' . mysql_escape_string( $val
11341145 ) . '%\' COLLATE latin1_general_ci' ), __METHOD__, array (
11351146 'LIMIT' => $result_limit
1136 - ) );
1137 - $match_count = $dbr->numRows( $result );
1138 - if ( $dbr->numRows( $result ) == 0 )
1139 - return '';
1140 - // $out='<ul>'."\n";
 1147+ ) );
11411148 $out = '';
11421149 while ( $row = $dbr->fetchObject( $result ) ) {
11431150 $person_name = $row->cl_sortkey;
11441151 $person_ary[$person_name] = true;
 1152+ }
 1153+
 1154+ if(count($person_ary)==0)
 1155+ return '';
 1156+
 1157+
 1158+ foreach($person_ary as $person_name=>$na){
11451159 // make sure the person page exists:
11461160 $personTitle = Title :: makeTitle( NS_MAIN, $person_name );
11471161 if ( $personTitle->exists() ) {
1148 - // get person full name from semantic table if available
1149 - $person_result = $dbr->select( 'smw_attributes', 'value_xsd', array (
1150 - 'attribute_title' => 'Full_Name',
1151 - 'subject_title' => $personTitle->getDBkey() ), __METHOD__ );
1152 - if ( $dbr->numRows( $person_result ) == 0 ) {
1153 - $person_full_name = $person_name;
1154 - } else {
1155 - $pvalue = $dbr->fetchObject( $person_result );
1156 - $person_full_name = $pvalue->value_xsd;
1157 - }
 1162+ // dont try and get person full name from semantic table if available
 1163+ $person_full_name = $person_name;
11581164 // format and output the line:
11591165 $out .= MV_SpecialMediaSearch :: format_ac_line( $person_full_name, $val, '', MV_SpecialMediaSearch :: getPersonImageURL( $person_name ), $format );
11601166 }
@@ -1162,6 +1168,24 @@
11631169 // return people people in the Person Category
11641170 return $out;
11651171 }
 1172+ //returns results via nickname via semantic query:
 1173+ function getViaNickname($partname, $limit=5){
 1174+ $query_string = '[[Nickname::~*'.ucfirst($partname).'*]] OR [[Nickname::'.ucfirst($partname).']]';
 1175+ $params=array('format' => 'broadtable',
 1176+ 'offset' => 0,
 1177+ 'limit' =>$limit);
 1178+ $results = array();
 1179+ $queryobj = SMWQueryProcessor::createQuery($query_string, $params, false, '', array());
 1180+ $queryobj->querymode = SMWQuery::MODE_INSTANCES;
 1181+ $res = smwfGetStore()->getQueryResult($queryobj);
 1182+
 1183+ for($i=0;$i< $res->getCount();$i++){
 1184+ $v = $res->getNext();
 1185+ $v = current(current($v)->getContent());
 1186+ array_push( $results,$v->getXSDValue());
 1187+ }
 1188+ return $results;
 1189+ }
11661190 function getPersonImageURL( $person_name ) {
11671191 // make the missing person image ref:
11681192 $imgTitle = Title :: makeTitle( NS_IMAGE, $person_name . '.jpg' );
@@ -1175,6 +1199,12 @@
11761200 }
11771201 return $img->getURL();
11781202 }
 1203+ function bill_formater($val){
 1204+ $val = preg_replace('/[Ss]\.?\s?([0-9])/','S._$1',$val);
 1205+ $val = preg_replace('/[Hh]\.?[Rr]\.?\s?([0-9])/','H.R._$1',$val);
 1206+ $val = preg_replace('/[Hh][Rr][Ee][Ss]\.?\s?([0-9])/','HRes._$1',$val);
 1207+ return $val;
 1208+ }
11791209 function format_ac_line( & $page_title, $val, $prefix = '', $img_link = 'no_image', $format = 'ac_line' ) {
11801210 // no underscores in display title:
11811211 $page_title_disp = str_replace( '_', ' ', $page_title );

Status & tagging log