Revision [7071]
This is an old revision of MyChangesAction made by TimoK on 2005-04-02 01:16:40.
My Changes Action
See also:
Documentation: MyChangesActionInfo.The php code:
<?php
// actions/mychanges.php
// written by Carlo Zottmann
// http://wakkawikki.com/CarloZottmann
if ($user = $this->GetUser())
{
$my_edits_count = 0;
if ($_REQUEST["alphabetically"] == 1)
{
print("<strong>This is a list of pages you've edited, along with the time of your last change (<a href=\"".$this->href("", $tag)."\">order by date</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user = '".mysql_real_escape_string($this->GetUserName())."' ORDER BY tag ASC, time DESC"))
{
foreach ($pages as $page)
{
if ($last_tag != $page["tag"]) {
$last_tag = $page["tag"];
$firstChar = strtoupper($page["tag"][0]);
if (!preg_match("/[A-Z,a-z]/", $firstChar)) {
$firstChar = "#";
}
if ($firstChar != $curChar) {
if ($curChar) print("<br />\n");
print("<strong>$firstChar</strong><br />\n");
$curChar = $firstChar;
}
// print entry
print(" (".$page["time"].") (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");
$my_edits_count++;
}
}
if ($my_edits_count == 0)
{
print("<em>You have not edited any pages yet.</em>");
}
}
else
{
print("<em>No pages found.</em>");
}
}
else
{
print("<strong>This is a list of pages you've edited, ordered by the time of your last change (<a href=\"".$this->href("", $tag, "alphabetically=1")."\">order alphabetically</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user = '".mysql_real_escape_string($this->GetUserName())."' ORDER BY time ASC, tag ASC"))
{
foreach ($pages as $page)
{
$edited_pages[$page["tag"]] = $page["time"];
}
$edited_pages = array_reverse($edited_pages);
foreach ($edited_pages as $page["tag"] => $page["time"])
{
// day header
list($day, $time) = explode(" ", $page["time"]);
if ($day != $curday)
{
if ($curday) print("<br />\n");
print("<strong>$day:</strong><br />\n");
$curday = $day;
}
// print entry
print(" ($time) (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");
$my_edits_count++;
}
if ($my_edits_count == 0)
{
print("<em>You have not edited any pages yet.</em>");
}
}
else
{
print("<em>No pages found.</em>");
}
}
}
else
{
print("<em>You're not logged in, thus the list of pages you've edited couldn't be retrieved.</em>");
}
?>
// actions/mychanges.php
// written by Carlo Zottmann
// http://wakkawikki.com/CarloZottmann
if ($user = $this->GetUser())
{
$my_edits_count = 0;
if ($_REQUEST["alphabetically"] == 1)
{
print("<strong>This is a list of pages you've edited, along with the time of your last change (<a href=\"".$this->href("", $tag)."\">order by date</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user = '".mysql_real_escape_string($this->GetUserName())."' ORDER BY tag ASC, time DESC"))
{
foreach ($pages as $page)
{
if ($last_tag != $page["tag"]) {
$last_tag = $page["tag"];
$firstChar = strtoupper($page["tag"][0]);
if (!preg_match("/[A-Z,a-z]/", $firstChar)) {
$firstChar = "#";
}
if ($firstChar != $curChar) {
if ($curChar) print("<br />\n");
print("<strong>$firstChar</strong><br />\n");
$curChar = $firstChar;
}
// print entry
print(" (".$page["time"].") (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");
$my_edits_count++;
}
}
if ($my_edits_count == 0)
{
print("<em>You have not edited any pages yet.</em>");
}
}
else
{
print("<em>No pages found.</em>");
}
}
else
{
print("<strong>This is a list of pages you've edited, ordered by the time of your last change (<a href=\"".$this->href("", $tag, "alphabetically=1")."\">order alphabetically</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user = '".mysql_real_escape_string($this->GetUserName())."' ORDER BY time ASC, tag ASC"))
{
foreach ($pages as $page)
{
$edited_pages[$page["tag"]] = $page["time"];
}
$edited_pages = array_reverse($edited_pages);
foreach ($edited_pages as $page["tag"] => $page["time"])
{
// day header
list($day, $time) = explode(" ", $page["time"]);
if ($day != $curday)
{
if ($curday) print("<br />\n");
print("<strong>$day:</strong><br />\n");
$curday = $day;
}
// print entry
print(" ($time) (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");
$my_edits_count++;
}
if ($my_edits_count == 0)
{
print("<em>You have not edited any pages yet.</em>");
}
}
else
{
print("<em>No pages found.</em>");
}
}
}
else
{
print("<em>You're not logged in, thus the list of pages you've edited couldn't be retrieved.</em>");
}
?>
The above code doesn't sort the pages properly when sorting by time.
I have re-coded the action like this:
<?php
// actions/mychanges.php
// written by Carlo Zottmann
// http://wakkawikki.com/CarloZottmann
// re-coded by Timo Kissing
// http://wikka.jsnx.com/TimoK
function print_edit(&$last, &$current, &$edit_count, $tag, $time) {
global $wakka;
if ($current != $last) {
if ($last) {
print("<br />\n");
}
print("<strong>$current</strong><br />\n");
$last = $current;
}
$rev_link = $wakka->Link($tag, "revisions", "history", 0);
$page_link = $wakka->Link($tag, "", "", 0);
print(" (".$time.") (".$rev_link.") ".$page_link."<br />\n");
$edit_count++;
}
if ($this->GetUser()) {
$user=$this->GetUserName();
$edit_count = 0;
$str_query = "SELECT tag, time FROM ". $this->config["table_prefix"];
$str_query.= "pages WHERE user = '". mysql_real_escape_string($user);
if ($_REQUEST["alphabetically"] == 1) {
$orderbyalpha = TRUE;
} elseif(is_string($vars["sorting"]) && $_REQUEST["alphabetically"] != 0) {
if($vars["sorting"] == "alpha" || $vars["sorting"] == "alphabetically") {
$orderbyalpha = TRUE;
}
} else {
$orderbyalpha = FALSE;
}
if ($orderbyalpha) {
$str_sorting = " along with the time of your last change ";
$str_linktxt = "order by date";
$str_linkpar = "alphabetically=0";
$str_query .= "' ORDER BY tag ASC, time DESC";
} else {
$str_sorting = " ordered by the time of your last change ";
$str_linktxt = "order alphabetically";
$str_linkpar = "alphabetically=1";
$str_query .= "' ORDER BY time ASC";
}
print("<strong>This is a list of pages you've edited,");
print($str_sorting."(<a href='".$this->href("", $tag, $str_linkpar));
print("'>".$str_linktxt."</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll($str_query)) {
if ($orderbyalpha) {
foreach ($pages as $page) {
if ($last_tag != $page["tag"]) {
$last_tag = $page["tag"];
$firstChar = strtoupper($page["tag"][0]);
if (!preg_match("/[A-Z]/", $firstChar)) {
$firstChar = "#";
}
print_edit($last,$firstChar,$edit_count,$page["tag"],$page["time"]);
}
}
} else {
foreach ($pages as $page) {
$edited_pages[$page["tag"]] = $page["time"];
}
arsort($edited_pages);
foreach ($edited_pages as $pagetag => $pagetime) {
list($day, $time) = explode(" ", $pagetime);
print_edit($curDay,$day,$edit_count,$pagetag,$time);
}
}
if ($edit_count == 0) {
print("<em>You have not edited any pages yet.</em>");
}
} else {
print("<em>No pages found.</em>");
}
} else {
print("<em>You're not logged in, thus the list of pages you've edited couldn't be retrieved.</em>");
}
?>
// actions/mychanges.php
// written by Carlo Zottmann
// http://wakkawikki.com/CarloZottmann
// re-coded by Timo Kissing
// http://wikka.jsnx.com/TimoK
function print_edit(&$last, &$current, &$edit_count, $tag, $time) {
global $wakka;
if ($current != $last) {
if ($last) {
print("<br />\n");
}
print("<strong>$current</strong><br />\n");
$last = $current;
}
$rev_link = $wakka->Link($tag, "revisions", "history", 0);
$page_link = $wakka->Link($tag, "", "", 0);
print(" (".$time.") (".$rev_link.") ".$page_link."<br />\n");
$edit_count++;
}
if ($this->GetUser()) {
$user=$this->GetUserName();
$edit_count = 0;
$str_query = "SELECT tag, time FROM ". $this->config["table_prefix"];
$str_query.= "pages WHERE user = '". mysql_real_escape_string($user);
if ($_REQUEST["alphabetically"] == 1) {
$orderbyalpha = TRUE;
} elseif(is_string($vars["sorting"]) && $_REQUEST["alphabetically"] != 0) {
if($vars["sorting"] == "alpha" || $vars["sorting"] == "alphabetically") {
$orderbyalpha = TRUE;
}
} else {
$orderbyalpha = FALSE;
}
if ($orderbyalpha) {
$str_sorting = " along with the time of your last change ";
$str_linktxt = "order by date";
$str_linkpar = "alphabetically=0";
$str_query .= "' ORDER BY tag ASC, time DESC";
} else {
$str_sorting = " ordered by the time of your last change ";
$str_linktxt = "order alphabetically";
$str_linkpar = "alphabetically=1";
$str_query .= "' ORDER BY time ASC";
}
print("<strong>This is a list of pages you've edited,");
print($str_sorting."(<a href='".$this->href("", $tag, $str_linkpar));
print("'>".$str_linktxt."</a>).</strong><br /><br />\n");
if ($pages = $this->LoadAll($str_query)) {
if ($orderbyalpha) {
foreach ($pages as $page) {
if ($last_tag != $page["tag"]) {
$last_tag = $page["tag"];
$firstChar = strtoupper($page["tag"][0]);
if (!preg_match("/[A-Z]/", $firstChar)) {
$firstChar = "#";
}
print_edit($last,$firstChar,$edit_count,$page["tag"],$page["time"]);
}
}
} else {
foreach ($pages as $page) {
$edited_pages[$page["tag"]] = $page["time"];
}
arsort($edited_pages);
foreach ($edited_pages as $pagetag => $pagetime) {
list($day, $time) = explode(" ", $pagetime);
print_edit($curDay,$day,$edit_count,$pagetag,$time);
}
}
if ($edit_count == 0) {
print("<em>You have not edited any pages yet.</em>");
}
} else {
print("<em>No pages found.</em>");
}
} else {
print("<em>You're not logged in, thus the list of pages you've edited couldn't be retrieved.</em>");
}
?>
For a comparison of the both versions see TimosChanges.
CategoryUserContributions