r39407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39406‎ | r39407 | r39408 >
Date:12:17, 15 August 2008
Author:siebrand
Status:old
Tags:
Comment:
* relevent -> relevant
* update crappy formatting of files I touched for previous issue (end of line whitespace, replace ^SPACETAB with ^TAB, remove "?>" at end of file)
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_Index.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_MetavidInterface.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php (modified) (history)
  • /trunk/extensions/MetavidWiki/languages/MV_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/includes/MV_Index.php
@@ -4,396 +4,396 @@
55 *
66 * All Metavid Wiki code is Released under the GPL2
77 * for more info visit http:/metavid.ucsc.edu/code
8 - *
 8+ *
99 * @author Michael Dale
1010 * @email dale@ucsc.edu
1111 * @url http://metavid.ucsc.edu
12 - *
 12+ *
1313 */
1414 /*
15 - * maintains the index table state on various updates
16 - * (need for indexed time ranged queries)
17 - * (currently stored in a mysql table)
18 - * in the future we should shift this to a search engine of some sort
 15+ * maintains the index table state on various updates
 16+ * (need for indexed time ranged queries)
 17+ * (currently stored in a mysql table)
 18+ * in the future we should shift this to a search engine of some sort
1919 * (ie lucene or sphinx) or just do everything with semantic relations
2020 * if we can get the speed to an acceptable level...
21 - *
 21+ *
2222 * keep an additional copy of the text table is not ideal but...
2323 * we keep a copy of every version of the page so its not so bad ;P
2424 */
2525 if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
2626
2727 class MV_Index {
28 - var $mvTitle =null;
29 - function __construct(& $mvTitle=null){
30 - if($mvTitle!=null)
31 - $this->mvTitle=$mvTitle;
32 - }
33 - /*
34 - * grabs near options count
35 - * (similar to getNearStreams but returns a count instead of a result set)
36 - *
37 - * @params:
38 - * $range_offset
39 - *
40 - * options:
41 - * limit_by_current_type *default ...only include meta chunks of the current mvTitle type
42 - * limit_by_type = $type ...include stream of given $type
43 - * all_in_rage *default...include all meta that have any portion in range
44 - * contained_in_range ...include only meta that are contained in the given range
45 - * start_or_end_in_range ...include only meta that start or end in the given range
46 - */
47 - /*function getNearCount($range_offset='', $options=array()){
48 - global $mvDefaultClipLength, $mvIndexTableName;
49 - if($range_offset=='')$range_offset=$mvDefaultClipLength;
50 - $dbr =& wfGetDB(DB_SLAVE);
51 - //set up the count sql query:
52 - $sql = "SELECT COUNT(1) as `count` FROM {$dbr->tableName($mvIndexTableName)} " .
53 - "WHERE `stream_id`={$this->mvTitle->getStreamId()} ";
54 - if(isset($options['limit_by_type'])){
55 - $sql.="AND `mvd_type`='{$options[limit_by_type]}' ";
56 - }else{
57 - $sql.="AND `mvd_type`='{$this->mvTitle->getMvdTypeKey()}' ";
58 - }
59 - $st = $this->mvTitle->getStartTimeSeconds() - $range_offset;
60 - if($st<0)$st=0;
61 - //if end time not present use startTime
62 - if($this->mvTitle->getStartTimeSeconds()){
63 - $et = $this->mvTitle->getStartTimeSeconds() + $range_offset;
64 - }else{
65 - $et = $this->mvTitle->getStartTimeSeconds() + $range_offset;
66 - }
67 - //make sure we don't exceed the stream duration
68 - if($et > $this->mvTitle->getDuration())$et=$this->mvTitle->getDuration();
69 - //default all in range:
70 - $sql.=' AND ( ';
71 - // double or set for null or non-null end time range queries:
72 - $sql.=" (`end_time` IS NULL
73 - AND `start_time` > {$st}
74 - AND `start_time` < {$et}
75 - )
76 - OR
77 - (`end_time` IS NOT NULL
78 - AND `end_time` > {$st}
79 - AND `start_time` < {$et}
80 - )
81 - )";
82 - $result = $dbr->query($sql, 'MV_Index:getNearCount');
83 - $row = $dbr->fetchObject( $result );
84 - //print_r($row);
85 - return $row->count;
86 - }*/
87 - function countMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all'){
88 - global $mvDefaultClipLength;
89 - $dbr =& wfGetDB(DB_SLAVE);
 28+ var $mvTitle =null;
 29+ function __construct(& $mvTitle=null){
 30+ if($mvTitle!=null)
 31+ $this->mvTitle=$mvTitle;
 32+ }
 33+ /*
 34+ * grabs near options count
 35+ * (similar to getNearStreams but returns a count instead of a result set)
 36+ *
 37+ * @params:
 38+ * $range_offset
 39+ *
 40+ * options:
 41+ * limit_by_current_type *default ...only include meta chunks of the current mvTitle type
 42+ * limit_by_type = $type ...include stream of given $type
 43+ * all_in_rage *default...include all meta that have any portion in range
 44+ * contained_in_range ...include only meta that are contained in the given range
 45+ * start_or_end_in_range ...include only meta that start or end in the given range
 46+ */
 47+ /*function getNearCount($range_offset='', $options=array()){
 48+ global $mvDefaultClipLength, $mvIndexTableName;
 49+ if($range_offset=='')$range_offset=$mvDefaultClipLength;
 50+ $dbr =& wfGetDB(DB_SLAVE);
 51+ //set up the count sql query:
 52+ $sql = "SELECT COUNT(1) as `count` FROM {$dbr->tableName($mvIndexTableName)} " .
 53+ "WHERE `stream_id`={$this->mvTitle->getStreamId()} ";
 54+ if(isset($options['limit_by_type'])){
 55+ $sql.="AND `mvd_type`='{$options[limit_by_type]}' ";
 56+ }else{
 57+ $sql.="AND `mvd_type`='{$this->mvTitle->getMvdTypeKey()}' ";
 58+ }
 59+ $st = $this->mvTitle->getStartTimeSeconds() - $range_offset;
 60+ if($st<0)$st=0;
 61+ //if end time not present use startTime
 62+ if($this->mvTitle->getStartTimeSeconds()){
 63+ $et = $this->mvTitle->getStartTimeSeconds() + $range_offset;
 64+ }else{
 65+ $et = $this->mvTitle->getStartTimeSeconds() + $range_offset;
 66+ }
 67+ //make sure we don't exceed the stream duration
 68+ if($et > $this->mvTitle->getDuration())$et=$this->mvTitle->getDuration();
 69+ //default all in range:
 70+ $sql.=' AND ( ';
 71+ // double or set for null or non-null end time range queries:
 72+ $sql.=" (`end_time` IS NULL
 73+ AND `start_time` > {$st}
 74+ AND `start_time` < {$et}
 75+ )
 76+ OR
 77+ (`end_time` IS NOT NULL
 78+ AND `end_time` > {$st}
 79+ AND `start_time` < {$et}
 80+ )
 81+ )";
 82+ $result = $dbr->query($sql, 'MV_Index:getNearCount');
 83+ $row = $dbr->fetchObject( $result );
 84+ //print_r($row);
 85+ return $row->count;
 86+ }*/
 87+ function countMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all'){
 88+ global $mvDefaultClipLength;
 89+ $dbr =& wfGetDB(DB_SLAVE);
9090
91 - $cond=array('stream_id'=>$stream_id);
92 - if($end_time)
93 - $cond[]='AND start_time <= '. $dbr->addQuotes($end_time);
94 - if($start_time)
95 - $cond[]='AND end_time >= '. $dbr->addQuotes($start_time);
 91+ $cond=array('stream_id'=>$stream_id);
 92+ if($end_time)
 93+ $cond[]='AND start_time <= '. $dbr->addQuotes($end_time);
 94+ if($start_time)
 95+ $cond[]='AND end_time >= '. $dbr->addQuotes($start_time);
9696 return $dbr->selectField('mv_mvd_index', 'COUNT(*)', $cond, __METHOD__ );
97 - }
98 - /*
99 - * getMVDInRange returns the mvd titles that are in the given range
100 - * param list got kind of crazy long... @@todo re-factor int a request object or something cleaner
101 - */
102 - function getMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all',$getText=false,$smw_properties='', $limit='200'){
103 - global $mvIndexTableName, $mvDefaultClipLength;
104 - $dbr =& wfGetDB(DB_SLAVE);
105 - //set up select vars:
106 - $conds=$options=$vars=array();
107 - $from_tables ='';
108 - //
109 - //set mvd_type if empty:
110 - if($mvd_type==null)$mvd_type='all';
111 - if($start_time<0)$start_time=0;
112 - //add base select vars:
113 - $vars= array('mv_page_id as id', 'mvd_type', 'wiki_title', 'stream_id', 'start_time', 'end_time');
114 - //add in base from:
115 - $from_tables.= $dbr->tableName('mv_mvd_index');
116 - if($smw_properties!=''){
117 - if(!isset($options['STRAIGHT_JOIN']))
118 - $options['STRAIGHT_JOIN']='';
119 - if(!is_array($smw_properties))
120 - $smw_properties = explode(',',$smw_properties);
121 - foreach($smw_properties as $prop_name){
122 - $vars[] = mysql_real_escape_string($prop_name).'.object_title as '.mysql_real_escape_string($prop_name);
123 - $from_tables.=' LEFT JOIN '. $dbr->tableName('smw_relations') .
124 - ' as ' . mysql_real_escape_string($prop_name) .
125 - ' ON (' . $dbr->tableName('mv_mvd_index') . '.mv_page_id'.
126 - ' = ' . mysql_real_escape_string($prop_name) . '.subject_id'.
127 - ' AND '. mysql_real_escape_string($prop_name).'.relation_title'.
128 - ' = ' . $dbr->addQuotes($prop_name) . ')';
129 - }
130 - }
131 - $conds = array('stream_id'=>$stream_id);
132 - if($mvd_type!='all'){
133 - $mvd_type=(is_object($mvd_type))?get_object_vars($mvd_type):$mvd_type;
134 - if(is_array($mvd_type)){
135 - $mvd_type_cond = '';
136 - foreach($mvd_type as $mtype){
 97+ }
 98+ /*
 99+ * getMVDInRange returns the mvd titles that are in the given range
 100+ * param list got kind of crazy long... @@todo re-factor int a request object or something cleaner
 101+ */
 102+ function getMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all',$getText=false,$smw_properties='', $limit='200'){
 103+ global $mvIndexTableName, $mvDefaultClipLength;
 104+ $dbr =& wfGetDB(DB_SLAVE);
 105+ //set up select vars:
 106+ $conds=$options=$vars=array();
 107+ $from_tables ='';
 108+ //
 109+ //set mvd_type if empty:
 110+ if($mvd_type==null)$mvd_type='all';
 111+ if($start_time<0)$start_time=0;
 112+ //add base select vars:
 113+ $vars= array('mv_page_id as id', 'mvd_type', 'wiki_title', 'stream_id', 'start_time', 'end_time');
 114+ //add in base from:
 115+ $from_tables.= $dbr->tableName('mv_mvd_index');
 116+ if($smw_properties!=''){
 117+ if(!isset($options['STRAIGHT_JOIN']))
 118+ $options['STRAIGHT_JOIN']='';
 119+ if(!is_array($smw_properties))
 120+ $smw_properties = explode(',',$smw_properties);
 121+ foreach($smw_properties as $prop_name){
 122+ $vars[] = mysql_real_escape_string($prop_name).'.object_title as '.mysql_real_escape_string($prop_name);
 123+ $from_tables.=' LEFT JOIN '. $dbr->tableName('smw_relations') .
 124+ ' as ' . mysql_real_escape_string($prop_name) .
 125+ ' ON (' . $dbr->tableName('mv_mvd_index') . '.mv_page_id'.
 126+ ' = ' . mysql_real_escape_string($prop_name) . '.subject_id'.
 127+ ' AND '. mysql_real_escape_string($prop_name).'.relation_title'.
 128+ ' = ' . $dbr->addQuotes($prop_name) . ')';
 129+ }
 130+ }
 131+ $conds = array('stream_id'=>$stream_id);
 132+ if($mvd_type!='all'){
 133+ $mvd_type=(is_object($mvd_type))?get_object_vars($mvd_type):$mvd_type;
 134+ if(is_array($mvd_type)){
 135+ $mvd_type_cond = '';
 136+ foreach($mvd_type as $mtype){
137137 //@@todo confirm its a valid mvd_type:
138 - $mvd_type_cond.= $or."mvd_type=".$dbr->addQuotes($mtype);
 138+ $mvd_type_cond.= $or."mvd_type=".$dbr->addQuotes($mtype);
139139 $or=' OR ';
140 - }
141 - $conds[] = $mvd_type_cond;
142 - }else if(is_string($mvd_type)){
143 - $conds['mvd_type']=$mvd_type;
144 - }
145 -
146 - }
147 - if($end_time)
148 - $conds[]='start_time <= '. $dbr->addQuotes($end_time);
149 - if($start_time)
150 - $conds[]='end_time >= '. $dbr->addQuotes($start_time);
151 -
152 - //add in ordering
153 - $options['ORDER BY']= 'start_time ASC';
154 - //add in limit
155 - $options['LIMIT'] = $limit;
156 - //run query:
157 - $result = $dbr->select( $from_tables,
 140+ }
 141+ $conds[] = $mvd_type_cond;
 142+ }else if(is_string($mvd_type)){
 143+ $conds['mvd_type']=$mvd_type;
 144+ }
 145+
 146+ }
 147+ if($end_time)
 148+ $conds[]='start_time <= '. $dbr->addQuotes($end_time);
 149+ if($start_time)
 150+ $conds[]='end_time >= '. $dbr->addQuotes($start_time);
 151+
 152+ //add in ordering
 153+ $options['ORDER BY']= 'start_time ASC';
 154+ //add in limit
 155+ $options['LIMIT'] = $limit;
 156+ //run query:
 157+ $result = $dbr->select( $from_tables,
158158 $vars,
159159 $conds,
160 - __METHOD__,
161 - $options);
 160+ __METHOD__,
 161+ $options);
162162 //print $dbr->lastQuery();
163163 //die;
164164 //echo $sql;
165 - //$result =& $dbr->query( $sql, 'MV_Index:time_index_query');
166 - return $result;
167 - }
 165+ //$result =& $dbr->query( $sql, 'MV_Index:time_index_query');
 166+ return $result;
 167+ }
168168 /*@@todo figure another way to get at this data...this is not a very fast query: */
169 - function getMVDTypeInRange($stream_id, $start_time=null, $end_time=null){
170 - $dbr =& wfGetDB(DB_SLAVE);
171 - //init vars
172 - $from_tables=$vars= $conds= $options=array();
173 -
174 - $from_tables = $dbr->tableName('mv_mvd_index');
175 - $vars = 'COUNT(*) as count, mvd_type';
176 - $conds = array('stream_id'=>$stream_id);
177 - if($end_time)
178 - $cond[] = ' AND start_time <= '. $dbr->addQuotes($end_time);
179 - if($start_time)
180 - $cond[] = ' AND end_time >= '. $dbr->addQuotes($start_time);
181 - $options['GROUP BY'] = 'mvd_type';
182 - return $dbr->select( $from_tables,
 169+ function getMVDTypeInRange($stream_id, $start_time=null, $end_time=null){
 170+ $dbr =& wfGetDB(DB_SLAVE);
 171+ //init vars
 172+ $from_tables=$vars= $conds= $options=array();
 173+
 174+ $from_tables = $dbr->tableName('mv_mvd_index');
 175+ $vars = 'COUNT(*) as count, mvd_type';
 176+ $conds = array('stream_id'=>$stream_id);
 177+ if($end_time)
 178+ $cond[] = ' AND start_time <= '. $dbr->addQuotes($end_time);
 179+ if($start_time)
 180+ $cond[] = ' AND end_time >= '. $dbr->addQuotes($start_time);
 181+ $options['GROUP BY'] = 'mvd_type';
 182+ return $dbr->select( $from_tables,
183183 $vars,
184184 $conds,
185 - __METHOD__,
 185+ __METHOD__,
186186 $options); ;
187 - }
188 - function remove_by_stream_id($stream_id){
189 - global $mvIndexTableName;
190 - $dbw =& wfGetDB(DB_WRITE);
191 - $dbw->delete($mvIndexTableName, array('stream_id'=>$stream_id));
192 - }
193 - /*
194 - * removes a single entry by wiki_title name
195 - */
196 - function remove_by_wiki_title($wiki_title){
197 - global $mvIndexTableName;
198 - $dbw =& wfGetDB(DB_WRITE);
199 - $dbw->delete($mvIndexTableName, array('wiki_title'=>$wiki_title));
200 - //print "ran sql:" . $dbw->lastQuery() . "\n";
201 - return true;
202 - }
203 - /*function doUnifiedFiltersQuery(&$filters, $metaDataIncludes=null){
204 - global $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
205 - $dbr =& wfGetDB(DB_SLAVE);
206 - //init vars
207 - $from_tables='';
208 - $vars= $conds= $options=array();
209 -
210 - //set options
211 - if( $mvDo_SQL_CALC_FOUND_ROWS)
212 - $options['SQL_CALC_FOUND_ROWS']=true;
213 - //set limit offset:
214 - list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
215 - if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
216 - $this->order = strtolower($wgRequest->getVal('order'));
 187+ }
 188+ function remove_by_stream_id($stream_id){
 189+ global $mvIndexTableName;
 190+ $dbw =& wfGetDB(DB_WRITE);
 191+ $dbw->delete($mvIndexTableName, array('stream_id'=>$stream_id));
 192+ }
 193+ /*
 194+ * removes a single entry by wiki_title name
 195+ */
 196+ function remove_by_wiki_title($wiki_title){
 197+ global $mvIndexTableName;
 198+ $dbw =& wfGetDB(DB_WRITE);
 199+ $dbw->delete($mvIndexTableName, array('wiki_title'=>$wiki_title));
 200+ //print "ran sql:" . $dbw->lastQuery() . "\n";
 201+ return true;
 202+ }
 203+ /*function doUnifiedFiltersQuery(&$filters, $metaDataIncludes=null){
 204+ global $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
 205+ $dbr =& wfGetDB(DB_SLAVE);
 206+ //init vars
 207+ $from_tables='';
 208+ $vars= $conds= $options=array();
 209+
 210+ //set options
 211+ if( $mvDo_SQL_CALC_FOUND_ROWS)
 212+ $options['SQL_CALC_FOUND_ROWS']=true;
 213+ //set limit offset:
 214+ list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
 215+ if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
 216+ $this->order = strtolower($wgRequest->getVal('order'));
217217 //force order type:
218 - if( !($this->order=='relevent' || $this->order=='recent' || $this->order=='viewed') )$this->order='relevent';
219 -
220 - foreach($filters as $f){
221 - $cur_cond=$aon=$asql='';
222 - //proocc and or for fulltext:
223 - if(!isset($f['a']))$f['a']='and';
224 - switch($f['a']){
225 - case 'and':$aon='+';$asql='AND';break;
226 - case 'or':$aon='';$asql='OR';break;
227 - case 'not':$aon='-';$asql='NOT';break;
228 - }
229 -
230 - }
231 -
232 -
233 - $result = $dbr->select( $from_tables,
 218+ if( !($this->order=='relevant' || $this->order=='recent' || $this->order=='viewed') )$this->order='relevant';
 219+
 220+ foreach($filters as $f){
 221+ $cur_cond=$aon=$asql='';
 222+ //proocc and or for fulltext:
 223+ if(!isset($f['a']))$f['a']='and';
 224+ switch($f['a']){
 225+ case 'and':$aon='+';$asql='AND';break;
 226+ case 'or':$aon='';$asql='OR';break;
 227+ case 'not':$aon='-';$asql='NOT';break;
 228+ }
 229+
 230+ }
 231+
 232+
 233+ $result = $dbr->select( $from_tables,
234234 $vars,
235235 $conds,
236 - __METHOD__,
237 - $options);
238 - }*/
239 -
240 - function doUnifiedFiltersQuery(&$filters, $metaDataIncludes=null){
241 - global $mvIndexTableName,$mvStreamFilesTable, $mvDefaultClipLength,$mvStreamTable,
242 - $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
243 -
244 - global $mvSpokenByInSearchResult, $mvCategoryInSearchResult, $mvBillInSearchResult;
 236+ __METHOD__,
 237+ $options);
 238+ }*/
245239
246 - //init vars
247 - $from_tables='';
248 - $vars= $conds= $options=array();
249 - //init top range generation query
250 - $from_tables_top='';
251 - $vars_top= $conds_top= $options_top=array();
252 -
253 - $do_top_range_query = false;
254 - $date_range_join=true;
255 -
256 - $dbr =& wfGetDB(DB_SLAVE);
257 - //organize the queries (group full-text searches and category/attributes)
258 - //if the attribute is not a numerical just add it to the fulltext query
259 - //$ftq_match_asql=$last_person_aon=$ftq_match=$ftq=$snq=$toplq_cat=$date_range_join=$date_range_where=$asql=''; //top query and full text query =''
260 - if($filters=='')return array();
261 - $ftq_match_asql=$date_cond='';
262 -
263 - //$selOpt = ($mvDo_SQL_CALC_FOUND_ROWS)?'SQL_CALC_FOUND_ROWS':'';
264 - if( $mvDo_SQL_CALC_FOUND_ROWS)
265 - $options[]='SQL_CALC_FOUND_ROWS';
266 -
267 - //set limit offset:
268 - list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
269 - if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
270 -
271 - $this->order = strtolower($wgRequest->getVal('order'));
272 - //force order type:
273 - if( !($this->order=='relevent' || $this->order=='recent' || $this->order=='viewed') )$this->order='relevent';
274 -
 240+ function doUnifiedFiltersQuery(&$filters, $metaDataIncludes=null){
 241+ global $mvIndexTableName,$mvStreamFilesTable, $mvDefaultClipLength,$mvStreamTable,
 242+ $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
275243
276 - $group_spoken=true;
277 - //$categoryTable = ;
278 - $valid_filter_count=0;
279 - foreach($filters as $f){
280 - //proocc and or for fulltext:
281 - if(!isset($f['a']))$f['a']='and';
282 - switch($f['a']){
283 - case 'and':$aon='+';$asql='AND';break;
284 - case 'or':$aon='';$asql='OR';break;
285 - case 'not':$aon='-';$asql='NOT';break;
286 - }
287 - //add to the fulltext query:
288 - switch($f['t']){
289 - case 'spoken_by':
290 - //skip if empty value:
291 - if(trim($f['v'])=='')continue;
292 - //if we have an OR set prev to OR
293 - if($last_person_aon=='+' && $aon==''){
294 - $ftq=str_replace('+"spoken by', '"spoken by', $ftq);
295 - $group_spoken=false;
296 - }
297 - //full text based semantic query:
298 - $ftq.=' '.$aon.'"spoken by '. mysql_real_escape_string($f['v']).'" ';
299 - //table based query:
300 - $last_person_aon=$aon;
301 - $valid_filter_count++;
302 - //$conds[]=
303 - break;
304 - case 'match':
305 - //skip if empty value:
306 - if(trim($f['v'])=='')continue;
307 - $ftq_match.=$aon.'"'.mysql_real_escape_string($f['v']).'"';
308 - //only need to split out ftq match if spoken by is more than one
309 - if($ftq_match_asql!='')
310 - $ftq_match_asql = $asql;
311 - $valid_filter_count++;
312 - break;
313 - //top level queries (sets up time ranges )
314 - case 'category':
315 - //skip if empty value:
316 - if(trim($f['v'])=='')continue;
317 - $do_top_range_query=true;
318 - //full text based category query:
319 - $toplq.=' '.$aon.'"category '.mysql_real_escape_string($f['v']).'" ';
320 - //$ftq.=' '.$aon.'category:'.mysql_escape_string($f['v']);
321 -
322 - //table based query:
323 - switch($f['a']){
324 - case 'and':$toplq_cat='AND';break;
325 - case 'or':$toplq_cat='OR';break;
326 - case 'not':$toplq_cat='NOT';break;
327 - }
328 - $toplq_cat.=$dbr->tableName( 'categorylinks').'.cl_to='.$dbr->addQuotes($f['v']);
329 - $valid_filter_count++;
330 - break;
331 - case 'date_range':
332 - $date_range_join = true;
333 - list($month, $day, $year) = explode('/',$f['vs']);
334 - $sts = mktime(0,0,0,$month, $day, $year);
335 - list($month, $day, $year) = explode('/',$f['ve']);
336 - $ets = mktime(0,0,0,$month, $day+1, $year); //(the start of the next day)
337 - //add date condtion:
338 - //note dissable and or for date range for now: $asql
339 - $conds[] = ' ( `mv_streams`.`date_start_time` > '
340 - . $dbr->addQuotes($sts) .
341 - ' AND `mv_streams`.`date_start_time` < '. $dbr->addQuotes($ets) .
342 - ') ';
343 - //print $date_cond;
344 - $valid_filter_count++;
345 - break;
346 - case 'stream_name':
347 - //skip if empty value:
348 - if(trim($f['v'])=='')continue;
349 - $stream =& mvGetMVStream($f['v']);
350 - //add stream cond
351 - $conds[]=$asql." stream_id = ". $dbr->addQuotes($stream->getStreamId());
352 - $valid_filter_count++;
353 - break;
354 - case 'smw_property':
355 - //more complicated query work needed
356 - break;
357 - }
358 - }
 244+ global $mvSpokenByInSearchResult, $mvCategoryInSearchResult, $mvBillInSearchResult;
 245+
 246+ //init vars
 247+ $from_tables='';
 248+ $vars= $conds= $options=array();
 249+ //init top range generation query
 250+ $from_tables_top='';
 251+ $vars_top= $conds_top= $options_top=array();
 252+
 253+ $do_top_range_query = false;
 254+ $date_range_join=true;
 255+
 256+ $dbr =& wfGetDB(DB_SLAVE);
 257+ //organize the queries (group full-text searches and category/attributes)
 258+ //if the attribute is not a numerical just add it to the fulltext query
 259+ //$ftq_match_asql=$last_person_aon=$ftq_match=$ftq=$snq=$toplq_cat=$date_range_join=$date_range_where=$asql=''; //top query and full text query =''
 260+ if($filters=='')return array();
 261+ $ftq_match_asql=$date_cond='';
 262+
 263+ //$selOpt = ($mvDo_SQL_CALC_FOUND_ROWS)?'SQL_CALC_FOUND_ROWS':'';
 264+ if( $mvDo_SQL_CALC_FOUND_ROWS)
 265+ $options[]='SQL_CALC_FOUND_ROWS';
 266+
 267+ //set limit offset:
 268+ list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
 269+ if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
 270+
 271+ $this->order = strtolower($wgRequest->getVal('order'));
 272+ //force order type:
 273+ if( !($this->order=='relevant' || $this->order=='recent' || $this->order=='viewed') )$this->order='relevant';
 274+
 275+
 276+ $group_spoken=true;
 277+ //$categoryTable = ;
 278+ $valid_filter_count=0;
 279+ foreach($filters as $f){
 280+ //proocc and or for fulltext:
 281+ if(!isset($f['a']))$f['a']='and';
 282+ switch($f['a']){
 283+ case 'and':$aon='+';$asql='AND';break;
 284+ case 'or':$aon='';$asql='OR';break;
 285+ case 'not':$aon='-';$asql='NOT';break;
 286+ }
 287+ //add to the fulltext query:
 288+ switch($f['t']){
 289+ case 'spoken_by':
 290+ //skip if empty value:
 291+ if(trim($f['v'])=='')continue;
 292+ //if we have an OR set prev to OR
 293+ if($last_person_aon=='+' && $aon==''){
 294+ $ftq=str_replace('+"spoken by', '"spoken by', $ftq);
 295+ $group_spoken=false;
 296+ }
 297+ //full text based semantic query:
 298+ $ftq.=' '.$aon.'"spoken by '. mysql_real_escape_string($f['v']).'" ';
 299+ //table based query:
 300+ $last_person_aon=$aon;
 301+ $valid_filter_count++;
 302+ //$conds[]=
 303+ break;
 304+ case 'match':
 305+ //skip if empty value:
 306+ if(trim($f['v'])=='')continue;
 307+ $ftq_match.=$aon.'"'.mysql_real_escape_string($f['v']).'"';
 308+ //only need to split out ftq match if spoken by is more than one
 309+ if($ftq_match_asql!='')
 310+ $ftq_match_asql = $asql;
 311+ $valid_filter_count++;
 312+ break;
 313+ //top level queries (sets up time ranges )
 314+ case 'category':
 315+ //skip if empty value:
 316+ if(trim($f['v'])=='')continue;
 317+ $do_top_range_query=true;
 318+ //full text based category query:
 319+ $toplq.=' '.$aon.'"category '.mysql_real_escape_string($f['v']).'" ';
 320+ //$ftq.=' '.$aon.'category:'.mysql_escape_string($f['v']);
 321+
 322+ //table based query:
 323+ switch($f['a']){
 324+ case 'and':$toplq_cat='AND';break;
 325+ case 'or':$toplq_cat='OR';break;
 326+ case 'not':$toplq_cat='NOT';break;
 327+ }
 328+ $toplq_cat.=$dbr->tableName( 'categorylinks').'.cl_to='.$dbr->addQuotes($f['v']);
 329+ $valid_filter_count++;
 330+ break;
 331+ case 'date_range':
 332+ $date_range_join = true;
 333+ list($month, $day, $year) = explode('/',$f['vs']);
 334+ $sts = mktime(0,0,0,$month, $day, $year);
 335+ list($month, $day, $year) = explode('/',$f['ve']);
 336+ $ets = mktime(0,0,0,$month, $day+1, $year); //(the start of the next day)
 337+ //add date condtion:
 338+ //note dissable and or for date range for now: $asql
 339+ $conds[] = ' ( `mv_streams`.`date_start_time` > '
 340+ . $dbr->addQuotes($sts) .
 341+ ' AND `mv_streams`.`date_start_time` < '. $dbr->addQuotes($ets) .
 342+ ') ';
 343+ //print $date_cond;
 344+ $valid_filter_count++;
 345+ break;
 346+ case 'stream_name':
 347+ //skip if empty value:
 348+ if(trim($f['v'])=='')continue;
 349+ $stream =& mvGetMVStream($f['v']);
 350+ //add stream cond
 351+ $conds[]=$asql." stream_id = ". $dbr->addQuotes($stream->getStreamId());
 352+ $valid_filter_count++;
 353+ break;
 354+ case 'smw_property':
 355+ //more complicated query work needed
 356+ break;
 357+ }
 358+ }
359359 if($valid_filter_count==0){
360360 return array();
361361 }
362 - //add the top query to the base query:
363 - $ftq.=$toplq;
 362+ //add the top query to the base query:
 363+ $ftq.=$toplq;
364364 $vars = "mv_page_id as id,". $dbr->tableName('mv_mvd_index').'.stream_id,
365365 ('.$dbr->tableName('mv_streams').'.date_start_time+'.$dbr->tableName('mv_mvd_index').
366 - '.start_time) AS mvd_date_start_time, '.
 366+ '.start_time) AS mvd_date_start_time, '.
367367 'start_time, end_time, view_count, wiki_title,'.
368 - $dbr->tableName( 'searchindex' ).'.si_text AS `text` ';
369 -
370 - if($mvSpokenByInSearchResult)
371 - $vars.=', smw_relations.object_title as spoken_by ';
372 -
373 - $from_tables.=$dbr->tableName('mv_mvd_index') . ' ';
374 - $from_tables.='JOIN '.$dbr->tableName( 'searchindex' ).
375 - ' ON (' .
376 - $dbr->tableName('mv_mvd_index').'.mv_page_id = '.
377 - $dbr->tableName( 'searchindex' ).'.si_page ) ';
378 -
379 - if($date_range_join)
380 - $from_tables.='LEFT JOIN '. $dbr->tableName('mv_streams').
381 - ' ON (' .
382 - $dbr->tableName('mv_mvd_index').'.stream_id = ' .
383 - $dbr->tableName('mv_streams').'.id ) ';
384 -
385 -
386 - //restrict to streams with valid $mvDefaultVideoQualityKey files:
 368+ $dbr->tableName( 'searchindex' ).'.si_text AS `text` ';
 369+
 370+ if($mvSpokenByInSearchResult)
 371+ $vars.=', smw_relations.object_title as spoken_by ';
 372+
 373+ $from_tables.=$dbr->tableName('mv_mvd_index') . ' ';
 374+ $from_tables.='JOIN '.$dbr->tableName( 'searchindex' ).
 375+ ' ON (' .
 376+ $dbr->tableName('mv_mvd_index').'.mv_page_id = '.
 377+ $dbr->tableName( 'searchindex' ).'.si_page ) ';
 378+
 379+ if($date_range_join)
 380+ $from_tables.='LEFT JOIN '. $dbr->tableName('mv_streams').
 381+ ' ON (' .
 382+ $dbr->tableName('mv_mvd_index').'.stream_id = ' .
 383+ $dbr->tableName('mv_streams').'.id ) ';
 384+
 385+
 386+ //restrict to streams with valid $mvDefaultVideoQualityKey files:
387387 global $mvDefaultVideoQualityKey;
388 - $from_tables.= 'JOIN '. $dbr->tableName('mv_stream_files').
389 - ' ON ' .
390 - '( '.$dbr->tableName('mv_mvd_index').'.stream_id = '.
391 - $dbr->tableName('mv_stream_files').'.stream_id '.
392 - ' AND '. $dbr->tableName('mv_stream_files').'.file_desc_msg = '.
393 - $dbr->addQuotes($mvDefaultVideoQualityKey).
394 - ') ';
 388+ $from_tables.= 'JOIN '. $dbr->tableName('mv_stream_files').
 389+ ' ON ' .
 390+ '( '.$dbr->tableName('mv_mvd_index').'.stream_id = '.
 391+ $dbr->tableName('mv_stream_files').'.stream_id '.
 392+ ' AND '. $dbr->tableName('mv_stream_files').'.file_desc_msg = '.
 393+ $dbr->addQuotes($mvDefaultVideoQualityKey).
 394+ ') ';
395395
396 - //date range join:
397 -
 396+ //date range join:
 397+
398398 //include spoken by relation in results (LEFT JOIN should not be *that* costly )
399399 if($mvSpokenByInSearchResult){
400400 /*$sql.="LEFT JOIN `smw_relations` ON (`mv_mvd_index`.`mv_page_id`=`smw_relations`.`subject_id` " .
@@ -402,43 +402,43 @@
403403 ' ON ' .
404404 '( '.$dbr->tableName('mv_mvd_index').'.mv_page_id = '.
405405 $dbr->tableName('smw_relations').'.subject_id '.
406 - ' AND '.$dbr->tableName('smw_relations').'.relation_title = \'Spoken_By\''.
 406+ ' AND '.$dbr->tableName('smw_relations').'.relation_title = \'Spoken_By\''.
407407 ') ';
408408 }
409 - //$sql.="WHERE ";
 409+ //$sql.="WHERE ";
410410 //$sql.=" ( `{$mvIndexTableName}`.`mvd_type`='ht_en' OR `{$mvIndexTableName}`.`mvd_type`='anno_en') AND" ;
411411
412 - //add conditions to last condition element (cuz we have to manually mannage and or):
413 -
414 - $conds[count($conds)]= ' '.$dbr->tableName('mv_mvd_index') . '.mvd_type = \'ht_en\' '.
415 - ' OR '. $dbr->tableName('mv_mvd_index') . '.mvd_type=\'anno_en\' ';
416 -
417 - //limit to ht_en & anno_en (for now) (future allow selection
418 - //$conds_inx = (count($conds)==0)?0:count($conds)-1;
419 - $two_part_anor='';
420 - if($group_spoken){
421 - $ftq.=$ftq_match;
422 - }else{
423 - if($ftq_match!=''){
424 - $conds[].=$ftq_match_asql.' MATCH ( '. $dbr->tableName( 'searchindex' ).'.si_text )'.
425 - ' AGAINST(\''.$ftq_match.'\' IN BOOLEAN MODE) ';
426 - //if($ftq!='')$sql.=' AND ';
427 - }
428 - }
429 - if($ftq!=''){
430 - $conds[].=" MATCH ( ".$dbr->tableName( 'searchindex' ).'.si_text ) '.
431 - ' AGAINST(\''.$ftq.'\' IN BOOLEAN MODE) ';
432 - }
433 - //print_r($conds);
 412+ //add conditions to last condition element (cuz we have to manually mannage and or):
 413+
 414+ $conds[count($conds)]= ' '.$dbr->tableName('mv_mvd_index') . '.mvd_type = \'ht_en\' '.
 415+ ' OR '. $dbr->tableName('mv_mvd_index') . '.mvd_type=\'anno_en\' ';
 416+
 417+ //limit to ht_en & anno_en (for now) (future allow selection
 418+ //$conds_inx = (count($conds)==0)?0:count($conds)-1;
 419+ $two_part_anor='';
 420+ if($group_spoken){
 421+ $ftq.=$ftq_match;
 422+ }else{
 423+ if($ftq_match!=''){
 424+ $conds[].=$ftq_match_asql.' MATCH ( '. $dbr->tableName( 'searchindex' ).'.si_text )'.
 425+ ' AGAINST(\''.$ftq_match.'\' IN BOOLEAN MODE) ';
 426+ //if($ftq!='')$sql.=' AND ';
 427+ }
 428+ }
 429+ if($ftq!=''){
 430+ $conds[].=" MATCH ( ".$dbr->tableName( 'searchindex' ).'.si_text ) '.
 431+ ' AGAINST(\''.$ftq.'\' IN BOOLEAN MODE) ';
 432+ }
 433+ //print_r($conds);
434434 //die;
435 - //date range stuff is SLOW when its the only filter (pulls up matches for everything)
436 - /*if($snq!='' || $ftq!='' && isset($date_range_andor))
437 - $sql.=$date_range_andor;
438 - $sql.=" $date_range_where ";*/
439 -
 435+ //date range stuff is SLOW when its the only filter (pulls up matches for everything)
 436+ /*if($snq!='' || $ftq!='' && isset($date_range_andor))
 437+ $sql.=$date_range_andor;
 438+ $sql.=" $date_range_where ";*/
 439+
440440 switch($this->order){
441 - case 'relevent':
442 - //@@todo need to add in some relevence metrics
 441+ case 'relevant':
 442+ //@@todo need to add in some relevence metrics
443443 break;
444444 case 'recent':
445445 $options['ORDER BY']='mvd_date_start_time DESC ';
@@ -447,564 +447,563 @@
448448 $options['ORDER BY']='view_count DESC ';
449449 break;
450450 }
451 - //echo $this->order;
 451+ //echo $this->order;
452452 //$sql.="LIMIT {$this->offset}, {$this->limit} ";
453453 $options['LIMIT']=$this->limit;
454454 $options['OFFSET']=$this->offset;
455 -
456 - $result = $dbr->select( $from_tables,
 455+
 456+ $result = $dbr->select( $from_tables,
457457 $vars,
458458 $conds,
459 - __METHOD__,
460 - $options);
461 -
462 - //echo "SQL:".$dbr->lastQuery($result)." \n";
 459+ __METHOD__,
 460+ $options);
 461+
 462+ //echo "SQL:".$dbr->lastQuery($result)." \n";
463463 //die;
464 - //$result = $dbr->query($sql, 'MV_Index:doFiltersQuery_base');
465 -
466 - $this->numResults=$dbr->numRows($result);
467 - if($dbr->numRows($result)==0) return array();
468 -
469 - if($mvDo_SQL_CALC_FOUND_ROWS){
470 - $resFound = $dbr->query('SELECT FOUND_ROWS() as `count`;');
471 - $found = $dbr->fetchObject( $resFound );
472 - $this->numResultsFound = $found->count;
473 - }else{
474 - $this->numResultsFound =null;
475 - }
476 -
477 - //@@TODO hide empty categories (if limit > rows found )
478 - //while($row = $dbr->fetchObject( $result )){
479 - // $ret_ary[]=$row;
480 - //}
481 - //return $ret_ary;
482 - //group by stream_name & time range:
 464+ //$result = $dbr->query($sql, 'MV_Index:doFiltersQuery_base');
483465
484 - //init ret_ary & stream_group
485 - $ret_ary = $stream_groups = array();
486 - while($row = $dbr->fetchObject( $result )){
487 - $ret_ary[$row->id]=$row;
488 - if(!isset($stream_groups[$row->stream_id])){
489 - $stream_groups[$row->stream_id]=array();
490 - }
491 - if(count($stream_groups[$row->stream_id])==0){
492 - $new_srange = array('s'=>$row->start_time,
 466+ $this->numResults=$dbr->numRows($result);
 467+ if($dbr->numRows($result)==0) return array();
 468+
 469+ if($mvDo_SQL_CALC_FOUND_ROWS){
 470+ $resFound = $dbr->query('SELECT FOUND_ROWS() as `count`;');
 471+ $found = $dbr->fetchObject( $resFound );
 472+ $this->numResultsFound = $found->count;
 473+ }else{
 474+ $this->numResultsFound =null;
 475+ }
 476+
 477+ //@@TODO hide empty categories (if limit > rows found )
 478+ //while($row = $dbr->fetchObject( $result )){
 479+ // $ret_ary[]=$row;
 480+ //}
 481+ //return $ret_ary;
 482+ //group by stream_name & time range:
 483+
 484+ //init ret_ary & stream_group
 485+ $ret_ary = $stream_groups = array();
 486+ while($row = $dbr->fetchObject( $result )){
 487+ $ret_ary[$row->id]=$row;
 488+ if(!isset($stream_groups[$row->stream_id])){
 489+ $stream_groups[$row->stream_id]=array();
 490+ }
 491+ if(count($stream_groups[$row->stream_id])==0){
 492+ $new_srange = array('s'=>$row->start_time,
493493 'e'=> $row->end_time,
494494 'rows'=>array($row));
495 - $stream_groups[$row->stream_id][]=$new_srange;
496 - }else{
497 - MV_Index::insert_merge_range($stream_groups[$row->stream_id], $stream_groups, $row);
498 - }
499 - }
500 - //print "<pre>";
501 - //print_r($ret_ary);
502 - //die;
503 - //throw out empty top level ranges
504 - /*foreach($ret_ary as &$stream_set){
505 - foreach($stream_set as $k=> &$srange){
506 - if(count($srange['rows'])==0){
507 - //print "throw out: ". $srange['s'] . $srange['e'];
508 - unset($stream_set[$k]);
509 - }
510 - }
511 - }*/
512 - //do category & bill lookup for search result ranges
513 - if($mvCategoryInSearchResult || $mvBillInSearchResult){
514 - $from_tables=$conds='';
515 - $vars= $options=array();
516 -
517 - //set up selected vars:
518 - $vars[]=$dbr->tableName('categorylinks').'.cl_to';
519 - $vars[]=$dbr->tableName('mv_mvd_index').'.stream_id';
520 - $vars[]=$dbr->tableName('mv_mvd_index').'.start_time';
 495+ $stream_groups[$row->stream_id][]=$new_srange;
 496+ }else{
 497+ MV_Index::insert_merge_range($stream_groups[$row->stream_id], $stream_groups, $row);
 498+ }
 499+ }
 500+ //print "<pre>";
 501+ //print_r($ret_ary);
 502+ //die;
 503+ //throw out empty top level ranges
 504+ /*foreach($ret_ary as &$stream_set){
 505+ foreach($stream_set as $k=> &$srange){
 506+ if(count($srange['rows'])==0){
 507+ //print "throw out: ". $srange['s'] . $srange['e'];
 508+ unset($stream_set[$k]);
 509+ }
 510+ }
 511+ }*/
 512+ //do category & bill lookup for search result ranges
 513+ if($mvCategoryInSearchResult || $mvBillInSearchResult){
 514+ $from_tables=$conds='';
 515+ $vars= $options=array();
 516+
 517+ //set up selected vars:
 518+ $vars[]=$dbr->tableName('categorylinks').'.cl_to';
 519+ $vars[]=$dbr->tableName('mv_mvd_index').'.stream_id';
 520+ $vars[]=$dbr->tableName('mv_mvd_index').'.start_time';
521521 $vars[]=$dbr->tableName('mv_mvd_index').'.end_time';
522522 $vars[]=$dbr->tableName('smw_relations').'.object_title as bill_to ';
523 -
 523+
524524 //set up from_tables
525 - $from_tables.=$dbr->tableName('mv_mvd_index') .
 525+ $from_tables.=$dbr->tableName('mv_mvd_index') .
526526 ' LEFT JOIN '.$dbr->tableName('categorylinks') .
527 - ' ON ( ' .
528 - $dbr->tableName('mv_mvd_index').'.mv_page_id = ' .
 527+ ' ON ( ' .
 528+ $dbr->tableName('mv_mvd_index').'.mv_page_id = ' .
529529 $dbr->tableName('categorylinks').'.cl_from ' .
530 - ' ) ' .
 530+ ' ) ' .
531531 ' LEFT JOIN '. $dbr->tableName('smw_relations') .
532 - ' ON ( ' .
533 - $dbr->tableName('mv_mvd_index').'.mv_page_id = ' .
 532+ ' ON ( ' .
 533+ $dbr->tableName('mv_mvd_index').'.mv_page_id = ' .
534534 $dbr->tableName('smw_relations').'.subject_id '.
535535 ' AND ' .
536536 $dbr->tableName('smw_relations').'.relation_title=\'bill\' '.
537 - ' ) ';
 537+ ' ) ';
538538 //generate stream_id, range sets
539 - $conds.= $dbr->tableName('mv_mvd_index').'.mvd_type=\'Anno_en\' ' .
 539+ $conds.= $dbr->tableName('mv_mvd_index').'.mvd_type=\'Anno_en\' ' .
540540 ' AND (';
541541 $or='';
542542 foreach($stream_groups as $stream_id=>$rangeSet){
543 - foreach($rangeSet as $range){
 543+ foreach($rangeSet as $range){
544544 $conds.= $or . ' ( '.$dbr->tableName('mv_mvd_index').'.stream_id ='.
545 - $dbr->addQuotes($stream_id);
 545+ $dbr->addQuotes($stream_id);
546546 $conds.=" AND `start_time` <= " . $dbr->addQuotes($range['s'])."";
547547 $conds.=" AND `end_time` >= " . $dbr->addQuotes($range['e']) . ' ) ';
548 - $or = ' OR ';
549 -
 548+ $or = ' OR ';
 549+
550550 }
551 - }
552 - $conds.=' ) ';
 551+ }
 552+ $conds.=' ) ';
553553 $options['LIMIT']=200;
554 -
555 - $result = $dbr->select( $from_tables,
 554+
 555+ $result = $dbr->select( $from_tables,
556556 $vars,
557557 $conds,
558 - __METHOD__,
559 - $options);
 558+ __METHOD__,
 559+ $options);
560560 //print "BEFORE merge: ";
561561 //print_r($ret_ary);
562562 //print_r($stream_groups);
563 -
564 - //merge category info back into base results:
 563+
 564+ //merge category info back into base results:
565565 //$result = $dbr->query($sql, 'MV_Index:doCategorySearchResult');
566566 while($cl_row = $dbr->fetchObject( $result )){
567 - //print_r($cl_row);
568 - foreach($stream_groups[$cl_row->stream_id] as &$range){
 567+ //print_r($cl_row);
 568+ foreach($stream_groups[$cl_row->stream_id] as &$range){
569569 foreach($range['rows'] as &$result_row){
570 - if($result_row->start_time <= $cl_row->end_time &&
 570+ if($result_row->start_time <= $cl_row->end_time &&
571571 $result_row->end_time >= $cl_row->start_time){
572 - //print "result row:"; print_r($result_row);
573 - if(isset($cl_row->cl_to) && isset($ret_ary[$result_row->id]))
 572+ //print "result row:"; print_r($result_row);
 573+ if(isset($cl_row->cl_to) && isset($ret_ary[$result_row->id]))
574574 $ret_ary[$result_row->id]->categories[$cl_row->cl_to]=true;
575575 if(isset($cl_row->bill_to) && isset($ret_ary[$result_row->id]))
576576 $ret_ary[$result_row->id]->bills[$cl_row->bill_to]=true;
577 - }
 577+ }
578578 }
579579 }
580580 }
581581 //print "AFTER MERGE: ";
582582 //print_r($ret_ary);
583 - }
584 - //print "<pre>";
585 - //print_r($ret_ary);
586 - //die;
587 - return $ret_ary;
588 - }
589 - /* do filter query with stream grouping */
590 - /*function doFiltersQuery(&$filters, $metaDataIncludes=null){
591 - global $mvIndexTableName,$mvStreamFilesTable, $mvDefaultClipLength,
592 - $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
593 -
594 - global $mvSpokenByInSearchResult, $mvCategoryInSearchResult, $mvBillInSearchResult;
595 -
596 - $dbr =& wfGetDB(DB_SLAVE);
597 - //organize the queries (group full-text searches and category/attributes)
598 - //if the attribute is not a numerical just add it to the fulltext query
599 - $ftq_match_asql=$last_person_aon=$ftq_match=$ftq=$snq=$toplq_cat=$date_range_join=$date_range_where=$asql=''; //top query and full text query =''
600 - if($filters=='')return array();
601 -
602 - $selOpt = ($mvDo_SQL_CALC_FOUND_ROWS)?'SQL_CALC_FOUND_ROWS':'';
603 -
604 - list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
605 - if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
 583+ }
 584+ //print "<pre>";
 585+ //print_r($ret_ary);
 586+ //die;
 587+ return $ret_ary;
 588+ }
 589+ /* do filter query with stream grouping */
 590+ /*function doFiltersQuery(&$filters, $metaDataIncludes=null){
 591+ global $mvIndexTableName,$mvStreamFilesTable, $mvDefaultClipLength,
 592+ $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
606593
607 - $group_spoken=true;
608 - $categoryTable = $dbr->tableName( 'categorylinks');
609 - foreach($filters as $f){
610 - //proocc and or for fulltext:
611 - if(!isset($f['a']))$f['a']='and';
612 - switch($f['a']){
613 - case 'and':$aon='+';$asql='AND';break;
614 - case 'or':$aon='';$asql='OR';break;
615 - case 'not':$aon='-';$asql='NOT';break;
616 - }
617 - //add to the fulltext query:
618 - switch($f['t']){
619 - case 'spoken_by':
620 - //if we have an OR set prev to OR
621 - if($last_person_aon=='+' && $aon==''){
622 - $ftq=str_replace('+"spoken by', '"spoken by', $ftq);
623 - $group_spoken=false;
624 - }
625 - //full text based semantic query:
626 - $ftq.=' '.$aon.'"spoken by '.mysql_escape_string($f['v']).'"';
627 - //table based query:
628 - $last_person_aon=$aon;
629 - break;
630 - case 'match':
631 - $ftq_match.=' '.$aon.'"'.mysql_escape_string($f['v']).'"';
632 - //only need to split out ftq match if spoken by is more than one
633 - if($ftq_match_asql!='')
634 - $ftq_match_asql = $asql;
635 - break;
636 - //top level queries (sets up time ranges )
637 - case 'category':
638 - //full text based category query:
639 - $toplq.=' '.$aon.'"category '.mysql_escape_string($f['v']).'" ';
640 - //$ftq.=' '.$aon.'category:'.mysql_escape_string($f['v']);
641 -
642 - //table based query:
643 - switch($f['a']){
644 - case 'and':$toplq_cat='AND';break;
645 - case 'or':$toplq_cat='OR';break;
646 - case 'not':$toplq_cat='NOT';break;
647 - }
648 - $toplq_cat.=" $categoryTable.`cl_to`='".mysql_escape_string($f['v'])."'";
649 - break;
650 - case 'date_range':
651 - $date_range_join = ' JOIN `mv_streams` ' .
652 - 'ON `'.$mvIndexTableName.'`.`stream_id` =`mv_streams`.`id` ';
653 -
654 - list($month, $day, $year) = explode('/',$f['vs']);
655 - $sts = mktime(0,0,0,$month, $day, $year);
656 - list($month, $day, $year) = explode('/',$f['ve']);
657 - $ets = mktime(0,0,0,$month, $day+1, $year); //(the start of the next day)
658 - $date_range_where.= '( `mv_streams`.`date_start_time` > '
659 - . mysql_escape_string($sts) .
660 - ' AND `mv_streams`.`date_start_time` < '. mysql_escape_string($ets) .
 594+ global $mvSpokenByInSearchResult, $mvCategoryInSearchResult, $mvBillInSearchResult;
 595+
 596+ $dbr =& wfGetDB(DB_SLAVE);
 597+ //organize the queries (group full-text searches and category/attributes)
 598+ //if the attribute is not a numerical just add it to the fulltext query
 599+ $ftq_match_asql=$last_person_aon=$ftq_match=$ftq=$snq=$toplq_cat=$date_range_join=$date_range_where=$asql=''; //top query and full text query =''
 600+ if($filters=='')return array();
 601+
 602+ $selOpt = ($mvDo_SQL_CALC_FOUND_ROWS)?'SQL_CALC_FOUND_ROWS':'';
 603+
 604+ list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset( 20, 'searchlimit' );
 605+ if($this->limit > $mvMediaSearchResultsLimit)$this->limit = $mvMediaSearchResultsLimit;
 606+
 607+ $group_spoken=true;
 608+ $categoryTable = $dbr->tableName( 'categorylinks');
 609+ foreach($filters as $f){
 610+ //proocc and or for fulltext:
 611+ if(!isset($f['a']))$f['a']='and';
 612+ switch($f['a']){
 613+ case 'and':$aon='+';$asql='AND';break;
 614+ case 'or':$aon='';$asql='OR';break;
 615+ case 'not':$aon='-';$asql='NOT';break;
 616+ }
 617+ //add to the fulltext query:
 618+ switch($f['t']){
 619+ case 'spoken_by':
 620+ //if we have an OR set prev to OR
 621+ if($last_person_aon=='+' && $aon==''){
 622+ $ftq=str_replace('+"spoken by', '"spoken by', $ftq);
 623+ $group_spoken=false;
 624+ }
 625+ //full text based semantic query:
 626+ $ftq.=' '.$aon.'"spoken by '.mysql_escape_string($f['v']).'"';
 627+ //table based query:
 628+ $last_person_aon=$aon;
 629+ break;
 630+ case 'match':
 631+ $ftq_match.=' '.$aon.'"'.mysql_escape_string($f['v']).'"';
 632+ //only need to split out ftq match if spoken by is more than one
 633+ if($ftq_match_asql!='')
 634+ $ftq_match_asql = $asql;
 635+ break;
 636+ //top level queries (sets up time ranges )
 637+ case 'category':
 638+ //full text based category query:
 639+ $toplq.=' '.$aon.'"category '.mysql_escape_string($f['v']).'" ';
 640+ //$ftq.=' '.$aon.'category:'.mysql_escape_string($f['v']);
 641+
 642+ //table based query:
 643+ switch($f['a']){
 644+ case 'and':$toplq_cat='AND';break;
 645+ case 'or':$toplq_cat='OR';break;
 646+ case 'not':$toplq_cat='NOT';break;
 647+ }
 648+ $toplq_cat.=" $categoryTable.`cl_to`='".mysql_escape_string($f['v'])."'";
 649+ break;
 650+ case 'date_range':
 651+ $date_range_join = ' JOIN `mv_streams` ' .
 652+ 'ON `'.$mvIndexTableName.'`.`stream_id` =`mv_streams`.`id` ';
 653+
 654+ list($month, $day, $year) = explode('/',$f['vs']);
 655+ $sts = mktime(0,0,0,$month, $day, $year);
 656+ list($month, $day, $year) = explode('/',$f['ve']);
 657+ $ets = mktime(0,0,0,$month, $day+1, $year); //(the start of the next day)
 658+ $date_range_where.= '( `mv_streams`.`date_start_time` > '
 659+ . mysql_escape_string($sts) .
 660+ ' AND `mv_streams`.`date_start_time` < '. mysql_escape_string($ets) .
661661 ')';
662662 $date_range_andor = ' '.$asql.' ';
663 - break;
664 - case 'stream_name':
665 - if($snq!=''){
 663+ break;
 664+ case 'stream_name':
 665+ if($snq!=''){
666666 switch($f['a']){
667 - case 'and':$snq='AND';break;
668 - case 'or':$snq='OR';break;
669 - case 'not':$snq='NOT';break;
670 - }
671 - }
672 - //get stream name:
673 - //print "f: " . $f['v'];
674 - $stream =& mvGetMVStream($f['v']);
675 - $snq.=" `stream_id` = {$stream->getStreamId()} ";
676 - break;
677 - case 'smw_property':
678 - //more complicated query work needed ;)
679 - break;
680 - }
681 - }
682 - $searchindexTable = $dbr->tableName( 'searchindex' );
683 - $ret_ary = array();
684 - //a join operation to restrict search results to streams with files
685 - $join_streams_with_low_ogg_sql = "JOIN `$mvStreamFilesTable` ON (`$mvIndexTableName`.`stream_id` = `$mvStreamFilesTable`.`stream_id` AND `$mvStreamFilesTable`.`file_desc_msg`='mv_ogg_low_quality') ";
686 - //only run the top range query if we have no secondary query
687 - if($toplq_cat!='' && $ftq==''){
688 - //@@todo unify top query with rannged query ... kind of tricky
689 -
690 - //@@todo we should only look in annotative layer for top level queries? ...
691 - //@@todo paging for top level queries? ... 200 hit limit is probably ok
692 -
693 - $sql = "SELECT `mv_page_id` as `id`, `$mvIndexTableName`.`stream_id`,`$mvIndexTableName`.`start_time`,`$mvIndexTableName`.`end_time`,`$mvIndexTableName`.`view_count`, `wiki_title`, $searchindexTable.`si_text` as `text`
694 - FROM `$mvIndexTableName`
695 - $date_range_join
696 - JOIN $categoryTable ON `$mvIndexTableName`.`mv_page_id` = $categoryTable.`cl_from`
697 - $join_streams_with_low_ogg_sql
698 - LEFT JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page`
699 - WHERE
 667+ case 'and':$snq='AND';break;
 668+ case 'or':$snq='OR';break;
 669+ case 'not':$snq='NOT';break;
 670+ }
 671+ }
 672+ //get stream name:
 673+ //print "f: " . $f['v'];
 674+ $stream =& mvGetMVStream($f['v']);
 675+ $snq.=" `stream_id` = {$stream->getStreamId()} ";
 676+ break;
 677+ case 'smw_property':
 678+ //more complicated query work needed ;)
 679+ break;
 680+ }
 681+ }
 682+ $searchindexTable = $dbr->tableName( 'searchindex' );
 683+ $ret_ary = array();
 684+ //a join operation to restrict search results to streams with files
 685+ $join_streams_with_low_ogg_sql = "JOIN `$mvStreamFilesTable` ON (`$mvIndexTableName`.`stream_id` = `$mvStreamFilesTable`.`stream_id` AND `$mvStreamFilesTable`.`file_desc_msg`='mv_ogg_low_quality') ";
 686+ //only run the top range query if we have no secondary query
 687+ if($toplq_cat!='' && $ftq==''){
 688+ //@@todo unify top query with rannged query ... kind of tricky
 689+
 690+ //@@todo we should only look in annotative layer for top level queries? ...
 691+ //@@todo paging for top level queries? ... 200 hit limit is probably ok
 692+
 693+ $sql = "SELECT `mv_page_id` as `id`, `$mvIndexTableName`.`stream_id`,`$mvIndexTableName`.`start_time`,`$mvIndexTableName`.`end_time`,`$mvIndexTableName`.`view_count`, `wiki_title`, $searchindexTable.`si_text` as `text`
 694+ FROM `$mvIndexTableName`
 695+ $date_range_join
 696+ JOIN $categoryTable ON `$mvIndexTableName`.`mv_page_id` = $categoryTable.`cl_from`
 697+ $join_streams_with_low_ogg_sql
 698+ LEFT JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page`
 699+ WHERE
700700 `mvd_type`='Anno_en' " .
701 - " $toplq_cat " .
702 - " $snq " .
703 - "$date_range_andor $date_range_where " .
704 - "LIMIT 0, 200";
705 - //echo "topQ: $sql \n\n";
706 - $top_result = $dbr->query($sql, 'MV_Index:doFiltersQuery_topQ');
707 - if($dbr->numRows($top_result)==0)return array();
708 - //set up ranges sql query
709 - $sql="SELECT $selOpt `mv_page_id` as `id`, `$mvIndexTableName`.`stream_id`,`start_time`,`end_time`,`view_count`, `wiki_title`, $searchindexTable.`si_text` as `text` ";
710 - if($mvSpokenByInSearchResult)$sql.=",`smw_relations`.`object_title` as `spoken_by` ";
711 - $sql.="FROM `$mvIndexTableName` " .
712 - $join_streams_with_low_ogg_sql .
713 - "JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page` ";
714 - if($mvSpokenByInSearchResult){
715 - $sql.="LEFT JOIN `smw_relations` ON (`mv_mvd_index`.`mv_page_id`=`smw_relations`.`subject_id` " .
716 - "AND `smw_relations`.`relation_title`='Spoken_By') ";
717 - }
718 - $sql.="WHERE ";
719 - $or='';
720 - $sql.='( ';
721 - while($row = $dbr->fetchObject( $top_result )){
722 - //also set initial sranges:
723 - if(!isset($ret_ary[$row->stream_id]))$ret_ary[$row->stream_id]=array();
724 - //insert into return ary:
725 - $insertRow = ($ftq=='')?true:false;
726 - //add that its a top level query to the row:
727 - $row->toplq=true;
728 - MV_Index::insert_merge_range($ret_ary[$row->stream_id], $ret_ary, $row, $insertRow);
729 -
730 - $sql.=$or. " (`$mvIndexTableName`.`stream_id`='{$row->stream_id}' AND " .
731 - '`start_time`>='.$row->start_time.' AND '.
732 - '`end_time`<='.$row->end_time.' ) ';
733 - $or=' OR ';
734 - }
735 - $sql.=') ';
736 - //if($ftq!='')
737 - // $sql.=" AND MATCH (text)
738 - // AGAINST('$ftq' IN BOOLEAN MODE) ";
739 - $sql.="LIMIT {$this->offset}, {$this->limit} ";
740 - }else{
741 - //add the top query to the base query:
742 - $ftq.=$toplq;
743 - $sql = "SELECT $selOpt `mv_page_id` as `id`,`$mvIndexTableName`.`stream_id`,`start_time`,`end_time`, `view_count`,`wiki_title`, $searchindexTable.`si_text` AS `text` ";
744 - if($mvSpokenByInSearchResult)$sql.=",`smw_relations`.`object_title` as `spoken_by` ";
745 - $sql.="FROM `$mvIndexTableName`
746 - JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page`
747 - $join_streams_with_low_ogg_sql
748 - $date_range_join ";
749 -
750 - //include spoken by relation in results (LEFT JOIN should not be *that* costly )
751 - if($mvSpokenByInSearchResult){
752 - $sql.="LEFT JOIN `smw_relations` ON (`mv_mvd_index`.`mv_page_id`=`smw_relations`.`subject_id` " .
753 - "AND `smw_relations`.`relation_title`='Spoken_By') ";
754 - }
755 - $sql.="WHERE ";
756 - $sql.=" ( `{$mvIndexTableName}`.`mvd_type`='ht_en' OR `{$mvIndexTableName}`.`mvd_type`='anno_en') AND" ;
757 - $sql.=" $snq ";
758 - //limit to ht_en & anno_en (for now)
759 -
760 - $two_part_anor='';
761 - if($group_spoken){
762 - $ftq.=$ftq_match;
763 - }else{
764 - if($ftq_match_asql)$sql.=' '.$ftq_match_asql.' ';
765 - if($ftq_match!=''){
766 - $sql.=" MATCH ( $searchindexTable.`si_text` )
767 - AGAINST('$ftq_match' IN BOOLEAN MODE) ";
768 - if($ftq!='')$sql.=' AND ';
769 - }
770 - }
771 - if($ftq!=''){
772 - $sql.=" MATCH ( $searchindexTable.`si_text` )
773 - AGAINST('$ftq' IN BOOLEAN MODE) ";
774 - }
775 - //date range stuff is SLOW when its the only filter (pulls up matches for everything)
776 - if($snq!='' || $ftq!='' && isset($date_range_andor))
777 - $sql.=$date_range_andor;
778 - $sql.=" $date_range_where ";
779 - $sql.="LIMIT {$this->offset}, {$this->limit} ";
780 - }
781 - //echo "SQL:".$sql." \n";
 701+ " $toplq_cat " .
 702+ " $snq " .
 703+ "$date_range_andor $date_range_where " .
 704+ "LIMIT 0, 200";
 705+ //echo "topQ: $sql \n\n";
 706+ $top_result = $dbr->query($sql, 'MV_Index:doFiltersQuery_topQ');
 707+ if($dbr->numRows($top_result)==0)return array();
 708+ //set up ranges sql query
 709+ $sql="SELECT $selOpt `mv_page_id` as `id`, `$mvIndexTableName`.`stream_id`,`start_time`,`end_time`,`view_count`, `wiki_title`, $searchindexTable.`si_text` as `text` ";
 710+ if($mvSpokenByInSearchResult)$sql.=",`smw_relations`.`object_title` as `spoken_by` ";
 711+ $sql.="FROM `$mvIndexTableName` " .
 712+ $join_streams_with_low_ogg_sql .
 713+ "JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page` ";
 714+ if($mvSpokenByInSearchResult){
 715+ $sql.="LEFT JOIN `smw_relations` ON (`mv_mvd_index`.`mv_page_id`=`smw_relations`.`subject_id` " .
 716+ "AND `smw_relations`.`relation_title`='Spoken_By') ";
 717+ }
 718+ $sql.="WHERE ";
 719+ $or='';
 720+ $sql.='( ';
 721+ while($row = $dbr->fetchObject( $top_result )){
 722+ //also set initial sranges:
 723+ if(!isset($ret_ary[$row->stream_id]))$ret_ary[$row->stream_id]=array();
 724+ //insert into return ary:
 725+ $insertRow = ($ftq=='')?true:false;
 726+ //add that its a top level query to the row:
 727+ $row->toplq=true;
 728+ MV_Index::insert_merge_range($ret_ary[$row->stream_id], $ret_ary, $row, $insertRow);
 729+
 730+ $sql.=$or. " (`$mvIndexTableName`.`stream_id`='{$row->stream_id}' AND " .
 731+ '`start_time`>='.$row->start_time.' AND '.
 732+ '`end_time`<='.$row->end_time.' ) ';
 733+ $or=' OR ';
 734+ }
 735+ $sql.=') ';
 736+ //if($ftq!='')
 737+ // $sql.=" AND MATCH (text)
 738+ // AGAINST('$ftq' IN BOOLEAN MODE) ";
 739+ $sql.="LIMIT {$this->offset}, {$this->limit} ";
 740+ }else{
 741+ //add the top query to the base query:
 742+ $ftq.=$toplq;
 743+ $sql = "SELECT $selOpt `mv_page_id` as `id`,`$mvIndexTableName`.`stream_id`,`start_time`,`end_time`, `view_count`,`wiki_title`, $searchindexTable.`si_text` AS `text` ";
 744+ if($mvSpokenByInSearchResult)$sql.=",`smw_relations`.`object_title` as `spoken_by` ";
 745+ $sql.="FROM `$mvIndexTableName`
 746+ JOIN $searchindexTable ON `$mvIndexTableName`.`mv_page_id` = $searchindexTable.`si_page`
 747+ $join_streams_with_low_ogg_sql
 748+ $date_range_join ";
 749+
 750+ //include spoken by relation in results (LEFT JOIN should not be *that* costly )
 751+ if($mvSpokenByInSearchResult){
 752+ $sql.="LEFT JOIN `smw_relations` ON (`mv_mvd_index`.`mv_page_id`=`smw_relations`.`subject_id` " .
 753+ "AND `smw_relations`.`relation_title`='Spoken_By') ";
 754+ }
 755+ $sql.="WHERE ";
 756+ $sql.=" ( `{$mvIndexTableName}`.`mvd_type`='ht_en' OR `{$mvIndexTableName}`.`mvd_type`='anno_en') AND" ;
 757+ $sql.=" $snq ";
 758+ //limit to ht_en & anno_en (for now)
 759+
 760+ $two_part_anor='';
 761+ if($group_spoken){
 762+ $ftq.=$ftq_match;
 763+ }else{
 764+ if($ftq_match_asql)$sql.=' '.$ftq_match_asql.' ';
 765+ if($ftq_match!=''){
 766+ $sql.=" MATCH ( $searchindexTable.`si_text` )
 767+ AGAINST('$ftq_match' IN BOOLEAN MODE) ";
 768+ if($ftq!='')$sql.=' AND ';
 769+ }
 770+ }
 771+ if($ftq!=''){
 772+ $sql.=" MATCH ( $searchindexTable.`si_text` )
 773+ AGAINST('$ftq' IN BOOLEAN MODE) ";
 774+ }
 775+ //date range stuff is SLOW when its the only filter (pulls up matches for everything)
 776+ if($snq!='' || $ftq!='' && isset($date_range_andor))
 777+ $sql.=$date_range_andor;
 778+ $sql.=" $date_range_where ";
 779+ $sql.="LIMIT {$this->offset}, {$this->limit} ";
 780+ }
 781+ //echo "SQL:".$sql." \n";
782782 //die;
783 - $result = $dbr->query($sql, 'MV_Index:doFiltersQuery_base');
784 -
785 - $this->numResults=$dbr->numRows($result);
786 - if($dbr->numRows($result)==0) return array();
787 -
788 - if($mvDo_SQL_CALC_FOUND_ROWS){
789 - $resFound = $dbr->query('SELECT FOUND_ROWS() as `count`;');
790 - $found = $dbr->fetchObject( $resFound );
791 - $this->numResultsFound = $found->count;
792 - }else{
793 - $this->numResultsFound =null;
794 - }
795 -
796 -
797 - //@@TODO hide empty categories (if limit > rows found )
798 -
799 - //group by time range in a given stream
800 -
801 - //while($row = $dbr->fetchObject( $result )){
802 - // $ret_ary[]=$row;
803 - //}
804 - //return $ret_ary;
805 - //group by stream_name & time range:
806 -
807 - //@@todo we should deprecate stream grouping
808 - while($row = $dbr->fetchObject( $result )){
809 - if(!isset($ret_ary[$row->stream_id])){
810 - $ret_ary[$row->stream_id]=array();
811 - }
812 - if(count($ret_ary[$row->stream_id])==0){
813 - $new_srange = array('s'=>$row->start_time,
 783+ $result = $dbr->query($sql, 'MV_Index:doFiltersQuery_base');
 784+
 785+ $this->numResults=$dbr->numRows($result);
 786+ if($dbr->numRows($result)==0) return array();
 787+
 788+ if($mvDo_SQL_CALC_FOUND_ROWS){
 789+ $resFound = $dbr->query('SELECT FOUND_ROWS() as `count`;');
 790+ $found = $dbr->fetchObject( $resFound );
 791+ $this->numResultsFound = $found->count;
 792+ }else{
 793+ $this->numResultsFound =null;
 794+ }
 795+
 796+
 797+ //@@TODO hide empty categories (if limit > rows found )
 798+
 799+ //group by time range in a given stream
 800+
 801+ //while($row = $dbr->fetchObject( $result )){
 802+ // $ret_ary[]=$row;
 803+ //}
 804+ //return $ret_ary;
 805+ //group by stream_name & time range:
 806+
 807+ //@@todo we should deprecate stream grouping
 808+ while($row = $dbr->fetchObject( $result )){
 809+ if(!isset($ret_ary[$row->stream_id])){
 810+ $ret_ary[$row->stream_id]=array();
 811+ }
 812+ if(count($ret_ary[$row->stream_id])==0){
 813+ $new_srange = array('s'=>$row->start_time,
814814 'e'=> $row->end_time,
815815 'rows'=>array($row));
816 - $ret_ary[$row->stream_id][]=$new_srange;
817 - }else{
818 - MV_Index::insert_merge_range($ret_ary[$row->stream_id], $ret_ary, $row);
819 - }
820 - }
821 - //throw out empty top level ranges
822 - foreach($ret_ary as &$stream_set){
823 - foreach($stream_set as $k=> &$srange){
824 - if(count($srange['rows'])==0){
825 - //print "throw out: ". $srange['s'] . $srange['e'];
826 - unset($stream_set[$k]);
827 - }
828 - }
829 - }
830 - //do category & bill lookup for search result ranges
831 - if($mvCategoryInSearchResult || $mvBillInSearchResult){
832 - $sql="SELECT {$dbr->tableName('categorylinks')}.`cl_to`, `mv_mvd_index`.`stream_id`,
833 - `$mvIndexTableName`.`start_time`,
 816+ $ret_ary[$row->stream_id][]=$new_srange;
 817+ }else{
 818+ MV_Index::insert_merge_range($ret_ary[$row->stream_id], $ret_ary, $row);
 819+ }
 820+ }
 821+ //throw out empty top level ranges
 822+ foreach($ret_ary as &$stream_set){
 823+ foreach($stream_set as $k=> &$srange){
 824+ if(count($srange['rows'])==0){
 825+ //print "throw out: ". $srange['s'] . $srange['e'];
 826+ unset($stream_set[$k]);
 827+ }
 828+ }
 829+ }
 830+ //do category & bill lookup for search result ranges
 831+ if($mvCategoryInSearchResult || $mvBillInSearchResult){
 832+ $sql="SELECT {$dbr->tableName('categorylinks')}.`cl_to`, `mv_mvd_index`.`stream_id`,
 833+ `$mvIndexTableName`.`start_time`,
834834 `$mvIndexTableName`.`end_time`,
835835 {$dbr->tableName('smw_relations')}.`object_title` as bill_to";
836836 $sql.=" FROM `$mvIndexTableName`
837 - LEFT JOIN {$dbr->tableName('categorylinks')} ON (`$mvIndexTableName`.`mv_page_id` = {$dbr->tableName('categorylinks')}.`cl_from`)
 837+ LEFT JOIN {$dbr->tableName('categorylinks')} ON (`$mvIndexTableName`.`mv_page_id` = {$dbr->tableName('categorylinks')}.`cl_from`)
838838 LEFT JOIN {$dbr->tableName('smw_relations')} ON (
839839 `$mvIndexTableName`.`mv_page_id` = {$dbr->tableName('smw_relations')}.`subject_id` AND
840 - {$dbr->tableName('smw_relations')}.`relation_title`='bill' ) ";
 840+ {$dbr->tableName('smw_relations')}.`relation_title`='bill' ) ";
841841 //generate stream_id, range sets
842842 $sql.=" WHERE `$mvIndexTableName`.`mvd_type`='Anno_en' AND (";
843843 $or='';
844844 foreach($ret_ary as $stream_id=>$rangeSet){
845845 foreach($rangeSet as $range){
846 - $sql.=$or . "( `$mvIndexTableName`.`stream_id`='$stream_id'";
 846+ $sql.=$or . "( `$mvIndexTableName`.`stream_id`='$stream_id'";
847847 $sql.=" AND `start_time` <= '" . $range['s']."'";
848848 $sql.=" AND `end_time` >= '" . $range['e'] . '\' ) ';
849 - $or = ' OR ';
 849+ $or = ' OR ';
850850 }
851851 }
852 - $sql.=') LIMIT 0, 200';
853 - //merge category info back into base results:
 852+ $sql.=') LIMIT 0, 200';
 853+ //merge category info back into base results:
854854 $result = $dbr->query($sql, 'MV_Index:doCategorySearchResult');
855 - while($cl_row = $dbr->fetchObject( $result )){
856 - foreach($ret_ary[$cl_row->stream_id] as &$range){
 855+ while($cl_row = $dbr->fetchObject( $result )){
 856+ foreach($ret_ary[$cl_row->stream_id] as &$range){
857857 foreach($range['rows'] as &$result_row){
858 - if($result_row->start_time <= $cl_row->end_time &&
 858+ if($result_row->start_time <= $cl_row->end_time &&
859859 $result_row->end_time >= $cl_row->start_time){
860 - if($cl_row->cl_to)
 860+ if($cl_row->cl_to)
861861 $result_row->categories[$cl_row->cl_to]=true;
862862 if($cl_row->bill_to)
863 - $result_row->bills[$cl_row->bill_to]=true;
864 - }
 863+ $result_row->bills[$cl_row->bill_to]=true;
 864+ }
865865 }
866866 }
867867 }
868 - }
869 - //print "<pre>";
870 - //print_r($ret_ary);
871 - //die;
872 - return $ret_ary;
873 - }*/
874 - function numResultsFound(){
875 - if(isset($this->numResultsFound)){
876 - return $this->numResultsFound;
877 - }else{
878 - return null;
879 - }
880 - }
881 - function numResults(){
882 - if(isset($this->numResults))
883 - return $this->numResults;
884 - return 0;
885 - }
886 - /*inserts search result into proper range and stream */
887 - function insert_merge_range(& $sranges, &$ret_ary, $row, $doRowInsert=true){
888 - foreach($sranges as & $srange){
889 - //skip if srange row 0 has same mvd (topq already inserted)
890 - //if($srange['rows'][0]->id==$row->id )continue ;
891 - //check if current $srow encapsulate and insert
892 - if($row->start_time <= $srange['s'] && $row->end_time >= $srange['e']){
893 - $srange['s']= $row->start_time;
894 - $srange['e']= $row->end_time;
895 - if($doRowInsert)
896 - $srange['rows'][]=$row;
897 - //grab rows from any other stream segment that fits in new srange:
898 - foreach($ret_ary as &$sbrange){
899 - if($row->start_time <= $sbrange['s'] && $row->end_time >= $sbrange['e']){
900 - foreach($sbrange['rows'] as $sbrow){
901 - $srange['rows'][]=$sbrow;
902 - }
903 - unset($sbrange);
904 - }
905 - }
906 - return ;
907 - }//else if current fits into srange insert
908 - else if($row->start_time >= $srange['s'] && $row->end_time <= $srange['e']){
909 - if($doRowInsert)
910 - $srange['rows'][]=$row;
911 - return ;
912 - }
913 - //make sure the current row does not already exist:
914 - foreach($srange['rows'] as $sbrow){
915 - if($sbrow->wiki_title == $row->wiki_title){
916 - return ;
917 - }
918 - }
919 - }
 868+ }
 869+ //print "<pre>";
 870+ //print_r($ret_ary);
 871+ //die;
 872+ return $ret_ary;
 873+ }*/
 874+ function numResultsFound(){
 875+ if(isset($this->numResultsFound)){
 876+ return $this->numResultsFound;
 877+ }else{
 878+ return null;
 879+ }
 880+ }
 881+ function numResults(){
 882+ if(isset($this->numResults))
 883+ return $this->numResults;
 884+ return 0;
 885+ }
 886+ /*inserts search result into proper range and stream */
 887+ function insert_merge_range(& $sranges, &$ret_ary, $row, $doRowInsert=true){
 888+ foreach($sranges as & $srange){
 889+ //skip if srange row 0 has same mvd (topq already inserted)
 890+ //if($srange['rows'][0]->id==$row->id )continue ;
 891+ //check if current $srow encapsulate and insert
 892+ if($row->start_time <= $srange['s'] && $row->end_time >= $srange['e']){
 893+ $srange['s']= $row->start_time;
 894+ $srange['e']= $row->end_time;
 895+ if($doRowInsert)
 896+ $srange['rows'][]=$row;
 897+ //grab rows from any other stream segment that fits in new srange:
 898+ foreach($ret_ary as &$sbrange){
 899+ if($row->start_time <= $sbrange['s'] && $row->end_time >= $sbrange['e']){
 900+ foreach($sbrange['rows'] as $sbrow){
 901+ $srange['rows'][]=$sbrow;
 902+ }
 903+ unset($sbrange);
 904+ }
 905+ }
 906+ return ;
 907+ }//else if current fits into srange insert
 908+ else if($row->start_time >= $srange['s'] && $row->end_time <= $srange['e']){
 909+ if($doRowInsert)
 910+ $srange['rows'][]=$row;
 911+ return ;
 912+ }
 913+ //make sure the current row does not already exist:
 914+ foreach($srange['rows'] as $sbrow){
 915+ if($sbrow->wiki_title == $row->wiki_title){
 916+ return ;
 917+ }
 918+ }
 919+ }
920920 //just add as new srange
921 - $new_srange = array('s'=>$row->start_time,
 921+ $new_srange = array('s'=>$row->start_time,
922922 'e'=> $row->end_time);
923923 if($doRowInsert){
924924 $new_srange['rows']=array($row);
925925 }else{
926926 $new_srange['rows']=array();
927927 }
928 - $ret_ary[$row->stream_id][]=$new_srange;
929 - }
930 - function getMVDbyId($id, $fields='*'){
931 - global $mvIndexTableName;
932 - $dbr =& wfGetDB(DB_SLAVE);
933 - $result = $dbr->select( $mvIndexTableName, $fields,
934 - array('mv_page_id'=>$id) );
935 - if($dbr->numRows($result)==0){
936 - return array();
937 - }else{
938 - //(mvd->id got renamed to more accurate mv_page_id)
939 - $row = $dbr->fetchObject( $result );
940 - $row->id=$row->mv_page_id;
941 - return $row;
942 - }
943 - }
944 - function getMVDbyTitle($title_key, $fields='*'){
945 - global $mvIndexTableName;
946 - $dbr =& wfGetDB(DB_SLAVE);
947 - $result = $dbr->select( $mvIndexTableName, $fields,
948 - array('wiki_title'=>$title_key) );
949 - if($dbr->numRows($result)==0){
950 - return null;
951 - }else{
952 - $row = $dbr->fetchObject( $result );
953 - $row->id=$row->mv_page_id;
954 - return $row;
955 - }
956 - }
957 - function update_index_title($old_title, $new_title){
958 - global $mvIndexTableName;
 928+ $ret_ary[$row->stream_id][]=$new_srange;
 929+ }
 930+ function getMVDbyId($id, $fields='*'){
 931+ global $mvIndexTableName;
 932+ $dbr =& wfGetDB(DB_SLAVE);
 933+ $result = $dbr->select( $mvIndexTableName, $fields,
 934+ array('mv_page_id'=>$id) );
 935+ if($dbr->numRows($result)==0){
 936+ return array();
 937+ }else{
 938+ //(mvd->id got renamed to more accurate mv_page_id)
 939+ $row = $dbr->fetchObject( $result );
 940+ $row->id=$row->mv_page_id;
 941+ return $row;
 942+ }
 943+ }
 944+ function getMVDbyTitle($title_key, $fields='*'){
 945+ global $mvIndexTableName;
 946+ $dbr =& wfGetDB(DB_SLAVE);
 947+ $result = $dbr->select( $mvIndexTableName, $fields,
 948+ array('wiki_title'=>$title_key) );
 949+ if($dbr->numRows($result)==0){
 950+ return null;
 951+ }else{
 952+ $row = $dbr->fetchObject( $result );
 953+ $row->id=$row->mv_page_id;
 954+ return $row;
 955+ }
 956+ }
 957+ function update_index_title($old_title, $new_title){
 958+ global $mvIndexTableName;
959959
960 - //make sure the new title is valid:
961 - $mvTitle = new MV_Title( $new_title );
962 - if( $mvTitle->validRequestTitle() ){
963 - //build the update row
964 - $update_ary = array(
 960+ //make sure the new title is valid:
 961+ $mvTitle = new MV_Title( $new_title );
 962+ if( $mvTitle->validRequestTitle() ){
 963+ //build the update row
 964+ $update_ary = array(
965965 'wiki_title'=>$mvTitle->getWikiTitle(),
966966 'mvd_type'=>$mvTitle->getTypeMarker(),
967 - 'stream_id'=>$mvTitle->getStreamId(),
 967+ 'stream_id'=>$mvTitle->getStreamId(),
968968 'start_time'=>$mvTitle->getStartTimeSeconds(),
969969 'end_time'=>$mvTitle->getEndTimeSeconds() );
970 - //get old row
971 - $mvd_row = MV_Index::getMVDbyTitle( $old_title );
972 - $dbw =& wfGetDB(DB_WRITE);
973 - $dbw->update($mvIndexTableName, $update_ary,
974 - array('mv_page_id'=>$mvd_row->mv_page_id));
975 - }else{
976 - //print "NOT VALID MOVE";
977 - //@@todo better error handling (tyring to move a MVD data into bad request form)
978 - throw new MWException("Invalid Page name for MVD namespace \n");
979 - }
980 - }
981 - /*
982 - * update_index_page updates the `mv_mvd_index` table (on MVD namespace saves)
983 - */
984 - function update_index_page(&$article, &$text){
985 - global $mvgIP, $mvIndexTableName;
986 - //check static or $this usage context
987 - //use mv title to split up the values:
 970+ //get old row
 971+ $mvd_row = MV_Index::getMVDbyTitle( $old_title );
 972+ $dbw =& wfGetDB(DB_WRITE);
 973+ $dbw->update($mvIndexTableName, $update_ary,
 974+ array('mv_page_id'=>$mvd_row->mv_page_id));
 975+ }else{
 976+ //print "NOT VALID MOVE";
 977+ //@@todo better error handling (tyring to move a MVD data into bad request form)
 978+ throw new MWException("Invalid Page name for MVD namespace \n");
 979+ }
 980+ }
 981+ /*
 982+ * update_index_page updates the `mv_mvd_index` table (on MVD namespace saves)
 983+ */
 984+ function update_index_page(&$article, &$text){
 985+ global $mvgIP, $mvIndexTableName;
 986+ //check static or $this usage context
 987+ //use mv title to split up the values:
988988 $mvTitle = new MV_Title($article->mTitle->getDBkey());
989 - //print "Wiki title: " . $mvTitle->getWikiTitle();
990 - //fist check if an mvd entry for this stream already exists:
 989+ //print "Wiki title: " . $mvTitle->getWikiTitle();
 990+ //fist check if an mvd entry for this stream already exists:
991991 $mvd_row = MV_Index::getMVDbyTitle( $mvTitle->getWikiTitle() );
992992 //set up the insert values:
993993 $insAry = array(
994994 'mv_page_id'=>$article->mTitle->getArticleID(),
995995 'wiki_title'=>$mvTitle->getWikiTitle(),
996996 'mvd_type'=>$mvTitle->getTypeMarker(),
997 - 'stream_id'=>$mvTitle->getStreamId(),
 997+ 'stream_id'=>$mvTitle->getStreamId(),
998998 'start_time'=>$mvTitle->getStartTimeSeconds(),
999 - 'end_time'=>$mvTitle->getEndTimeSeconds(),
 999+ 'end_time'=>$mvTitle->getEndTimeSeconds(),
10001000 );
1001 -
1002 - $dbw =& wfGetDB(DB_WRITE);
1003 - if(count($mvd_row)==0){
1004 - return $dbw->insert( $mvIndexTableName , $insAry);
1005 - }else{
1006 - $dbw->update($mvIndexTableName, $insAry,
1007 - array('mv_page_id'=>$mvd_row->mv_page_id));
1008 - }
1009 - }
1010 - }
1011 -?>
 1001+
 1002+ $dbw =& wfGetDB(DB_WRITE);
 1003+ if(count($mvd_row)==0){
 1004+ return $dbw->insert( $mvIndexTableName , $insAry);
 1005+ }else{
 1006+ $dbw->update($mvIndexTableName, $insAry,
 1007+ array('mv_page_id'=>$mvd_row->mv_page_id));
 1008+ }
 1009+ }
 1010+}
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php
@@ -4,7 +4,7 @@
55 *
66 * All Metavid Wiki code is Released Under the GPL2
77 * for more info visit http:/metavid.ucsc.edu/code
8 - *
 8+ *
99 * overwrites the existing special search to add in metavid specific features
1010 */
1111 if (!defined('MEDIAWIKI'))
@@ -12,7 +12,7 @@
1313
1414 class MediaSearch extends SpecialPage{
1515 function __construct(){
16 - parent::__construct('MediaSearch');
 16+ parent::__construct('MediaSearch');
1717 }
1818 }
1919 function wfSpecialMediaSearch(){
@@ -26,16 +26,16 @@
2727 global $wgOut, $wgRequest;
2828 mvfAddHTMLHeader('search');
2929 $MvSpecialSearch = new MV_SpecialMediaSearch();
30 - $MvSpecialSearch->doSearchPage( $wgRequest->getVal('search') );
 30+ $MvSpecialSearch->doSearchPage( $wgRequest->getVal('search') );
3131 SpecialPage :: SpecialPage('Search');
3232 }
3333 }
3434 /*
35 - * simple/quick implementation ...
36 - * @@todo future version should be better integrated with semantic wiki and or
 35+ * simple/quick implementation ...
 36+ * @@todo future version should be better integrated with semantic wiki and or
3737 * an external scalable search engine ie sphinx or lucene
38 - *
39 - * example get request: filter 0, type match, value = wars
 38+ *
 39+ * example get request: filter 0, type match, value = wars
4040 * ?f[0]['t']=m&f[0]['v']=wars
4141 */
4242 class MV_SpecialMediaSearch {
@@ -45,18 +45,18 @@
4646 'spoken_by',
4747 'category',
4848 'date_range', //search in a given date range
49 - //not yet active:
 49+ //not yet active:
5050 //'stream_name', //search within a particular stream
5151 //'layers' //specify a specific meta-layer set
52 - //'smw_property'
 52+ //'smw_property'
5353 //'smw_property_numeric'
54 -
 54+
5555 );
5656 var $sel_filter_andor = array (
5757 'and',
5858 'or',
5959 'not',
60 -
 60+
6161 );
6262 var $unified_term_search = '';
6363 var $adv_search = false;
@@ -69,14 +69,14 @@
7070
7171 var $limit = 20;
7272 var $offset = 0;
73 - var $order = 'relevent';
 73+ var $order = 'relevant';
7474
7575 function doSearchPage($term = '') {
7676 global $wgRequest, $wgOut, $wgUser;
7777 $this->setUpFilters();
7878 //do the search
7979 $this->doSearch();
80 - //page control:
 80+ //page control:
8181 $this->outputInlineHeader = false;
8282 if ($wgRequest->getVal('seq_inline') == 'true') {
8383 $this->outputContainer = false;
@@ -87,9 +87,9 @@
8888 //@@todo cleaner exit
8989 //exit ();
9090 } else {
91 - //add nessesary js to wgOut:
 91+ //add nessesary js to wgOut:
9292 mvfAddHTMLHeader('search');
93 - //add the search placeholder
 93+ //add the search placeholder
9494 //$wgOut->addWikiText( wfMsg( 'searchresulttext' ) );
9595 $sk = $wgUser->getSkin();
9696 $title = Title :: MakeTitle(NS_SPECIAL, 'Search');
@@ -111,7 +111,7 @@
112112 if ($doDSC)
113113 $wgOut->addHTML($this->dynamicSearchControl());
114114
115 - //$wgOut->addHTML($this->getResultsBar());
 115+ //$wgOut->addHTML($this->getResultsBar());
116116 $wgOut->addHTML($this->getUnifiedResultsHTML());
117117 }
118118 }
@@ -121,20 +121,20 @@
122122
123123 $o = "<div id=\"msms_form_search_row\" class=\"form_search_row\">
124124 <form id=\"mv_media_search\" method=\"get\" " .
125 - "action=\"$action\">\n
 125+ "action=\"$action\">\n
126126 <input type=\"hidden\" id=\"advs\" name=\"advs\" value=\"";
127127 $o .= ($this->adv_search) ? '1' : '0';
128 - $o .= "\">
 128+ $o .= "\">
129129 <span class=\"advs_basic\" style=\"display:";
130130 $o .= ($this->adv_search) ? 'none' : 'inline';
131131 $o .= "\">
132 - <input type=\"text\" class=\"searchField\" name=\"mv_search\" id=\"searchInput\" value=\"{$this->unified_term_search}\"/>
 132+ <input type=\"text\" class=\"searchField\" name=\"mv_search\" id=\"searchInput\" value=\"{$this->unified_term_search}\"/>
133133 </span>
134134 <span class=\"advs_adv\" id=\"adv_filters\" style=\"display:";
135135 $o .= ($this->adv_search) ? 'inline' : 'none';
136 - $o .= "\">
 136+ $o .= "\">
137137 {$this->list_active_filters()}
138 - </span>
 138+ </span>
139139 <button class=\"grey_button\" type=\"submit\"><span>&nbsp;&nbsp; " . wfMsg('mv_video_search') . " &nbsp;&nbsp;</span></button>
140140 <a href=\"javascript:mv_toggle_advs()\" class=\"advanced_search_tag\">
141141 <span class=\"advs_basic\" style=\"display:";
@@ -155,7 +155,7 @@
156156 function setupFilters($defaultType = 'empty', $opt = null) {
157157 global $wgRequest;
158158
159 - //set advs flag:
 159+ //set advs flag:
160160 $advs = $wgRequest->getVal('advs');
161161 $this->adv_search = ($advs == '' || $advs == 0) ? false : true;
162162
@@ -173,14 +173,14 @@
174174 );
175175 $this->unified_term_search = $term;
176176 //if not doing advanced search we are done
177 -
 177+
178178 if (!$this->adv_search)
179179 return;
180180 }
181181
182182 //print "CUR un: " . $this->unified_term_search;
183183
184 - //first try any key titles:
 184+ //first try any key titles:
185185 $title_str = $wgRequest->getVal('title');
186186 $tp = split('/', $title_str);
187187 if (count($tp) == 3) {
@@ -200,7 +200,7 @@
201201 if (isset ($_GET['f'])) {
202202 $this->filters = $_GET['f'];
203203 //@@todo more input proccessing
204 - //grab unified_term_search if not already listed:
 204+ //grab unified_term_search if not already listed:
205205 if ($this->unified_term_search == '') {
206206 foreach ($this->filters as $f) {
207207 if ($f['t'] == 'match') {
@@ -210,7 +210,7 @@
211211 }else if($f['t']=='spoken_by'){
212212 $this->unified_term_search = $f['v'];
213213 }
214 -
 214+
215215 }
216216 }
217217 } else {
@@ -234,7 +234,7 @@
235235 break;
236236 }
237237 }
238 - }
 238+ }
239239 }
240240 function doSearch($log_search=true) {
241241 global $mvEnableSearchDigest, $mvSearchDigestTable;
@@ -244,15 +244,15 @@
245245 if ($mvEnableSearchDigest && $wgRequest->getVal('tl') != '1' && $log_search) {
246246 $dbw = & wfGetDB(DB_WRITE);
247247 $dbr = & wfGetDB(DB_READ);
248 - //print "DO SEARCH FOR: ". $this->getFilterDesc($query_key = true) . "\n";
 248+ //print "DO SEARCH FOR: ". $this->getFilterDesc($query_key = true) . "\n";
249249 //print var_dump(debug_backtrace());
250 -
251 - //@@todo non-blocking insert... is that supported in mysql/php?
 250+
 251+ //@@todo non-blocking insert... is that supported in mysql/php?
252252 $dbw->insert($mvSearchDigestTable, array (
253253 'query_key' => $this->getFilterDesc($query_key = true
254254 ), 'time' => time()), 'Database::searchDigestInsert');
255255 //make sure the query key exists and is updated
256 - //@@todo I think we can do a INSERT IF not found here?
 256+ //@@todo I think we can do a INSERT IF not found here?
257257 $res = $dbr->select('mv_query_key_lookup', array (
258258 'filters'
259259 ), array (
@@ -264,7 +264,7 @@
265265 ), 'filters' => serialize($this->filters)));
266266 }
267267 }
268 -
 268+
269269 $this->results = $mvIndex->doUnifiedFiltersQuery($this->filters);
270270 $this->num = $mvIndex->numResults();
271271 $this->numResultsFound = $mvIndex->numResultsFound();
@@ -299,7 +299,7 @@
300300
301301 $o .= '<h5 class="search_results_header">' . $this->getFilterDesc() . '</h5>';
302302
303 - $o .= '<div id="resultsArea">
 303+ $o .= '<div id="resultsArea">
304304 <ul id="metaResults">';
305305 if (count($this->results) == 0) {
306306 $o .= '<h2><span class="mw-headline">' . wfMsg('mv_search_no_results') . '</span></h2>';
@@ -323,13 +323,13 @@
324324 $o .= '<li class="prevnext">' . $prevnext . '</li>';
325325 }
326326
327 - //make rss link:
 327+ //make rss link:
328328 $sTitle = Title :: MakeTitle(NS_SPECIAL, 'MvExportSearch');
329329 $o .= '<li class="rss">';
330330 $o .= $sk->makeKnownLinkObj($sTitle, 'RSS', $this->get_httpd_filters_query());
331331 $o .= '</li>';
332332
333 - //make miro link:
 333+ //make miro link:
334334 $o .= '<li class="subscribe"><a href="http://subscribe.getMiro.com/?url1=' .
335335 'http%3A%2F%2F' . $_SERVER['HTTP_HOST'] . htmlspecialchars($sTitle->escapeLocalURL($this->get_httpd_filters_query())) . '" ' .
336336 'title="Subscribe with Miro"><img src="' . $wgStylePath . '/mvpcf/images/button_subscribe.png" alt="Miro Video Player" border="0" /></a></li>';
@@ -337,15 +337,15 @@
338338 //check order prefrence:
339339 $br='<br>';
340340 $enddash='';
341 - foreach (array ('relevent','recent','viewed') as $type) {
 341+ foreach (array ('relevant','recent','viewed') as $type) {
342342 if ($this->order == $type) {
343343 $o .= $enddash.'<li class="relevant">'.$br . wfMsg('mv_most_' . $type) . '</li>' ;
344344 } else {
345345 $q_req = $this->get_httpd_filters_query();
346346 if($wgRequest->getVal('limit')!='' || $wgRequest->getVal('order')!='')
347347 $q_req.='&'.http_build_query(array('limit'=>$this->limit, 'offset'=>$this->offset));
348 - $q_req.='&order='.$type;
349 - $o .= $enddash.'<li class="relevant">'.$br .$sk->makeKnownLinkObj(SpecialPage :: getTitleFor('MediaSearch'),
 348+ $q_req.='&order='.$type;
 349+ $o .= $enddash.'<li class="relevant">'.$br .$sk->makeKnownLinkObj(SpecialPage :: getTitleFor('MediaSearch'),
350350 wfMsg('mv_most_' . $type), $q_req) . '</li>';
351351 }
352352 $br='';
@@ -353,11 +353,11 @@
354354 }
355355 $o .= '</ul>';
356356
357 - //output results:
 357+ //output results:
358358 //collect categories and people for sidebarbucket
359359 $sideBarLinkBucket = array ();
360360 $o .= ' <ul id="results">';
361 - foreach ($this->results as $inx => & $mvd) {
 361+ foreach ($this->results as $inx => & $mvd) {
362362 $mvTitle = new MV_Title($mvd->wiki_title);
363363 $mvd_cnt_links = '';
364364 if (isset ($mvd->spoken_by)) {
@@ -391,20 +391,20 @@
392392 assoc_array_increment($sideBarLinkBucket, 'bill', $bill_id);
393393 }
394394 }
395 - //link directly to the current range:
 395+ //link directly to the current range:
396396 $mvStreamTitle = Title :: MakeTitle(MV_NS_STREAM, $mvTitle->getNearStreamName($extra_range = '0'));
397 - //$mvTitle->getStreamName() .'/'.$mvTitle->getStartTime() .'/'. $mvTitle->getEndTime() );
 397+ //$mvTitle->getStreamName() .'/'.$mvTitle->getStartTime() .'/'. $mvTitle->getEndTime() );
398398 $mvd_text = $mvd->text;
399399
400400 $o .= '<li class="result">
401401 <span class="vid_img" id="mvimg_' . htmlspecialchars($mvd->id) . '">
402 - ' . $sk->makeKnownLinkObj($mvStreamTitle,
403 - '<img alt="image for ' . htmlspecialchars($mvTitle->getStreamNameText()) .
 402+ ' . $sk->makeKnownLinkObj($mvStreamTitle,
 403+ '<img alt="image for ' . htmlspecialchars($mvTitle->getStreamNameText()) .
404404 ' ' . $mvTitle->getTimeDesc() . '" src="' . $mvTitle->getStreamImageURL('small') .
405 - '"/>') . '
 405+ '"/>') . '
406406 </span>
407407 <div class="result_description">
408 - <h4>' .
 408+ <h4>' .
409409 $sk->makeKnownLinkObj($mvStreamTitle, $mvTitle->getStreamNameText() .
410410 ' :: ' . $mvTitle->getTimeDesc()) .
411411 '</h4>
@@ -421,9 +421,9 @@
422422 wfMsg('mv_play_inline') . '</a></span>
423423 </div>
424424 </li>';
425 - }
 425+ }
426426 $o .= '</ul>';
427 - //add in prev-next at bottom too:
 427+ //add in prev-next at bottom too:
428428 $o .= '<li class="prevnext">' . $prevnext . '</li>';
429429 $o .= '</div>';
430430 if(!$show_sidebar)return $o;
@@ -437,7 +437,7 @@
438438 $first_block = ' first_block';
439439 $matches = 0;
440440 $person_out_ary=array();
441 - $person_out = MV_SpecialMediaSearch :: auto_complete_person($this->unified_term_search, 3, 'person_html', $matches, $person_out_ary);
 441+ $person_out = MV_SpecialMediaSearch :: auto_complete_person($this->unified_term_search, 3, 'person_html', $matches, $person_out_ary);
442442 if ($person_out != '' || count($sideBarLinkBucket['person']) != 0) {
443443 //for now don't include({$matches})
444444 $o .= "<div class=\"block{$first_block}\">
@@ -460,10 +460,10 @@
461461 $o .= '</div>';
462462 $first_block = '';
463463 }
464 - //get categories
 464+ //get categories
465465 $category_out = MV_SpecialMediaSearch :: auto_complete_search_categories($this->unified_term_search, 3, 'block_html', $matches);
466466 if ($category_out != '' || count($sideBarLinkBucket['category']) != 0) {
467 - $o .= '<div class="block'.htmlspecialchars($first_block).'\">
 467+ $o .= '<div class="block'.htmlspecialchars($first_block).'\">
468468 <h6>' . wfMsg('mv_category_results') . '</h6>
469469 </div>';
470470 $o .= '<div class="block wide_block">' . $category_out;
@@ -504,7 +504,7 @@
505505 $o .= '</div>';
506506 $first_block = '';
507507 }
508 - //intrest out is just simple title matching (for now)
 508+ //intrest out is just simple title matching (for now)
509509 $intrest_out = MV_SpecialMediaSearch :: auto_complete_category('Interest_Group', $this->unified_term_search, 3, 'block_html', $matches);
510510 if ($intrest_out != '') {
511511 $o .= "<div class=\"block{$first_block}\">
@@ -525,7 +525,7 @@
526526 if ($this->outputContainer)
527527 $o .= '<div id="mv_search_results_container">';
528528
529 - //for each stream range:
 529+ //for each stream range:
530530 if (count($this->results) == 0) {
531531 $o .= '<h2><span class="mw-headline">' . wfMsg('mv_search_no_results') . '</span></h2>';
532532 if ($this->outputContainer)
@@ -543,7 +543,7 @@
544544 //media pagging: (only display if we have num of results > limit
545545 $prevnext = mvViewPrevNext($this->offset, $this->limit, SpecialPage :: getTitleFor('MediaSearch'), $this->get_httpd_filters_query(), ($this->num < $this->limit));
546546 $o .= "<br /><span id=\"mv_search_pagging\">{$prevnext}</span>\n";
547 - //add the rss link:
 547+ //add the rss link:
548548 $sTitle = Title :: MakeTitle(NS_SPECIAL, 'MvExportSearch');
549549 $o .= '<span style="float:right;">';
550550 $o .= $sk->makeKnownLinkObj($sTitle, '<img border="0" src="' . $mvgScriptPath . '/skins/images/feed-icon-28x28.png">', $this->get_httpd_filters_query());
@@ -561,16 +561,16 @@
562562 $matches++;
563563 $mvTitle = new MV_Title($mvd->wiki_title);
564564
565 - //retrieve only the first article:
 565+ //retrieve only the first article:
566566 //$title = Title::MakeTitle(MV_NS_MVD, $mvd->wiki_title);
567 - //$article = new Article($title);
 567+ //$article = new Article($title);
568568
569569 $bgcolor = MV_Overlay :: getMvdBgColor($mvd);
570 - //output indent if not the first and count more than one
 570+ //output indent if not the first and count more than one
571571 if (count($srange['rows']) != 1 && $inx != 0)
572572 $mvd_out .= '&nbsp; &nbsp; &nbsp; &nbsp;';
573 - //'<img src="'. $mvgScriptPath . '/skins/images/film.png">'
574 - //$mvd_out .= '<div class="mv_rtdesc" title="' . wfMsg('mv_expand_play') . '" '.
 573+ //'<img src="'. $mvgScriptPath . '/skins/images/film.png">'
 574+ //$mvd_out .= '<div class="mv_rtdesc" title="' . wfMsg('mv_expand_play') . '" '.
575575 // '> ';
576576 $mvd_out .= '<img style="float:left;width:84px;cursor:pointer;border:solid #' .htmlspecialchars($bgcolor) . '" ' .
577577 ' onclick="mv_ex(\'' . htmlspecialchars($mvd->id) . '\')" width="80" height="60" src="' . htmlspecialchars($mvTitle->getStreamImageURL('icon')) . '">';
@@ -598,22 +598,22 @@
599599 '</a>' .
600600 '&nbsp;&nbsp;';
601601 //output control links:
602 - //make stream title link:
 602+ //make stream title link:
603603 $mvStreamTitle = Title :: MakeTitle(MV_NS_STREAM, $mvTitle->getNearStreamName());
604604 //$mvTitle->getStreamName() .'/'.$mvTitle->getStartTime() .'/'. $mvTitle->getEndTime() );
605605 $mvd_cnt_links .= $sk->makeKnownLinkObj($mvStreamTitle, '<img border="1" src="' . $mvgScriptPath . '/skins/images/run_mv_stream.png"> ' . wfMsg('mv_improve_transcript'), '', '', '', '', ' title="' . htmlspecialchars(wfMsg('mv_view_in_stream_interface')) . '" ');
606606 $mvd_cnt_links .= '<br>';
607607 //$title = MakeTitle::()
608 - //don't inclue link to wiki page (too confusing)
 608+ //don't inclue link to wiki page (too confusing)
609609 //$mvd_out .='&nbsp;';
610610 $mvdTitle = Title :: MakeTitle(MV_NS_MVD, $mvd->wiki_title);
611 - //$mvd_out .= $sk->makeKnownLinkObj($mvdTitle, '<img border="0" src="' . $mvgScriptPath . '/skins/images/run_mediawiki.png">', '', '', '', '', ' title="' . wfMsg('mv_view_wiki_page') . '" ');
 611+ //$mvd_out .= $sk->makeKnownLinkObj($mvdTitle, '<img border="0" src="' . $mvgScriptPath . '/skins/images/run_mediawiki.png">', '', '', '', '', ' title="' . wfMsg('mv_view_wiki_page') . '" ');
612612
613613 $mvd_out .= '<span id="mvr_desc_' . htmlspecialchars($mvd->id) . '">';
614614
615615 if (!isset ($mvd->toplq))
616616 $mvd->toplq = false;
617 - //output short desc send partial regEx:
 617+ //output short desc send partial regEx:
618618 if (!$mvd->toplq) {
619619 $mvd_out .= $this->termHighlight($mvd->text, implode('|', $this->getTerms()));
620620 } else {
@@ -626,7 +626,7 @@
627627 }
628628 //@@todo parse category info if present
629629 $cat_html = '';
630 - //run via parser to add in Category info:
 630+ //run via parser to add in Category info:
631631 $parserOptions = ParserOptions :: newFromUser($wgUser);
632632 $parserOptions->setEditSection(false);
633633 $parserOptions->setTidy(true);
@@ -643,10 +643,10 @@
644644 $mvd_out .= $cat_html;
645645
646646 $mvd_out .= (count($srange['rows']) - 1 == 1) ? wfMsg('mv_match_text_one') : wfMsg('mv_match_text', count($srange['rows']) - 1);
647 - //$wgOut->addCategoryLinks( $parserOutput->getCategories() );
 647+ //$wgOut->addCategoryLinks( $parserOutput->getCategories() );
648648 //$cat_html = $sk->getCategories();
649649 //empty out the categories
650 - //$wgOut->mCategoryLinks = array();
 650+ //$wgOut->mCategoryLinks = array();
651651 }
652652 $mvd_out .= '</span>';
653653 $mvd_out .= '<br>' . $mvd_cnt_links;
@@ -654,12 +654,12 @@
655655 $mvd_out .= '<div id="mvr_' . htmlspecialchars($mvd->id) . '" style="display:none;background:#' . htmlspecialchars($bgcolor) . ';" ></div>';
656656 }
657657 $stream_out .= $mvd_out;
658 - /*if(count($srange['rows'])!=1){
659 - $stream_out .= '&nbsp;' . $cat_html . ' In range:' .
 658+ /*if(count($srange['rows'])!=1){
 659+ $stream_out .= '&nbsp;' . $cat_html . ' In range:' .
660660 seconds2ntp($srange['s']) . ' to ' . seconds2ntp($srange['e']) .
661661 wfMsg('mv_match_text', count($srange['rows'])).'<br />' . "\n";
662662 $stream_out .= $mvd_out;
663 - }else{
 663+ }else{
664664 $stream_out .= $mvd_out;
665665 }*/
666666 }
@@ -694,7 +694,7 @@
695695
696696 break;
697697 case 'smw_property_number' :
698 - //should be special case for numeric values
 698+ //should be special case for numeric values
699699 break;
700700 }
701701 }
@@ -708,14 +708,14 @@
709709 $term_pat.=$or.$term;
710710 $or='|';
711711 }
712 - }
 712+ }
713713 if($term_pat=='')return;
714714 //@@TODO:: someone somewhere has written a better wiki_text page highlighter
715715 $pat1 = "/(\[\[(.*)\]\]|(.*)($term_pat)(.*)/i";
716716 //print "pattern: ". $pat1 . "\n\n";
717717 return preg_replace( $pat1,
718718 "$1<span class='searchmatch'>\\2</span>$3", $text );
719 - //print "\n\ncur text:". $text;
 719+ //print "\n\ncur text:". $text;
720720 }*/
721721 /*very similar to showHit in SpecialSearch.php */
722722 function termHighlight(& $text, $terms, $contextlines = 1, $contextchars = 50) {
@@ -759,7 +759,7 @@
760760 //$extract .= " <small>{$lineno}: {$line}</small>\n";
761761 $extract .= " {$line}\n";
762762 }
763 - //if we found no matches just return the first line:
 763+ //if we found no matches just return the first line:
764764 if ($extract == '')
765765 return ' ' . $wgContLang->truncate($text, ($contextchars * 2), '...') . '';
766766 //wfProfileOut( "$fname-extract" );
@@ -788,7 +788,7 @@
789789 $wgOut->getHTML() .
790790 '</span>';
791791
792 - //return page html:
 792+ //return page html:
793793 return $embedHTML . $pageHTML . '<div style="clear: both;"/>';
794794 } else {
795795 return wfMsg('mvBadMVDtitle');
@@ -802,7 +802,7 @@
803803 //return $wgOut->parse($article->getContent());
804804 }
805805 function get_httpd_filters_query() {
806 - //get all the mvd ns selected:
 806+ //get all the mvd ns selected:
807807 $opt = $this->powerSearchOptions();
808808 return http_build_query($opt + array (
809809 'f' => $this->filters
@@ -821,8 +821,8 @@
822822 if (!isset ($filter['a'])) //and, or, not
823823 $filter['a'] = '';
824824
825 - //output the master selecter per line:
826 - $s .= '<br><span id="mvs_' . htmlspecialchars($i) . '">';
 825+ //output the master selecter per line:
 826+ $s .= '<br><span id="mvs_' . htmlspecialchars($i) . '">';
827827 $s .= '&nbsp;&nbsp;';
828828 //selctor (don't display if i==0')
829829 $s .= $this->selector($i, 'a', $filter['a'], ($i == 0) ? false : true);
@@ -837,7 +837,7 @@
838838 $s .= $this->text_entry($i, 'v', $filter['v']);
839839 break;
840840 case 'date_range' :
841 - $s .= wfMsg('mv_time_separator', $this->text_entry($i, 'vs', $filter['vs'], 'date-pick_' . $i, array('id'=>'vs_' . $i )),
 841+ $s .= wfMsg('mv_time_separator', $this->text_entry($i, 'vs', $filter['vs'], 'date-pick_' . $i, array('id'=>'vs_' . $i )),
842842 $this->text_entry($i, 've', $filter['ve'], 'date-pick_' . $i, array('id'=>'ve_' . $i )));
843843 //also output dateObj (if not already output):
844844 if (!$dateObjOut) {
@@ -848,7 +848,7 @@
849849 '<!-- required plugins -->
850850 <script type="text/javascript" src="' . $mvgScriptPath . '/skins/mv_embed/jquery/plugins/date.js"></script>
851851 <!--[if IE]><script type="text/javascript" src="' . $mvgScriptPath . '/skins/mv_embed/jquery/plugins/jquery.bgiframe.js"></script><![endif]-->
852 -
 852+
853853 <!-- jquery.datePicker.js -->
854854 <script type="text/javascript" src="' . $mvgScriptPath . '/skins/mv_embed/jquery/plugins/jquery.datePicker.js"></script>
855855 <script language="javascript" type="text/javascript">' .
@@ -876,13 +876,13 @@
877877 $s .= '</span>';
878878 }
879879 $s .= '</div>';
880 - //reference remove
 880+ //reference remove
881881 $s .= '<a id="mv_ref_remove" style="display:none;" ' .
882882 'href="">' .
883883 '<img title="' . htmlspecialchars( wfMsg('mv_remove_filter') ) . '" ' .
884884 'src="' . $mvgScriptPath . '/skins/images/cog_delete.png"></a>';
885885
886 - //ref missing person image ref:
 886+ //ref missing person image ref:
887887 $s .= $this->get_ref_person();
888888
889889 //add link:
@@ -921,7 +921,7 @@
922922 if ($inx != 0)
923923 $a = ' ' . wfMsg('mv_search_' . $f['a']) . ' ';
924924 $o .= ($query_key) ? $a : $a . wfMsg('mv_' . $f['t']) . ' ';
925 - if ($f['t'] == 'date_range') { //handle special case of date range:
 925+ if ($f['t'] == 'date_range') { //handle special case of date range:
926926 $o .= wfMsg('mv_time_separator', $bo . htmlspecialchars($f['vs']) . $bc, $bo . htmlspecialchars($f['ve']) . $bc);
927927 } else {
928928 $o .= $bo . str_replace('_', ' ', htmlspecialchars($f['v'])) . $bc;
@@ -940,7 +940,7 @@
941941 $person_name = '';
942942 $disp = 'none';
943943 }
944 - //make the missing person image ref:
 944+ //make the missing person image ref:
945945 $imgTitle = Title :: makeTitle(NS_IMAGE, $person_name . '.jpg');
946946 if (!$imgTitle->exists()) {
947947 $imgTitle = Title :: makeTitle(NS_IMAGE, MV_MISSING_PERSON_IMG);
@@ -961,9 +961,9 @@
962962 }
963963 function selector($i, $key, $selected = '', $display = true) {
964964 $disp = ($display) ? '' : 'display:none;';
965 - $s = '<select id="mvsel_' . htmlspecialchars($key) . '_' .
 965+ $s = '<select id="mvsel_' . htmlspecialchars($key) . '_' .
966966 htmlspecialchars($i) . '" class="mv_search_select" style="font-size: 12px;' .
967 - htmlspecialchars($disp) . '" name="f[' . htmlspecialchars($i) . '][' .
 967+ htmlspecialchars($disp) . '" name="f[' . htmlspecialchars($i) . '][' .
968968 htmlspecialchars($key) . ']" >' . "\n";
969969 $items = ($key == 't') ? $this->sel_filter_types : $this->sel_filter_andor;
970970 if ($key == 'a' && $selected == '')
@@ -979,14 +979,14 @@
980980 $s .= '</select>';
981981 return $s;
982982 }
983 - //could be a suggest:
 983+ //could be a suggest:
984984 function text_entry($i, $key, $val = '', $more_class = '', $more_attr = array()) {
985985 if ($more_class != '')
986986 $more_class = ' ' . $more_class;
987987 foreach($more_attr as $k=>$v){
988988 $more_attr_out.=' '.htmlspecialchars($k).'="'.$v.'"';
989989 }
990 - $s = '<input ' . $more_attr_out . ' class="mv_search_text' . htmlspecialchars($more_class) . '" style="font-size: 12px;" onchange=""
 990+ $s = '<input ' . $more_attr_out . ' class="mv_search_text' . htmlspecialchars($more_class) . '" style="font-size: 12px;" onchange=""
991991 size="9" type="text" name="f[' . htmlspecialchars($i) . '][' . htmlspecialchars($key) . ']" value="' . htmlspecialchars($val) . '">';
992992 return $s;
993993 }
@@ -998,7 +998,7 @@
999999
10001000 $catNStxt = $wgContLang->getNsText(NS_CATEGORY);
10011001
1002 - //make sure people know they can "search" too (formated by
 1002+ //make sure people know they can "search" too (formated by
10031003 $out = 'do_search|' . wfMsg('mv_search_transcripts_for', '<B>$1</B>') . '|no_image' . "\n";
10041004 //get keywords
10051005 $category_out = MV_SpecialMediaSearch :: auto_complete_search_categories($val, 3);
@@ -1012,7 +1012,7 @@
10131013 $out .= $catNStxt . ':Person|<h6>' . wfMsg('mv_people_matches') . '</h6>|no_image' . "\n";
10141014 $out .= $person_out;
10151015 }
1016 - //get bills
 1016+ //get bills
10171017 $bill_out = MV_SpecialMediaSearch :: auto_complete_category('Bill', $val, 3);
10181018 if ($bill_out != '') {
10191019 $out .= $catNStxt . ':Bill|<h6>' . wfMsg('mv_bill_matches') . '</h6>|no_image' . "\n";
@@ -1081,7 +1081,7 @@
10821082 while ($row = $dbr->fetchObject($result)) {
10831083 $person_name = $row->cl_sortkey;
10841084 $person_ary[$person_name]=true;
1085 - //make sure the person page exists:
 1085+ //make sure the person page exists:
10861086 $personTitle = Title :: makeTitle(NS_MAIN, $person_name);
10871087 if ($personTitle->exists()) {
10881088 //get person full name from semantic table if available
@@ -1103,7 +1103,7 @@
11041104 return $out;
11051105 }
11061106 function getPersonImageURL($person_name) {
1107 - //make the missing person image ref:
 1107+ //make the missing person image ref:
11081108 $imgTitle = Title :: makeTitle(NS_IMAGE, $person_name . '.jpg');
11091109 if (!$imgTitle->exists()) {
11101110 $imgTitle = Title :: makeTitle(NS_IMAGE, MV_MISSING_PERSON_IMG);
@@ -1116,9 +1116,9 @@
11171117 return $img->getURL();
11181118 }
11191119 function format_ac_line(& $page_title, $val, $prefix = '', $img_link = 'no_image', $format = 'ac_line') {
1120 - //no underscores in display title:
 1120+ //no underscores in display title:
11211121 $page_title_disp = str_replace('_', ' ', $page_title);
1122 - //bold matching part of title:
 1122+ //bold matching part of title:
11231123 $bs = stripos($page_title_disp, str_replace('_', ' ', $val));
11241124 if ($bs !== false) {
11251125 $page_title_disp = substr($page_title_disp, 0, $bs) .
@@ -1142,7 +1142,7 @@
11431143 return "<p class=\"people2_match last_match\"><img src=\"{$img_link}\">" . $sk->makeKnownLinkObj($title, $page_title_disp) . '</p>';
11441144 }
11451145 }
1146 - //return a json date obj
 1146+ //return a json date obj
11471147 //@@todo fix for big sites...(will start to be no fun if number of streams is > 2000 )
11481148 function getJsonDateObj($obj_name = 'mv_result') {
11491149 $dbr = & wfGetDB(DB_SLAVE);
@@ -1180,4 +1180,3 @@
11811181 ), 'ed' => date('m/d/Y', $end_day), 'sdays' => $sDays), $obj_name);
11821182 }
11831183 }
1184 -?>
Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_MetavidInterface.php
@@ -4,152 +4,151 @@
55 *
66 * All Metavid Wiki code is Released Under the GPL2
77 * for more info visit http:/metavid.ucsc.edu/code
8 - *
9 - *
 8+ *
 9+ *
1010 * The metavid interface class
1111 * provides the metavid interface for Metavid: requests
1212 * provides the base metadata
13 - *
 13+ *
1414 */
1515 if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
1616
17 -
 17+
1818 class MV_MetavidInterface{
19 - var $components = array();
20 - var $context=null;
21 - var $page_title='';
22 - var $page_header='';
23 - //list the properties we are intersted and there default values:
24 - var $smwProperties = array('playback_resolution'=>null);
25 - function __construct($contextType, & $contextArticle=null ){
26 - global $mv_default_view;
27 - $this->context = $contextType;
28 - if($contextArticle)
29 - $this->article = & $contextArticle;
30 - //set up base layout for each context:
31 - switch($contextType){
32 - case 'special':
33 - $this->setupSpecialView();
34 - break;
35 - case 'edit_sequence':
36 - $this->setupEditSequenceView();
37 - break;
38 - case 'sequence':
39 - $this->setupSequenceView();
40 - break;
41 - case 'stream':
42 - $this->setupStreamView();
43 - break;
44 - }
45 - }
46 - /*function setupSequenceView(){
47 - global $mvgIP;
48 - //set up the base sequence:
49 - foreach(array('MV_VideoPlayer', ''
50 - /*foreach(array('MV_VideoPlayer') as $cp_name){
 19+ var $components = array();
 20+ var $context=null;
 21+ var $page_title='';
 22+ var $page_header='';
 23+ //list the properties we are intersted and there default values:
 24+ var $smwProperties = array('playback_resolution'=>null);
 25+ function __construct($contextType, & $contextArticle=null ){
 26+ global $mv_default_view;
 27+ $this->context = $contextType;
 28+ if($contextArticle)
 29+ $this->article = & $contextArticle;
 30+ //set up base layout for each context:
 31+ switch($contextType){
 32+ case 'special':
 33+ $this->setupSpecialView();
 34+ break;
 35+ case 'edit_sequence':
 36+ $this->setupEditSequenceView();
 37+ break;
 38+ case 'sequence':
 39+ $this->setupSequenceView();
 40+ break;
 41+ case 'stream':
 42+ $this->setupStreamView();
 43+ break;
 44+ }
 45+ }
 46+ /*function setupSequenceView(){
 47+ global $mvgIP;
 48+ //set up the base sequence:
 49+ foreach(array('MV_VideoPlayer', ''
 50+ /*foreach(array('MV_VideoPlayer') as $cp_name){
5151 require_once($mvgIP . '/includes/MV_MetavidInterface/'.$cp_name.'.php');
52 - $this->components[$cp_name] = new $cp_name(
 52+ $this->components[$cp_name] = new $cp_name(
5353 array('mv_interface'=>&$this)
54 - );
 54+ );
5555 }
56 - }*/
57 - function setupEditSequenceView(){
58 - global $mvgIP, $wgTitle;
59 - foreach(array('MV_SequencePlayer', 'MV_SequenceTools', 'MV_SequenceTimeline') as $cp_name){
60 - $this->components[$cp_name] = new $cp_name(
 56+ }*/
 57+ function setupEditSequenceView(){
 58+ global $mvgIP, $wgTitle;
 59+ foreach(array('MV_SequencePlayer', 'MV_SequenceTools', 'MV_SequenceTimeline') as $cp_name){
 60+ $this->components[$cp_name] = new $cp_name(
6161 array('mv_interface'=>&$this)
62 - );
 62+ );
6363 }
6464 //set up additonal pieces
65 - $this->page_title=wfMsg('mv_edit_sequence', $wgTitle->getText() );
66 - }
67 - function setupStreamView(){
68 - global $mvgIP, $mvDefaultStreamViewLength, $wgOut,$mvgScriptPath,$wgUser;
69 -
70 - //set default time range if null time range request
71 - $this->article->mvTitle->setStartEndIfEmpty();
72 - //grab relevent article semantic properties (so far playback_resolution) for user overwriting playback res
73 - $this->grabSemanticProp();
74 -
 65+ $this->page_title=wfMsg('mv_edit_sequence', $wgTitle->getText() );
 66+ }
 67+ function setupStreamView(){
 68+ global $mvgIP, $mvDefaultStreamViewLength, $wgOut,$mvgScriptPath,$wgUser;
 69+
 70+ //set default time range if null time range request
 71+ $this->article->mvTitle->setStartEndIfEmpty();
 72+ //grab relevant article semantic properties (so far playback_resolution) for user overwriting playback res
 73+ $this->grabSemanticProp();
 74+
7575 //set up the interface objects:
7676 foreach(array('MV_VideoPlayer', 'MV_Overlay','MV_Tools') as $cp_name){
77 - $this->components[$cp_name] = new $cp_name(
 77+ $this->components[$cp_name] = new $cp_name(
7878 array('mv_interface'=>&$this)
79 - );
 79+ );
8080 }
8181 //process track request:
82 - $this->components['MV_Overlay']->procMVDReqSet();
 82+ $this->components['MV_Overlay']->procMVDReqSet();
8383 //add in title & tracks var:
8484 global $mvgScriptPath;
85 - $wgOut->addScript('<script type="text/javascript">/*<![CDATA[*/'.'
86 - var mvTitle = \''.htmlspecialchars($this->article->mvTitle->getWikiTitle()).'\';
87 - var mvTracks = \''.htmlspecialchars($this->components['MV_Overlay']->getMVDReqString()). '\';
88 - var mvgScriptPath = \''.htmlspecialchars($mvgScriptPath).'\';
89 - /*]]>*/</script>');
90 -
91 - //also add prev next paging
 85+ $wgOut->addScript('<script type="text/javascript">/*<![CDATA[*/'.'
 86+ var mvTitle = \''.htmlspecialchars($this->article->mvTitle->getWikiTitle()).'\';
 87+ var mvTracks = \''.htmlspecialchars($this->components['MV_Overlay']->getMVDReqString()). '\';
 88+ var mvgScriptPath = \''.htmlspecialchars($mvgScriptPath).'\';
 89+ /*]]>*/</script>');
 90+
 91+ //also add prev next paging
9292 $this->page_header ='<h1 class="videoHeader">'.
93 - $this->article->mvTitle->getStreamNameText().' :: '.
94 - $this->components['MV_Tools']->stream_paging_links('prev') .
 93+ $this->article->mvTitle->getStreamNameText().' :: '.
 94+ $this->components['MV_Tools']->stream_paging_links('prev') .
9595 ' <span title="'.htmlspecialchars(wfMsg('mv_click_to_edit')).'" id="mv_stream_time">'.$this->article->mvTitle->getTimeDesc($span_separated=true) . '</span>'.
9696 $this->components['MV_Tools']->stream_paging_links('next') .
97 - wfMsg('mv_of') . seconds2ntp($this->article->mvTitle->getDuration()) .
98 - '</h1>';
99 -
 97+ wfMsg('mv_of') . seconds2ntp($this->article->mvTitle->getDuration()) .
 98+ '</h1>';
 99+
100100 //add export cmml icon
101101 $this->page_header.='<span id="cmml_link"/>';
102 - $sTitle = Title::makeTitle(NS_SPECIAL, 'MvExportStream');
 102+ $sTitle = Title::makeTitle(NS_SPECIAL, 'MvExportStream');
103103 $sk = $wgUser->getSkin();
104104 $this->page_header.= $sk->makeKnownLinkObj($sTitle,
105105 '<img style="width:28px;height:28px;" src="'.htmlspecialchars($mvgScriptPath) . '/skins/images/Feed-icon_cmml_28x28.png">',
106106 'feed_format=roe&stream_name='.htmlspecialchars($this->article->mvTitle->getStreamName()).'&t='.htmlspecialchars($this->article->mvTitle->getTimeRequest()),
107107 '','','title="'.htmlspecialchars(wfMsg('mv_export_cmml')).'"');
108 - $this->page_header.='</span>';
 108+ $this->page_header.='</span>';
109109 $this->page_title = $this->article->mvTitle->getStreamNameText().' '.$this->article->mvTitle->getTimeDesc();
110 - }
111 - //grab semantic properties if availiable:
112 - //@@todo we need to think this through a bit
113 - function grabSemanticProp(){
114 - if(SMW_VERSION){
115 - //global $smwgIP;
116 - $smwStore =& smwfGetStore();
117 - foreach($this->smwProperties as $propKey=>$val){
118 - $propTitle = Title::newFromText($propKey, SMW_NS_PROPERTY);
119 - $smwProps = $smwStore->getPropertyValues($this->article->mTitle,$propTitle );
120 - //just a temp hack .. we need to think about this abstraction a bit...
121 - if(count($smwProps)!=0){
122 - $v = current($smwProps);
123 - $this->smwProperties[$propKey]=$v->getXSDValue();
124 - }
125 - }
126 - }
127 - }
128 - /*
129 - * renders the full page to the wgOut object
130 - */
131 - function render_full(){
132 - global $wgOut;
133 - //add some variables for the interface:
134 -
135 - //output title and header:
136 - $wgOut->setHTMLTitle($this->page_title);
137 -
138 - if($this->page_header=='')$this->page_header = '<span style="position:relative;top:-12px;font-weight:bold">' .
139 - htmlspecialchars($this->page_title) . '</span>';
140 - $wgOut->addHTML($this->page_header);
141 -
142 - //@@todo dynamic re-size page_spacer:
143 - $wgOut->addHTML('<div id="mv_interface_container">');
144 - foreach($this->components as $cpKey => &$component){
145 - $component->render_full();
146 - }
147 - $wgOut->addHTML('</div>');
148 - //for now output spacers
149 - //@@todo output a dynamic spacer javascript layout
150 - //$out='';
151 - //for($i=0;$i<28;$i++)$out.="<br />";
152 - //$wgOut->addHTML($out);
153 - //}
154 - }
155 - }
156 -?>
 110+ }
 111+ //grab semantic properties if availiable:
 112+ //@@todo we need to think this through a bit
 113+ function grabSemanticProp(){
 114+ if(SMW_VERSION){
 115+ //global $smwgIP;
 116+ $smwStore =& smwfGetStore();
 117+ foreach($this->smwProperties as $propKey=>$val){
 118+ $propTitle = Title::newFromText($propKey, SMW_NS_PROPERTY);
 119+ $smwProps = $smwStore->getPropertyValues($this->article->mTitle,$propTitle );
 120+ //just a temp hack .. we need to think about this abstraction a bit...
 121+ if(count($smwProps)!=0){
 122+ $v = current($smwProps);
 123+ $this->smwProperties[$propKey]=$v->getXSDValue();
 124+ }
 125+ }
 126+ }
 127+ }
 128+ /*
 129+ * renders the full page to the wgOut object
 130+ */
 131+ function render_full(){
 132+ global $wgOut;
 133+ //add some variables for the interface:
 134+
 135+ //output title and header:
 136+ $wgOut->setHTMLTitle($this->page_title);
 137+
 138+ if($this->page_header=='')$this->page_header = '<span style="position:relative;top:-12px;font-weight:bold">' .
 139+ htmlspecialchars($this->page_title) . '</span>';
 140+ $wgOut->addHTML($this->page_header);
 141+
 142+ //@@todo dynamic re-size page_spacer:
 143+ $wgOut->addHTML('<div id="mv_interface_container">');
 144+ foreach($this->components as $cpKey => &$component){
 145+ $component->render_full();
 146+ }
 147+ $wgOut->addHTML('</div>');
 148+ //for now output spacers
 149+ //@@todo output a dynamic spacer javascript layout
 150+ //$out='';
 151+ //for($i=0;$i<28;$i++)$out.="<br />";
 152+ //$wgOut->addHTML($out);
 153+ //}
 154+ }
 155+}
Index: trunk/extensions/MetavidWiki/languages/MV_Messages.php
@@ -33,7 +33,7 @@
3434 'mvexportsearch' => 'Metavid export',
3535 'mvexportsequence' => 'Metavid export sequence',
3636 'mvexportstream' => 'Metavid export stream',
37 -
 37+
3838 'mv_add_stream_page' => 'Mv add stream',
3939 'mv_edit_strea_docu' => '<p>Edit stream <b>admin</b><br />for normal user view/edit see $1 page',
4040 'mv_add_stream_docu' => '<p>Add a new Stream with the field below.</p>
@@ -63,8 +63,8 @@
6464 'mv_label_stream_name' => 'Stream name',
6565 'mv_label_stream_desc' => 'Stream description',
6666 'add_stream_permission' => 'You lack permission to add a new stream',
67 - 'edit_stream_missing' => 'Missing stream name',
68 - 'mv_missing_req_time' => 'Missing request time',
 67+ 'edit_stream_missing' => 'Missing stream name',
 68+ 'mv_missing_req_time' => 'Missing request time',
6969 'mv_missing_cat' => 'Missing category name',
7070 'mv_stream_already_exists' => 'The stream <a href="$2">$1</a> already exists',
7171 'mv_summary_add_stream' => 'stream added by form',
@@ -79,7 +79,7 @@
8080 'mv_metavid_live' => 'Set up live stream',
8181 'mv_upload_file' => 'Upload file',
8282 'mv_external_file' => 'External file',
83 - 'mv_stream_delete_warning' => 'Deleting this stream will additionally remove $1 pages of metadata',
 83+ 'mv_stream_delete_warning' => 'Deleting this stream will additionally remove $1 pages of metadata',
8484
8585 #tools
8686 'mv_tool_search' => 'Search',
@@ -102,7 +102,7 @@
103103 'mv_people_matches' => 'People matches',
104104 'mv_category_matches' => 'Category matches',
105105 'mv_bill_matches' => 'Bill matches',
106 - 'mv_interest_group_matches' => 'Interest group matches',
 106+ 'mv_interest_group_matches' => 'Interest group matches',
107107 'mv_click_to_edit' => 'click to edit',
108108
109109 #mvd types:
@@ -131,7 +131,7 @@
132132 'mv_list_streams_none' => 'No streams exist',
133133
134134 #messages for metavid export feed:
135 - 'mvvideofeed' => 'Metavid video feed export',
 135+ 'mvvideofeed' => 'Metavid video feed export',
136136 'mvexportask' => 'Semantic video feed export',
137137 'video_feed_cat' => 'Video feed for category:',
138138 'mv_cat_search_note' => 'Note: Categories only lists top level categories.
@@ -166,16 +166,16 @@
167167 'mv_start_desc' => 'Start time',
168168 'mv_end_desc' => 'End time',
169169 'mv_of' => '&#32;of&#32;',
170 -
 170+
171171 'mv_edit_metadata' => 'Edit metadata',
172172 'mv_advanced_edit' => 'Advanced edit',
173173 'mv_basic_edit' => 'Basic edit',
174174 'mv_remove_category' => 'Remove category',
175175 'mv_existing_categories' => 'Existing categories:',
176 - 'mv_add_category' => 'Add a categorization',
 176+ 'mv_add_category' => 'Add a categorization',
177177 'mv_basic_text_desc' => 'Text description (optional)',
178 -
179 -
 178+
 179+
180180 #search
181181 'mediasearch' => 'Media search',
182182 'mv_search_sel_t' => 'Select search type',
@@ -197,13 +197,13 @@
198198 'mv_stream_name' => 'stream name',
199199 'mv_date_range' => 'date range',
200200 'mv_date_last_week' => 'Last week',
201 -
 201+
202202 'mv_category_results' => 'Category results',
203203 'mv_people_results' => 'People results',
204204 'mv_bill_results' => 'Bill results',
205205 'mv_intrest_group_results' => 'Interst groups',
206 -
207 - 'mv_most_relevent' => 'Most relevent',
 206+
 207+ 'mv_most_relevant' => 'Most relevant',
208208 'mv_most_recent' => 'Most recent',
209209 'mv_most_viewed' => 'Most viewed',
210210
@@ -437,7 +437,7 @@
438438 'thomas_en_desc' => "ترانس سكريبت توماس الرسمي من خدمة تسجيل THOMAS الرسمية.
439439 وقت المصدر معدل بواسطة C-SPAN's c-spanarchives.org",
440440 'mvd_default_mismatch' => 'خطأ في ملف الإعدادات',
441 - 'mvd_default_mismatch_text' => 'هناك خطأ في ملف إعداداتك.
 441+ 'mvd_default_mismatch_text' => 'هناك خطأ في ملف إعداداتك.
442442 $mvMVDTypeDefaultDisp يجب أن تكون جزء من $mvMVDTypeAllAvailable',
443443 'mv_data_page_title' => '$1 ل$2 من $3',
444444 'mv_time_separator' => '$1 إلى $2',
@@ -3672,4 +3672,3 @@
36733673 $messages['vo'] = array(
36743674 'mv_search_category' => 'Klad',
36753675 );
3676 -

Status & tagging log