2 /* This extension embeds a video in a mediawiki page.
3 Currently vimeo is supported.
6 To embed the vimeo video
7 https://vimeo.com/104778486
9 the following HTML code has to be inserted into mediawiki:
10 <iframe src="//player.vimeo.com/video/104778486?byline=0&portrait=0&color=51735d" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
12 This extension allows this by the following tag:
13 <wrvideo id="104778486" />
14 <wrvideo id="104778486" width="500" height="281" />
22 /// Renders the <video> tag.
23 /// @param $content string - the content of the <video> tag
24 /// @param $args array - the array of attribute name/value pairs for the tag
25 /// @param $parser Parser - the MW Parser object for the current page
27 /// @return string - the html for rendering the map
28 public static function render($content, $args, $parser, $frame) {
29 $parserOutput = $parser->getOutput();
30 $parserOutput->addModules(['ext.wrvideo']);
34 $properties = array('width' => 500, 'height' => 281);
37 if (isset($args['id'])) $properties['id'] = (int) $args['id']; // video ID
38 if (isset($args['width'])) $properties['width'] = (int) $args['width']; // width as int value
39 if (isset($args['height'])) $properties['height'] = (int) $args['height']; // height as int value
42 if (!isset($properties['id'])) throw new Exception(wfMessage('wrvideo-error-no-id')->text());
45 $doc = new DOMDocument();
46 $child = $doc->appendChild($doc->createElement('iframe'));
47 $child->setAttribute('src', '//player.vimeo.com/video/' . $properties['id'] . '?byline=0&portrait=0&color=014e9a');
48 $child->setAttribute('width', $properties['width']);
49 $child->setAttribute('height', $properties['height']);
50 $child->setAttribute('frameborder', 0);
51 $child->setAttribute('webkitallowfullscreen', '');
52 $child->setAttribute('mozallowfullscreen', '');
53 $child->setAttribute('allowfullscreen', '');
54 } catch (Exception $e) {
55 $doc = new DOMDocument();
56 $child = $doc->appendChild($doc->createElement('div'));
57 $child->setAttribute('class', 'error');
58 $child->appendChild($doc->createTextNode(wfMessage('wrvideo-error-msg')->text() . $e->getMessage()));
60 return array($doc->saveHTML($doc->firstChild), 'markerType' => 'nowiki');
63 public static function ParserFirstCallInitHook(Parser &$parser) {
64 $parser->setHook('wrvideo', 'WrVideo::render');