Skip to content

Commit

Permalink
More cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
remko committed Jul 20, 2008
1 parent 04cd163 commit 9f2b8a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
2 changes: 0 additions & 2 deletions TODO
@@ -1,7 +1,5 @@
Backend
-------
- Try to parse page in history, and link to it
- Add link to retrieve a revision of a page
- Add diffs to history
- Auto-link plain-text links
- Wikify links
Expand Down
63 changes: 27 additions & 36 deletions index.php
Expand Up @@ -23,10 +23,6 @@
// Helpers
// --------------------------------------------------------------------------

function wikify($text) {
return $text;
}

function getHistory($file = "") {
$output = array();
git("log --pretty=format:'%H>%T>%an>%ae>%aD>%s' -- $file", $output);
Expand Down Expand Up @@ -58,11 +54,6 @@ function getHistory($file = "") {
return $history;
}

function getThemeDir() {
global $THEME;
return "themes/$THEME";
}

function getAuthorForUser($user) {
global $AUTHORS, $DEFAULT_AUTHOR;

Expand Down Expand Up @@ -155,6 +146,19 @@ function parseResource($resource) {
return array("page" => $page, "type" => $type);
}


// --------------------------------------------------------------------------
// Wikify
// --------------------------------------------------------------------------

function wikify($text) {
// FIXME: Wikify

// Textilify
$textile = new Textile();
return $textile->TextileThis($text);
}

// --------------------------------------------------------------------------
// Utility functions (for use inside templates)
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -216,6 +220,11 @@ function getCSSURL() {
return getThemeDir() . "/style.css";
}

function getThemeDir() {
global $THEME;
return "themes/$THEME";
}

// --------------------------------------------------------------------------
// Initialize globals
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -284,15 +293,8 @@ function getCSSURL() {
$data = fread($handle, filesize($wikiFile));
fclose($handle);

// Add wiki links and other transformations
$wikifiedData = wikify($data);

// Textilify
$textile = new Textile();
$formattedData = $textile->TextileThis($wikifiedData);

// Put in template
$wikiContent = $formattedData;
$wikiContent = wikify($data);
include(getThemeDir() . "/view.php");
}
// Editing
Expand All @@ -306,32 +308,21 @@ function getCSSURL() {
$wikiData = $data;
include(getThemeDir() . "/edit.php");
}
// History
else if ($wikiSubPage == "history") {
$wikiHistory = getHistory($wikiPage);
include(getThemeDir() . "/history.php");
}
else {
// Try commit.
// FIXME: Try to put this in an else if
// Specific version
else if (eregi("[0-9A-F]{20,20}", $wikiSubPage)) {
$output = array();
if (git("cat-file -p " . $wikiSubPage . ":$wikiPage", $output)) {
$data = join("\n", $output);
// FIXME Factor this out
// Add wiki links and other transformations
$wikifiedData = wikify($data);

// Textilify
$textile = new Textile();
$formattedData = $textile->TextileThis($wikifiedData);

// Put in template
// FIXME: Remove edit links
$wikiContent = $formattedData;
include(getThemeDir() . "/view.php");
if (!git("cat-file -p " . $wikiSubPage . ":$wikiPage", $output)) {
return;
}

// Fallback
$wikiContent = wikify(join("\n", $output));
include(getThemeDir() . "/view.php");
}
else {
print "Unknow subpage: " . $wikiSubPage;
}
}
Expand Down

0 comments on commit 9f2b8a8

Please sign in to comment.