Jump to content

Extension:Iframe

From mediawiki.org
MediaWiki extensions manual
Iframe
Release status: beta
Implementation Tag , Special page
Description Allows to integrate external web pages into a page
Author(s) Sigbert Klinke (Sigberttalk)
Latest version 0.11 (2023-03-03)
MediaWiki 1.25 - 1.39.1
Database changes No
License Apache License 2.0
Download

  • ‎<iframe>
[edit]

Embedding external webpage into MediaWiki has two issues:

  • Copyright violation: Embedding an external web page may violate copyrights. So, make sure that the domains that can be used in the extension are trusted!
  • Security issue: External web pages may contain malicious code. Again make sure that the domains that can be used in the extension are trusted!

The extension uses keys to select web servers which are given by the wiki administrator during installation. Therefore, behind the key should only be trusted domains.

Known problems

[edit]
  • If you use the Visual Editor then iframe are not shown as code.
  • The extension does not work properly with the MobileFrontend extension.
  • Templates do not correctly pass keys and instead always use the local key.
    • Workaround:
      1. Add $wgIframe['server']['local'] = [ 'scheme' => 'https', 'domain' => 'mydomain.com' ]; to LocalSettings.php.
      2. Use {{#tag:iframe|level="www"|path="desired/path/{{{1}}}"}} in the template page.
        • The downside is that only one domain can be targeted, as you only have one local key.

Download

[edit]

You can obtain the extension from Github.

Installation

[edit]

NOTE: A new version 0.10 is at Github. It should solve a problem on someone else server, but I could not reproduce his error. Therefore wait some days until the NOTE vanishes!

  1. Go to the extensions directory and
  2. clone it from GitHub
    git clone https://github.com/sigbertklinke/Iframe
    
  3. for earlier MediaWiki versions than 1.36.1 you may use
    git checkout 'master@{2021-06-01 00:00:00}'
    
    if the current version does not work
  4. Add to the bottom of LocalSettings.php
    $wgIframe = array();
    wfLoadExtension('Iframe');
    

The global variable $wgIframe controls various aspects of the extensions, e.g. additional web adresses, delay of iframe loadings etc.

Adding other web addresses

[edit]

If, for example, you want to embed a page with the address https://www.mydomain.com/example/page&hl=en, then under the wfLoadExtension('Iframe') statement in LocalSettings.php add

$wgIframe['server']['mykey'] = [ 'scheme' => 'https', 'domain' => 'mydomain.com' ];

and then in the wiki page, add

<iframe key="mykey" level="www" path="example/page&hl=en" />

Category

[edit]

For easy finding of all wiki pages which have a

<iframe ... />

inside a category is added by

[[Category:Iframe]]

the name of the category can be controlled in LocalSettings.php by setting

 $wgIframe['category'] = 'Iframe';

Notes:

  • The extension does NOT create the page Category:Iframe, that is left to the wiki administrator or user.
  • If you create the page Category:Iframe then it might be useful to use hidden categories.

Width and height of an iframe

[edit]

The default width and height of an iframe is 800x600 pixel. This can be set in LocalSettings.php via

$wgIframe['width'] = 640;
$wgIframe['height'] = 400;

If no width and height is given then these defaults are used.

Delay of iframe loading

[edit]

Usually a HTML document is shown if all parts of a document are loaded. If a iframe on a server, e.g. a Shiny server, triggers a lengthy computation then the document will appear only after all iframe(s) are loaded. Therefore a delay mechanism with JavaScript is included which starts the loading of the iframe(s) only after the document is ready. By $wgIframe['delay'] the delay is controlled:

  1. If in LocalSettings.php
      $wgIframe['delay'] = -1;
    
    (or any negative value) is set then the iframe(s) will be loaded immediately, no delay will take place.
  2. If in LocalSettings.php
      $wgIframe['delay'] = 100;
    
    (the default) is set then the first iframe will be loaded 100 ms after the document is loaded, the second 200 ms, and so on.

Examples

[edit]

1. Shows the test page of my shiny server

<iframe key="wiwi" path="" />

2. Shows the example app for R codes which I use (to load a file click on , select File select and choose an example file).

<iframe key="wiwi" path="examples" />

3. As 2., but the iframe window has only VGA size (640x480).

<iframe key="wiwi" path="examples" size="vga" />

Usage

[edit]

The tag iframe has the following attributes

Attribute Usage Required? Default Remark
size Size of an iframe window Optional for an overview see size array in the code. Setting height and/or width overwrites this setting.
height Height of an iframe window Optional 600
width Width of an iframe window Optional 800
key Select a specific domain Required local
level Domain prefix Required empty
path Path in domain Required empty
allowfullscreen Frame is allowed to be placed into full screen mode Optional

The final URL is build by scheme://level.domain/path where scheme and domain are given by the key, e.g. the examples above will generate the URLs

Note: you can abbreviate the keys, e.g. for the examples above could be used

<iframe k="wiwi" p="" />
<iframe k="wiwi" p="examples" />
<iframe k="wiwi" p="examples" s="vga" />

Usage in templates

[edit]

Due to a bug, the below behavior is not accurate. Please see the "Known problems" section above for how to use IFrames in templates.

If you want to use the iframe tag in templates then use in the template:

{{#tag:iframe|key="wiwi"|path="examples"}}

This will also allow to embed parameters, e.g.

{{#tag:iframe|key="wiwi"|path="examples/{{{1}}}"}}

Wikis

[edit]

Mailing list

[edit]

There is a mailing list available: iframe.mediawiki@lists.hu-berlin.de. Note: as author of the extension I rarely read the discusson page but I read my e-mail every day ;)

See also

[edit]