r41404 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41403‎ | r41404 | r41405 >
Date:00:00, 30 September 2008
Author:dale
Status:old
Tags:
Comment:
improved ~high level resource description~ parsing and SMIL output
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/articlepages/MV_SequencePage.php (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_playlist.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/includes/articlepages/MV_SequencePage.php
@@ -58,9 +58,9 @@
5959 //this is the heavy lifting of the getSequenceSMIL function:
6060 $this->resolveHLRD();
6161
62 - print "the final xml:\n";
 62+ //print "the final xml:\n";
6363 print $this->getSmilXml();
64 - die;
 64+ //die;
6565
6666 //get parser Output Object (maybe cleaner way to do this?
6767 //maybe parser cache is not the right place for this?)
@@ -99,15 +99,9 @@
100100 //@@todo optimize to do all queries/lookups at once.
101101 if(isset($tag['attributes'])){
102102 if(isset($tag['attributes']['uri'])){
103 - //turn the uri into a title:
104 - $uriTitle = Title::newFromDBkey($tag['attributes']['uri']);
105 - if( $uriTitle->exists() ){
106 - //switch output type based on namespace
107 - $this->getResourceArrayFromTitle($this->aHLRD[$i], $uriTitle);
108 - }else{
109 - //uri not found
110 - $this->aHLRD[$i]['value']=wfMsg('mv_resource_not_found', htmlspecialchars($tag['attributes']['uri']) );
111 - }
 103+ //if resolved resource is done for current pass: continue
 104+ if( $this->resolveResource($i) )
 105+ continue;
112106 }
113107 }
114108
@@ -125,56 +119,120 @@
126120 break;
127121 }
128122 $tag= $this->aHLRD[$i++];
129 - }
 123+ }
 124+ //init val if not set:
 125+ if(!isset($this->aHLRD[ $open_inx-1 ][ 'value' ]))
 126+ $this->aHLRD[ $open_inx-1 ][ 'value' ]='';
130127 //swap in the wiki parsed innerHTML:
131 - $parserOutput = $wgParser->parse(
 128+ $this->aHLRD[ $open_inx-1 ][ 'value' ].=
132129 $this->ary2xml(
133130 array_splice(
134131 $this->aHLRD, $open_inx, ($close_inx-$open_inx)
135132 )
136 - ),$this->mTitle, ParserOptions::newFromUser( $wgUser )
137 - );
138 - if(isset($this->aHLRD[ $open_inx-1 ][ 'value' ])){
139 - $this->aHLRD[ $open_inx-1 ][ 'value' ].= $parserOutput->getText();
140 - }else{
141 - $this->aHLRD[ $open_inx-1 ][ 'value' ] = $parserOutput->getText();
142 - }
143 - $this->aHLRD[ $open_inx-1 ][ 'type' ] = 'complete';
 133+ );
 134+
 135+ //$this->aHLRD[ $open_inx-1 ][ 'type' ] = 'complete';
144136 //remove the close index
145137 if($this->aHLRD[$open_inx]['type']=='close')
146138 unset($this->aHLRD[$open_inx]);
147139 //update the index (now that we have spliced the array ):
148140 $i= $open_inx-1; //(will ++ on next loop)
149141 }
 142+ //$this->aHLRD[ $open_inx-1 ][ 'value' ] = $parserOutput->getText();
150143 }
151144 }
152145 }
 146+ //print_r($this->aHLRD);
 147+ //now that inner xml has been parse and outputed parse innerValue of tag as wiki_text:
 148+ for($i=0;$i<count($this->aHLRD);$i++){
 149+ $parserOutput = $wgParser->parse($this->aHLRD[ $i ][ 'value' ] ,$this->mTitle, ParserOptions::newFromUser( $wgUser ));
 150+ $this->aHLRD[ $i ][ 'value' ] = $parserOutput->getText();
 151+ }
153152 //print "resolveHLRD:";
154153 //print_r($this->aHLRD);
155154 //die;
156155 }
157 - function getResourceArrayFromTitle(&$tag, &$title){
158 - print "f:getResourceArrayFromTitle";
159 - switch( $title){
 156+ /*
 157+ * resolves any resource refrences and gets things ready to be parsed as wikiText
 158+ */
 159+ function resolveResource(& $i){ //pass in the current index
 160+ $tag = $this->aHLRD[ $i ];
 161+ $uriTitle = Title::newFromDBkey($tag['attributes']['uri']);
 162+ if( !$uriTitle->exists() ){
 163+ $this->aHLRD[$i]['value']=wfMsg('mv_resource_not_found', htmlspecialchars($tag['attributes']['uri']) );
 164+ $this->aHLRD[ $i ]['attributes']['type']='text/html';
 165+ return false;
 166+ }
 167+ //print "f:getResourceArrayFromTitle";
 168+ switch( $uriTitle->getNamespace() ){
160169 case NS_MAIN:
161170 //top level ref includes of pages in the main namespace not supported
162171 break;
163 - case NS_TEMPLATE:
164 - //top level ref includes of temples is not supported
 172+ case NS_TEMPLATE:
 173+ //grab all the template paramaters
 174+ //ignore any tags other than root param values
 175+ //print('on tag: ' .$i. ':' . print_r($tag, true));
 176+ $paramAry = array();
 177+ if($tag['type'] == 'open'){
 178+ $open_inx = $i;
 179+ $base_depth = $tag['level'];
 180+ //find close tag
 181+ while( $i<count( $this->aHLRD ) ){
 182+ if($tag['type'] == 'close' && $base_depth == $tag['level'] ){
 183+ $close_inx = $i-1;
 184+ break;
 185+ }
 186+ if($tag['tag']=='param'
 187+ && isset( $tag['attributes'] )
 188+ && isset( $tag['attributes']['name'] ) ){
 189+ //set via innerHTML
 190+ if( isset( $tag['value'] ) )
 191+ $paramAry[ $tag['attributes']['name'] ] = $tag['value'];
 192+ //or set via value attribute
 193+ if(isset( $tag['attributes']['value'] ) )
 194+ $paramAry[ $tag['attributes']['name'] ] = $tag['attributes']['value'];
 195+
 196+ }
 197+ $tag= $this->aHLRD[ $i++ ];
 198+ }
 199+ //remove the striped children (that sounds bad)
 200+ $tmp = array_splice($this->aHLRD, $open_inx, ($close_inx-$open_inx));
 201+ //print "Removed: " . print_r($tmp, true);
 202+ //restore the original tag:
 203+ $tag = $this->aHLRD[ $open_inx ];
 204+ //restore the index:
 205+ $i= $open_inx-1;
 206+ }
 207+ //print('NOW on tag: ' .$i. ':' . print_r($this->aHLRD[ $i ], true)); ;
 208+ //$tag_pre_val=$tag['value'];
 209+ //set up wiki_text value:
 210+ $this->aHLRD[ $i ]['value'] = '{{' . $uriTitle->getText();
 211+ $nl='';
 212+ foreach($paramAry as $name=>$val){
 213+ $this->aHLRD[ $i ]['value'].= "\n| ". $name . ' = ' . $val;
 214+ $nl="\n";
 215+ }
 216+ $this->aHLRD[ $i ]['value'].=$nl.'}}';
 217+ $this->aHLRD[ $i ]['type']='complete';
 218+ //set type attribute:
 219+ $this->aHLRD[ $i ]['attributes']['type']='text/html';
 220+ return true;
165221 break;
166222 case NS_IMAGE:
167223 global $mvDefaultVideoPlaybackRes;
168224 list($width,$height)= explode('x',$mvDefaultVideoPlaybackRes);
169 - //@@todo more flexiblity with image grabbing
 225+ //@@todo more flexiblity with image grabbing
170226
171 - //check for video
172 -
173227 // (probably should be hanndled via "figure" namespace which could allow arbitary crop, resize, overlay)
174 - $img = wfFindFile( $title );
 228+ $img = wfFindFile( $uriTitle );
 229+ //set type attribute:
 230+ $this->aHLRD[ $i ]['attributes']['type']=$img->getMimeType();
 231+
175232 //get a default width wide image;
176233 $thumbnail = $img->transform( array('width'=>$width) );
177234 //a direct link to media
178 - $tag['attributes']['src']=$thumbnail->file->getURL();
 235+ $this->aHLRD[ $i ]['attributes']['src']=$thumbnail->file->getURL();
 236+ return true;
179237 break;
180238 case MV_NS_SEQUENCE:
181239 //transclude a sequence
@@ -200,7 +258,12 @@
201259 xml_get_current_line_number($xml_parser)
202260 );
203261 }
204 - xml_parser_free($xml_parser);
 262+ xml_parser_free($xml_parser);
 263+
 264+ //maybe easier to go DOM based model:
 265+ //$doc = new DOMDocument();
 266+ //$doc->loadXML($this->mHLRD);
 267+
205268 //validate input with $mvHLRDTags definition
206269 //*Currently dissabled ~~unclear if we really need to do this~~~
207270 /*
@@ -375,19 +438,22 @@
376439 //print_r($this->clips);
377440 }*/
378441 function doSeqReplace( &$input, &$argv, &$parser ) {
379 - global $wgTitle, $wgUser, $wgRequest, $markerList;
 442+ global $wgTitle, $wgUser, $wgRequest, $markerList, $mvDefaultVideoPlaybackRes;
380443 $sk = $wgUser->getSkin();
381444 $title = Title::MakeTitle( NS_SPECIAL, 'MvExportSequence/' . $wgTitle->getDBKey() );
382 - $title_url = $title->getFullURL();
 445+ $title_url = $title->getFullURL();
 446+
 447+
383448 $oldid = $wgRequest->getVal( 'oldid' );
384 - if ( isset( $oldid ) ) {
385 - // @@ugly hack .. but really this whole sequencer needs a serious rewrite)
 449+ if ( isset( $oldid ) ) {
386450 $ss = ( strpos( $title_url, '?' ) === false ) ? '?':'&';
387451 $title_url .= $ss . 'oldid=' . $oldid;
388 - }
389 -
 452+ }
 453+
 454+ list($width, $height) = explode('x', $mvDefaultVideoPlaybackRes);
 455+
390456 $vidtag = '<div id="file" class="fullImageLink"><playlist';
391 - $vidtag .= ' width="400" height="300" src="' . htmlspecialchars( $title_url ) . '">';
 457+ $vidtag .= ' width="'.$width.'" height="'.$height.'" src="' . htmlspecialchars( $title_url ) .'">';
392458 $vidtag .= '</playlist></div><hr>';
393459
394460 $marker = "xx-marker" . count( $markerList ) . "-xx";
Index: trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php
@@ -178,7 +178,7 @@
179179
180180 $wgHooks['TitleMoveComplete'][] = 'mvMoveHook';
181181
182 - // note this hook is not avaliable by default in medaiwiki
 182+ // @@NOTE this hook is not avaliable by default in medaiwiki
183183 // to use this hook you should add this function to moveTo() in Title.php:
184184 /*
185185 $err = wfRunHooks('TitleisValidMove', array( &$this, &$nt, &$wgUser, $auth));
@@ -195,6 +195,29 @@
196196
197197 $wgParser->setFunctionHook( 'mvData', 'mvMagicParserFunction_Render' );
198198
 199+
 200+ /*
 201+ * OggHandler extension overides
 202+ * if the OggHandler is included remap the object for copatibility with metavid
 203+ * MV_OggHandler.php hanndles all the re-mapping
 204+ */
 205+ if($wgMediaHandlers['application/ogg'] == 'OggHandler'){
 206+ $wgMediaHandlers['application/ogg']='mvOggHandler';
 207+ $wgParserOutputHooks['OggHandler'] = array( 'mvOggHandler', 'outputHook' );
 208+ foreach($wgHooks['LanguageGetMagic'] as & $hook_function){
 209+ if($hook_function=='OggHandler::registerMagicWords'){
 210+ $hook_function='mvOggHandler::registerMagicWords';
 211+ }
 212+ }
 213+ foreach($wgExtensionCredits as & $ext){
 214+ if($ext['name']=='OggHandler'){
 215+ $ext['description'].=' Integrated with the <b>MetaVidWiki Extension</b>';
 216+ }
 217+ }
 218+ }
 219+
 220+
 221+
199222 // $wgHooks['BeforePageDisplay'][] = 'mvDoSpecialPage';
200223 // $wgHooks['ArticleViewHeader'][] = 'mvArticleViewOpts';
201224 /**********************************************/
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_playlist.js
@@ -146,7 +146,8 @@
147147 //load sequencer:
148148 mv_do_sequence({
149149 "sequence_container_id":'modalbox',
150 - "mv_pl_url_id":_this.src //kind of redundant but make for a clean "cancel"..
 150+ "mv_pl_url_id":_this.src, //kind of redundant but make for a clean "cancel"..
 151+ "mv_pl_hlrd_url":_this.hlrd
151152 // we could switch to moving around dom elements if performance is an issue
152153 });
153154

Status & tagging log