Extension:SimpleUploads.php

From Organic Design wiki
Revision as of 19:49, 28 December 2008 by Sven (talk | contribs) (rm trailing ?>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?php

  1. Extension:SimpleUploads
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:RobCategory:Extensions created with Template:Extension

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

define('SIMPLEUPLOADS_VERSION','1.0.0, 2007-09-20');

$wgSimpleUploadsMagic = "foo"; $wgSimpleUploadsTag = "bar"; $wgExtensionFunctions[] = 'wfSetupSimpleUploads'; $wgHooks['LanguageGetMagic'][] = 'wfSimpleUploadsLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'SimpleUploads', 'author' => 'User:Rob', 'description' => 'Convenient uploading of files to the wiki with WebDAV', 'url' => 'http://www.organicdesign.co.nz/Extension:SimpleUploads', 'version' => SIMPLEUPLOADS_VERSION );

class SimpleUploads {

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

# Constructor function SimpleUploads() { global $wgHooks,$wgParser,$wgSimpleUploadsMagic,$wgSimpleUploadsTag;

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

# Add the tagHook $wgParser->setHook($wgSimpleUploadsTag,array($this,'tagBar'));

}

# Expand the foo-magic function magicFoo(&$parser) {

# Populate $argv with both named and numeric parameters $argv = array(); 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; }

# Build text of expanded result $args = ; foreach ($argv as $k => $v) $args .= "*$k: $v\n"; $text = "=== magicFoo(): ===\n$args";

# Return result with available parser flags return array( $text, found => true, nowiki => false, noparse => false, noargs => false, isHTML => false );

}

# Convert the <bar> tags to HTML function tagBar($text,$argv,&$parser) { $args = ;

foreach ($argv as $k => $v) $args .= "

  • $k: $v
  • \n"; return "

    tagBar():

    \n

      $args
    • Content: $text

    \n";

    }

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

    	}
    
    
    1. Called from $wgExtensionFunctions array when initialising extensions

    function wfSetupSimpleUploads() { global $wgSimpleUploads; $wgSimpleUploads = new SimpleUploads(); }

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

    function wfSimpleUploadsLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgSimpleUploadsMagic; $magicWords[$wgSimpleUploadsMagic] = array(0,$wgSimpleUploadsMagic); return true; }