DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:show_changes_in_recents_list

Show changes in the recents list

Using this hack you can easily see what has been changed from one version to another right there in the recents list. It provides you with a small javascript link that will show or hide a diff (the same that's used when comparing two versions of a page the regular way) between the current and the previous version of the page. It looks like this:

The quality of the code is horrendous but I couldn't find the right event to insert additional information into the recents list. There is an event that provides the HTML code after the list has been put together but trying to figure out the current version and ID of each entry would be just as hacky. Anyway, on to the code… it's a patch, so apply with something like patch < this_patch.txt:

Index: inc/html.php
===================================================================
--- inc/html.php	(revision 1178)
+++ inc/html.php	(revision 1304)
@@ -566,6 +566,8 @@
  * @author Ben Coburn <btcoburn@silicodon.net>
  */
 function html_recent($first=0){
+  require_once(DOKU_INC.'inc/DifferenceEngine.php');
+
   global $conf;
   global $lang;
   global $ID;
@@ -646,6 +648,69 @@
     $form->addElement(form_makeCloseTag('span'));
 
     $form->addElement(form_makeCloseTag('div'));
+
+    if ((getNS($recent['id']) != 'playground') && getRevisionInfo($recent['id'], $recent['date'])) {
+      $revs = getRevisions($recent['id'], 0, 10);
+
+      $previous_revision = false;
+
+      foreach ($revs as $rev_date) {
+        if (getNS($rev['id']) == 'playground') { break; }
+
+        // skip seen ones
+        // if(isset($seen[$recent['id']])) return false;
+
+        $rev = getRevisionInfo($recent['id'], $rev_date);
+
+        // skip minors
+        //if($rev['type']===DOKU_CHANGE_TYPE_MINOR_EDIT && ($flags & RECENTS_SKIP_MINORS)) continue;
+
+        // remember in seen to skip additional sights
+        // $seen[$rev['id']] = 1;
+
+        // check if it's a hidden page
+        if(isHiddenPage($rev['id'])) continue;
+
+        // filter namespace
+        if (($ns) && (strpos($rev['id'],$ns.':') !== 0)) continue;
+
+        // exclude subnamespaces
+        if (($flags & RECENTS_SKIP_SUBSPACES) && (getNS($rev['id']) != $ns)) continue;
+
+        // check ACL
+        if (auth_quickaclcheck($rev['id']) < AUTH_READ) continue;
+
+        // check existance
+        if((!@file_exists(wikiFN($rev['id']))) && ($flags & RECENTS_SKIP_DELETED)) continue;
+
+        if ($rev['date'] < $recent['date']) {
+          $previous_revision = $rev;
+          break;
+        }
+      }
+    }
+
+    $content = '';
+    if($previous_revision) {
+      $content .= '<div><a href="#" onclick="document.getElementById(\'changes-'.$recent['id'].'-'.$recent['date'].'\').style.display = ((document.getElementById(\'changes-'.$recent['id'].'-'.$recent['date'].'\').style.display == \'none\') ? \'block\' : \'none\'); return false;">'.$lang['show_changes'].'</a>';
+      $content .= '<div style="color: black; display: none;" id="changes-'.$recent['id'].'-'.$recent['date'].'">';
+
+      $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($recent['id'], $previous_revision['date']))),
+        explode("\n",htmlspecialchars(rawWiki($recent['id'], $recent['date']))));
+      $previous_date = strftime($conf['dformat'],$previous_revision['date']);
+
+      $tdf = new TableDiffFormatter();
+      $content .= '<table>';
+      $content .= '<tr><th colspan="2" width="50%">'.$previous_date.'</th>';
+      $content .= '<th colspan="2" width="50%">'.$date.'</th></tr>';
+      $content .= $tdf->format($df);
+      $content .= '</table>';
+
+      $content .= '</div></div>';
+
+      $form->addElement($content);
+    }
+
     $form->addElement(form_makeCloseTag('li'));
   }
   $form->addElement(form_makeCloseTag('ul'));
Index: inc/lang/de/lang.php
===================================================================
--- inc/lang/de/lang.php	(revision 1178)
+++ inc/lang/de/lang.php	(revision 1304)
@@ -231,3 +231,4 @@
 $lang['mu_progress']           = '@PCT@% hochgeladen';
 $lang['mu_filetypes']          = 'Erlaubte Dateitypen';
 $lang['recent_global']         = 'Im Moment sehen Sie die Änderungen im Namensraum <b>%s</b>. Sie können auch <a href="%s">die Änderungen im gesamten Wiki sehen</a>.';
+$lang['show_changes']          = 'Änderungen anzeigen';
Index: inc/lang/en/lang.php
===================================================================
--- inc/lang/en/lang.php	(revision 1178)
+++ inc/lang/en/lang.php	(revision 1304)
@@ -251,5 +251,6 @@
 $lang['mu_filetypes'] = 'Allowed Filetypes';
 
 $lang['recent_global'] = 'You\'re currently watching the changes inside the <b>%s</b> namespace. You can also <a href="%s">view the recent changes of the whole wiki</a>.';
+$lang['show_changes'] = 'Show changes';
 
 //Setup VIM: ex: et ts=2 enc=utf-8 :

The code assumes that minor edits and edits in the playground: namespace are skipped, and that if a page has been changed multiple times it will also appear multiple times. The code that creates the recents lists has to do the same, so you can apply the following patch as well. Otherwise you will have to change the above code.

Index: inc/html.php
===================================================================
--- inc/html.php	(revision 1176)
+++ inc/html.php	(revision 1177)
@@ -573,10 +573,10 @@
    * decide if this is the last page or is there another one.
    * This is the cheapest solution to get this information.
    */
-  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
+  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID), RECENTS_SKIP_MINORS);
   if(count($recents) == 0 && $first != 0){
     $first=0;
-    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
+    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID), RECENTS_SKIP_MINORS);
   }
   $hasNext = false;
   if (count($recents)>$conf['recent']) {
Index: inc/changelog.php
===================================================================
--- inc/changelog.php	(revision 1176)
+++ inc/changelog.php	(revision 1177)
@@ -251,8 +251,10 @@
   $recent = parseChangelogLine($line);
   if ($recent===false) { return false; }
 
+  //if (getNS($recent['id']) == 'playground') { return false; }
+
   // skip seen ones
-  if(isset($seen[$recent['id']])) return false;
+  //if(isset($seen[$recent['id']])) return false;
 
   // skip minors
   if($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT && ($flags & RECENTS_SKIP_MINORS)) return false;
If you got any questions or problems, please contact me: Georg Sorst.
tips/show_changes_in_recents_list.txt · Last modified: 2009/05/25 20:38 by 85.127.150.130