=====My Changes Action===== >> ==Implemented in 1.2== ==See also:== Documentation: MyChangesActionInfo.>>This is the development page for the my changes action.::c:: The php code: %%(php) GetUser()) { $my_edits_count = 0; if ($_REQUEST["alphabetically"] == 1) { print("This is a list of pages you've edited, along with the time of your last change (href("", $tag)."\">order by date).

\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("
\n"); print("$firstChar
\n"); $curChar = $firstChar; } // print entry print("   (".$page["time"].") (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."
\n"); $my_edits_count++; } } if ($my_edits_count == 0) { print("You have not edited any pages yet."); } } else { print("No pages found."); } } else { print("This is a list of pages you've edited, ordered by the time of your last change (href("", $tag, "alphabetically=1")."\">order alphabetically).

\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("
\n"); print("$day:
\n"); $curday = $day; } // print entry print("   ($time) (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."
\n"); $my_edits_count++; } if ($my_edits_count == 0) { print("You have not edited any pages yet."); } } else { print("No pages found."); } } } else { print("You're not logged in, thus the list of pages you've edited couldn't be retrieved."); } ?> %% ---- The above code doesn't sort the pages properly when sorting by time. I have re-coded the action like this: %%(php) \n"); } print("$current
\n"); $last = $current; } $rev_link = "history"; $page_link ="".$tag.""; print("  (".$time.") (".$rev_link.") ".$page_link."
\n"); } } if ($this->GetUser()) { $user = $this->GetUserName(); global $baseurl; $baseurl = $this->config["base_url"]; $str_q1 = "SELECT DATE_FORMAT(time,'%Y-%m-%d') as pdate, "; $str_q1.= "DATE_FORMAT(time,'%H:%i:%s') as ptime, "; $str_q1.= "tag FROM ". $this->config["table_prefix"]; $str_q1.= "pages WHERE user = '". mysql_real_escape_string($user); if ($_REQUEST["alphabetically"] == "1") { $orderbyalpha = TRUE; } elseif ($_REQUEST["alphabetically"] == "0") { $orderbyalpha = FALSE; } elseif (is_string($vars["sorting"])) { 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_q2 = "' 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_q2 = "' ORDER BY pdate DESC, tag ASC, ptime DESC"; } print("This is a list of pages you've edited,"); print($str_sorting."(".$str_linktxt.").

\n"); if ($pages = $this->LoadAll($str_q1.$str_q2)) { 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,$page["tag"],$page["pdate"]." ".$page["ptime"]); } } } else { foreach($pages as $page) { if ($last_tag != $page["tag"]) { $last_tag = $page["tag"]; print_edit($curDay,$page["pdate"],$page["tag"],$page["ptime"]); } } } } else { print("No pages found."); } } else { print("You're not logged in, thus the list of pages you've edited couldn't be retrieved."); } ?> %% For a comparison of the both versions see [[http://ranta.info/TimosChanges | TimosChanges]]. That page uses the above code, but statically assumes TimoK as user, no matter if you are logged in or not. Thanks to JavaWoman who helped me a lot tonight with questions and ideas. Without you I couldn't have done this. The above code seems stable, safe and fast (225 out of ~260 rows fetched in 0.07 seconds compared to 0.25 seconds with the old code), but it's 1:35AM as I am writing this, so I would be happy if some others could test it on their own wikkas and let me know if there are any problems. ---- CategoryUserContributions