Extension:Painting/Code/Painting.php

Title
 * 3) To activate the extension, include it from your LocalSettings.php
 * 4) with: include("extensions/painting.php");
 * 1) with: include("extensions/painting.php");

function wfPainting { global $wgParser; $wgParser->setHook( "painting", "renderPainting" ); $wgParser->disableCache; }

function renderPainting( $input, $argv=array ) { global $wgParser,$wgUser,$wgScriptPath,$wgTitle,$wgRequest,$wgArticlePath,$wgSitename;

$pagetitle = $wgTitle->getPrefixedText; $width = empty($argv['width'])?"500":$argv['width']; $height = empty($argv['height'])?"500":$argv['height']; $locked = empty($argv['locked'])?"":$argv['locked'];

if (!empty($argv['imgmx'])) {		$imgmx = $argv['imgmx']; $imgmy = $argv['imgmy']; if (empty($argv['width'])) {			$width = $imgmx+200; $height = $imgmy+20; if ($imgmy < 360) { $height = 380; $width = $imgmx*($height-20)/$imgmy+200; }		}	}

$wgParser->disableCache; $IP = wfGetIP; if ($wgUser->mName == "") $user = $IP; else $user = $wgUser->mName; $lines = split("\n",$input); $title = $lines[0];

if ($title == "RECENT CHANGES") {	$fn = "../paintinglog.txt"; if (!file_exists($fn)) { return "Internal error"; } $txt = fopen($fn,"r"); if (!$txt) { return "Internal error #2"; } $str = ""; $nblig=0; fseek($txt,-5000,SEEK_END); $lig = fgets($txt); while (!feof($txt)) {		$lig = fgets($txt); $lig = trim($lig); if ($lig != FALSE) {			$item = split("\t",$lig); if (count($item)>=9) $str = ' '.$item[0].'  '.$item[1].' '.$item[8].'  '. $item[4].' .(empty($item[10])?'':$item[10]).  '.$str; }		}	fclose($txt); return ' '; }

$filename = str_replace('?','P',str_replace(' ','_',$title)); $filename = str_replace(':','D',str_replace('@','A',$filename)); $filename = str_replace('/','S',str_replace('\\','s',$filename)); $filename = str_replace('*','E',str_replace('"','G',$filename));	$filename = str_replace('>','g',str_replace('<','p',$filename));	$filename = str_replace('|','P',$filename);	$str = ''.$title.' ';

$urlbase = $wgSitename == "WikiPoll" ? "http://localhost" : "http://wikipainting.free.fr";

if (!empty($_POST['painttitle']) && empty($locked)) if ($_POST['painttitle'] == $filename) // applet ? return ' '.$str. '     '. (empty($imgmx)?'':'		  <param name=imgmy value="'.$imgmy.'">'). ' <BR>';

$fn = "/mnt/128/free.fr/d/a/wikipainting/paintings/".$filename.".txt"; $i = -1; if (file_exists($fn)) {	$txt = fopen($fn,"r"); // check the revision number if ($txt) {		while (!feof($txt)) {		$a = fgets($txt); if ($a != FALSE) $i++; }	fclose($txt); }	}

if (empty($locked)) return $str.' '; else return '<img src="'.	$wgScriptPath.'/../paintings/'.$filename.'.png" width='.$width.' height='.$height.'>'; }

?>