Wikka Wiki Default Category Pages


What It Does

With these changes, a category page reference such as CategoryLinux or CategorySoftware when displayed on an existing page, will not render as a missing page. It will look the same as any other page link to a page that does exist. If the category page has not been created by a user, WikkaWiki will generate the page with default contents including links to all pages in that category.

Why It's Useful

The goal is to simplify the user experience by allowing them to categorize their pages by simply putting the category in the page. They no longer have to separately create the category page. Hopefully, the result of this will be better categorized pages resulting in a better organized documentation set (wiki).

License

WikkaWiki is licensed under the GPL as are these changes.

Usage

Nothing special needs done to use and see the results of this hack. Simply start adding categories to your pages.

Installation

Please note that since this is a change to the default functionality of the engine and not simply an add-on action, it will need reapplied after any upgrades.
Although there are more recent versions of WikkaWiki available, these modifications were made and reference version 1.1.6.0. The code may differ slightly in newer versions, so adjust accordingly.

This change requires a simple modification to two WikkaWiki core php files. Since the changes are minor and the core files may differ by version, it is recommended that you simply make the changes noted here. No download is provided for this change.

show.php

The default show.php file must be altered to create the default text for missing category pages.


Replace line
print("<p>This page doesn't exist yet. Maybe you want to <a href=\"".$this->Href("edit")."\">create</a> it?</p></div>");

with
if (strpos($this->GetPageTag(),"Category") === 0) {
//if (substr($this->GetPageTag(),0,8) == "Category") {
	  // Build a default category page.
	  $defaultPage = "\"\"<p>\"\"This is a default category page. Please edit to add your own content.\"\"</p>\"\"";
	  $defaultPage .= "\n----\n\n{{Category col=\"3\"}}\n\n\n----";
	  $defaultPage .= "\n[[CategoryCategory List of all categories]]\n";
	  // Display the default category page
	  print($this->Format($defaultPage, "wakka")."</div>");
} else {
	  print("<p>This page doesn't exist yet. Maybe you want to <a href=\"".$this->Href("edit")."\">create</a> it?</p></div>");
}


diff

Here’s a diff of my two files.
diff show.php show.php.bk
11,21c11
<               if (strpos($this->GetPageTag(),"Category") === 0) {

<               //if (substr($this->GetPageTag(),0,8) == "Category") {
<                       // Build a default category page.
<                       $defaultPage = "\"\"<p>\"\"This is a default category page. Please edit to add your own content.\"\"</p>\"\"";

<                       $defaultPage .= "\n----\n\n{{Category col=\"3\"}}\n\n\n----";
<                       $defaultPage .= "\n[[CategoryCategory List of all categories]]\n";
<                       // Display the default category page
<                       print($this->Format($defaultPage, "wakka")."</div>");

<               } else {
<                       print("<p>This page doesn't exist yet. Maybe you want to <a href=\"".$this->Href("edit")."\">create</a> it?</p></div>");

<               }
---
>               print("<p>This page doesn't exist yet. Maybe you want to <a href=\"".$this->Href("edit")."\">create</a> it?</p></div>");


wikka.php

The default wikka.php file must be altered to set the link type correctly for missing category pages.


Replace line
return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."$anchor\" title=\"$title\">".$text."</a>" : "<a class=\"missingpage\" href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">".$text."</a>");

with
if (strpos($tag,"Category") === 0) {
//if (substr($tag,0,8) == "Category") {
		// Treat Category [[]]pages as if they always exist and we will create
		// a default if not.
		return ("<a href=\"".$this->Href($method, $tag)."$anchor\" title=\"$title\">".$text."</a>");
} else {
		return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."$anchor\" title=\"$title\">".$text."</a>" : "<a class=\"missingpage\" href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">".$text."</a>");
}


diff

Here’s a diff of my two files.
diff wikka.php wikka.php.bk
680,688c680
< //return strpos($tag,"Category");
<                       if (strpos($tag,"Category") === 0) {

<                       //if (substr($tag,0,8) == "Category") {
<                               // Treat Category pages as if they always exist and we will create
<                               // a default if not.
<                               return ("<a href=\"".$this->Href($method, $tag)."$anchor\" title=\"$title\">".$text."</a>");

<                       } else {
<                               return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."$anchor\" title=\"$title\">".$text."</a>" : "<a class=\"missingpage\" href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">".$text."</a>");

<                       }
---
>                       return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."$anchor\" title=\"$title\">".$text."</a>" : "<a class=\"missingpage\" href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">".$text."</a>");


That’s it! Default category pages are ready go on your site. Test it, then notify your users and have fun!

Issues


Screenshots

Missing Category Page


 Screenshot

Default Category Page


 Screenshot



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