UserChanges Action

Last edited by JavaWoman:
Modified links pointing to docs server
Mon, 28 Jan 2008 00:14 UTC [diff]


See also:
AdminModules
This action is meant as a module to integrate the MyChanges action into the UserAdmin tool.
To use it as a standalone action simply add:
{{userchanges user="UserName"}} in the page body.
 


This is an upgraded version of the MyChanges action. It allows not only to display pages edited by current user but also by any other registered user specified either via a user action parameter or via a user GET variable.

Save the code below as actions/userchanges.php.

The action

Current version: 0.4

Changes:

To do:




actions/userchanges.php



<?php

/**
 * Display a list of recent changes made by a user.
 *
 * This action can be used to display a list of pages modified by a specific user. It
 * accepts a user value both as an action parameter and as a GET parameter. The
 * specified user must be an existing user. If no user parameter is specified
 * or the specified user is invalid, an error message is printed. If no user parameter
 * is specified or the specified user is invalid, and the current user is logged in,
 * the action will display a list of pages recently changed by the current user.
 *
 * @package     Actions
 * @name        Userchanges
 *
 * @author      {@link http://web.archive.org/web/20040616194824/http://www.wakkawiki.com/CarloZottmann Carlo Zottmann} (original code)
 * @author      {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} (modified action)
 * @version     0.4
 * @since       Wikka 1.1.X.X
 * @output      list of pages recently modified by the specified user
 * @input       string  $user  optional: a valid user name;
 *              default: current user, if user is logged in;
 *              the default can be overridden by providing a URL parameter 'user';
 * @todo
 *              - (Optionally) create a config option allowing admins to decide whether users can
 *              display pages modified by other users;
 */


$author =''; #initializing variable

switch(true) {
    case (isset($_GET['user']) && $this->LoadUser($_GET['user'])): # a valid user is specified as an URL parameter
    $author = $_GET['user'];
    break;

    case (isset($user) && $this->LoadUser($user)): # a valid user parameter is used
    $author = $user;
    break;

    case ($this->GetUser()):
    $author = $this->GetUserName();
    break;
}

$page = $this->GetPageTag();

if ($author)
{
    $user_edits_count = 0;

    if ($_GET["alpha"] == 1)
    {
        echo $this->Format("== Pages modified by [[".$author."]] == --- --- ");
        print("This is a list of pages edited by ".$this->Link($author).", along with the time of the last edit (<a
href=\""
.$this->Href("", "", "user=".$author."&date=1&action=changes")."\">order by date</a>).<br /><br />\n");

        if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user =
'"
.mysql_real_escape_string($author)."' 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("&nbsp;&nbsp;&nbsp;(".$page["time"].") (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");
   
                    $user_edits_count++;
                }
            }
           
            if ($user_edits_count == 0)
            {
                print("<em>User has not edited any pages yet.</em>");
            }
        }
        else
        {
            print("<em>No pages found.</em>");
        }
    }
    else
    {

                echo $this->Format("== Pages modified by [[".$author."]] == --- --- ");
                print("This is a list of pages edited by ".$this->Link($author).", ordered by the time of last edit (<a
href=\""
.$this->Href("", "", "user=".$author."&alpha=1&action=changes")."\">order alphabetically</a>).<br /><br />\n");

        if ($pages = $this->LoadAll("SELECT tag, time FROM ".$this->config["table_prefix"]."pages WHERE user =
'"
.mysql_real_escape_string($author)."' 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("&nbsp;&nbsp;&nbsp;($time) (".$this->Link($page["tag"], "revisions", "history", 0).") ".$this->Link($page["tag"], "", "", 0)."<br />\n");

                $user_edits_count++;
            }
           
            if ($user_edits_count == 0)
            {
                print("<em>User has not edited any pages yet.</em>");
            }
        }
        else
        {
            print("<em>No pages found.</em>");
        }
    }
}
else
{
    print("<em>No user specified</em>");
}

?>



CategoryDevelopmentActions CategoryDevelopmentAdmin
Comments
Comment by dpc69190001.direcpc.com
2005-03-01 18:04:50
Hi,

I get the following message when using the useradmin action. The userfeedback and userpages work fine, but the userchanges and usercomments actions do not.

Warning: includebuffered(actions/userchanges.php): failed to open stream: Permission denied in c:\inetpub\wwwroot\wikka\wikka.php on line 163

Warning: includebuffered(): Failed opening 'actions/userchanges.php' for inclusion (include_path='.;c:\php4\pear') in c:\inetpub\wwwroot\wikka\wikka.php on line 163

Bob English
Comment by MovieLady
2005-03-01 21:08:11
It looks like your php include_path doesn't include the wwwroot directory. The information to set this for Windows is here (toward the bottom of the page): http://us3.php.net/manual/en/configuration.changes.php
Comment by TimoK
2005-04-18 20:54:02
Wouldn't it be better to use 'my' recoding of MyChangesAction? Actually I think with a little tweaking of both the userchanges-action could just include the mychanges-action. That way improvement of the latter one would automatically improve the former one without the need to update it. (keyword code-reusage)
Comment by DarTar
2005-04-22 14:47:21
TimoK, what do you mean by 'your' recoding ?
Comment by TimoK
2005-04-25 06:41:51
See the second half of http://wikka.jsnx.com/MyChangesAction :)
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki