]> git.mjollnir.org Git - moodle.git/commitdiff
Replaced some needed plugins.
authormchurch <mchurch>
Wed, 2 Jun 2004 18:17:30 +0000 (18:17 +0000)
committermchurch <mchurch>
Wed, 2 Jun 2004 18:17:30 +0000 (18:17 +0000)
mod/wiki/ewiki/plugins/action/diff.php [new file with mode: 0755]
mod/wiki/ewiki/plugins/aview/backlinks.php [new file with mode: 0755]
mod/wiki/ewiki/plugins/feature/imgresize_gd.php [new file with mode: 0755]
mod/wiki/ewiki/plugins/markup/footnotes.php [new file with mode: 0755]
mod/wiki/ewiki/plugins/page/orphanedpages.php [new file with mode: 0755]
mod/wiki/ewiki/plugins/page/pageindex.php [new file with mode: 0755]

diff --git a/mod/wiki/ewiki/plugins/action/diff.php b/mod/wiki/ewiki/plugins/action/diff.php
new file mode 100755 (executable)
index 0000000..bcf3a46
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+ # this is the "stupid diff", which shows up changes between two
+ # saved versions of a WikiPage; even if working very unclean it
+ # allows to see what has changed
+ # it is accessible through the "info about page" action
+
+
+
+ $ewiki_plugins["action"]["diff"] = "ewiki_page_stupid_diff";
+ $ewiki_config["action_links"]["info"]["diff"] = "diff";
+
+
+
+ function ewiki_page_stupid_diff($id, $data, $action) {
+
+
+    if ($uu=$GLOBALS["ewiki_diff_versions"]) {
+       list($new_ver, $old_ver) = $uu;
+       $data = ewiki_database("GET", array("id" => $id, "version" => $new_ver));
+    }
+    else {
+       $new_ver = $data["version"];
+       $old_ver = $new_ver - 1;
+    }
+    if ($old_ver > 0) {
+       $data0 = ewiki_database("GET", array("id" => $id, "version" => $old_ver));
+    }
+
+    $o = ewiki_make_title($id, "Differences between version $new_ver and $old_ver of »{$id}«");
+
+    $txt0 = preg_split("/\s*\n/", trim($data0["content"]));
+    $txt2 = preg_split("/\s*\n/", trim($data["content"]));
+
+    $diff0 = array_diff($txt0, $txt2);
+    $diff2 = array_diff($txt2, $txt0);
+
+    foreach ($txt2 as $i => $line) {
+
+       $line = htmlentities($line);
+
+       $i2 = $i;
+       while ($rm = $diff0[$i2++]) {
+          $o .= "<b>-</b><font color=\"#990000\"> <tt>$rm</tt></font><br>\n";
+          unset($diff0[$i2-1]);
+       }
+
+       if (in_array($line, $diff2)) {
+          $o .= "<b>+</b><font color=\"#009900\"> <tt>$line</tt></font><br>\n";
+       }
+       else {
+          $o .= "&nbsp; $line<br>\n";
+       }
+
+    }
+
+    foreach ($diff0 as $rm) {
+       $o .= "<b>-</b><font color=\"#990000\"> <tt>$rm</tt></font><br>\n";
+    }
+
+    return($o);
+ }
+
+
+?>
\ No newline at end of file
diff --git a/mod/wiki/ewiki/plugins/aview/backlinks.php b/mod/wiki/ewiki/plugins/aview/backlinks.php
new file mode 100755 (executable)
index 0000000..fd616af
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+#
+#  this plugin prints the "pages linking to" below a page (the same
+#  information the "links/" action does)
+#
+# altered to use ewiki_get_backlinks() by AndyFundinger.
+
+$ewiki_plugins["view_append"][] = "ewiki_view_append_backlinks";
+
+function ewiki_view_append_backlinks($id, $data, $action) {
+    $pages = ewiki_get_backlinks($id);
+    
+    $o="";
+    foreach ($pages as $id) {
+        $o .= ' <a href="'.ewiki_script("",$id).'">'.$id.'</a>';
+    }
+    ($o) && ($o = "<div class=\"wiki_backlinks\"><small>Backlinks:</small><br>$o</div>\n");
+    
+    return($o);
+}
+
+
+?>
\ No newline at end of file
diff --git a/mod/wiki/ewiki/plugins/feature/imgresize_gd.php b/mod/wiki/ewiki/plugins/feature/imgresize_gd.php
new file mode 100755 (executable)
index 0000000..e88c998
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+#  if someone uploads an image, which is larger than the allowed
+#  image size (EWIKI_IMAGE_MAXSIZE), then this plugin tries to
+#  rescale that image until it fits; it utilizes the PHP libgd
+#  functions to accomplish this
+
+#  NOTE: It is currently disabled for Win32, because nobody knows, if
+#  this will crash the PHP interpreter on those systems.
+
+
+define("EWIKI_IMGRESIZE_WIN", 0);
+
+
+if (!strstr(PHP_VERSION, "-dev") && !function_exists("imagecreate") && function_exists("dl")) {   #-- try to load gd lib
+   @dl("php_gd2.dll") or @dl("gd.so");
+}
+if (function_exists("imagecreate")) {
+   $ewiki_plugins["image_resize"][] = "ewiki_binary_resize_image_gd";
+}
+
+
+function ewiki_binary_resize_image_gd(&$filename, &$mime, $return=0) {
+
+           /*** this disallows Win32 ***/
+   if (    (DIRECTORY_SEPARATOR!="/") && !EWIKI_IMAGERESIZE_WIN
+       || (strpos($mime, "image/")!==0) )
+   { 
+      return(false);
+   }
+
+   $tmp_rescale = $filename;
+
+   #-- initial rescale
+   $r = EWIKI_IMAGE_MAXSIZE / filesize($tmp_rescale);
+   $r = ($r) + ($r - 1) * ($r - 1);
+
+   #-- read orig image
+   strtok($mime, "/");
+   $type = strtok("/");
+   if (function_exists($pf = "imagecreatefrom$type")) {
+      $orig_image = $pf($filename);
+   }
+   else {
+      return(false);
+   }
+   $orig_x = imagesx($orig_image);
+   $orig_y = imagesy($orig_image);
+
+   #-- change mime from .gif to .png
+   if (($type == "gif") && (false || function_exists("imagepng") && !function_exists("imagegif"))) {
+      $type = "png";
+   }
+
+   #-- retry resizing
+   $loop = 20;
+   while (($loop--) && (filesize($tmp_rescale) > EWIKI_IMAGE_MAXSIZE)) {
+
+      if ($filename == $tmp_rescale) {
+         $tmp_rescale = tempnam(EWIKI_TMP, "ewiki.img_resize_gd.tmp.");
+      }
+
+      #-- sizes
+      $new_x = (int) ($orig_x * $r);
+      $new_y = (int) ($orig_y * $r);
+
+      #-- new gd image
+      $tc = function_exists("imageistruecolor") && imageistruecolor($orig_image);
+      if (!$tc || ($type == "gif")) {
+         $new_image = imagecreate($new_x, $new_y);
+         imagepalettecopy($new_image, $orig_image);
+      }
+      else {
+         $new_image = imagecreatetruecolor($new_x, $new_y);
+      }
+
+      #-- resize action
+      imagecopyresized($new_image, $orig_image, 0,0, 0,0, $new_x,$new_y, $orig_x,$orig_y);
+
+      #-- special things
+      if ( ($type == "png") && function_exists("imagesavealpha") ) {
+         imagesavealpha($new_image, 1);
+      }
+
+      #-- save
+      if (function_exists($pf = "image$type")) {
+         $pf($new_image, $tmp_rescale);
+      }
+      else {
+         return(false);   # cannot save in orig format (.gif)
+      }
+
+      #-- prepare next run
+      imagedestroy($new_image);
+      clearstatcache();
+      $r *= 0.95;
+   }
+
+   #-- stop
+   imagedestroy($orig_image);
+
+   #-- security check filesizes, abort
+   if (!filesize($filename) || !filesize($tmp_rescale) || (filesize($tmp_rescale) > EWIKI_IMAGE_MAXSIZE)) {
+      unlink($tmp_rescale);
+      return($false);
+   }
+
+   #-- set $mime, as it may have changed (.gif)
+   $mime = strtok($mime, "/") . "/" . $type;
+   if (!strstr($filename, ".$type")) {
+      unlink($filename);
+      $filename .= ".$type";
+   }
+
+   #-- move tmp file to old name
+   copy($tmp_rescale, $filename);
+   unlink($tmp_rescale);
+   return(true);
+
+}
+
+?>
\ No newline at end of file
diff --git a/mod/wiki/ewiki/plugins/markup/footnotes.php b/mod/wiki/ewiki/plugins/markup/footnotes.php
new file mode 100755 (executable)
index 0000000..6f9021d
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+ /*
+
+   this plugin introduces markup for footnotes, use it like:
+
+      ...
+      some very scientific sentence {{this is a footnote explaination}}
+      ...
+
+   this may be useful in some rare cases; usually one should create
+   a WikiLink to explain a more complex task on another page;
+   your decision
+
+*/  
+
+
+
+$ewiki_plugins["format_source"][] = "ewiki_format_source_footnotes";
+
+
+
+function ewiki_format_source_footnotes (&$source) {
+
+   $notenum = 0;
+
+   $l = 0;
+   while (
+            ($l = strpos($source, "{{", $l))
+        &&  ($r = strpos($source, "}}", $l))
+         )
+   {
+      $l += 2;
+
+      #-- skip "{{...\n...}}"
+      if (strpos($source, "\n", $l) < $r) {
+         continue;
+      }
+
+      $notenum++;
+
+      #-- extract "footnote"
+      $footnote = substr($source, $l, $r - $l);
+
+      #-- strip "{{footnote}}"
+      $source = substr($source, 0, $l - 2)
+             . "<a href=\"#fn$notenum\">·$notenum</a>"
+             . substr($source, $r + 2);
+
+      #-- add "footnote" to the end of the wiki page source
+      if ($notenum==1) {
+         $source .= "\n----";
+      }
+      $source .= "\n" .
+                 "<a name=\"fn$notenum\">·$notenum</a> ". $footnote . "\n<br>";
+      
+   }
+}
+
+
+?>
\ No newline at end of file
diff --git a/mod/wiki/ewiki/plugins/page/orphanedpages.php b/mod/wiki/ewiki/plugins/page/orphanedpages.php
new file mode 100755 (executable)
index 0000000..17b1979
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+#  lists all pages, which are not referenced from others
+#  (works rather unclean and dumb)
+
+
+define("EWIKI_PAGE_ORPHANEDPAGES", "OrphanedPages");
+$ewiki_plugins["page"][EWIKI_PAGE_ORPHANEDPAGES] = "ewiki_page_orphanedpages";
+
+
+function ewiki_page_orphanedpages($id, $data, $action) {
+
+   global $ewiki_links;
+
+   $o = ewiki_make_title($id, $id, 2);
+
+   $pages = array();
+   $refs = array();
+   $orphaned = array();
+
+   #-- read database
+   $db = ewiki_database("GETALL", array("refs", "flags"));
+   $n=0;
+   while ($row = $db->get()) {
+
+      $p = $row["id"];
+
+      #-- remove self-reference
+      $row["refs"] = str_replace("\n$p\n", "\n", $row["refs"]);
+
+      #-- add to list of referenced pages
+      $rf = explode("\n", trim($row["refs"]));
+      $refs = array_merge($refs, $rf);
+      if ($n++ > 299) {
+         $refs = array_unique($refs);
+         $n=0;
+      } // (clean-up only every 300th loop)
+
+      #-- add page name
+      if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
+         $pages[] = $row["id"];
+      }
+   }
+   $refs = array_unique($refs);
+
+    #-- check pages to be referenced from somewhere
+    foreach ($pages as $p) {    
+        if (!ewiki_in_array($p, $refs)) {
+            if (!EWIKI_PROTECTED_MODE || EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($p, $uu, "view")) {
+                $orphaned[] = $p;    
+            }  
+        }
+    }
+
+   #-- output
+   $o .= ewiki_list_pages($orphaned, 0);
+
+   return($o);
+}
+
+
+?>
\ No newline at end of file
diff --git a/mod/wiki/ewiki/plugins/page/pageindex.php b/mod/wiki/ewiki/plugins/page/pageindex.php
new file mode 100755 (executable)
index 0000000..87039a5
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+ # this plugins provides the internal page "PageIndex", which lists all
+ # pages alphabetically
+
+
+define("EWIKI_PAGE_PAGEINDEX", "PageIndex");
+$ewiki_plugins["page"][EWIKI_PAGE_PAGEINDEX] = "ewiki_page_index";
+
+
+function ewiki_page_index($id=0, $data=0, $action=0, $args=array()) {
+
+   global $ewiki_plugins;
+
+   $o = ewiki_make_title($id, $id, 2);
+
+   $sorted = array();
+   $sorted = array_merge($sorted, array_keys($ewiki_plugins["page"]));
+
+   $exclude = "\n" . implode("\n",
+      preg_split("/\s*[,;:\|]\s*/", $args["exclude"])) .
+      "\n";
+
+   $result = ewiki_database("GETALL", array("flags"));
+   while ($row = $result->get()) {
+    if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $uu, "view")) {
+        continue;
+    }   
+    if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
+        if (!stristr($exclude, "\n".$row["id"]."\n")) {
+            $sorted[] = $row["id"];
+        }
+    }
+   }
+
+   natcasesort($sorted);
+
+   $o .= ewiki_list_pages($sorted, 0, 0, $ewiki_plugins["list_dict"][0]);
+
+   return($o);
+}
+
+
+?>
\ No newline at end of file