function efABCInit(&$parser) { global $wgOut, $abcOggHandler; $parser->setHook('abc', 'efABCRender'); if ($abcOggHandler) { $oh = new OggHandler(); $oh->setHeaders($wgOut); } return true; }
/** * Generates the HTML code for a score tag. * * @param $parser Parser MediaWiki parser. * @param $code string Score code. * @param $options array of rendering options. * The options keys are: * * factory_directory: string Path to directory in which files * may be generated without stepping on someone else's * toes. The directory may not exist yet. Required. * * generate_vorbis: bool Whether to create an Ogg/Vorbis file in * an OggHandler. If set to true, the override_ogg option * must be set to false. Required. * * image_path_prefix: string Prefix to the local image path. * Required. * * image_url_prefix: string Prefix to the image URL. Required. * * lang: string Score language. Required. * * link_midi: bool Whether to link to a MIDI file. Required. * * midi_path: string Local MIDI path. Required if the link_midi * option is set to true, ignored otherwise. * * midi_url: string MIDI URL. Required if the link_midi option * is set to true, ignored otherwise. * * ogg_name: string Name of the OGG file. Required if the * override_ogg option is set to true, ignored otherwise. * * ogg_path: string Local Ogg/Vorbis path. Required if the * generate_vorbis option is set to true, ignored * otherwise. * * ogg_url: string Ogg/Vorbis URL. Required if the * generate_vorbis option is set to true, ignored * otherwise. * * override_ogg: bool Whether to generate a wikilink to a * user-provided OGG file. If set to true, the vorbis * option must be set to false. Required. * * raw: bool Whether to assume raw LilyPond code. Ignored if the * language is not lilypond, required otherwise. * * @return string HTML. * * @throws ScoreException if an error occurs. */ private static function generateHTML( &$parser, $code, $options ) { global $wgOut; $prof = new ScopedProfiling( __METHOD__ ); try { /* Generate PNG and MIDI files if necessary */ $imagePath = "{$options['image_path_prefix']}.png"; $multi1Path = "{$options['image_path_prefix']}-1.png"; if ( !$options['link_midi'] && $options['generate_vorbis'] && !file_exists( $options['ogg_path'] ) ) { /* We need a MIDI file to generate a Vorbis file */ $options['midi_path'] = "{$options['factory_directory']}/file.midi"; } if ( ( !file_exists( $imagePath ) && !file_exists( $multi1Path ) ) || ( array_key_exists( 'midi_path', $options ) && !file_exists( $options['midi_path'] ) ) ) { self::generatePngAndMidi( $code, $options ); } /* Generate Ogg/Vorbis file if necessary */ if ( $options['generate_vorbis'] && !file_exists( $options['ogg_path'] ) ) { self::generateOgg( $options ); } /* return output link(s) */ if ( file_exists( $imagePath ) ) { $link = Html::rawElement( 'img', array( 'src' => "{$options['image_url_prefix']}.png", 'alt' => $code, ) ); } elseif ( file_exists( $multi1Path ) ) { $multiPathFormat = "{$options['image_path_prefix']}-%d.png"; $multiUrlFormat = "{$options['image_url_prefix']}-%d.png"; $link = ''; for ( $i = 1; file_exists( sprintf( $multiPathFormat, $i ) ); ++$i ) { $link .= Html::rawElement( 'img', array( 'src' => sprintf( $multiUrlFormat, $i ), 'alt' => wfMessage( 'score-page' )->inContentLanguage()->numParams( $i )->plain() ) ); } } else { /* No images; this may happen in raw mode or when the user omits the score code */ throw new ScoreException( wfMessage( 'score-noimages' ) ); } if ( $options['link_midi'] ) { $link = Html::rawElement( 'a', array( 'href' => $options['midi_url'] ), $link ); } if ( $options['generate_vorbis'] ) { try { $oh = new OggHandler(); $oh->setHeaders( $wgOut ); $oad = new OggAudioDisplay( new UnregisteredLocalFile( false, false, $options['ogg_path'] ), $options['ogg_url'], self::DEFAULT_PLAYER_WIDTH, 0, 0, $options['ogg_url'], false ); $link .= $oad->toHtml( array( 'alt' => $code ) ); } catch ( Exception $e ) { throw new ScoreException( wfMessage( 'score-novorbislink', $e->getMessage() ), 0, $e ); } } if ( $options['override_ogg'] !== false ) { try { $link .= $parser->recursiveTagParse( "[[File:{$options['ogg_name']}]]" ); } catch ( Exception $e ) { throw new ScoreException( wfMessage( 'score-novorbislink', $e->getMessage() ), 0, $e ); } } } catch ( Exception $e ) { self::eraseFactory( $options['factory_directory'] ); throw $e; } self::eraseFactory( $options['factory_directory'] ); return $link; }
function runJS_Stats( $vid_url = '' ) { global $wgOut, $wgScriptPath, $wgUser , $wgProxyKey; $scriptPath = OggHandler::getMyScriptPath(); // include the javascript and do the stats $jsUserHash = sha1( $wgUser->getName() . $wgProxyKey ); $wgOut->addHTML( ' <script type="text/javascript" src="' . htmlspecialchars( $scriptPath ) . '/OggPlayer.js"></script> <script type="text/javascript" src="' . htmlspecialchars( $wgScriptPath ) . '/extensions/PlayerStatsGrabber/playerStats.js"></script> <script type="text/javascript"> wgOggPlayer.userHash = ' . Xml::encodeJsVar( $jsUserHash ) . '; wgOggPlayer.videoUrl=' . Xml::encodeJsVar( $vid_url ) . '; wgOggPlayer.doStats(); </script>' ); }
function toHtml($options = array()) { if (count(func_get_args()) == 2) { throw new MWException(__METHOD__ . ' called in the old style'); } OggTransformOutput::$serial++; $url = wfExpandUrl($this->videoUrl, PROTO_RELATIVE); // Normalize values $length = floatval($this->length); $width = intval($this->width); $height = intval($this->height); $alt = empty($options['alt']) ? $this->file->getTitle()->getText() : $options['alt']; $scriptPath = OggHandler::getMyScriptPath(); $showDescIcon = false; if ($this->isVideo) { $msgStartPlayer = wfMsg('ogg-play-video'); $imgAttribs = array('src' => $this->url, 'width' => $width, 'height' => $height, 'alt' => $alt); $playerHeight = $height; } else { // Sound file if ($height > 100) { // Use a big file icon global $wgStylePath; $imgAttribs = array('src' => "{$wgStylePath}/common/images/icons/fileicon-ogg.png", 'width' => 125, 'height' => 125, 'alt' => $alt); } else { // Make an icon later if necessary $imgAttribs = false; $showDescIcon = !$this->noIcon; //$thumbDivAttribs = array( 'style' => 'text-align: right;' ); } $msgStartPlayer = wfMsg('ogg-play-sound'); $playerHeight = 35; } // Set $thumb to the thumbnail img tag, or the thing that goes where // the thumbnail usually goes $descIcon = false; if (!empty($options['desc-link'])) { $linkAttribs = $this->getDescLinkAttribs($alt); if ($showDescIcon) { // Make image description icon link $imgAttribs = array('src' => "{$scriptPath}/info.png", 'width' => 22, 'height' => 22, 'alt' => $alt); $linkAttribs['title'] = wfMsg('ogg-desc-link'); $descIcon = Xml::tags('a', $linkAttribs, Xml::element('img', $imgAttribs)); $thumb = ''; } elseif ($imgAttribs) { $thumb = Xml::tags('a', $linkAttribs, Xml::element('img', $imgAttribs)); } else { $thumb = ''; } $linkUrl = $linkAttribs['href']; } else { // We don't respect the file-link option, click-through to download is not appropriate $linkUrl = false; if ($imgAttribs) { $thumb = Xml::element('img', $imgAttribs); } else { $thumb = ''; } } $id = "ogg_player_" . OggTransformOutput::$serial; $playerParams = Xml::encodeJsVar((object) array('id' => $id, 'videoUrl' => $url, 'width' => $width, 'height' => $playerHeight, 'length' => $length, 'linkUrl' => $linkUrl, 'isVideo' => $this->isVideo)); $s = Xml::tags('div', array('id' => $id, 'class' => 'ogg_player'), ($thumb ? Xml::tags('div', array(), $thumb) : '') . Xml::tags('div', array(), Xml::tags('button', array('onclick' => "if (typeof(wgOggPlayer) != 'undefined') wgOggPlayer.init(false, {$playerParams});", 'style' => "width: {$width}px; text-align: center", 'title' => $msgStartPlayer), Xml::element('img', array('src' => "{$scriptPath}/play.png", 'width' => 22, 'height' => 22, 'alt' => $msgStartPlayer)))) . ($descIcon ? Xml::tags('div', array(), $descIcon) : '')); return $s; }