commit 0cc6728257fb598fa98afa881a69d340589347a9 Author: Fabien Benetou Date: Thu May 19 19:22:04 2011 +0200 adding the first file, will have to decide a structre diff --git a/pim_functions.php b/pim_functions.php new file mode 100644 index 0000000..9ef2128 --- /dev/null +++ b/pim_functions.php @@ -0,0 +1,179 @@ +"; +} + +//display editions through an horizontal line +/* +fomally done via GnuPlot, cf http://fabien.benetou.fr/Wiki/Visualization#timeline +http://www.scholarpedia.org/article/Spike-response_model is probably too complicated for the small resolution + +*/ +function DisplayVisualEdits($pagename){ + global $ScriptUrl, $PubDir, $FarmD; + + $processingpath = '/pub/libraries/processing.js'; + $processingfile = "/pub/visualization/edits_per_page/$pagename.pjs"; + $processinglib = ""; + $first_edit = 1212192000; + $now = time(); + // draw the timeline from the first edit to now() + // get the list of edits of the current page + // "get inspired" by PrintDiff() in scripts/pagerev.php + $canvaswidth = 600-2*10; + $canvasheight = 10; + $block_width = 4; + $block_height = 8; + $page = ReadPage($pagename); + if (!$page) return; + krsort($page); reset($page); + // newest first + // for each edit + $canvas = " + void setup() + { + size($canvaswidth, $canvasheight); +PFont font; +font = loadFont(\"FFScala-Bold-12.vlw\"); +textFont(font); + } + void mouseMoved() { + checkButtons(); + } + + void mouseDragged() { + checkButtons(); + } + void draw() + { + background(251); + fill(0,0,255,20); + noStroke(); +"; + $mousePressed = "void mousePressed() {"; + $destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=diff#diff"; + $mousePressed .= "\t\tif (lastHovered>0) { link(\"$destination_link\"+lastHovered); }\n"; + $checkButtons = "void checkButtons() {"; + print $processinglib.''; + // set to false to de-activate cache (practical for tests) + $newest_diff = true; + //$newest_diff = false; + foreach($page as $k=>$v) { + if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue; + + $diff = $match[1]; + + $diffclass = $match[3]; + if ($diffclass=='minor') + { $canvas .= "\t\tfill(0,255,0,20);\n"; } + else + { $canvas .= "\t\tfill(0,0,255,20);\n"; } + + $buttonname = "over".$diff."Button"; + //$bools .= "boolean $buttonname = false;\n"; + if (file_exists($FarmD.$processingfile) && $newest_diff) + if ( filemtime($FarmD.$processingfile) > $diff) + return; + $newest_diff = false; + // add a sightly transparent tick rectangle with its Unix timestamp link to the diff page + // the mouse over a certain edit should change its color + // see http://processingjs.org/learning/basic/embeddedlinks + // or clicablerects.js via Pomax on :mozilla2/#processing.js (14/05/2011 ~11pm) + $x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$diff)) / ($now - $first_edit))); + $y = 1; + $checkButtons .= "\t\tif ( mouseX > $x && mouseX < $x+$block_width) lastHovered = $diff; \n"; + // if (mouseY > $y && mouseY < $y+$block_height) not really required + // others should be set to false else one always jump to the olded diff mouved over + $canvas .= "\t\trect($x,$y,$block_width,$block_height);\n"; + } + $canvas .= "\t\tstroke(0,155);\n"; + $canvas .= "\t\tfill(0,0,255,80);\n"; + $canvas .= "\t\ttext(\"Edits:\",2,10 );\n"; + $canvas .= "\t\tfill(0,0,255,40);\n"; + for ($year=2009;$year<2012;$year++){ //each year until now + $unixyear = mktime(0,0,0,1,1,$year); + $x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$unixyear)) / ($now - $first_edit))); + $y = 0; + $canvas .= "line($x,$y,$x,$y+$block_height+2); text(\"$year\",$x+2,$y+10 );\n"; + } + $canvas = $bools . $canvas ."}" . $mousePressed ."}" .$checkButtons . "}"; + + // load ProcessinJS + + $write_result = file_put_contents($FarmD.$processingfile,$canvas); + + // print resulting canvas + + $older_gnuplot_version = "
\"/pub/visualization/edits_per_page/{$pagename}.png\"/
(visualization details).

"; +} + + +//display images with transparancy invertionnaly proportional to last time of update +// http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#VisualDecayOfInformation +function DisplayDecay($pagename){ + +/* + consider + adding threshold + not keeping it linear (e.g. log) + but still constantly inscreasing between 0 and 1 + use a factor when matches (e.g. regex changing $impeding_factor or $first_edit) + regex would match groupname (e.g. "Person." with fast decay) or pagename or both (e.g. "Math" with slow decay) + yellowish background, looking like old paper + ...rest got deleted by a dumb rm... +*/ + global $ScriptUrl; + $first_edit = 1212192000; + $now = time(); + //load page + $page = ReadPage($pagename); + if (!$page) return; + + $last_edit = $page["time"]; + //get last edit + + $destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=edit"; + + //use the previous equation adding 1 - () + $opacity = round ( 1 - ( (($now - $first_edit)-($now-$last_edit)) / ($now - $first_edit)) , 2 ); + + $opacitymsg = "opacity=$opacity"; + if ($opacity > 0.8) + $opacitymsg = "".$opacitymsg.""; + + //if user if admin + if ( $GLOBALS['Author'] == 'Fabien' || $GLOBALS['Author'] == 'Utopiah' ) { + //for 1 to a multiplier of value + for ($i=0;$i<$opacity*10;$i++){ + // display another visual problem with a link back to improvingwiki#visualdecay + print "
" + .decbin(rand(0,10000))."
"; + } + // add a good practice msg + print "
+ $opacitymsg edits should be done to check if + the informamtion presented is still relevant, + links are working, + opinion expressed still correct, etc. +
"; + } + + + //print img with opacity + warning message + + print "
If you can read this text ($opacitymsg) if means the page has not been edited for a long time. Consequently the information it holds might be deprecated or no longer represent the opinion of this author.
"; + +}