Check of a page for recent edits

I mentioned all of this in a response to comments made on another page....I thought I'd post the code so that people could play with it. Basically, if a page has been recently edited (by someone at a different IP....which makes it difficult to see how it works from a test implementation unless you go into the database table and edit the IP to a different one than the one you're at) then two red exclamation marks appear next to the page name at the top. Below is all the different pieces of code....the install was on a version of wikka. It doesn't "lock" the page, just warns if recently edited (not even if still "open" interest was in warning about recent activity).

Sorry the presentation of the code isn't "fancy" & well-laid out, but it's late and I have to teach tomorrow early in the morning. Here is a graphic of how it looks when it is showing a recent edit....
(Note that you can't see the brilliant red floating tooltip when you hover over the exclamation marks...produced by the javascript I provided the link for below.) Oh, and there's a similar little "refresh" graphic beside the "edit" link in the footer as well. Have fun.


CREATE TABLE `wikka_usersonline` (
  `ip` varchar(15) NOT NULL default '',
  `expire` int(10) unsigned NOT NULL default '0',
  `username` varchar(255) NOT NULL default '',
  `recentpage` varchar(50) NOT NULL default '',
  `recentpageedittime` int(10) unsigned default NULL,
  `recentpageeditname` varchar(50) default NULL,
  UNIQUE KEY `ip` (`ip`)

pageinuse.php (place in actions directory)

$thispagename = $this->getPageTag();
$usernameP = $this->GetUserName();
$table = $this->config["table_prefix"].usersonline;
$output = "SELECT * FROM ".$table." WHERE recentpageeditname='$thispagename' AND username NOT LIKE '$usernameP' ORDER BY username";
    $result = mysql_query($output);
    while ($row = mysql_fetch_array($result))
      extract ($row);
      if (($recentpage == $recentpageeditname) && (($expire-$recentpageedittime)<600))
        echo "<a href='javascript:void(0);' onmouseover=\"this.T_DELAY=0;this.T_PADDING=10;this.T_WIDTH=130;this.T_BGCOLOR='#FF3300';this.T_FONTCOLOR='#000000';this.T_FONTWEIGHT='bold';return escape('File Edited in Last Ten Minutes')\"><B><font color=#ff0000>!!</font></B></A>";
echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"./actions/wz_tooltip.js\"></script>";

Code modified in header.php (around line 40; notice that small graphic for reload is missing...I just captured and used the one from IE)

<h2><?php echo "<a href='".$this->GetConfigValue("base_url").$this->MiniHref($method, $tag)."' title=\"Refresh this page to see if editing is safe.\"><IMG SRC=\"./images/reload.gif\" BORDER=0></a>".$this->config["wakka_name"] ?> : <a href="<?php echo $this->href("", "TextSearch", "phrase=").urlencode($this->GetPageTag()); ?>"><?php echo $this->GetPageTag(); ?></a><? include("pageinuse.php"); ?></h2>

The wz_tooltip.js (referred to above), which allows "better" tooltips (in this case, more recognizable) is available at as a free download....put into actions directory

recentpageedit.php (put in actions directory)

$time2wait = 900; // Number of seconds
$thispagenameX = $this->getPageTag();
$table = $this->config["table_prefix"]."usersonline";

mysql_query("UPDATE ".$table." SET expire = '".(time()+$time2wait)."', recentpage = '".$thispagenameX."', recentpageedittime = '".(time()+$time2wait)."', recentpageeditname = '".$thispagenameX."' WHERE ip='".$REMOTE_ADDR."'");
echo "<center><B>Make sure you save your file at least every 10 Minutes!</b></center>";

edit.php (add the following line 4)


Valid XHTML :: Valid CSS: :: Powered by WikkaWiki