Author: Jorg Sowa (jorgsowa)
Committer: Derick Rethans (derickr)
Date: 2026-11-30T14:56:03Z

Commit: 
https://github.com/php/web-wiki/commit/bde7775a9e764057bb57b01a78788cd453f9c4f3
Raw diff: 
https://github.com/php/web-wiki/commit/bde7775a9e764057bb57b01a78788cd453f9c4f3.diff

Bind doodle vote data to its page

A doodle with the same title on another page shared the data file, letting it
edit, delete or add votes in the original poll, even after it was closed.
Existing title-only files are still read until the page's own file is written.

Changed paths:
  M  dokuwiki/lib/plugins/doodle/syntax.php


Diff:

diff --git a/dokuwiki/lib/plugins/doodle/syntax.php 
b/dokuwiki/lib/plugins/doodle/syntax.php
index 6bff767c..9518e36c 100755
--- a/dokuwiki/lib/plugins/doodle/syntax.php
+++ b/dokuwiki/lib/plugins/doodle/syntax.php
@@ -49,8 +49,7 @@
  *
  * If closed=="true", then no one can vote anymore. The result will still be 
shown on the page.
  *
- * The doodle's data is saved in '<dokuwiki>/data/meta/title_of_vote.doodle'. 
The filename is the (masked) title.
- * This has the advantage that you can move your doodle to another page, 
without loosing the data.
+ * The doodle's data is saved in '<dokuwiki>/data/meta/<page 
id>.doodle.<masked title>', so it is bound to its page.
  */
 class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
 {
@@ -570,6 +569,10 @@ function getInputTR() {
      */
     function readDoodleDataFromFile() {
         $dfile     = $this->getDoodleFileName();
+        if (!file_exists($dfile)) {
+            // read-only fallback: writes always go to the page-bound file
+            $dfile = $this->getLegacyDoodleFileName();
+        }
         $doodle    = array();
         if (file_exists($dfile)) {
             $doodle = unserialize(file_get_contents($dfile));
@@ -605,10 +608,19 @@ function writeDoodleDataToFile() {
     }
 
     /**
-     * create unique filename for this doodle from its title.
-     * (replaces space with underscore etc.)
+     * create unique filename for this doodle from the current page and its 
title.
      */
     function getDoodleFileName() {
+        global $ID;
+        // no dots, so page "a" + title "b.doodle.c" can't collide with page 
"a.doodle.b" + title "c"
+        $titleId = str_replace(array(':', '.'), '_', 
cleanID($this->params['title']));
+        return metaFN($ID, '.doodle.' . $titleId);
+    }
+
+    /**
+     * filename shared by all doodles with the same title, regardless of page
+     */
+    function getLegacyDoodleFileName() {
         if (empty($this->params['title'])) {
           debout('Doodle must have title.');
           return 'doodle.doodle';

Reply via email to