Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
Linkifying.
Browse files Browse the repository at this point in the history
Some more cleanups.
  • Loading branch information
remko committed Jul 20, 2008
1 parent 4e3cff1 commit bc06008
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
10 changes: 4 additions & 6 deletions TODO
@@ -1,11 +1,9 @@
Backend
-------
- Wikify links
- Auto-link plain-text links
- Auto-insert newline after h?
- Auto-insert newline after h*. section headers
- Add section edit links ?
- Add diffs to history

ExtJS theme
-----------
- Create
Themes
------
Create an ExtJS theme
34 changes: 28 additions & 6 deletions index.php
Expand Up @@ -23,7 +23,7 @@
// Helpers
// --------------------------------------------------------------------------

function getHistory($file = "") {
function getGitHistory($file = "") {
$output = array();
git("log --pretty=format:'%H>%T>%an>%ae>%aD>%s' -- $file", $output);
$history = array();
Expand Down Expand Up @@ -120,6 +120,7 @@ function git($command, &$output = "") {
print join("\n", $output) . "\n";
//print "Error code: " . $result . "\n";
print "</pre>";
return 0;
}
return 1;
}
Expand Down Expand Up @@ -156,7 +157,15 @@ function parseResource($resource) {
// --------------------------------------------------------------------------

function wikify($text) {
// FIXME: Wikify
global $SCRIPT_URL;

// FIXME: Do not apply this in <pre> and <notextile> blocks.

// Linkify
$text = preg_replace('@[^:](https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);

// WikiLinkify
$text = preg_replace('@\[([A-Z]\w+)\]@', '<a href="' . $SCRIPT_URL . '/$1">$1</a>', $text);

// Textilify
$textile = new Textile();
Expand Down Expand Up @@ -230,6 +239,21 @@ function getThemeDir() {
return "themes/$THEME";
}

function getFile() {
global $wikiFile;
return $wikiFile;
}

function getContent() {
global $wikiContent;
return $wikiContent;
}

function getRawData() {
global $wikiData;
return $wikiData;
}

// --------------------------------------------------------------------------
// Initialize globals
// --------------------------------------------------------------------------
Expand All @@ -239,9 +263,7 @@ function getThemeDir() {
$resource = parseResource($_GET['r']);
$wikiPage = $resource["page"];
$wikiSubPage = $resource["type"];

$wikiFile = $DATA_DIR . "/" . $wikiPage;
$wikiCSS = $CSS;


// --------------------------------------------------------------------------
Expand Down Expand Up @@ -282,7 +304,7 @@ function getThemeDir() {
else {
// Global history
if ($wikiPage == "history") {
$wikiHistory = getHistory();
$wikiHistory = getGitHistory();
$wikiPage = "";
include(getThemeDir() . "/history.php");
}
Expand Down Expand Up @@ -315,7 +337,7 @@ function getThemeDir() {
}
// History
else if ($wikiSubPage == "history") {
$wikiHistory = getHistory($wikiPage);
$wikiHistory = getGitHistory($wikiPage);
include(getThemeDir() . "/history.php");
}
// Specific version
Expand Down
2 changes: 1 addition & 1 deletion themes/default/edit.php
Expand Up @@ -18,7 +18,7 @@

<div id="form">
<form method="post" action="<?php print getPostURL(); ?>">
<p><textarea name="data" cols="80" rows="20" style="width: 100%"><?php print $wikiData; ?></textarea></p>
<p><textarea name="data" cols="80" rows="20" style="width: 100%"><?php print getRawData(); ?></textarea></p>
<p><input type="submit" value="publish" /></p>
</form>
</div>
Expand Down
2 changes: 2 additions & 0 deletions themes/default/history.php
Expand Up @@ -20,6 +20,7 @@
</div>

<div id="history">
<p>
<table>
<tr><th>Date</th><th>Author</th><th>Page</th><th>Message</th></tr>
<?php
Expand All @@ -35,6 +36,7 @@
}
?>
</table>
</p>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions themes/default/style.css
Expand Up @@ -115,6 +115,8 @@ acronym, abbr {

#history table {
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
}

#history td {
Expand Down
4 changes: 2 additions & 2 deletions themes/default/view.php
Expand Up @@ -19,11 +19,11 @@
</div>

<div id="content">
<?php print $wikiContent; ?>
<?php print getContent(); ?>
</div>

<div id="footer">
<p>Last modified on <?php print date("F d Y H:i:s", filemtime($wikiFile)); ?> </p>
<p>Last modified on <?php print date("F d Y H:i:s", filemtime(getFile())); ?> </p>
</div>
</body>
</html>

0 comments on commit bc06008

Please sign in to comment.