![]() |
MediaWiki > Collaborative programming >
This was an aborted project to look into leveraging ways to use MediaWiki by outside influences.
What follows is the complete contents of the MediaWiki page I had. I don’t know if I performed some magic therein, so I’m leaving it as-is without interpretation or editing.
= PCLinuxOS MediaWiki collaborative programming =
== notes ==
... crap, I can't find my proper notes on how I set up the crontab to do the updating. oh well
== the wiki page ==
<?php
/*
* [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit}} view/edit the source]
* [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=raw}} download the source code]
* [[Talk:{{PAGENAME}}|View discussion and bug reports]]
** [{{SERVER}}{{localurl:Talk:{{PAGENAME}}|action=edit§ion=new}} file a bug report or request]
<pre>
*/
/*=========================================================================
* This is a very badly-coded 'search and replace' script created to help
* convert WikkaWiki syntax to MediaWiki syntax.
*
* Freeware
* ABSOLUTELY NO WARRANTY WHATSOEVER. USE AT YOUR OWN RISK.
*=======================================================================*/
//=========================================================================
// Initialise variables
//=========================================================================
// Change $build as you update, unless $build is 9, then change $version
$version = "0.3";
$build = "6";
//=========================================================================
// Disclaimer from JMan
// Added as a variable so I can use it more than once
$disclaimer = "<b>include</b> "<span style='color:#ff0000'>disclaimer.inc</span>"<br>
ABSOLUTELY NO WARRANTY WHATSOEVER. USE AT YOUR OWN RISK.<br><br>
Be sure to <u>preview</u> your text before posting it into the wiki.
<br><br>
<big>Outstanding problems</big>
<ul>
<li>Muck up links even more than before,</li>
<li>won't convert anchors,</li>
<li>break image tags.</li>
</ul>
Apologies for this in advance, I know it can be fixed but I'm unsure how to do it.";
//=========================================================================
// FROM WIKKAWAKKA SOURCE CODE, (GPLV2?)
function fncLink($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
if (!$text) $text = $tag;
// escape text?
if ($escapeText) $text = htmlspecialchars($text);
$tag = htmlspecialchars($tag); #142 & #148
$method = htmlspecialchars($method);
$title_attr = $title ? ' title="'.htmlspecialchars($title).'"' : '';
$url = '';
// is this an interwiki link?
if (preg_match("/^([A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+)[:](\S*)$/", $tag, $matches)) # before the : should be a WikiName; anything after can be (nearly) anything that's allowed in a URL
{
$url = $matches[1].$matches[2]; //GetInterWikiUrl($matches[1], $matches[2]);
}
elseif (preg_match("/^(http|https|ftp):\/\/([^\\s\"<>]+)$/", $tag))
{
$url = $tag; // this is a valid external URL
}
// is this a full link? ie, does it contain alpha-numeric characters?
elseif (preg_match("/[^[:alnum:],ÄÖÜ,ßäöü]/", $tag))
{
// check for email addresses
if (preg_match("/^.+\@.+$/", $tag))
{
$url = "mailto:".$tag;
}
// check for protocol-less URLs
else if (!preg_match("/:/", $tag))
{
$url = "http://".$tag;
}
}
else
{
// it's a wiki link
//if ($_SESSION["linktracking"] && $track) $this->TrackLinkTo($tag);
//$linkedPage = $this->LoadPage($tag);
// return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."\">".$text."</a>" : "<span class=\"missingpage\">".$text."</span><a href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">?</a>");
return ($linkedPage ? "<a href=\"".$method.$tag."\"$title_attr>".$text."</a>" : "<a class=\"missingpage\" href=\"edit".$tag."\" title=\"Create this page\">".$text."</a>");
}
$external_link_tail = " \'\'\'link\!\'\'\'"; //$this->GetConfigValue("external_link_tail");
return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
}
//=========================================================================
// Misc Variables
$translate = "<!-- Translated output -->";
//=========================================================================
// Check if a form has been sent
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//=================================================================
// Begin translating - full of cheap workarounds
//=================================================================
// $_POST['wakin'] is the textarea's content
//=================================================================
// Prevent ---- lines from being converted to start with
$translate = str_replace("----", "[hr]", $_POST['wakin']);
//=================================================================
// Clean up some of the basic things
// Remove double stars around items
$translate = preg_replace("/(\*\*)(.+?)(\*\*)/i", "\\2", $translate);
//=================================================================
// Replace // with ''
$translate = str_replace("//", "''", $translate);
//=================================================================
// If there is a ~- or just - at the beginning of a new line
// (\n, \r or \r\n depending on your OS), turn it into a bullet point
// **[just realised this removes the indent, someone needs to look at this]**
$translate = preg_replace("/(\r|\n|\r\n)([\~]?)(\-)/", "\n*", $translate);
//=================================================================
// Convert indents: ~ to :
// For some reason, these have never worked for me
$translate = str_replace("~", ":", $translate);
$translate = str_replace("~-", ":*", $translate);
//=================================================================
// Remove = signs - very bad workaround to get this to work =(
$translate = str_replace("======", "=", $translate);
$translate = str_replace("=====", "=", $translate);
$translate = str_replace("====", "=", $translate);
$translate = str_replace("===", "=", $translate);
$translate = str_replace("==", "=", $translate);
// The following won't work for more than 1 = - I think I'm doing something wrong =/
$translate = preg_replace("/([\=])(.+?)([\=])/i", "= \\2 =", $translate);
//=================================================================
// Bullet lists - need a new line before it starts
// **[Tends to break bold effect on new lines - needs fixing/moving!]**
//$translate = preg_replace("/(\r|\n|\r\n)\*/", "\n#.", $translate);
//=================================================================
// Numbered lists - need a new line before it starts
// **[just realised first one removes the indent, someone needs to look at this]**
$translate = preg_replace("/(\r|\n|\r\n)([\~]?)([0-9])([.])/", "\n#", $translate);
//$translate = preg_replace("/(\r|\n|\r\n)([0-9])([.])/", "\n#", $translate);
//=================================================================
// Remove quad quotes
$translate = preg_replace("/(\"\")(.+?)(\"\")/i", "\\2", $translate);
//=================================================================
// Fix up some silly errors
$translate = str_replace("http:''", "http://", $translate);
//=================================================================
// URI/URL PARSING - REQUESTS FIX!
// This just repairs external links so far
//$translate = preg_replace("/(\[\[http:\/\/)(.+?)(\]\])/i","[http://\\2]",$translate);
//=================================================================
// FROM WIKKAWAKKA SOURCE CODE, (GPLV2?)
if ($translate == "<")
return "<";
else if ($translate == ">")
return ">";
// float box left
else if ($translate == "<<")
{
return (++$trigger_floatl % 2 ? "<div class=\"floatl\">\n" : "\n</div>\n");
}
// float box right
else if ($translate == ">>")
{
return (++$trigger_floatl % 2 ? "<div class=\"floatr\">\n" : "\n</div>\n");
}
// urls
else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $translate, $matches))
{
$url = $matches[1];
/* Inline images are disabled for security reason, use {{image action}} #142
But if you still need this functionality, update this file like below
if (preg_match("/\.(gif|jpg|png|svg)$/si", $url)) {
return '<img src="'.fncLink($url).'" alt="image" />'.$wakka->htmlspecialchars_ent($matches[2]);
} else */
// Mind Mapping Mod
if (preg_match("/\.(mm)$/si", $url)) { #145
//$translate = Action("mindmap ".$url);
} else
$translate = fncLink($url).$matches[2];
}
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
else if (preg_match("/^\[\[(\S*)(\s+(.+))?\]\]$/s", $translate, $matches)) # recognize forced links across lines
{
list (, $url, , $text) = $matches;
if ($url)
{
//if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>";
if (!$text) $text = $url;
//$text=preg_replace("/@@|££|\[\[/","",$text);
$translate = $result.fncLink($url, "", $text);
}
else
{
// don't do anything;
}
}
// interwiki links!
else if (preg_match("/^[A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+[:]\S*$/s", $translate))
{
//$translate = fncLink($translate);
}
// wiki links!
else if (preg_match("/^[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*$/s", $translate))
{
$translate = fncLink($translate);
}
//=================================================================
// IMAGE PARSING - REQUESTS FIX!
// {{image url="http://www.pclinuxonline.com/wiki/upimages/wallp/personalize-superkaramba.png"}}
// $translate = preg_replace("/(\{\{image class=\")(.+?)(\ url=\")(.+?)(\")(.+?)(\"\}\})/i","[[Image:\\2|\\3\\4]]",$translate);
$translate = preg_replace("/(\{\{image url=\")(.+?)(\"\}\})/i","[[Image:\\2]]",$translate);
//=================================================================
// Put the horizontal line back in
$translate = str_replace("[hr]", "----", $translate);
//=================================================================
// Parse and add cleanup tag
$translate = "<h2>Here's the translated output:</h2>
<textarea>{{Cleanup|This has been ported using an automated script, which might have broken vital details. It needs to be reviewed to get it up to the latest standards!}}\n\n".$translate."</textarea><br><br>\n";
/*=================================================================
NOTES:
This copied more or less directly out of the new WiKi
This appears to work in this script, but is coded incorrectly:
//
=>
''
This appears to work in this script:
**
=>
'''
[[MangledPageName Mangled page name]]
=>
[[Mangled page name]]
[[MangledPageName Alternate Name]]
=>
[[mangled page name|Alternate Name]]
[[http://foo.com]]
=>
http://foo.com
This appears to work in this script:
[[http://foo.com Link name]]
=>
[http://foo.com Link name]
This appears to work in this script:
""PCLinuxOS""
=>
PCLinuxOS
@@{{image url="http://www.pclinuxonline.com/wiki/upimages/wallp/personalize-superkaramba.png"}}@@
=>
[[Image:[last].png]]
=================================================================*/
}
//=========================================================================
// Print the page to the html output
print <<<EOF
<html><head><title>TranslateMe™ - PCLinuxOS WiKi markup converter</title>
<style type='text/css'>
a {
color: #000800;
}
body, html { font-family: "Deja-vu sans",Helvetica,Tahoma,sans-serif;
font-size: 12px;
}
h1 { border-bottom: 1px solid #000800;
font-size: 28px;
margin: 0px;
margin-bottom: 5px;
padding: 3px;
}
h2 { font-size: 20px;
margin: 2px;
padding: 2px;
}
input, textarea { border: 1px solid #000;
border-left: 3px solid #000;
font-family: "Deja-vu sans",Helvetica,Tahoma,sans-serif;
font-size: 12px;
}
input { font-weight: bold;
}
.jman { float: right;
font-size: 8px;
}
textarea { height: 200px;
width: 80%;
}
</style>
</head><body>
<h1>PCLinuxOS WiKi markup converter $version-$build</h1>
<div class='jman'>Written by the PCLinuxOS documentation team</div>
This can’t distinguish a bunch of stuff (see disclaimer), sorry, but it should help speed up translation nevertheless.<br><br>
$disclaimer<br><br>
EOF;
//=========================================================================
// If there's something translated, print it.
print $translate;
//=========================================================================
print <<<EOF
<br><h2>Translate something:</h2><form name='translateform' method='POST' action='{$_SERVER['PHP_SELF']}'>
<textarea name='wakin' onFocus='if(this.value=="Type or paste text here..."){this.value="";}'>Type or paste text here...</textarea><br>
<input type='submit' value='Translate it!'>
</form></body></html>
EOF;
?>
<!--
</pre>
-->

