Revision [3519]

This is an old revision of WikkaMenulets made by DarTar on 2004-12-20 10:53:19.

 

Wikka Menulets

Last edited by DarTar:
Here comes a bunch of Wikka gadgets :)
Mon, 20 Dec 2004 10:53 UTC [diff]



As part of my proposal for a general overhaul of the menu management system in WikkaWiki, I suggest we replace the current system-generated items that occur in the main menu and footer menu with a series of menulets, i.e. mini-actions generating content for menu items.
Any of these mini-actions can of course be used in the page body as well.

Here's a list of potential menulets and their output, that I've uploaded to this server.
Suggestions/modifications are welcome.


{{acls}}

Prints a link to CurrentPage/acls if the user has access to the ACLs:

<?php
if ($this->page){
    if ($owner = $this->GetPageOwner()){
        if ($owner == "(Public)"){
            print $this->IsAdmin() ? "<a href=\"".$this->href("acls")."\">(Edit ACLs)</a>\n" : ""; #i18n
        } elseif ($this->UserIsOwner()){
            print "<a href=\"".$this->href("acls")."\">Edit ACLs</a>\n"; #i18n
        }
    } else {
        print ($this->GetUser()) ? " (<a href=\"".$this->href("claim")."\">Take Ownership</a>)\n" : ""; #i18n
    }
}
?>



{{contact}}

Prints a mailto: link to the Wikka administrator's address: Contact
Note: plain mailto links are a common source of spam.

<?php
$email = $this->config['admin_email'];

// print plain mailto link
//echo "<a href=\"mailto:".$email."\" title=\"Write to us\">Contact</a>"; #i18n

// print antispam link
$patterns = array("'@'", "'\.'");
$replace = array("[at]", "[dot]");
echo "<a href=\"mailto:".preg_replace($patterns, $replace, $email)."\" title=\"Contact\">Contact</a>"; #i18n

// display contact link only to registered users
// echo ($this->GetUser()) ? "<a href=\"mailto:".$email."\" title=\"Write to us\">Contact</a>" : ""; #i18n
 
?>



{{countusers}}

Prints the number of registered users: 4606

<?php
$userdata = $this->LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."users ");
echo "Registered users: ".$userdata["num"]; #i18n
?>



{{countpages}}

Prints the total number of pages: 1735

<?php
$pagedata = $this->LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."pages WHERE latest = 'Y'");
echo "Number of pages: ".$pagedata["num"]; #i18n
?>



{{delete}}

Prints a link to CurrentPage/delete if the user has delete privileges:

<?php
echo  ($this->IsAdmin())? "<a href=\"".$this->href("delete")."\" title=\"Click to delete this page\">Delete this page</a>\n" : "";  #i18n
?>



{{edit}}

Prints a link to CurrentPage/edit: Show code

<?php
if ($this->HasAccess("write")) {
        echo  "<a href=\"".$this->href("edit")."\" title=\"Click to edit this page\">Edit this page</a>\n"; #i18n
} else {
        echo  "<a href=\"".$this->href("showcode")."\" title=\"Click to display the page source\">Show code</a>\n"; #i18n
}
?>



{{history}}

Prints a link to CurrentPage/history: Page History

<?php
        echo "<a href=\"".$this->href("history")."\" title=\"Click to view recent edits to this page\">Page History</a>\n"; #i18n
?>



{{homepage}}

Prints a link to the wiki homepage specified in the config file: HomePage

<?php
echo $this->Link($this->config['root_page']);
?>



{{lasteditauthor}}

Prints the author of the last page version: BrianKoontz

<?php
$page = $this->LoadSingle("SELECT * FROM ".$this->config['table_prefix']."pages WHERE tag='".$this->GetPageTag()."' AND latest = 'Y'");
$user = ($this->LoadUser($page["user"]))? $this->Link($page["user"]) : "anonymous";
echo $user;
?>



{{lasteditnotes}}

Prints the last edit notes: Replaces old-style internal links with new pipe-split links.

<?php
$page = $this->LoadSingle("SELECT * FROM ".$this->config['table_prefix']."pages WHERE tag='".$this->GetPageTag()."' AND latest = 'Y'");
echo ($page["note"])? $this->Format("//".$page["note"]."//") : "";
?>




Displays a wikka logo set by admins (in the future the path should be set in the config file):
logo

<?php
echo $this->Format('{{image alt="logo" title="'.$this->config['wakka_name'].'" url="images/wizard.gif" link="HomePage"}}');
?>



{{mysqlversion}}

Displays the current MySQL version: n/a

<?php
echo "MySQL version ".mysql_get_server_info();
?>



{{owner}}

Displays page ownership infos: Owner: DarTar

<?php
if ($this->page) {
    if ($owner = $this->GetPageOwner()){
        if ($owner == "(Public)"){
            print "Public page"; #i18n
        }
        elseif ($this->UserIsOwner()) {
                if ($this->IsAdmin()) {
                print "Owner: ".$this->Link($owner, "", "", 0)."\n"; #i18n
                } else {
                print"You own this page.\n"; #i18n
            }
        } else {
            print "Owner: ".$this->Link($owner, "", "", 0)."\n"; #i18n
        }
    } else {
        print "Nobody\n"; #i18n
    }
}
?>



{{phpversion}}

Displays the current php version: n/a

<?php
echo "PHP version ".phpversion();
?>



{{recentchangesrss}}

Prints a link (RSS feed for recent changes) to CurrentPage/recentchanges.xml: XML

<?php
echo "<a href=\"".$this->href("recentchanges.xml")."\" title=\"Click to view recent changes in XML format.\"><img src=\"images/xml.png\" width=\"36\" height=\"14\" align=\"middle\" style=\"border : 0px;\" alt=\"XML\" /></a>"; #i18n
?>



{{referrers}}

Prints a link to CurrentPage/referrers:

<?php
if ($this->GetUser()) {
    echo "<a href='".$this->href("referrers")."' title='Click to view a list of URLs referring to this page.'>Referrers</a>\n";  #i18n
}
?>



{{revisions}}

Prints a link to CurrentPage/revisions: 2004-12-20 10:53:19

<?php
if ($this->GetPageTime()) {
        echo "<a href=\"".$this->href("revisions")."\" title=\"Click to view recent revisions list for this page\">".$this->GetPageTime()."</a>\n"; #i18n
}
?>



{{revisionsrss}}

Prints a link (RSS feed for page revisions) to CurrentPage/revisions.xml: XML

<?php
if ($this->GetPageTime()) {
    echo "<a href=\"".$this->href("revisions.xml")."\" title=\"Click to view recent page revisions in XML format.\"><img src=\"images/xml.png\" width=\"36\" height=\"14\" align=\"middle\" style=\"border : 0px;\" alt=\"XML\" /></a>"; #i18n 
}
?>




Prints a searchbox:
Search:


<?php
echo $this->FormOpen("", "TextSearch", "get");
echo 'Search: <input name="phrase" size="15" class="searchbox" />'; #i18n
echo $this->FormClose();
?>



{{skin}}

Displays a clickable link to the current skin:

<?
$skin = ($this->GetCookie("wikiskin"))? $this->GetCookie("wikiskin") : $this->config['stylesheet'];
echo "<a href=\"".$this->config['base_url']."css/".$skin."\" title=\"Display stylesheet\">".$skin."</a>";
?>



{{time}}

Prints the current time: 19:52

<?php
echo date("H:i");
?>



{{title}}

Prints the title of the current page: WikkaMenulets

<?php
echo $this->PageTitle();
?>



{{today}}

Prints the current date: June 19, 2019

<?php
echo date("F j, Y");
?>



{{url}}

Prints the complete URL of the current page: http://wikkawiki.org/WikkaMenulets

<?php
echo $this->href("", $this->GetPageTag());

//clickable link
//echo $this->Link($this->href("", $this->GetPageTag()));
?>




{{version}}

Prints the current wikka version: Unknown action ""version""

<?php
echo $this->VERSION;
?>



{{who}}

Prints the name of the current user:

<?php
if ($this->GetUser()) {
        echo "You are ".$this->Format($this->GetUserName()); #i18n
}
?>

Here's my take (untested!):
<?php
// define output format (i18n)
define('WHO_OUT', "You are %1");    # %1 is either user name or remote address
// get name or remote address
if ($this->GetUser())
{
    $who = $this->Format($this->GetUserName());
}
else
{
    if (isset($_SERVER['REMOTE_HOST']))
    {
         $who = $_SERVER['REMOTE_HOST'];
    }
    else
    {
         $who = $_SERVER['REMOTE_ADDR'];
    }
}
// display output
echo str_replace(' ','&nbsp;',sprintf(WHO_OUT, $who));
?>

By putting the whole phrase in a define, we are taking care of differences in word order in different languages; at the output stage we replace spaces by no-breaking spaces to keep the whole string together. This also takes care of usage of {{who}} in the main_menu (displaying address instead of user name). --JavaWoman
"Nice way of doing it JavaWoman.
<?php
// define output format (i18n)
define('WHO_OUT', "You are %1");    # %1 is either user name or remote address
// get name or remote address
$who = ($this->GetUser()) ? $this->Format($this->GetUserName()) : ( (isset($_SERVER['remote_host'])) ? $_SERVER['remote_host'] : $_SERVER['remote_addr'] ) ;
// display output
echo str_replace( ' ', '&nbsp;', sprintf(WHO_OUT, $who));
?>
Here is a smaller take on the same code... -- GeorgePetsagourakis
Ya, it's smaller - but not faster. In fact, it's exactly the same thing, just harder to read. I just happen to like readable code. I wrote it like that for a reason: it's faster to maintain. ;-) --JavaWoman
It is probably cause I never had the chance to use the (condition)? smth : oth_th ; syntax and I am so excited about it .. :D --GeorgePetsagourakis
It is indeed a very handy syntax and I do use it - but IMO usage beyond a single if-then-else level should be avoided: that's where it gets hard to parse for humans although PHP has no problem with it. ;-) --JavaWoman


{{wikkaname}}

Prints the name of the current Wikka: Wikka

<?php
echo $this->config['wakka_name'];
?>


...

DarTar, can you post your code for these actions here? The way some of the menu items are formatted now should be improved - but if this little project moves ahead (I hope) we might as well do it in the "menulets" action code instead of the current code. And new code should be ready for i18n as well (I don't know if yours is...) --JavaWoman


CategoryDevelopment
There are 18 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki