Difference between revisions of "Extension:Wiklets.php"
(currently has to use iFrames not div's) |
m |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <?php | + | {{legacy}} |
− | # Extension:Wiklets | + | <php><?php |
+ | # Extension:Wiklets | ||
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | ||
− | # - Author: [http://www.organicdesign.co.nz/nad User:Nad] | + | # - Author: [http://www.organicdesign.co.nz/nad User:Nad] |
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
− | define('WIKLETS_VERSION','0.0 | + | define('WIKLETS_VERSION','0.1.0, 2007-06-28'); |
$wgWikletsMagic = "wiklet"; # The parser-function name for making a wiklet (transcluded content in a popup) | $wgWikletsMagic = "wiklet"; # The parser-function name for making a wiklet (transcluded content in a popup) | ||
Line 13: | Line 14: | ||
$wgWikletsOffScreen = false; # Set to true if you want wiklets to be able to be dragged outside the screen boundaries | $wgWikletsOffScreen = false; # Set to true if you want wiklets to be able to be dragged outside the screen boundaries | ||
− | $wgExtensionFunctions[] | + | $wgExtensionFunctions[] = 'wfSetupWiklets'; |
$wgHooks['LanguageGetMagic'][] = 'wfWikletsLanguageGetMagic'; | $wgHooks['LanguageGetMagic'][] = 'wfWikletsLanguageGetMagic'; | ||
Line 31: | Line 32: | ||
# Constructor | # Constructor | ||
function Wiklets() { | function Wiklets() { | ||
− | global $wgParser,$wgWikletsMagic,$wgWikletsLoadJS,$wgWikletsToTop,$wgWikletsOffScreen; | + | global $wgParser,$wgOut,$wgHooks,$wgWikletsMagic,$wgWikletsLoadJS, |
+ | $wgWikletsToTop,$wgWikletsOffScreen,$wgWikletsUseCSS; | ||
$wgParser->setFunctionHook($wgWikletsMagic,array($this,'magic')); | $wgParser->setFunctionHook($wgWikletsMagic,array($this,'magic')); | ||
if ($wgWikletsLoadJS) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgWikletsLoadJS\"></script>"); | if ($wgWikletsLoadJS) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgWikletsLoadJS\"></script>"); | ||
$script = ''; | $script = ''; | ||
− | if ($wgWikletsToTop) $script .= "bringSelectedIframeToTop(true);\n"; | + | if ($_REQUEST['action'] == 'render' && isset($_REQUEST['wiklet'])) |
− | + | $wgHooks['OutputPageBeforeHTML'][] = $this; | |
− | + | else { | |
+ | if ($wgWikletsToTop) $script .= "bringSelectedIframeToTop(true);\n"; | ||
+ | if ($wgWikletsOffScreen) $script .= "allowDragOffScreen(true);\n"; | ||
+ | if ($script) $wgOut->addScript("<script type=\"text/javascript\">$script</script>"); | ||
+ | } | ||
} | } | ||
Line 47: | Line 53: | ||
foreach (func_get_args() as $arg) if (!is_object($arg)) { | foreach (func_get_args() as $arg) if (!is_object($arg)) { | ||
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $content = $arg; | if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $content = $arg; | ||
+ | } | ||
+ | if (preg_match('/^\\w/',$argv['src'])) { | ||
+ | $title = Title::newFromText($argv['src']); | ||
+ | $argv['src'] = $title->getLocalURL('action=render&wiklet'); | ||
} | } | ||
$args = ''; | $args = ''; | ||
Line 52: | Line 62: | ||
$text = "<iframe$args id=\"$id\" name=\"$id\"></iframe>"; | $text = "<iframe$args id=\"$id\" name=\"$id\"></iframe>"; | ||
return array($text, 'noparse' => true, 'isHTML' => true); | return array($text, 'noparse' => true, 'isHTML' => true); | ||
+ | } | ||
+ | |||
+ | function onOutputPageBeforeHTML(&$out,&$text) { | ||
+ | global $wgWikletsUseCSS; | ||
+ | $head = $out->getScript(); | ||
+ | if ($wgWikletsUseCSS) | ||
+ | $head .= '<link rel="stylesheet" type="text/css" media="all" href="'. $wgWikletsUseCSS.'" />'; | ||
+ | $body = "onLoad=\"addHandle(document.getElementsByTagName('body').item(0),window);\""; | ||
+ | $text = "<html><head>$head</head><body $body>$text</body></html>"; | ||
+ | return true; | ||
} | } | ||
# Needed in some versions to prevent Special:Version from breaking | # Needed in some versions to prevent Special:Version from breaking | ||
function __toString() { return 'Wiklets'; } | function __toString() { return 'Wiklets'; } | ||
− | + | } | |
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
Line 62: | Line 82: | ||
global $wgWiklets; | global $wgWiklets; | ||
$wgWiklets = new Wiklets(); | $wgWiklets = new Wiklets(); | ||
− | |||
} | } | ||
Line 72: | Line 91: | ||
} | } | ||
?> | ?> | ||
+ | </php> | ||
+ | [[Category:Legacy Extensions]] |
Latest revision as of 14:56, 22 October 2014
<php><?php
- Extension:Wiklets
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:Nad
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('WIKLETS_VERSION','0.1.0, 2007-06-28');
$wgWikletsMagic = "wiklet"; # The parser-function name for making a wiklet (transcluded content in a popup) $wgWikletsLoadJS = ""; # The URL of the dragiframe.js file, leave empty if loaded from elsewhere $wgWikletsToTop = true; # Raise wiklets to top when clicked $wgWikletsOffScreen = false; # Set to true if you want wiklets to be able to be dragged outside the screen boundaries
$wgExtensionFunctions[] = 'wfSetupWiklets'; $wgHooks['LanguageGetMagic'][] = 'wfWikletsLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'Wiklets', 'author' => 'User:Nad', 'description' => 'Transclude templates into movable floating panels', 'url' => 'http://www.mediawiki.org/wiki/Extension:Wiklets', 'version' => WIKLETS_VERSION );
class Wiklets {
# Properties var $id = 0;
# Constructor function Wiklets() { global $wgParser,$wgOut,$wgHooks,$wgWikletsMagic,$wgWikletsLoadJS, $wgWikletsToTop,$wgWikletsOffScreen,$wgWikletsUseCSS; $wgParser->setFunctionHook($wgWikletsMagic,array($this,'magic')); if ($wgWikletsLoadJS) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgWikletsLoadJS\"></script>"); $script = ; if ($_REQUEST['action'] == 'render' && isset($_REQUEST['wiklet'])) $wgHooks['OutputPageBeforeHTML'][] = $this; else { if ($wgWikletsToTop) $script .= "bringSelectedIframeToTop(true);\n"; if ($wgWikletsOffScreen) $script .= "allowDragOffScreen(true);\n"; if ($script) $wgOut->addScript("<script type=\"text/javascript\">$script</script>"); } }
# Expand the wiklet-magic function magic(&$parser) { $id = 'wiklet-'.$this->id++; $argv = array(); $content = ; foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $content = $arg; } if (preg_match('/^\\w/',$argv['src'])) { $title = Title::newFromText($argv['src']); $argv['src'] = $title->getLocalURL('action=render&wiklet'); } $args = ; foreach ($argv as $k => $v) $args .= " $k=\"$v\""; $text = "<iframe$args id=\"$id\" name=\"$id\"></iframe>"; return array($text, 'noparse' => true, 'isHTML' => true); }
function onOutputPageBeforeHTML(&$out,&$text) { global $wgWikletsUseCSS; $head = $out->getScript(); if ($wgWikletsUseCSS) $head .= '<link rel="stylesheet" type="text/css" media="all" href="'. $wgWikletsUseCSS.'" />'; $body = "onLoad=\"addHandle(document.getElementsByTagName('body').item(0),window);\""; $text = "$head$text"; return true; }
# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'Wiklets'; } }
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWiklets() { global $wgWiklets; $wgWiklets = new Wiklets(); }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfWikletsLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgWikletsMagic; $magicWords[$wgWikletsMagic] = array(0,$wgWikletsMagic); return true; } ?> </php>