Permalink
Browse files

Linkifying.

Some more cleanups.
  • Loading branch information...
1 parent 4e3cff1 commit bc06008eef742e3971fdbe3859c442acdbd4d1a4 @remko committed Jul 20, 2008
Showing with 39 additions and 15 deletions.
  1. +4 −6 TODO
  2. +28 −6 index.php
  3. +1 −1 themes/default/edit.php
  4. +2 −0 themes/default/history.php
  5. +2 −0 themes/default/style.css
  6. +2 −2 themes/default/view.php
View
10 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
View
@@ -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();
@@ -120,6 +120,7 @@ function git($command, &$output = "") {
print join("\n", $output) . "\n";
//print "Error code: " . $result . "\n";
print "</pre>";
+ return 0;
}
return 1;
}
@@ -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();
@@ -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
// --------------------------------------------------------------------------
@@ -239,9 +263,7 @@ function getThemeDir() {
$resource = parseResource($_GET['r']);
$wikiPage = $resource["page"];
$wikiSubPage = $resource["type"];
-
$wikiFile = $DATA_DIR . "/" . $wikiPage;
- $wikiCSS = $CSS;
// --------------------------------------------------------------------------
@@ -282,7 +304,7 @@ function getThemeDir() {
else {
// Global history
if ($wikiPage == "history") {
- $wikiHistory = getHistory();
+ $wikiHistory = getGitHistory();
$wikiPage = "";
include(getThemeDir() . "/history.php");
}
@@ -315,7 +337,7 @@ function getThemeDir() {
}
// History
else if ($wikiSubPage == "history") {
- $wikiHistory = getHistory($wikiPage);
+ $wikiHistory = getGitHistory($wikiPage);
include(getThemeDir() . "/history.php");
}
// Specific version
View
@@ -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>
@@ -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
@@ -35,6 +36,7 @@
}
?>
</table>
+ </p>
</div>
</body>
</html>
View
@@ -115,6 +115,8 @@ acronym, abbr {
#history table {
border-collapse: collapse;
+ margin-left: auto;
+ margin-right: auto;
}
#history td {
View
@@ -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.