r39517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39516‎ | r39517 | r39518 >
Date:01:48, 17 August 2008
Author:dale
Status:old
Tags:
Comment:
some updates to the stream interface
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_Index.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_MagicWords.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_MetavidInterface.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Navigator.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Overlay.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_Stream.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_Title.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/articlepages/MV_SequencePage.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialExport.php (modified) (history)
  • /trunk/extensions/MetavidWiki/languages/MV_Messages.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/scrape_and_insert.inc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php
@@ -215,8 +215,8 @@
216216 //get wiki stream id:
217217 $wikiStream = new MV_Stream(array('name'=>$stream->name));
218218 //first remove all bot edited pages:
219 - $mvd_res = MV_Index::getMVDInRange($wikiStream->getStreamId(),null,null,'Anno_en');
220 - while($row = $dbr->fetchObject($mvd_res)){
 219+ $mvd_rows = MV_Index::getMVDInRange($wikiStream->getStreamId(),null,null,'Anno_en');
 220+ foreach($mvd_rows as $row){
221221 $title = Title::newFromText($row->wiki_title, MV_NS_MVD);
222222 $current = Revision::newFromTitle( $title );
223223 if($current->getUserText()==$botUserName){
Index: trunk/extensions/MetavidWiki/maintenance/scrape_and_insert.inc.php
@@ -510,12 +510,12 @@
511511 }
512512 function get_aligned_time_title(&$pData, $preFix='Anno_en', $stream){
513513 $dbr =& wfGetDB(DB_SLAVE);
514 - $mvd_anno_res = MV_Index::getMVDInRange($stream->getStreamId(),
 514+ $mvd_rows = MV_Index::getMVDInRange($stream->getStreamId(),
515515 $pData['wiki_start_time']-120,$pData['wiki_end_time']+120,
516516 $mvd_type='Anno_en',$getText=false,$smw_properties='Speech_by');
517517
518518 $doSpeechInsert=true;
519 - while($row = $dbr->fetchObject($mvd_anno_res)){
 519+ foreach($mvd_rows as $row){
520520 if($row->Speech_by){
521521 if($row->Speech_by == $pData['Spoken_by']){
522522 print "match update existing: $row->Speech_by == ". $pData['Spoken_by']. "\n";
Index: trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php
@@ -105,6 +105,7 @@
106106 $wgAutoloadClasses['MV_SequenceTimeline'] = dirname(__FILE__) .'/MV_MetavidInterface/MV_SequenceTimeline.php';
107107 $wgAutoloadClasses['MV_VideoPlayer'] = dirname(__FILE__) .'/MV_MetavidInterface/MV_VideoPlayer.php';
108108 $wgAutoloadClasses['MV_Tools'] = dirname(__FILE__) .'/MV_MetavidInterface/MV_Tools.php';
 109+ $wgAutoloadClasses['MV_Navigator'] = dirname(__FILE__) .'/MV_MetavidInterface/MV_Navigator.php';
109110 $wgAutoloadClasses['MV_EditPageAjax'] = dirname(__FILE__) .'/MV_MetavidInterface/MV_EditPageAjax.php';
110111
111112 $wgAutoloadClasses['MV_CategoryPage'] = dirname(__FILE__) .'/articlepages/MV_CategoryPage.php';
Index: trunk/extensions/MetavidWiki/includes/MV_Stream.php
@@ -218,14 +218,12 @@
219219 if($removeMVDs){
220220 //delete metadata pages:
221221 //@@todo figure out a way to do this quickly/group sql queries.
222 - $res = MV_Index::getMVDInRange($this->getStreamId());
223 - if($dbr->numRows($res) != 0){
224 - while($row = $dbr->fetchObject($res)){
 222+ $mvd_rows = MV_Index::getMVDInRange($this->getStreamId());
 223+ foreach($mvd_rows as $row){
225224 $title = Title::newFromText($row->wiki_title, MV_NS_MVD);
226225 $article = new Article($title);
227226 $article->doDelete('parent stream removed');
228 - }
229 - }
 227+ }
230228 }
231229 return true;
232230 }
Index: trunk/extensions/MetavidWiki/includes/MV_MagicWords.php
@@ -150,17 +150,17 @@
151151 '</span>';
152152 //try to get metadata from anno_en first.
153153 //@@todo maybe the following metadata grabbing could be abstracted to a single function in mv_index
154 - $mvd_result = MV_Index::getMVDInRange(
 154+ $mvd_rows = MV_Index::getMVDInRange(
155155 $row->stream_id,
156156 $row->start_time,
157157 $row->end_time,
158158 $mvd_type='anno_en',
159159 $getText=true,
160160 $smw_properties=array('Speech_by', 'Bill'),
161 - $limit='1'
 161+ $options=array('limit'=>1)
162162 );
163 - if($dbr->numRows($mvd_result)!=0){
164 - $mvd_row = $dbr->fetchObject($mvd_result);
 163+ if(count($mvd_rows)!=0){
 164+ $mvd_row = current($mvd_rows);
165165 if($mvd_row->Speech_by){
166166 $ptitle = Title::MakeTitle(NS_MAIN, $mvd_row->Speech_by);
167167 $o.='<span class="keywords">'.
Index: trunk/extensions/MetavidWiki/includes/MV_Index.php
@@ -98,12 +98,13 @@
9999 * getMVDInRange returns the mvd titles that are in the given range
100100 * param list got kind of crazy long... @@todo re-factor int a request object or something cleaner
101101 */
102 - function getMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all',$getText=false,$smw_properties='', $limit='200'){
 102+ function getMVDInRange($stream_id, $start_time=null, $end_time=null, $mvd_type='all',$getText=false,$smw_properties='', $options=array()){
103103 global $mvIndexTableName, $mvDefaultClipLength;
104104 $dbr =& wfGetDB(DB_SLAVE);
105105 //set up select vars:
106 - $conds=$options=$vars=array();
 106+ $conds=$vars=array();
107107 $from_tables ='';
 108+ $do_cat_lookup=false;
108109 //
109110 //set mvd_type if empty:
110111 if($mvd_type==null)$mvd_type='all';
@@ -112,19 +113,27 @@
113114 $vars= array('mv_page_id as id', 'mvd_type', 'wiki_title', 'stream_id', 'start_time', 'end_time');
114115 //add in base from:
115116 $from_tables.= $dbr->tableName('mv_mvd_index');
 117+ //print_r($smw_properties);
116118 if($smw_properties!=''){
117 - if(!isset($options['STRAIGHT_JOIN']))
118 - $options['STRAIGHT_JOIN']='';
119119 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) . ')';
 120+ $smw_properties = explode(',',$smw_properties);
 121+ foreach($smw_properties as $prop_name){
 122+ if($prop_name=='category'){
 123+ $do_cat_lookup=true;
 124+ }else{
 125+ //if(SMW_VERSION >=1.2){
 126+ // $getSMWTags=true;
 127+ //}else{
 128+ $vars[] = mysql_real_escape_string($prop_name).'.object_title as '.mysql_real_escape_string($prop_name);
 129+ $from_tables.=' ' .
 130+ ' LEFT JOIN '. $dbr->tableName('smw_relations') .
 131+ ' as ' . mysql_real_escape_string($prop_name) .
 132+ ' ON (' . $dbr->tableName('mv_mvd_index') . '.mv_page_id'.
 133+ ' = ' . mysql_real_escape_string($prop_name) . '.subject_id'.
 134+ ' AND '. mysql_real_escape_string($prop_name).'.relation_title'.
 135+ ' = ' . $dbr->addQuotes($prop_name) . ')';
 136+ //}
 137+ }
129138 }
130139 }
131140 $conds = array('stream_id'=>$stream_id);
@@ -143,15 +152,21 @@
144153 }
145154
146155 }
147 - if($end_time)
 156+ //print "Start time: $start_time END TIME: $end_time\n";
 157+ if($end_time!=null)
148158 $conds[]='start_time <= '. $dbr->addQuotes($end_time);
149 - if($start_time)
150 - $conds[]='end_time >= '. $dbr->addQuotes($start_time);
151 -
 159+
 160+ if($start_time!=null)
 161+ $conds[]='end_time >= '. $dbr->addQuotes($start_time);
 162+
152163 //add in ordering
153 - $options['ORDER BY']= 'start_time ASC';
 164+ if(!isset($options['ORDER BY']))
 165+ $options['ORDER BY']= 'start_time ASC';
 166+
154167 //add in limit
155 - $options['LIMIT'] = $limit;
 168+ if(!isset($options['LIMIT']))
 169+ $options['LIMIT'] = 200;
 170+
156171 //run query:
157172 $result = $dbr->select( $from_tables,
158173 $vars,
@@ -159,10 +174,64 @@
160175 __METHOD__,
161176 $options);
162177 //print $dbr->lastQuery();
 178+
 179+ $ret_ary=array();
 180+ $from_tables=$vars=$options=array();
 181+ $conds='';
 182+ $or='';
 183+ while($row=$dbr->fetchObject($result)){
 184+ $ret_ary[$row->id]=$row;
 185+ if($do_cat_lookup){
 186+ if($do_cat_lookup){
 187+ $conds.=$or . ' cl_from ='.$dbr->addQuotes($row->id);
 188+ $or=' OR ';
 189+ }
 190+ }
 191+ }
 192+
 193+ //not very fast:
 194+ /*if($getSMWTags){
 195+ foreach($ret_ary as $row){
 196+ $smwStore =& smwfGetStore();
 197+ $rowTitle = Title::newFromText($row->wiki_title, MV_NS_MVD);
 198+ //print "Title: ".$title->getDBKey() . "\n";
 199+ $smwProps = $smwStore->getSemanticData($rowTitle);
 200+ foreach($smwProps as $smwProp){
 201+ print "val: " . $smwProp->getValue();
 202+ }
 203+ }
 204+ }*/
 205+
 206+ if($do_cat_lookup){
 207+ $from_tables = $dbr->tableName('categorylinks');
 208+ $from_tables.=' LEFT JOIN '.$dbr->tableName('mv_mvd_index').
 209+ ' ON ( ' .
 210+ $dbr->tableName('categorylinks') . '.cl_from = ' .
 211+ $dbr->tableName('mv_mvd_index'). '.mv_page_id'.
 212+ ' ) ';
 213+
 214+ $vars=array('cl_from','cl_to');
 215+
 216+ $options['LIMIT'] = 2000; //max avarage 5 categories per page
 217+
 218+ $result_cat = $dbr->select( $from_tables,
 219+ $vars,
 220+ $conds,
 221+ __METHOD__,
 222+ $options);
 223+ //print $dbr->lastQuery($result_cat);
 224+ //die();
 225+ while($cat_row=$dbr->fetchObject($result_cat)){
 226+ if(!isset($ret_ary[$cat_row->cl_from]->category))
 227+ $ret_ary[$cat_row->cl_from]->category=array();
 228+ $ret_ary[$cat_row->cl_from]->category[]=$cat_row->cl_to;
 229+ }
 230+ }
 231+ //print $dbr->lastQuery();
163232 //die;
164233 //echo $sql;
165234 //$result =& $dbr->query( $sql, 'MV_Index:time_index_query');
166 - return $result;
 235+ return $ret_ary;
167236 }
168237 /*@@todo figure another way to get at this data...this is not a very fast query: */
169238 function getMVDTypeInRange($stream_id, $start_time=null, $end_time=null){
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialExport.php
@@ -276,7 +276,7 @@
277277 $streamTitle = new MV_Title($this->stream_name.'/'.$this->req_time);
278278 $wgTitle = Title::newFromText($this->stream_name.'/'.$this->req_time, MV_NS_STREAM);
279279 //do mvd_index query:
280 - $mvd_res = MV_Index::getMVDInRange($streamTitle->getStreamId(),
 280+ $mvd_rows = MV_Index::getMVDInRange($streamTitle->getStreamId(),
281281 $streamTitle->getStartTimeSeconds(),
282282 $streamTitle->getEndTimeSeconds(), $tracks);
283283 //get the stream stream req
@@ -285,11 +285,10 @@
286286 if(!$inline)print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'."\n";
287287 //if(!$inline)print '<!DOCTYPE cmml SYSTEM "http://svn.annodex.net/standards/cmml_2_0.dtd">'."\n";
288288 $tracks=array();
289 - if(count($dbr->numRows($mvd_res))!=0){
 289+ if(count($mvd_rows)!=0){
290290 global $wgOut;
291291 $MV_Overlay = new MV_Overlay();
292 - while($mvd = $dbr->fetchObject($mvd_res)){
293 -
 292+ foreach($mvd_rows as $mvd){
294293 if(!isset($tracks[$mvd->mvd_type]))$tracks[$mvd->mvd_type]='';
295294 $tracks[$mvd->mvd_type].='
296295 <'.$ns.'clip id="mvd_'.htmlentities($mvd->id).'" start="npt:'.htmlentities(seconds2ntp($mvd->start_time)).'" end="npt:'.htmlentities(seconds2ntp($mvd->end_time)).'">
Index: trunk/extensions/MetavidWiki/includes/articlepages/MV_SequencePage.php
@@ -93,13 +93,14 @@
9494 //for now just lookup all ... @@todo future expose diffrent language tracks
9595 if($clip['desc']==''){
9696 $dbr =& wfGetDB(DB_SLAVE);
97 - $mvd_res = MV_Index::getMVDInRange($streamTitle->getStreamId(),
 97+ $mvd_rows = MV_Index::getMVDInRange($streamTitle->getStreamId(),
9898 $streamTitle->getStartTimeSeconds(),
9999 $streamTitle->getEndTimeSeconds());
100 - if(count($dbr->numRows($mvd_res))!=0){
 100+
 101+ if(count($mvd_rows)!=0){
101102 $MV_Overlay = new MV_Overlay();
102103 $wgOut->clearHTML();
103 - while($mvd = $dbr->fetchObject($mvd_res)){
 104+ foreach($mvd_rows as $mvd){
104105 //output a link /line break
105106 $MV_Overlay->outputMVD($mvd);
106107 $wgOut->addHTML('<br>');
Index: trunk/extensions/MetavidWiki/includes/MV_Title.php
@@ -111,9 +111,7 @@
112112 function getStartTime(){ return $this->start_time;}
113113 function getTimeRequest(){ return $this->start_time.'/'.$this->end_time;}
114114 function getEndTime(){ return $this->end_time;}
115 - function getMwTitle(){return Title::MakeTitle(MV_NS_MVD, $this->wiki_title);}
116 -
117 -
 115+ function getMwTitle(){return Title::MakeTitle(MV_NS_MVD, $this->wiki_title);}
118116 function setStartEndIfEmpty(){
119117 global $mvDefaultStreamViewLength;
120118 if($this->start_time==null){
@@ -336,7 +334,7 @@
337335 htmlspecialchars( $this->getEndTime() ) .
338336 '</span>';
339337 }
340 - $o.='<'.htmlspecialchars($tag);
 338+ $o.='<'.htmlspecialchars($tag).' ';
341339 $o.=($vid_id=='')?'':' id="'.htmlspecialchars($vid_id).'" ';
342340 $o.='thumbnail="'.$this->getStreamImageURL($size, null, $force_server).'" '.
343341 'roe="'.$roe_url.'" '.
@@ -356,7 +354,7 @@
357355 htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultFlashQualityKey)) .
358356 '" src="'.$flash_stream_url .'"></source>';
359357
360 - $o.='</video>';
 358+ $o.='</'.htmlspecialchars($tag).'>';
361359 return $o;
362360 }else{
363361 return wfMsg('mv_error_stream_missing');
Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_MetavidInterface.php
@@ -72,7 +72,7 @@
7373 $this->grabSemanticProp();
7474
7575 //set up the interface objects:
76 - foreach(array('MV_VideoPlayer', 'MV_Overlay','MV_Tools') as $cp_name){
 76+ foreach(array('MV_VideoPlayer', 'MV_Navigator','MV_Overlay','MV_Tools') as $cp_name){
7777 $this->components[$cp_name] = new $cp_name(
7878 array('mv_interface'=>&$this)
7979 );
Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Navigator.php
@@ -7,12 +7,71 @@
88 */
99 class MV_Navigator extends MV_Component{
1010 function getHTML(){
 11+ global $wgUser;
 12+ $o='';
 13+ $sk = $wgUser->getSkin();
 14+ $dbr =& wfGetDB(DB_SLAVE);
1115 //get all annotative layers
12 - return wfMsg()
 16+ $stream_id = $this->mv_interface->article->mvTitle->getStreamId();
 17+ $stream_name = $this->mv_interface->article->mvTitle->getStreamName();
 18+ $stream_time_req = $this->mv_interface->article->mvTitle->getTimeRequest();
 19+ $start_sec = $this->mv_interface->article->mvTitle->getStartTimeSeconds();
 20+ $duration_sec = $this->mv_interface->article->mvTitle->getDuration();
 21+ $end_sec = $this->mv_interface->article->mvTitle->getEndTimeSeconds();
 22+ //print "start $start_sec end:$end_sec \n ";
 23+ $prev_end ='';
 24+ foreach(array('prev','next') as $pntype){
 25+ if($o!='')$o.=' ';
 26+ if($pntype=='prev'){
 27+ if($start_sec==0)
 28+ continue;
 29+ $qstart = 0;
 30+ $qend = $start_sec;
 31+ $orderby = 'end_time ASC';
 32+ }else if($pntype=='next'){
 33+ if($prev_end!=''){
 34+ $qstart = $prev_end+1;
 35+ }else{
 36+ $qstart = $end_sec+1;
 37+ }
 38+ $qend = $duration_sec;
 39+ $orderby = 'start_time ASC';
 40+ }
 41+ //print "Qstart: $qstart Qend:$qend \n";
 42+ $mvd_rows = MV_Index::getMVDInRange(
 43+ $stream_id,
 44+ $qstart,
 45+ $qend,
 46+ $mvd_type='anno_en',
 47+ $getText=false,
 48+ $smw_properties=array('speech_by','bill','category'),
 49+ $options=array('LIMIT'=>1, 'ORDER BY'=>$orderby)
 50+ );
 51+ //print "SHOULD GET $pntype for $stream_time_req";
 52+ //print_r($mvd_rows);
 53+ //die;
 54+ if(count($mvd_rows)!=0){
 55+ $row = current($mvd_rows);
 56+ $prev_end = $row->end_time;
 57+ $stime_req = seconds2ntp($row->start_time) . '/' . seconds2ntp($row->end_time);
 58+ $streamTitle = Title::newFromText($stream_name .'/'. $stime_req, MV_NS_STREAM);
 59+ if(trim($row->speech_by)!=''){
 60+ $o.=wfMsg('mv_'.$pntype.'_speech', $sk->makeKnownLinkObj($streamTitle, $row->speech_by));
 61+ }else if(trim($row->bill)!=''){
 62+ $o.=wfMsg('mv_'.$pntype.'_bill', $sk->makeKnownLinkObj($streamTitle, $row->bill));
 63+ }else if(count($row->category)!=0){
 64+ $first_cat = current($row->category);
 65+ $o.=wfMsg('mv_'.$pntype.'_cat', $sk->makeKnownLinkObj($streamTitle, $first_cat));
 66+ }
 67+ }
 68+ }
 69+
 70+ return $o;
1371 }
1472 function render_full(){
 73+ global $wgOut;
1574 $wgOut->addHTML('<div id="MV_Navigator">');
16 - $this->getHTML();
 75+ $wgOut->addHTML($this->getHTML());
1776 $wgOut->addHTML('</div>');
1877 }
1978 }
Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Overlay.php
@@ -102,16 +102,12 @@
103103 //global $mvgIP;
104104 //require_once($mvgIP . '/includes/MV_Index.php');
105105 $dbr =& wfGetDB(DB_SLAVE);
106 - $result = & MV_Index::getMVDInRange($this->mv_interface->article->mvTitle->getStreamId(),
 106+ $mvd_rows = & MV_Index::getMVDInRange($this->mv_interface->article->mvTitle->getStreamId(),
107107 $this->mv_interface->article->mvTitle->getStartTimeSeconds(),
108108 $this->mv_interface->article->mvTitle->getEndTimeSeconds(),
109109 $this->mvd_tracks);
110 - if($dbr->numRows($result) == 0){
111 - $this->mvd_pages=array();
112 - }else{
113 - while($row = $dbr->fetchObject($result)){
114 - $this->mvd_pages[$row->id]=$row;
115 - }
 110+ foreach($mvd_rows as $row){
 111+ $this->mvd_pages[$row->id]=$row;
116112 }
117113 }
118114 /*functions for transcript pages
Index: trunk/extensions/MetavidWiki/languages/MV_Messages.php
@@ -254,8 +254,12 @@
255255 'mv_bad_tool_request' => 'bad tool line should be form: tool_name|tool_display_name',
256256 'mv_update_layers' => 'update layers view',
257257
258 - 'mv_prev_speech' => 'Previous speech:',
259 - 'mv_next_speech' => 'Next speech:',
 258+ 'mv_prev_speech' => 'Previous speech: $1',
 259+ 'mv_next_speech' => 'Next speech: $1',
 260+ 'mv_prev_bill' => 'Previous Bill: $1',
 261+ 'mv_next_bill' => 'Next Bill: $1',
 262+ 'mv_prev_cat' => 'Previous Category: $1',
 263+ 'mv_next_cat' => 'Next Category: $1',
260264 'mv_navigate_stream' => 'Navigate stream',
261265
262266 #msg for overlay interface:

Status & tagging log