user6774350
user6774350

Reputation: 87

How to have a script tag in a particular wiki page?

How can I have a tag in a particular wiki page? I know this is possible to have wide js in Common.js or in header. But I need to have it within the source of a page to embed a video. How is possible? The tag is this:

<div id="15897897929"><script type="text/JavaScript" src="https://www.aparat.com/embed/19bwT?data[rnddiv]=15897897929&data[responsive]=yes"></script></div>

Mediawiki has an EmbedVideo extension, but it doesn't support this aparat service. Any way to have this embed video link as js in a wiki page?

aparat, alternatively provide iframe too. If not possible to have the script above in a page, how to have this iframe in a wiki page instead?

<style>.h_iframe-aparat_embed_frame{position:relative;}.h_iframe-aparat_embed_frame .ratio{display:block;width:100%;height:auto;}.h_iframe-aparat_embed_frame iframe{position:absolute;top:0;left:0;width:100%;height:100%;}</style><div class="h_iframe-aparat_embed_frame"><span style="display: block;padding-top: 57%"></span><iframe src="https://www.aparat.com/video/video/embed/videohash/19bwT/vt/frame" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe></div>

Upvotes: 0

Views: 810

Answers (2)

klml
klml

Reputation: 1768

You can use the mw.config variable wgPageName to limit your function in Common.js to a particular pagename (in this example Bar)

if ( mw.config.get( 'wgPageName' ) === "Bar") {
    $.getScript("https://www.aparat.com/embed/19bwT?data[rnddiv]=15897897929&data[responsive]=yes", function() {
        console.log("Script loaded but not necessarily executed.");
    });
}

PS https://www.aparat.com/embed/19bwT?data[rnddiv]=15897897929&data[responsive]=yes seems broken

Upvotes: 0

Florian
Florian

Reputation: 2874

You can not simply embed HTML (including the script tag) into a MediaWiki page. This is for security reasons, as arbitrary users would be able to include any JavaScript, even unsafe one, which is then executed for all users.

Your best bet in this case here is, to write your own extension, just like the EmbedVideo extension, which provides a parser tag. With this parser tag, you would be able to provide the relevant data (which seems to be the video ID, 19bwT?) by the user, the rest of the script tags contents should be static inside of the extension, in order to avoid security flaws.

The page I linked above contains more information on how to create an extension, as well as example code for creating a parser tag extension. I think it would be completely out of scope to provide a full implementation of an extension here. However, you can also take a look on the embedvideo extension (which you already mentioned), try to create a new one based on it, or even better, extend it to be able to handle apart as well.

Upvotes: 1

Related Questions