Difference between revisions of "Extension:FileSync.php"

From Organic Design wiki
(A template which can be added to an article to make it synchronise with a file)
 
m
Line 1: Line 1:
?php
+
<?php
 
# Extension:FileSync{{Category:Extensions}}{{php}}
 
# Extension:FileSync{{Category:Extensions}}{{php}}
 
# - 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}}
 
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
 +
# - Started: 2007-08-02
  
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
  
define('FILESYNC_VERSION','1.0.0, 2007-08-02');
+
define('FILESYNC_VERSION','0.0.0, 2007-08-02');
  
 
$wgFileSyncMagic              = "filesync";
 
$wgFileSyncMagic              = "filesync";
Line 32: Line 33:
 
# Add the parser-function
 
# Add the parser-function
 
$wgParser->setFunctionHook($wgFileSyncMagic,array($this,'magicFilesync'));
 
$wgParser->setFunctionHook($wgFileSyncMagic,array($this,'magicFilesync'));
 
# Add the tagHook
 
$wgParser->setHook($wgFileSyncTag,array($this,'tagBar'));
 
  
 
}
 
}
 
   
 
   
# Expand the filesync-magic
+
# Process the filesync-magic
 
function magicFilesync(&$parser) {
 
function magicFilesync(&$parser) {
 +
 +
$msg  = '';
 +
$argv  = array();
 +
$paths = array();
  
 
# Populate $argv with both named and numeric parameters
 
# Populate $argv with both named and numeric parameters
$argv = array();
 
 
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 $argv[] = $arg;
+
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $paths[] = $arg;
 
}
 
}
  
# Build text of expanded result
+
return $msg;
$args = '';
 
foreach ($argv as $k => $v) $args .= "*'''$k:''' ''$v''\n";
 
$text = "=== magicFilesync(): ===\n$args";
 
 
 
# Return result with available parser flags
 
return array(
 
$text,
 
found  => true,
 
nowiki  => false,
 
noparse => false,
 
noargs  => false,
 
isHTML  => false
 
);
 
 
 
 
}
 
}
  

Revision as of 03:16, 2 August 2007

<?php

  1. Extension:FileSync
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension
  3. - Started: 2007-08-02

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('FILESYNC_VERSION','0.0.0, 2007-08-02');

$wgFileSyncMagic = "filesync"; $wgExtensionFunctions[] = 'wfSetupFileSync'; $wgHooks['LanguageGetMagic'][] = 'wfFileSyncLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'FileSync', 'author' => 'User:Nad', 'description' => 'A template which can be added to an article to make it synchronise with a file', 'url' => 'http://www.organicdesign.co.nz/Extension:FileSync', 'version' => FILESYNC_VERSION );

class FileSync {

# Properties var $prop1 = 'default value'; var $prop2 = 'default value';

# Constructor function FileSync() { global $wgHooks,$wgParser,$wgFileSyncMagic,$wgFileSyncTag,$wgJavaScriptFunctions;

# Add the parser-function $wgParser->setFunctionHook($wgFileSyncMagic,array($this,'magicFilesync'));

}

# Process the filesync-magic function magicFilesync(&$parser) {

$msg = ; $argv = array(); $paths = array();

# Populate $argv with both named and numeric parameters foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $paths[] = $arg; }

return $msg; }

# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'FileSync'; }

	}
  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupFileSync() { global $wgFileSync; $wgFileSync = new FileSync(); }

  1. Needed in MediaWiki >1.8.0 for magic word hooks to work properly

function wfFileSyncLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgFileSyncMagic; $magicWords[$wgFileSyncMagic] = array(0,$wgFileSyncMagic); return true; } ?>