Extension talk:FreeMind/ru

Версия для Mediawiki 1.18.1

edit

Расширение FreeMind не работает с MediaWiki 1.18+ потому что Image class был удалён. Протестировано на Ubuntu 11.04 и MediaWiki 18.1. Этот код вставить в FreeMind.php:

<?php
// Freemind mindmap WikiMedia extension
// (C) Dimitry Polivaev 2006, Günter Gratzer 8.02.2012 (modifed for MediaWiki 18)
// Example:
$wgExtensionFunctions[] = "wfFreemindExtension";

function wfFreemindExtension()
{
    global $wgParser;
    // Defines the tag <mindmap> ... </mindmap>
    // The second parameter is the callback function for
    // processing the text between the tags
    $wgParser->setHook("mm", "renderMindmap");
}
// The callback function for converting the input text to HTML output
function renderMindmap($input)
{
    // Default parameter values:
    $mm_height = "800";
    $mm_type = "flash";
    $mm_target = "embedded";
    $mm_notitle = 0;

    if (preg_match('/^\s*\[{2}\s*:\s*(\w.*)\]{2}\s*$/', $input, $matches)) {
        $mm_target = "link";
        $input = $matches[1];
    } else
    if (preg_match('/^\s*\[{2}\s*(\w.*)\]{2}\s*$/', $input, $matches)) {
        $mm_target = "embedded";
        $input = $matches[1];
    } else{
    	return MindmapHelp($input);
	}

    $mm_title = "";
    $mm_description = "";

    $paramVector = explode("|", $input);
    $url = $paramVector[0];
    $paramNumber = count($paramVector);
    for ($i = 1; $i < $paramNumber; $i++) {
        $param = trim($paramVector[$i]);
        if (preg_match('/^\s*[0-9]+p[xt]$/', $param)) {
        	$mm_height = $param;
        }
        else if (preg_match('/^(\w+)\s+(.*)$/', $param, $pair)) {
            if ("title" === $pair[1]) {
                $mm_title = $pair[2];
            } else if ("parameters" === $pair[1]) {
                preg_match_all('/(\\w+?)\\s*=\\s*"(.+?)"/', $pair[2], $match, PREG_SET_ORDER);
                foreach ($match as $i) $params[$i[1]] = $i[2];
                preg_match_all('/(\\w+?)\s*=\s*([^"\s]+?)/', $pair[2], $match, PREG_SET_ORDER);
                foreach ($match as $i) $params[$i[1]] = $i[2];
            } else {
                if ($mm_description != "")
                    $mm_description .= '|';
                $mm_description .= $param;
            }
        } else {
            if ("flash" === $param || "applet" === $param) {
                $mm_type = $param;
            } elseif ("notitle" === $param) {
                $mm_notitle = 1;
            } else {
                $mm_description .= $param;
            }
        }
    }

    if ($mm_description === "") {
        $mm_description = $url;
    }

	if($mm_notitle){
		$mm_title = "";
	}
  elseif ($mm_title === "") {
        $mm_title = $url;
  }
  $imageTitle = Title::makeTitleSafe("Image", $url);
  if($imageTitle == NULL){
    	return MindmapNotFoundError($url);
	}
  $file = wfLocalFile($imageTitle);

  if($file->exists() == NULL){
    	return MindmapNotFoundError($url);
	}
    $url = $file->getViewURL(false);

    global $wgServer, $wgScriptPath, $wgTitle, $wgUrlProtocols, $wgUser;
    static $flashContentCounter = 0;
    if ($mm_type === "flash") {
        $params['initLoadFile'] = $url;
        if (isset($params['openUrl'])) unset($params['openUrl']);
        if (! isset($params['startCollapsedToLevel'])) $params['startCollapsedToLevel'] = "5";
        if (strcasecmp($mm_target, "embedded") == 0) {
            $flashContentCounter++;
            require_once("freemind/flashwindowFunction.php");
            $output = getMindMapFlashOutput($mm_title, $params, $flashContentCounter, $mm_height, "$wgScriptPath/extensions/freemind/");
        } else if (strcasecmp($mm_target, "link") == 0) {
            $ref = "$wgScriptPath/extensions/freemind/flashwindow.php?";
        } else {
            $output = MindmapHelp($url);
        }
    } else if ($mm_type === "applet") {
        $server = $_SERVER['SERVER_NAME'];
        $params['browsemode_initial_map'] = "http://$server$url";
        if (isset($params['type'])) unset($params['type']);
        if (isset($params['scriptable'])) unset($params['scriptable']);
        if (isset($params['modes'])) unset($params['modes']);
        if (isset($params['initial_mode'])) unset($params['initial_mode']);

        if (strcasecmp($mm_target, "embedded") == 0) {
            require_once("freemind/appletwindowFunction.php");
            $output = getMindMapAppletOutput($mm_title, $params, $mm_height, "$wgScriptPath/extensions/freemind/");
        } else if (strcasecmp($mm_target, "link") == 0) {
            $ref = "$wgScriptPath/extensions/freemind/appletwindow.php?";
        } else {
            $output = MindmapHelp($url);
        }
    } else {
        $output = MindmapHelp($url);
    }
    if (! isset($output) && $mm_target === "link") {
        $params['mm_title'] = rawurlencode($mm_title);
        $params['mm_height'] = $mm_height;
        foreach ($params as $key => $value) {
            $ref .= "$key=$value&";
        }
        $ref = substr($ref, 0, -1);
        $output .= "<a href=$ref>$mm_description</a>";
    }
    if ($mm_target == "embedded")
        $output = "$output";
    return $output;
}

function MindmapHelp($input)
{
    return '<div style=\'border: solid red 1px\'>
<p style="text-align:center;"><b>Ebbedded Mind Map Syntax error in </b>: <code><mm>'.$input.'</mm></code></p><br>
<p><b> Syntax: </b>
<blockquote><b><code><mm>[[{name}|{options}|parameters {parameters}]]</mm></code></b><br>
<b><code><mm>[[:{name}|{options}|parameters {parameters}]]</mm></code></b></blockquote>
<b> Examples:</b>
<blockquote>
<ul>
<li><code><mm>[[Hello.mm]]</mm></code>
<li><code><mm>[[Hello.mm|flash]]</mm></code>
<li><code><mm>[[Hello.mm|applet]]</mm></code>
<li><code><mm>[[Hello.mm|flash|80pt]]</mm></code>
<li><code><mm>[[Hello.mm|applet|150px|title example map]]</mm></code>
<li><code><mm>[[:Hello.mm]]</mm></code>
<li><code><mm>[[:Hello.mm|description]]</mm></code>
<li><code><mm>[[:Hello.mm|flash|title the map in flash|map in flash]]</mm></code>
</ul></blockquote>
</div>';
}

function MindmapNotFoundError($input)
{
    return '<div style=\'border: solid red 1px\'>
<p style="text-align:center;"><b>Error: Mind Map file <code>'.$input.'</code> not found</b></p><br>
</div>';
}
?>

I'm not an expert, so I don't know if the code is ok. Maybe one of the experts can have a look at the code.

--Günter Gratzer 16:35, 8 February 2012 (UTC)

  • Gunter - Very Senks!!!! It's Works on Ubuntu 11.04 + MW 18.1

1.18, bugs

edit

Thanks that ALMOST works now. The Mindmap does not show, that was due to me using IIS, please see below, but the MM controls does.

I STILL get this error in php-errors.log:

[22-Feb-2012 16:57:55 UTC] PHP Notice:  Undefined variable: mm_bgcolor ..
in C:\inetpub\FSWiki181-ny\extensions\freemind\flashwindowFunction.php on line 13

--Asset (talk) 17:02, 22 February 2012 (UTC)Reply

In IIS you need to specify the mimetype (whatever that is) as mm and application/xml

I don't have the problem with undefined variable. Maybe I have different flashwindowFunction.php. This is my code:

<?php
function getMindMapFlashOutput($mm_title, $parameters, $flashContentCounter, $mm_height, $path) {
$output = '';
$mm_bgcolor = '';

if($mm_title != ""){
	$output='
<p style="text-align:center"><a href="'.$parameters['initLoadFile'].'">'.$mm_title.'</a></p>';
}
	$output.='
<script type="text/javascript" src="'.$path.'flashobject.js"></script>'
.'<div id="flashcontent'.$flashContentCounter.'"> Flash plugin or Javascript are turned off. Activate both  and reload to view the mindmap</div>
<script type="text/javascript">
// <![CDATA[
var fo = new FlashObject("'.$path.'visorFreemind.swf", "'.$path.'visorFreeMind", "100%", "'.$mm_height.'", 6, "'.$mm_bgcolor.'");
fo.addParam("quality", "high");
fo.addParam("bgcolor", "#ffffff");
';
	foreach ($parameters as $key => $value)
		$output.="fo.addVariable(\"$key\", \"$value\");\n";
	$output.='fo.addVariable("openUrl", "_blank");
fo.write("flashcontent'.$flashContentCounter.'");
// ]]>
</script>';
	return $output;
}
?>

--Günter Gratzer 13:43, 27 February 2012 (UTC)

Return to "FreeMind/ru" page.