Difference between revisions of "Extension:Wiklets.php"

From Organic Design wiki
(general structure)
 
m
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
<?php
+
{{legacy}}
# Extension:Wiklets{{Category:Extensions}}{{#Security:*|dev}}{{#Security:view|*}}{{php}}
+
<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]{{Category:Extensions created with Template:Extension}}{{Category:Wiklets}}
+
# - 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.1, 2007-05-15');
+
define('WIKLETS_VERSION','0.1.0, 2007-06-28');
+
 
$wgWikletsMagic               = "wiklet";
+
$wgWikletsMagic     = "wiklet"; # The parser-function name for making a wiklet (transcluded content in a popup)
$wgExtensionFunctions[]       = 'wfSetupWiklets';
+
$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';
 
$wgHooks['LanguageGetMagic'][] = 'wfWikletsLanguageGetMagic';
+
 
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
 
'name'        => 'Wiklets',
 
'name'        => 'Wiklets',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
 
'description' => 'Transclude templates into movable floating panels',
 
'description' => 'Transclude templates into movable floating panels',
'url'        => 'http://www.organicdesign.co.nz/Extension:Wiklets',
+
'url'        => 'http://www.mediawiki.org/wiki/Extension:Wiklets',
 
'version'    => WIKLETS_VERSION
 
'version'    => WIKLETS_VERSION
 
);
 
);
+
 
 
class Wiklets {
 
class Wiklets {
+
 
 
# Properties
 
# Properties
 
var $id = 0;
 
var $id = 0;
+
 
 
# Constructor
 
# Constructor
 
function Wiklets() {
 
function Wiklets() {
global $wgParser,$wgWikletsMagic;
+
global $wgParser,$wgOut,$wgHooks,$wgWikletsMagic,$wgWikletsLoadJS,
$wgParser->setFunctionHook($wgWikletsMagic,array($this,'magicWiklet'));
+
$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
 
# Expand the wiklet-magic
function magicWiklet(&$parser) {
+
function magic(&$parser) {
$this->addJS();
+
$id   = 'wiklet-'.$this->id++;
$id = $this->id++;
 
 
$argv = array();
 
$argv = array();
 
$content = '';
 
$content = '';
Line 40: Line 54:
 
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 = '';
 +
foreach ($argv as $k => $v) $args .= " $k=\"$v\"";
 +
$text = "<iframe$args id=\"$id\" name=\"$id\"></iframe>";
 
return array($text, 'noparse' => true, 'isHTML'  => true);
 
return array($text, 'noparse' => true, 'isHTML'  => true);
 
}
 
}
+
 
# Add the javascript to the output object if not added yet and there is at least one tree
+
function onOutputPageBeforeHTML(&$out,&$text) {
function addJS() {
+
global $wgWikletsUseCSS;
global $wgOut,$wgJS,$wgJsMimeType;
+
$head = $out->getScript();
if (isset($wgJS['DisplayFilter'])) return;
+
if ($wgWikletsUseCSS)
$wgJS['Wiklets'] = true;
+
$head .= '<link rel="stylesheet" type="text/css" media="all" href="'. $wgWikletsUseCSS.'" />';
$wgOut->addScript('<script type="'.$wgJsMimeType.'">
+
$body = "onLoad=\"addHandle(document.getElementsByTagName('body').item(0),window);\"";
function wikletCreate(id) {
+
$text = "<html><head>$head</head><body $body>$text</body></html>";
}
+
return true;
function wikletDelete(id) {
 
}
 
function wikletSetPosition(id) {
 
}
 
function wikletSetSize(id) {
 
}
 
function wikletToFront(id) {
 
}
 
function wikletToBack(id) {
 
}
 
function wikletSetContent(id) {
 
}
 
</script>');
 
 
}
 
}
+
 
 
# 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
 
function wfSetupWiklets() {
 
function wfSetupWiklets() {
 
global $wgWiklets;
 
global $wgWiklets;
 
$wgWiklets = new Wiklets();
 
$wgWiklets = new Wiklets();
$wgWiklets->addJS(); # addScript doesn't seem to work from within parser
 
 
}
 
}
+
 
 
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly
 
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly
 
function wfWikletsLanguageGetMagic(&$magicWords,$langCode = 0) {
 
function wfWikletsLanguageGetMagic(&$magicWords,$langCode = 0) {
Line 84: Line 91:
 
}
 
}
 
?>
 
?>
 +
</php>
 +
[[Category:Legacy Extensions]]

Latest revision as of 14:56, 22 October 2014

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

<php><?php

  1. Extension:Wiklets
  2. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  3. - 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'; } }

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupWiklets() { global $wgWiklets; $wgWiklets = new Wiklets(); }

  1. 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>