r41240 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41239‎ | r41240 | r41241 >
Date:22:46, 24 September 2008
Author:dale
Status:old
Tags:
Comment:
improved error check for thumb insert, improved sequence parser
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Overlay.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/maintenance/ogg_thumb_insert.php (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/ogg_thumb_insert.php
@@ -23,8 +23,8 @@
2424 USAGE
2525 php ogg_thumb_insert.php stream_name filename interval duration
2626
27 -EXAMPLE
28 - ogg_thumb_insert.php stream_name stream.ogg 20
 27+EXAMPLE where stream.ogg is 10min 20 seconds long and we get a frame every 5 seconds:
 28+ ogg_thumb_insert.php stream_name stream.ogg 5 620
2929
3030 Notes:
3131 if possible you want to use the source footage rather than the ogg to generate the thumbnails (ie the mpeg2 or dv)
@@ -44,5 +44,9 @@
4545 $dbw = $dbr = wfGetDB( DB_MASTER );
4646 for ( $i = 0; $i < $duration; $i += $interval ) {
4747 shell_exec( "ffmpeg -ss $i -i {$filename} -vcodec mjpeg -vframes 1 -an -f rawvideo -y {$filedir}/{$i}.jpg" );
48 - $dbw->query( "INSERT INTO `mv_stream_images` (`stream_id`, `time`) VALUES ($stream_id, $i)" );
 48+ if(is_file("{$filedir}/{$i}.jpg")){
 49+ $dbw->query( "INSERT INTO `mv_stream_images` (`stream_id`, `time`) VALUES ($stream_id, $i)" );
 50+ }else{
 51+ print "failed to create file: {$filedir}/{$i}.jpg \n";
 52+ }
4953 }
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialExport.php
@@ -142,7 +142,7 @@
143143 case 'sequence':
144144 if ( $this->par != '' ) {
145145 $this->seq_title = $this->par;
146 - $this->get_sequence_xspf();
 146+ $this->get_sequence_xml();
147147 }
148148 break;
149149 case 'ask':
@@ -155,7 +155,13 @@
156156 $wgOut->addHTML( $error_page );
157157 }
158158 }
159 - function get_sequence_xspf() {
 159+ function get_sequence_xml(){
 160+ $seqTitle = Title::newFromText( $this->seq_title, MV_NS_SEQUENCE );
 161+ $seqArticle = new MV_SequencePage( $seqTitle );
 162+ header( 'Content-Type: text/xml' );
 163+ print $seqArticle->getParsedSequence();
 164+ }
 165+ /*function get_sequence_xspf() {
160166 // get the sequence article and export in xspf format:
161167 $seqTitle = Title::newFromText( $this->seq_title, MV_NS_SEQUENCE );
162168 $seqArticle = new MV_SequencePage( $seqTitle );
@@ -178,7 +184,7 @@
179185 $o .= ' </trackList>' . "\n";
180186 $o .= '</playlist>';
181187 print $o;
182 - }
 188+ }*/
183189 function get_row_data() {
184190 // returns a high level description with cmml links (or inline-populated upon request)
185191 $this->mvTitle = new MV_Title( $this->stream_name . '/' . $this->req_time );
Index: trunk/extensions/MetavidWiki/includes/articlepages/MV_SequencePage.php
@@ -1,165 +1,205 @@
22 <?php
33 /*
44 * MV_SequencePage.php Created on Oct 17, 2007
5 - *
 5+ *
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 - *
13 - * redirects the user to the sequence interface.
 12+ *
 13+ * redirects the user to the sequence interface.
1414 */
15 - // sequence just adds some sequence hooks:
 15+// sequence just adds some sequence hooks:
1616 if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
1717
18 -define( 'SEQUENCE_TAG', 'sequence' );
 18+define( 'SEQUENCE_TAG', 'sequence_xml' );
1919
2020 class MV_SequencePage extends Article {
21 - var $outMode = 'page';
22 - var $clips = array();
23 - function __construct( $title ) {
24 - global $wgRequest;
25 - /*mvfAddHTMLHeader('sequence');
26 - if($title!=null){
27 - parent::__construct($title);
28 - }
29 - return $this;*/
30 - return parent::__construct( $title );
31 - }
32 - /*function doSeqReplace(&$input, &$argv, &$parser){
33 - return
34 - }*/
35 - /*function parsePlaylist(){
36 - global $wgParser,$wgOut;
37 - //valid playlist in-line-attributes:
 21+ var $outMode = 'page';
 22+ var $clips = array();
 23+ function __construct( $title ) {
 24+ global $wgRequest;
 25+ /*mvfAddHTMLHeader('sequence');
 26+ if($title!=null){
 27+ parent::__construct($title);
 28+ }
 29+ return $this;*/
 30+ return parent::__construct( $title );
 31+ }
 32+ /*
 33+ * returns the xml output of the sequence with all wiki-text templates/magic words swaped out
 34+ * also resolves all image and media locations with absolute paths.
 35+ */
 36+ function getParsedSequence(){
 37+ global $wgParser,$wgOut, $wgUser, $wgEnableParserCache;
 38+ $parserOutput=false;
 39+ //temporarlly stop cache:
 40+ $wgEnableParserCache=false;
 41+
 42+ if($wgEnableParserCache){
 43+ $mvParserCache = & MV_ParserCache::singleton();
 44+ $mvParserCache->addToKey( 'seq-xml' ); //differentiate the articles xml from article
 45+ $parserOutput = $mvParserCache->get( $this, $wgUser );
 46+ }
 47+ if($parserOutput!=false)
 48+ return $parserOutput->getText();
 49+ //get seqXML:
 50+ $seq_text_xml = $this->getSequenceText();
 51+ $seqXML=array();
 52+ //parse
 53+ $xml_parser = xml_parser_create( 'UTF-8' ); // UTF-8 or ISO-8859-1
 54+ xml_parser_set_option( $xml_parser, XML_OPTION_CASE_FOLDING, 0 );
 55+ xml_parser_set_option( $xml_parser, XML_OPTION_SKIP_WHITE, 1 );
 56+ xml_parse_into_struct( $xml_parser, $seq_text_xml, $seqXML );
 57+ xml_parser_free($xml_parser);
 58+ //print_r($seqXML);
 59+ //die;
 60+
 61+
 62+ $parserOutput = $wgParser->parse($seq_text, $this->mTitle, ParserOptions::newFromUser( $wgUser ));
 63+
 64+ //save to cache if parser cache enabled:
 65+ if($wgEnableParserCache)
 66+ $mvParserCache->save( $parserOutput, $this, $wgUser );
 67+
 68+
 69+ return $parserOutput->getText();
 70+ }
 71+ /*function doSeqReplace(&$input, &$argv, &$parser){
 72+ return
 73+ }*/
 74+ /*function parsePlaylist(){
 75+ global $wgParser,$wgOut;
 76+ //valid playlist in-line-attributes:
3877 $mvInlineAttr = array('wClip', 'mvClip', 'title','linkback','desc','desc','image');
39 -
40 - //build a associative array of "clips"
41 - $seq_text = $this->getSequenceText();
42 -
43 - $seq_lines = explode("\n",$seq_text);
44 - $parseBucket=$cur_attr='';
45 - $clip_inx=-1;
46 - foreach($seq_lines as $line){
47 - //actions start with |
48 - $e = strpos($line, '=');
49 - if($e!==false){
50 - $cur_attr = substr($line, 1,$e-1);
51 - }
52 - if(in_array($cur_attr, $mvInlineAttr)){
53 - if($cur_attr=='mvClip'){
54 - $clip_inx++;
55 - }
56 - //close the parse bucket (found a valid inline attr)
57 - if($parseBucket!=''&& $cur_attr!='desc'){
58 - $output = $wgParser->parse( $parseBucket, $parser->mTitle, $parser->mOptions, true, false );
59 - $parseBucket='';
60 - }
61 - }
62 - $start_pos = ($e!==false)?$e+1:0;
63 - if($clip_inx!=-1){
64 - if(!isset($this->clips[$clip_inx]))$this->clips[$clip_inx]=array();
65 - if(!isset($this->clips[$clip_inx][$cur_attr]))$this->clips[$clip_inx][$cur_attr]='';
66 - $this->clips[$clip_inx][$cur_attr].= substr($line, $start_pos);
67 - }
68 - }
69 - //poluate data (this could go here or somewhere else)
70 - foreach($this->clips as $inx=>&$clip){
71 - if(trim($clip['mvClip'])==''){
72 - unset($this->clips[$inx]);
73 - continue;
74 - }
75 - if($clip['mvClip']){
76 - $sn = str_replace('?t=','/', $clip['mvClip']);
77 - $streamTitle = new MV_Title($sn);
78 - $wgStreamTitle = Title::newFromText($sn, MV_NS_STREAM);
79 - if($streamTitle->doesStreamExist()){
80 - //mvClip is a substitue for src so assume its there:
81 - $clip['src']=$streamTitle->getWebStreamURL();
82 - //title
83 - if(!isset($clip['title']))$clip['title']='';
84 - if($clip['title']=='')
85 - $clip['title']=$streamTitle->getTitleDesc();
86 -
87 - if(!isset($clip['info']))$clip['info']='';
88 - if($clip['info']=='')
89 - $clip['info']=$wgStreamTitle->getFullURL();
90 - }
91 - //check if we should look up the image:
92 - if(!isset($clip['image']))$clip['image']=='';
93 - if($clip['image']=='')
94 - $clip['image'] =$streamTitle->getFullStreamImageURL();
95 - //check if desc was present:
96 - if(!isset($clip['desc']))$clip['desc']='';
97 - //for now just lookup all ... @@todo future expose diffrent language tracks
98 - if($clip['desc']==''){
99 - $dbr =& wfGetDB(DB_SLAVE);
100 - $mvd_rows = MV_Index::getMVDInRange($streamTitle->getStreamId(),
101 - $streamTitle->getStartTimeSeconds(),
102 - $streamTitle->getEndTimeSeconds());
103 -
104 - if(count($mvd_rows)!=0){
105 - $MV_Overlay = new MV_Overlay();
106 - $wgOut->clearHTML();
107 - foreach($mvd_rows as $mvd){
108 - //output a link /line break
109 - $MV_Overlay->outputMVD($mvd);
110 - $wgOut->addHTML('<br>');
111 - }
112 - $clip['desc']=$wgOut->getHTML();
113 - $wgOut->clearHTML();
114 - }
115 - }
116 - }
117 -
118 - }
119 - //print_r($this->clips);
120 - }*/
121 - function doSeqReplace( &$input, &$argv, &$parser ) {
122 - global $wgTitle, $wgUser, $wgRequest, $markerList;
123 - $sk = $wgUser->getSkin();
124 - $title = Title::MakeTitle( NS_SPECIAL, 'MvExportSequence/' . $wgTitle->getDBKey() );
125 - $title_url = $title->getFullURL();
126 - $oldid = $wgRequest->getVal( 'oldid' );
 78+
 79+ //build a associative array of "clips"
 80+ $seq_text = $this->getSequenceText();
 81+
 82+ $seq_lines = explode("\n",$seq_text);
 83+ $parseBucket=$cur_attr='';
 84+ $clip_inx=-1;
 85+ foreach($seq_lines as $line){
 86+ //actions start with |
 87+ $e = strpos($line, '=');
 88+ if($e!==false){
 89+ $cur_attr = substr($line, 1,$e-1);
 90+ }
 91+ if(in_array($cur_attr, $mvInlineAttr)){
 92+ if($cur_attr=='mvClip'){
 93+ $clip_inx++;
 94+ }
 95+ //close the parse bucket (found a valid inline attr)
 96+ if($parseBucket!=''&& $cur_attr!='desc'){
 97+ $output = $wgParser->parse( $parseBucket, $parser->mTitle, $parser->mOptions, true, false );
 98+ $parseBucket='';
 99+ }
 100+ }
 101+ $start_pos = ($e!==false)?$e+1:0;
 102+ if($clip_inx!=-1){
 103+ if(!isset($this->clips[$clip_inx]))$this->clips[$clip_inx]=array();
 104+ if(!isset($this->clips[$clip_inx][$cur_attr]))$this->clips[$clip_inx][$cur_attr]='';
 105+ $this->clips[$clip_inx][$cur_attr].= substr($line, $start_pos);
 106+ }
 107+ }
 108+ //poluate data (this could go here or somewhere else)
 109+ foreach($this->clips as $inx=>&$clip){
 110+ if(trim($clip['mvClip'])==''){
 111+ unset($this->clips[$inx]);
 112+ continue;
 113+ }
 114+ if($clip['mvClip']){
 115+ $sn = str_replace('?t=','/', $clip['mvClip']);
 116+ $streamTitle = new MV_Title($sn);
 117+ $wgStreamTitle = Title::newFromText($sn, MV_NS_STREAM);
 118+ if($streamTitle->doesStreamExist()){
 119+ //mvClip is a substitue for src so assume its there:
 120+ $clip['src']=$streamTitle->getWebStreamURL();
 121+ //title
 122+ if(!isset($clip['title']))$clip['title']='';
 123+ if($clip['title']=='')
 124+ $clip['title']=$streamTitle->getTitleDesc();
 125+
 126+ if(!isset($clip['info']))$clip['info']='';
 127+ if($clip['info']=='')
 128+ $clip['info']=$wgStreamTitle->getFullURL();
 129+ }
 130+ //check if we should look up the image:
 131+ if(!isset($clip['image']))$clip['image']=='';
 132+ if($clip['image']=='')
 133+ $clip['image'] =$streamTitle->getFullStreamImageURL();
 134+ //check if desc was present:
 135+ if(!isset($clip['desc']))$clip['desc']='';
 136+ //for now just lookup all ... @@todo future expose diffrent language tracks
 137+ if($clip['desc']==''){
 138+ $dbr =& wfGetDB(DB_SLAVE);
 139+ $mvd_rows = MV_Index::getMVDInRange($streamTitle->getStreamId(),
 140+ $streamTitle->getStartTimeSeconds(),
 141+ $streamTitle->getEndTimeSeconds());
 142+
 143+ if(count($mvd_rows)!=0){
 144+ $MV_Overlay = new MV_Overlay();
 145+ $wgOut->clearHTML();
 146+ foreach($mvd_rows as $mvd){
 147+ //output a link /line break
 148+ $MV_Overlay->outputMVD($mvd);
 149+ $wgOut->addHTML('<br>');
 150+ }
 151+ $clip['desc']=$wgOut->getHTML();
 152+ $wgOut->clearHTML();
 153+ }
 154+ }
 155+ }
 156+
 157+ }
 158+ //print_r($this->clips);
 159+ }*/
 160+ function doSeqReplace( &$input, &$argv, &$parser ) {
 161+ global $wgTitle, $wgUser, $wgRequest, $markerList;
 162+ $sk = $wgUser->getSkin();
 163+ $title = Title::MakeTitle( NS_SPECIAL, 'MvExportSequence/' . $wgTitle->getDBKey() );
 164+ $title_url = $title->getFullURL();
 165+ $oldid = $wgRequest->getVal( 'oldid' );
127166 if ( isset( $oldid ) ) {
128 - // @@ugly hack .. but really this whole sequencer needs a serious rewrite)
 167+ // @@ugly hack .. but really this whole sequencer needs a serious rewrite)
129168 $ss = ( strpos( $title_url, '?' ) === false ) ? '?':'&';
130169 $title_url .= $ss . 'oldid=' . $oldid;
131 - }
132 -
133 - $vidtag = '<div id="file" class="fullImageLink"><playlist';
 170+ }
 171+
 172+ $vidtag = '<div id="file" class="fullImageLink"><playlist';
134173 $vidtag .= ' width="400" height="300" src="' . htmlspecialchars( $title_url ) . '">';
135174 $vidtag .= '</playlist></div><hr>';
136 -
 175+
137176 $marker = "xx-marker" . count( $markerList ) . "-xx";
138 - $markerList[] = $vidtag;
139 - return $marker;
140 - }
141 - function getPageContent() {
142 - global $wgRequest;
143 - $base_text = parent::getContent();
144 - // strip the sequence
145 - $seqClose = strpos( $base_text, '</' . SEQUENCE_TAG . '>' );
146 - if ( $seqClose !== false ) {
147 - return trim( substr( $base_text, $seqClose + strlen( '</' . SEQUENCE_TAG . '>' ) ) );
148 - }
149 - }
150 - function getSequenceText() {
151 - // check if the current article exists:
152 - if ( $this->mTitle->exists() ) {
153 - $base_text = parent::getContent();
154 - $seqClose = strpos( $base_text, '</' . SEQUENCE_TAG . '>' );
155 - if ( $seqClose !== false ) {
156 - // strip the sequence tag:
157 - $seqText = "\n" . trim( substr( $base_text, strlen( '<' . SEQUENCE_TAG . '>' ), $seqClose - strlen( '</' . SEQUENCE_TAG . '>' ) ) ) . "\n";
158 - return $seqText;
159 - }
160 - }
 177+ $markerList[] = $vidtag;
 178+ return $marker;
 179+ }
 180+ function getPageContent() {
 181+ global $wgRequest;
 182+ $base_text = parent::getContent();
 183+ // strip the sequence
 184+ $seqClose = strpos( $base_text, '</' . SEQUENCE_TAG . '>' );
 185+ if ( $seqClose !== false ) {
 186+ return trim( substr( $base_text, $seqClose + strlen( '</' . SEQUENCE_TAG . '>' ) ) );
 187+ }
 188+ }
 189+ //@@support static call if aritle is provided:
 190+ function getSequenceText($article=null) {
 191+ // check if the current article exists:
 192+ if ( $this->mTitle->exists() ) {
 193+ $base_text = parent::getContent();
 194+ $seqClose = strpos( $base_text, '</' . SEQUENCE_TAG . '>' );
 195+ if ( $seqClose !== false ) {
 196+ // strip the sequence tag:
 197+ $seqText = "\n" . trim( substr( $base_text, strlen( '<' . SEQUENCE_TAG . '>' ), $seqClose - strlen( '</' . SEQUENCE_TAG . '>' ) ) ) . "\n";
 198+ return $seqText;
 199+ }
 200+ }
161201 // return a "new empty sequence ..only set the title:"
162 - return '|title=' . $this->mTitle->getText() . "\n";
163 -
164 - }
165 - }
 202+ return '';
 203+
 204+ }
 205+}
166206 ?>
Index: trunk/extensions/MetavidWiki/includes/MV_MetavidInterface/MV_Overlay.php
@@ -266,16 +266,19 @@
267267 }
268268 // use the cache by default:
269269 // $usepCache = (isset($mvd_page->usePcache))?$mvd_page->usePcache:true;
270 -
 270+
271271 /*try to pull from cache: separate out cache for internal links vs external links cache*/
272 - $MvParserCache = & MV_ParserCache::singleton();
273 - $add_opt = ( $absolute_links ) ? 'a':'';
274 - // add the dbKey since I don't know how to easy purge the cache and we are getting cache missmatch
275 - $add_opt .= $mvdTitle->getDBkey();
276 - $MvParserCache->addToKey( $add_opt );
277 -
278 - $parserOutput = $MvParserCache->get( $mvdArticle, $wgUser );
279 -
 272+ if( $wgEnableParserCache ) {
 273+ $MvParserCache = & MV_ParserCache::singleton();
 274+ $add_opt = ( $absolute_links ) ? 'a':'';
 275+ // add the dbKey since I don't know how to easy purge the cache and we are getting cache missmatch
 276+ $add_opt .= $mvdTitle->getDBkey();
 277+ $MvParserCache->addToKey( $add_opt );
 278+
 279+ $parserOutput = $MvParserCache->get( $mvdArticle, $wgUser );
 280+ }else{
 281+ $parserOutput=false;
 282+ }
280283 if ( $parserOutput !== false ) {
281284 // print "js_log('found in cache: with hash: " . $MvParserCache->getKey( $mvdArticle, $wgUser )."');\n";
282285 // found in cache output and be done with it:
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -29,7 +29,7 @@
3030 //media_server mv_embed_path (the path on media servers to mv_embed for java iframe with leading and trailing slashes)
3131 var mv_media_iframe_path = '/mv_embed/';
3232
33 -//the default height/width of the vidoe (if no style or width parm provided)
 33+//the default height/width of the vidoe (if no style or width attr provided)
3434 var mv_default_video_size = '400x300';
3535
3636 //this restricts playable sources to ROE xml media without start end time atttribute
@@ -1261,9 +1261,7 @@
12621262 '</div>');
12631263 //$j('body').append();
12641264 }else{
1265 - //if($j('#metaBox_'+this.pe.id).css('display')!='none'){
12661265 $j('#metaBox_'+this.pe.id).fadeIn("fast");
1267 - //}
12681266 }
12691267 },
12701268 close:function(){
@@ -2693,16 +2691,6 @@
26942692 out+='</blockquote>'+getMsg('download_text')+"<blockquote>"+dl_txt_list+'</blockquote></span>';
26952693 return out;
26962694 },
2697 - /*getDLlist:function(transform_function){
2698 -
2699 - var dl_list=dl_txt_list='';
2700 - $j.each(this.media_element.getSources(), function(index, source)
2701 - {
2702 -
2703 - });
2704 -
2705 - return out;
2706 - },*/
27072695 /*
27082696 * base embed controls
27092697 * the play button calls
@@ -2849,7 +2837,8 @@
28502838 }
28512839 }
28522840
2853 -/* returns html for a transparent png (for ie<7)*/
 2841+/* returns html for a transparent png (for ie<7)
 2842+ * not currently used:
28542843 function getTransparentPng(image){
28552844 if(!image.style)image.style='';
28562845 if( embedTypes.msie ){
@@ -2861,6 +2850,7 @@
28622851 image.src + '">';
28632852 }
28642853 }
 2854+*/
28652855
28662856 /*
28672857 * utility functions:
@@ -3097,28 +3087,6 @@
30983088 //in case of "throw error" type usage
30993089 return false;
31003090 }
3101 -function getNextHighestZindex(obj){
3102 - var highestIndex = 0;
3103 - var currentIndex = 0;
3104 - var elArray = Array();
3105 - if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }
3106 - for(var i=0; i < elArray.length; i++){
3107 - if (elArray[i].currentStyle){
3108 - currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
3109 - }else if(window.getComputedStyle){
3110 - currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
3111 - }
3112 - if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
3113 - }
3114 - return(highestIndex+1);
3115 -}
3116 -function var_dump(obj) {
3117 - if(typeof obj == "object") {
3118 - return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
3119 - } else {
3120 - return "Type: "+typeof(obj)+"\nValue: "+obj;
3121 - }
3122 -}
31233091
31243092 function js_error(string){
31253093 alert(string);