function mvLinkBegin($skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret)
{
    //if a stream title and the base stream exists give a valid link
    if ($target->getNamespace() == MV_NS_STREAM) {
        $mvTitle = new MV_Title($target);
        if ($mvTitle->doesStreamExist()) {
            if (in_array('broken', $options)) {
                foreach ($options as $k => $v) {
                    if ($v == 'broken') {
                        $options[$k] = 'known';
                    }
                }
            } elseif (!in_array('known', $options)) {
                $options[] = 'known';
            }
        }
    }
    return true;
}
    function outPutItem($wikiTitle, $desc_html = '')
    {
        global $wgOut, $wgUser;
        $sk = $wgUser->getSkin();
        $mvTitle = new MV_Title($wikiTitle);
        $mStreamTitle = Title::makeTitle(MV_NS_STREAM, ucfirst($mvTitle->getStreamName()) . '/' . $mvTitle->getTimeRequest());
        // only output media RSS item if its valid media:
        if (!$mvTitle->doesStreamExist()) {
            return;
        }
        // @@todo this should be cached
        $thumb_ref = $mvTitle->getFullStreamImageURL('320x240', null, '', true);
        if ($desc_html == '') {
            $article = new Article($wikiTitle);
            $wgOut->clearHTML();
            $wgOut->addWikiText($article->getContent());
            $desc_html = $wgOut->getHTML();
            $wgOut->clearHTML();
        }
        //get the parent meta if allowed:
        global $mvGetParentMeta;
        $pmvd = false;
        if ($mvGetParentMeta && strtolower($mvTitle->getMvdTypeKey()) == 'ht_en') {
            $pmvd = MV_Index::getParentAnnotativeLayers($mvTitle);
            if ($pmvd->wiki_title) {
                $pMvTitle = new MV_Title($pmvd->wiki_title);
                $pAnnoStreamTitle = Title::MakeTitle(MV_NS_STREAM, $pMvTitle->getNearStreamName(0));
            }
        }
        $desc_xml = '<![CDATA[
			<center class="mv_rss_view_only">
				<a href="' . htmlspecialchars($mStreamTitle->getFullUrl()) . '"><img src="' . $thumb_ref . '" border="0" /></a>
			</center>
			<br />' . $desc_html . ']]>';
        $stream_url = $mvTitle->getWebStreamURL();
        $talkpage = $wikiTitle->getTalkPage();
        $type_desc = $mvTitle->getMvdTypeKey() ? wfMsg($mvTitle->getMvdTypeKey()) : '';
        $time_desc = $mvTitle->getTimeDesc() ? $mvTitle->getTimeDesc() : '';
        ?>
<item>
<link>
		<?php 
        echo mvRSSFeed::xmlEncode($mStreamTitle->getFullUrl());
        ?>
</link>
<title><?php 
        echo mvRSSFeed::xmlEncode($mvTitle->getStreamNameText() . ' ' . $time_desc);
        ?>
</title>
<description>
<?php 
        echo $desc_xml;
        ?>
</description>
<?php 
        global $mvDefaultVideoQualityKey, $mvVidQualityMsgKeyType, $mvDefaultVideoHighQualityKey, $mvDefaultFlashQualityKey;
        //check a few different types in order of prefrence:
        if ($stream_url = $mvTitle->getWebStreamURL($mvDefaultVideoHighQualityKey)) {
            $mk = $mvDefaultVideoHighQualityKey;
        } elseif ($stream_url = $mvTitle->getWebStreamURL($mvDefaultVideoQualityKey)) {
            $mk = $mvDefaultVideoQualityKey;
        } elseif ($stream_url = $mvTitle->getWebStreamURL($mvDefaultFlashQualityKey)) {
            $mk = $mvDefaultFlashQualityKey;
        }
        if ($stream_url) {
            echo '<enclosure name="' . wfMsg($mk) . '" type="video/ogg" ' . 'url="' . mvRSSFeed::xmlEncode($stream_url) . '"/>';
        }
        ?>

<comments>
<?php 
        echo mvRSSFeed::xmlEncode($talkpage->getFullUrl());
        ?>
</comments>
<?php 
        $person = '';
        if ($pmvd && $pmvd->Speech_by) {
            $personTitle = Title::newFromText($pmvd->Speech_by);
            ?>
<media:person label="<?php 
            echo $personTitle->getText();
            ?>
" url="<?php 
            echo mvRSSFeed::xmlEncode($personTitle->getFullURL());
            ?>
" />
<?php 
        }
        //handle any parent clip tag info:
        if ($pmvd) {
            ?>
<media:parent_clip url="<?php 
            echo mvRSSFeed::xmlEncode($pAnnoStreamTitle->getFullUrl());
            ?>
" />
<?php 
            if ($pmvd->Bill) {
                $bTitle = Title::newFromText($pmvd->Bill);
                ?>
<media:bill label="<?php 
                echo $bTitle->getText();
                ?>
" url="<?php 
                echo mvRSSFeed::xmlEncode($bTitle->getFullURL());
                ?>
" />
<?php 
            }
            if ($pmvd->category) {
                foreach ($pmvd->category as $cat_titlekey) {
                    $cTitle = $cTitle = Title::MakeTitle(NS_CATEGORY, $cat_titlekey);
                    ?>
<media:category label="<?php 
                    echo $cTitle->getText();
                    ?>
" url="<?php 
                    echo mvRSSFeed::xmlEncode($cTitle->getFullUrl());
                    ?>
" />
<?php 
                }
            }
        }
        ?>
<media:thumbnail
	url="<?php 
        echo mvRSSFeed::xmlEncode($thumb_ref);
        ?>
" />
<media:roe_embed
	url="<?php 
        echo mvRSSFeed::xmlEncode($mvTitle->getROEURL());
        ?>
" />
<media:group>
<?php 
        global $mvDefaultFlashQualityKey, $mvVidQualityMsgKeyType, $mvDefaultFlashQualityKey;
        //add in media group:
        $vid_types = array($mvDefaultVideoQualityKey, 'mv_ogg_high_quality', $mvDefaultFlashQualityKey);
        foreach ($vid_types as $vid_key) {
            $stream_url = $mvTitle->getWebStreamURL($vid_key);
            if ($stream_url !== false && isset($mvVidQualityMsgKeyType[$vid_key])) {
                ?>
	<media:content
		blip:role="<?php 
                echo mvRSSFeed::xmlEncode($vid_key);
                ?>
"
		expression="full"
		type="<?php 
                echo mvRSSFeed::xmlEncode($mvVidQualityMsgKeyType[$vid_key]);
                ?>
"
		url="<?php 
                echo htmlentities($stream_url);
                ?>
"></media:content>
		<?php 
            }
        }
        ?>
</media:group>
</item>
<?
	}
	function outPutItem($wikiTitle, $desc_html=''){
		global $wgOut;		
		$mvTitle = new MV_Title($wikiTitle);
		$mStreamTitle = Title::makeTitle(MV_NS_STREAM, ucfirst($mvTitle->getStreamName()) . '/'.$mvTitle->getTimeRequest());
		
		//only output media RSS item if its valid media: 
		if(!$mvTitle->doesStreamExist())return ;

		//@@todo this should be cached 	
		$thumb_ref = $mvTitle->getStreamImageURL('320x240');
		if($desc_html==''){			
			$article = new Article($wikiTitle);
			$wgOut->clearHTML(); 			
			$wgOut->addWikiText($article->getContent() );
			$desc_html = $wgOut->getHTML();		
			$wgOut->clearHTML();					
		}
		$desc_xml ='<![CDATA[				
			<center class="mv_rss_view_only">
				<a href="'.$mStreamTitle->getFullUrl().'"><img src="'.$thumb_ref.'" border="0" /></a>
			</center>
			<br />'.
			$desc_html. 
			']]>';
				
		$stream_url = $mvTitle->getWebStreamURL();			
		$talkpage = $wikiTitle->getTalkPage();			
					
		$type_desc = ($mvTitle->getMvdTypeKey())?wfMsg($mvTitle->getMvdTypeKey()):'';			
		$time_desc = ($mvTitle->getTimeDesc())?$mvTitle->getTimeDesc():'';					
		?>	
		<item>
		<link><?=mvRSSFeed::xmlEncode($mStreamTitle->getFullUrl())?></link>
		<title><?=mvRSSFeed::xmlEncode(
			$mvTitle->getStreamNameText() . ' ' .  $time_desc)?></title>
		<description><?=$desc_xml?></description>
		<enclosure type="video/ogg" url="<?=mvRSSFeed::xmlEncode($stream_url)?>"/>
		<comments><?=mvRSSFeed::xmlEncode($talkpage->getFullUrl())?></comments>
		<media:thumbnail url="<?=mvRSSFeed::xmlEncode($thumb_ref)?>"/>
		<? /*todo add in alternate streams HQ, lowQ archive.org etc: 
		<media:group>
    		<media:content blip:role="Source" expression="full" fileSize="2702848" height="240" isDefault="true" type="video/msvideo" url="http://blip.tv/file/get/Conceptdude-EroticDanceOfANiceBabe266.avi" width="360"></media:content>
    		<media:content blip:role="web" expression="full" fileSize="3080396" height="240" isDefault="false" type="video/x-flv" url="http://blip.tv/file/get/Conceptdude-EroticDanceOfANiceBabe266.flv" width="360"></media:content>
  		</media:group>
  		*/ ?> 
		</item>
		<?
	}
$srt_ary = file($srt_file);
if ($srt_ary === false) {
    die(' could not find srt file: ' . $srt_file);
}
//time stamp:
$org_start_time = intval(trim(str_replace('starttime', '', $srt_ary[2])));
class streamObject
{
}
$stream = new streamObject();
$stream->name = $stream_name;
$stream->date_start_time = $org_start_time;
$stream->sync_status = 'in_sync';
$stream->duration = $duration;
$mvTitle = new MV_Title('Stream:' . $stream_name);
if (!$mvTitle->doesStreamExist()) {
    print $stream_name . " does not exist ... creating\n";
    // print 'do stream desc'."\n";
    if (!isset($MVStreams)) {
        $MVStreams = array();
    }
    // init the stream (legacy from old stream insert system)
    $MVStreams[$stream->name] = new MV_Stream($stream);
    do_add_stream($mvTitle, $stream);
}
$stream_id = $mvTitle->getStreamId();
print 'got stream id: ' . $stream_id . "\n";
//check for & update stream files:
do_stream_file_check($stream);
$filedir = '/video/metavid/mvprime_stream_images/' . MV_StreamImage::getRelativeImagePath($stream_id);
if (!is_dir($filedir)) {
function do_stream_insert($mode, $stream_name = '')
{
    global $mvgIP, $MVStreams, $options, $args, $wgDBname;
    $dbr = wfGetDB(DB_SLAVE);
    if ($mode == 'all') {
        $sql = "SELECT * FROM `metavid`.`streams` WHERE `sync_status`='in_sync'";
    } elseif ($mode == 'files') {
        $sql = "SELECT * FROM `metavid`.`streams` WHERE `trascoded` != 'none'";
    } elseif ($mode == 'all_in_wiki') {
        $sql = "SELECT `metavid`.`streams`.* FROM `{$wgDBname}`.`mv_streams` LEFT JOIN `metavid`.`streams` ON (`{$wgDBname}`.`mv_streams`.`name` = `metavid`.`streams`.`name`) ";
    } elseif ($mode == 'all_sync_past_date') {
        print "doing all after: " . $args[$options['date']] . "\n";
        list($month, $day, $year) = explode('/', $args[$options['date']]);
        $date_time = mktime(0, 0, 0, $month, $day, $year);
        $sql = "SELECT * FROM `metavid`.`streams` WHERE `sync_status`= 'in_sync' AND `adj_start_time` > {$date_time}";
    } else {
        $sql = "SELECT * FROM `metavid`.`streams` WHERE `name` LIKE '{$stream_name}'";
    }
    $res = $dbr->query($sql);
    if ($dbr->numRows($res) == 0) {
        die('could not find stream: ' . $stream_name . "\n");
    }
    // load all stream names:
    while ($row = $dbr->fetchObject($res)) {
        $streams[] = $row;
    }
    print "working on " . count($streams) . ' streams' . "\n";
    foreach ($streams as $stream) {
        print "on stream {$stream->name} \n";
        $force = isset($options['force']) ? true : false;
        // init the stream
        $MVStreams[$stream->name] = new MV_Stream($stream);
        // check if the stream has already been added to the wiki (if not add it)
        $mvTitle = new MV_Title('Stream:' . $stream->name);
        if (!$mvTitle->doesStreamExist()) {
            // print 'do stream desc'."\n";
            do_add_stream($mvTitle, $stream);
            echo "stream " . $mvTitle->getStreamName() . " added \n";
        } else {
            do_update_wiki_page($stream->name, mv_semantic_stream_desc($mvTitle, $stream), MV_NS_STREAM, $force);
            // $updated = ' updated' echo "stream " . $mvTitle->getStreamName() . " already present $updated\n";
        }
        if ($mode != 'all_in_wiki') {
            // add duration and start_time attr
            do_stream_attr_check($stream);
        }
        // do insert/copy all media images
        if (!isset($options['skipimage'])) {
            do_process_images($stream, $force);
            print "done with images\n";
        }
        if (!isset($options['skipfiles'])) {
            // check for files (make sure they match with metavid db values
            do_stream_file_check($stream);
        }
        if (!isset($options['skiptext'])) {
            // process all stream text:
            do_process_text($stream, $force);
        }
        if (!isset($options['skipSpeechMeta'])) {
            // do annoative track for continus speches
            do_annotate_speeches($stream, $force);
        }
    }
}
 function add_stream()
 {
     $out = '';
     $mvTitle = new MV_Title($this->stream_name);
     //fist check if the given stream name already exists
     if ($mvTitle->doesStreamExist()) {
         $mv_page = Title::newFromText($this->stream_name, MV_NS_STREAM);
         return '<span class="error">' . wfMsg('mv_stream_already_exists', $this->stream_name, $mv_page->getFullURL()) . '</span> ';
     } else {
         //get the stream pointer
         //$stream =& mvGetMVStream(array('name'=>$this->stream_name,'sitting_id'=>$this->sitting_id));
         //$strarray = array($key=>val);
         //foreach ($this as $key => $val) {
         //	if (isset ($key)) {
         //		$strarray[$key] = $val;
         //	}
         //}
         $stream = new MV_Stream(array('name' => $this->stream_name, 'state' => $this->state, 'date_start_time' => $this->date_start_time, 'duration' => $this->duration, 'sitting_id' => $this->sitting_id));
         $stream->db_load_stream();
         //if the stream is inserted proceed with page insertion
         if ($stream->insertStream($this->stream_type)) {
             global $wgUser;
             $sk = $wgUser->getSkin();
             //insert page
             $streamTitle = Title::newFromText($this->stream_name, MV_NS_STREAM);
             $wgArticle = new Article($streamTitle);
             $success = $wgArticle->doEdit($this->stream_desc, wfMsg('mv_summary_add_stream'));
             if ($success) {
                 //stream inserted succesfully report to output
                 //$streamLink = $sk->makeLinkObj( $streamTitle,  $this->stream_name );
                 //$out='stream '.$streamLink.' added';
                 return true;
             } else {
                 //$out=wfMsg('mv_error_stream_insert');
                 return false;
             }
         } else {
             //stream failed insert
             return false;
         }
     }
     //return $out;
 }
 function parsePlaylist()
 {
     global $wgParser, $wgOut;
     //valid playlist in-line-attributes:
     $mvInlineAttr = array('wClip', 'mvClip', 'title', 'linkback', 'desc', 'desc', 'image');
     //build a associative array of "clips"
     $seq_text = $this->getSequenceText();
     $seq_lines = explode("\n", $seq_text);
     $parseBucket = $cur_attr = '';
     $clip_inx = -1;
     foreach ($seq_lines as $line) {
         //actions start with |
         $e = strpos($line, '=');
         if ($e !== false) {
             $cur_attr = substr($line, 1, $e - 1);
         }
         if (in_array($cur_attr, $mvInlineAttr)) {
             if ($cur_attr == 'mvClip') {
                 $clip_inx++;
             }
             //close the parse bucket (found a valid inline attr)
             if ($parseBucket != '' && $cur_attr != 'desc') {
                 $output = $wgParser->parse($parseBucket, $parser->mTitle, $parser->mOptions, true, false);
                 $parseBucket = '';
             }
         }
         $start_pos = $e !== false ? $e + 1 : 0;
         if ($clip_inx != -1) {
             if (!isset($this->clips[$clip_inx])) {
                 $this->clips[$clip_inx] = array();
             }
             if (!isset($this->clips[$clip_inx][$cur_attr])) {
                 $this->clips[$clip_inx][$cur_attr] = '';
             }
             $this->clips[$clip_inx][$cur_attr] .= substr($line, $start_pos);
         }
     }
     //poluate data (this could go here or somewhere else)
     foreach ($this->clips as $inx => &$clip) {
         if (trim($clip['mvClip']) == '') {
             unset($this->clips[$inx]);
             continue;
         }
         if ($clip['mvClip']) {
             $sn = str_replace('?t=', '/', $clip['mvClip']);
             $streamTitle = new MV_Title($sn);
             $wgStreamTitle = Title::newFromText($sn, MV_NS_STREAM);
             if ($streamTitle->doesStreamExist()) {
                 //mvClip is a substitue for src so assume its there:
                 $clip['src'] = $streamTitle->getWebStreamURL();
                 //title
                 if (!isset($clip['title'])) {
                     $clip['title'] = '';
                 }
                 if ($clip['title'] == '') {
                     $clip['title'] = $streamTitle->getTitleDesc();
                 }
                 if (!isset($clip['info'])) {
                     $clip['info'] = '';
                 }
                 if ($clip['info'] == '') {
                     $clip['info'] = $wgStreamTitle->getFullURL();
                 }
             }
             //check if we should look up the image:
             if (!isset($clip['image'])) {
                 $clip['image'] == '';
             }
             if ($clip['image'] == '') {
                 $clip['image'] = $streamTitle->getFullStreamImageURL();
             }
             //check if desc was present:
             if (!isset($clip['desc'])) {
                 $clip['desc'] = '';
             }
             //for now just lookup all ... @@todo future expose diffrent language tracks
             if ($clip['desc'] == '') {
                 $dbr =& wfGetDB(DB_SLAVE);
                 $mvd_res = MV_Index::getMVDInRange($streamTitle->getStreamId(), $streamTitle->getStartTimeSeconds(), $streamTitle->getEndTimeSeconds());
                 if (count($dbr->numRows($mvd_res)) != 0) {
                     $MV_Overlay = new MV_Overlay();
                     $wgOut->clearHTML();
                     while ($mvd = $dbr->fetchObject($mvd_res)) {
                         //output a link /line break
                         $MV_Overlay->outputMVD($mvd);
                         $wgOut->addHTML('<br>');
                     }
                     $clip['desc'] = $wgOut->getHTML();
                     $wgOut->clearHTML();
                 }
             }
         }
     }
     //print_r($this->clips);
 }
 function resolveResourceNode(&$node)
 {
     global $wgUser, $wgParser;
     //print 'resolveResourceNode:' . $node->nodeName . " : " . $node->nodeValue . "\n";
     //don't process free flowing text
     //@@todo (we should probably throw it out)
     if ($node instanceof DOMText) {
         return $node;
     }
     $nodeAttr = $node->attributes;
     $node_uri = false;
     if (!is_null($nodeAttr)) {
         foreach ($nodeAttr as $atrr) {
             if ($atrr->nodeName == 'uri') {
                 $node_uri = $atrr->nodeValue;
             }
         }
     }
     //if no resource uri is provided just parse inner html and return
     if (!$node_uri) {
         $node->setAttribute('type', 'text/html');
         return $this->parseInnerWikiText($node);
     }
     $uriTitle = Title::newFromDBkey($node_uri);
     //figure out if how we should parse innerHTML:
     switch ($uriTitle->getNamespace()) {
         case NS_MAIN:
             //top level ref includes of pages in the main namespace not supported
             break;
         case MV_NS_SEQUENCE:
             //type sequence ..@@todo transclude the sequence into present sequence
             //@@todo we should
             //change the node type to "par" to group the sequence under a single element (helpfull for editor representation)
             /*$parElm = $node->ownerDocument->createElement('par');
             
             				$seqArticle = new MV_SequencePage( $uriTitle );
              				$seqArticle->getSequenceSMIL();*/
             break;
         case MV_NS_STREAM:
             global $mvDefaultVideoQualityKey, $mvDefaultFlashQualityKey;
             //we could include relevant timed text and relevant different source types.
             //make sure the stream exists:
             $mvTitle = new MV_Title($uriTitle);
             if (!$mvTitle->doesStreamExist()) {
                 $node->setAttribute('type', 'text/html');
                 $this->parseInnerWikiText($node, wfMsg('mv_resource_not_found', $uriTitle->getText()));
                 return $node;
             }
             //get urls for flash and ogg
             $stream_web_url = $mvTitle->getWebStreamURL($mvDefaultVideoQualityKey);
             $flash_stream_url = $mvTitle->getWebStreamURL($mvDefaultFlashQualityKey);
             if (!$stream_web_url && !$flash_stream_url) {
                 $node->setAttribute('type', 'text/html');
                 $this->parseInnerWikiText($node, wfMsg('mv_resource_not_found', $uriTitle->getText()));
                 return $node;
             }
             //by default set the ogg source
             //@@todo parse child nodes for stream request params?
             if ($stream_web_url) {
                 $node->setAttribute('type', htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultVideoQualityKey)));
                 $node->setAttribute('src', $stream_web_url);
                 $node->setAttribute('poster', $mvTitle->getStreamImageURL());
             }
             //add in flash as a fallback method:
             if ($flash_stream_url) {
                 $f = $node->ownerDocument->createDocumentFragment();
                 $f->appendXML('<source type="' . htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultFlashQualityKey)) . '" src="' . $flash_stream_url . '"></source>');
                 $node->appendChild($f);
             }
             break;
         case NS_TEMPLATE:
             //templates are of type text/html
             $node->setAttribute('type', 'text/html');
             //print "none type: ". $node->getAttribute('type');
             //if template look for template parameters:
             $templateText = '{{' . $uriTitle->getText();
             $addedParamFlag = false;
             $paramVars = array();
             while ($node->childNodes->length) {
                 if ($node->firstChild->nodeName == 'param') {
                     $param =& $node->firstChild;
                     //make sure we have a name:
                     if ($param->hasAttribute('name')) {
                         //we have parameters:
                         $templateText .= "|\n";
                         $templateText .= $param->getAttribute('name') . '=';
                         //try and get the value from the value attribute or innerHTML
                         if ($param->hasAttribute('value')) {
                             $templateText .= $param->getAttribute('value');
                             $paramVars[$param->getAttribute('name')] = $param->getAttribute('value');
                         } else {
                             //grab from inner html:
                             $inerHTML = '';
                             while ($param->childNodes->length) {
                                 $inerHTML .= $param->ownerDocument->saveXML($param->firstChild);
                                 $param->removeChild($param->firstChild);
                             }
                             $templateText .= $inerHTML;
                             $paramVars[$param->getAttribute('name')] = $inerHTML;
                         }
                     }
                     $addedParamFlag = true;
                 }
                 $node->removeChild($node->firstChild);
             }
             //close up the template wikiText call:
             $templateText .= $addedParamFlag ? "\n}}" : '}}';
             //$parserOutput = $wgParser->parse($templateText  ,$this->mTitle, ParserOptions::newFromUser( $wgUser ));
             //print "should parse: \n $templateText";
             $this->parseInnerWikiText($node, $templateText);
             //re-add the param nodes
             $phtml = '';
             foreach ($paramVars as $name => $val) {
                 $phtml .= '<param name="' . htmlentities($name) . '">' . htmlentities($val) . '</param>';
             }
             if ($phtml != '') {
                 $f = $node->ownerDocument->createDocumentFragment();
                 $f->appendXML($phtml);
                 $node->appendChild($f);
             }
             break;
         case NS_IMAGE:
         case NS_FILE:
             //lookup the file/stream
             global $mvDefaultVideoPlaybackRes;
             list($width, $height) = explode('x', $mvDefaultVideoPlaybackRes);
             //@@todo more flexibility with image grabbing
             // (probably should be handled via "figure" namespace which could allow arbitrary crop, resize, overlay)
             $img = wfFindFile($uriTitle);
             if (!$img) {
                 $node->setAttribute('type', 'text/html');
                 $this->parseInnerWikiText($node, wfMsg('mv_resource_not_found', $uriTitle->getText()));
                 return $node;
             }
             //print "resource found set: " . $img->getMimeType();
             //set type attribute:
             //get a default wide media;
             $thumbnail = $img->transform(array('width' => $width));
             if ($thumbnail->isError()) {
                 $this->parseInnerWikiText($node, $thumbnail->toHtml());
             } else {
                 $node->setAttribute('type', $img->getMimeType());
                 $node->setAttribute('src', $img->getURL());
                 //if type is ogg: (set dur and poster)
                 if ($img->getMimeType() == 'application/ogg') {
                     //set the durationHint to the real media duration:
                     $node->setAttribute('durationHint', $thumbnail->file->getLength());
                     //set up default dur to media length if not already set:
                     if (!$node->hasAttribute('dur')) {
                         $node->setAttribute('dur', $thumbnail->file->getLength());
                     }
                     //set the poster attribute:
                     if (!$node->hasAttribute('poster')) {
                         $node->setAttribute('poster', $thumbnail->getURL());
                     }
                 }
             }
             break;
         default:
             $node->setAttribute('type', 'text/html');
             $this->parseInnerWikiText($node, wfMsg('mv_resource_not_supported', $uriTitle->getNsText() . $uriTitle->getText()));
             break;
     }
     return $node;
 }
function mvDoMetavidStreamPage(&$title, &$article)
{
    $mvTitle = new MV_Title($title->mDbkeyform);
    if ($mvTitle->doesStreamExist()) {
        // @@TODO check if we have /name corresponding to a view or
        // /ss:ss:ss or /ss:ss:ss/ee:ee:ee corresponding to a time request
        // force metavid to be special
        // (@@todo clean up skin.php to enable better tab controls)
        // $title->mNamespace= NS_SPECIAL;
        // add a hit to the digest if enabled:
        // @@todo (maybe in the future use javascript to confirm they acutally "watched" the clip)
        global $mvEnableClipViewDigest, $wgRequest;
        // don't log views without end times (default stream view)
        if ($mvEnableClipViewDigest && $mvTitle->end_time != null && $wgRequest->getVal('tl') != '1') {
            $dbw = wfGetDB(DB_WRITE);
            $dbw->insert('mv_clipview_digest', array('stream_id' => $mvTitle->getStreamId(), 'start_time' => $mvTitle->getStartTimeSeconds(), 'end_time' => $mvTitle->getEndTimeSeconds(), 'query_key' => $mvTitle->getStreamId() . $mvTitle->getStartTimeSeconds() . $mvTitle->getEndTimeSeconds(), 'view_date' => time()));
            // compensate for $mvDefaultClipRange around clips
            global $mvDefaultClipRange;
            $start_time = $mvTitle->getStartTimeSeconds() + $mvDefaultClipRange < 0 ? 0 : $mvTitle->getStartTimeSeconds() + $mvDefaultClipRange;
            $end_time = $mvTitle->getEndTimeSeconds() - $mvDefaultClipRange > $mvTitle->getDuration() ? 0 : $mvTitle->getEndTimeSeconds() - $mvDefaultClipRange;
            // also increment the mvd_page if we find a match:
            $dbw->update('mv_mvd_index', array('`view_count`=`view_count`+1'), array('stream_id' => $mvTitle->getStreamId(), 'start_time' => $start_time, 'end_time' => $end_time));
            // print $dbw->lastQuery();
            // also update the mvd_page if directly requested:
            $dbw->update('mv_mvd_index', array('`view_count`=`view_count`+1'), array('stream_id' => $mvTitle->getStreamId(), 'start_time' => $mvTitle->getStartTimeSeconds(), 'end_time' => $mvTitle->getEndTimeSeconds()));
            // print $dbw->lastQuery();
        }
        // @@todo check if the requested title is already just the stream name:
        $streamTitle = Title::newFromText($mvTitle->getStreamName(), MV_NS_STREAM);
        // print " new title: " . $streamTitle . "\n";
        $article = new MV_StreamPage($streamTitle, $mvTitle);
    } else {
        mvMissingStreamPage($mvTitle->stream_name);
    }
}
 function add_stream($stream = null)
 {
     $out = '';
     $mvTitle = new MV_Title($this->stream_name);
     // fist check if the given stream name already exists
     if ($mvTitle->doesStreamExist()) {
         $mv_page = Title::newFromText($this->stream_name, MV_NS_STREAM);
         return '<span class="error">' . wfMsg('mv_stream_already_exists', $this->stream_name, $mv_page->getFullURL()) . '</span> ';
     } else {
         // get the stream pointer
         if (!$stream) {
             $stream =& mvGetMVStream(array('name' => $this->stream_name));
         }
         // if the stream is inserted proced with page insertion
         if ($stream->insertStream($this->stream_type)) {
             global $wgUser;
             $sk = $wgUser->getSkin();
             // insert page
             $streamTitle = Title::newFromText($this->stream_name, MV_NS_STREAM);
             $article = new Article($streamTitle);
             $status = $article->doEdit($this->stream_desc, wfMsg('mv_summary_add_stream'));
             if ($status === true || is_object($status) && $status->isOK()) {
                 // stream inserted sucesfully report to output
                 $out = wfMsg('mv_stream_added', $sk->makeLinkObj($streamTitle, htmlspecialchars($this->stream_name)));
             } else {
                 $out = wfMsg('mv_error_stream_insert');
             }
         } else {
             // stream failed insert
         }
     }
     return $out;
 }
function mvDoMetavidStreamPage(&$title, &$article){
	$mvTitle = new MV_Title( $title->mDbkeyform); 	
	if($mvTitle->doesStreamExist()){				
		//@@TODO check if we have /name corresponding to a view or
		// /ss:ss:ss or /ss:ss:ss/ee:ee:ee corresponding to a time request
		//force metavid to be special 
		//(@@todo clean up skin.php to enable better tab controls)
		//$title->mNamespace= NS_SPECIAL;
		
		//@@todo check if the requested title is already just the stream name:		 	
		$streamTitle = Title::newFromText( $mvTitle->getStreamName(), MV_NS_STREAM);
		//print " new title: " . $streamTitle . "\n";		
		$article = new MV_StreamPage($streamTitle, $mvTitle);
	}else{				
		mvMissingStreamPage($mvTitle->stream_name);
	}	
}