Extension:Popup
Appearance
This extension is not to be confused with the Popups extension used by Wikimedia on their wiki family.
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. Please see the following alternatives that you may wish to install instead of this extension: |
Popup Release status: unmaintained |
|
---|---|
Implementation | Notify |
Description | Shows a popup on every nth page request. |
Author(s) | Johannes Perl (Jperltalk) |
Latest version | 0.1 (2012-06-18) |
MediaWiki | 1.7.0+ |
Database changes | No |
License | GNU General Public License 2.0 or later |
Download | See the code section |
|
|
The Popup extension shows a popup on every nth page request of a user by setting a cookie and counting page requests.
Installation
[edit]- Copy the code into a file and place the file(s) in a directory called
Popup
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php file:
require_once "$IP/extensions/Popup/Popup.php";
- Done â Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Code
[edit]- Popup.php
<?php
/**
* Popup extension showing a popup on every nth page request.
*
* @author [http://www.perlproductions.at Johannes Perl]
* @licence GNU General Public Licence 2.0 or later
*/
if(!defined('MEDIAWIKI')) die('Not an entry point.');
$wgEnablePopup = true;
$wgExtensionCredits['other'][] = array(
'name' => "Popup",
'author' => "[http://www.perlproductions.at Johannes Perl]",
'description' => "Shows a simple popup on every nth page request",
'url' => "https://www.mediawiki.org/wiki/Extension:Popup",
'version' => "0.1"
);
if(!isset($wgEnablePopup) || !$wgEnablePopup) return;
$wgHooks['BeforePageDisplay'][] = 'showPopup'; # hook to add js and show popup
$wgPopupPath = $wgScriptPath."/extensions/Popup/Popup.html"; # path to popup html file
$wgPopupHeight = 300; # height of popup
$wgPopupWidth = 200; # width of popup
$wgPopupTitle = "Popup Title"; # title of popup
$wgPause = 10; # show the popup every 10th time
$wgCookieName = "MWPopupCounter"; # name of cookie
$wgPopupPosX = 20; $wgPopupPosY = 20;
$wgCookieExpire = 0; # the time the cookie expires
$wgPopupScript = "win = window.open('{$wgPopupPath}','{$wgPopupTitle}','height={$wgPopupHeight},width={$wgPopupWidth}'); win.moveTo({$wgPopupPosX}, {$wgPopupPosY});";
function showPopup( OutputPage &$out, Skin &$skin )
{
global $wgPopupPath, $wgPopupHeight, $wgPopupWidth, $wgPause, $wgCookieName, $wgPopupScript, $wgCookieExpire;
if(!isset($_COOKIE[$wgCookieName])) //cookie does not exist yet
{
setcookie($wgCookieName, 1, $wgCookieExpire);
$reqno = 1;
}
else //cookie already exists
{
$reqno = $_COOKIE[$wgCookieName] + 1;
setcookie($wgCookieName, $_COOKIE[$wgCookieName] + 1, $wgCookieExpire);
}
if($reqno == 1 || $reqno % $wgPause == 0)
{
$out->addInlineScript($wgPopupScript);
}
return true;
}
#if you want to delete the cookie for testing purpose use the code below
#setcookie($wgCookieName, "", $wgCookieExpire);
- Popup.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Testpopup</title>
</head>
<body>
<p>This is just a test popup page. Edit me.</p>
</body>
</html>
TODO
[edit]- The extension should use the ResourceLoader for MW versions >= 1.17