1 |
// Wiki |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include <cxx/standard.hh> |
8 |
|
9 |
#include <api/files.hpp> |
10 |
#include <api/pcre/regex.hpp> |
11 |
|
12 |
#include "Wiki.hpp" |
13 |
|
14 |
Wiki::Wiki(const cse::String &sitemap, const cse::String &base, ext::Queue<Url> &queue, api::ThreadMutex &queueLock, const _R<WikiCommand> &command) : CommandRunner(sitemap, queue, queueLock) |
15 |
{ |
16 |
api::Cout << _B("Wiki") << ios::NewLine; |
17 |
|
18 |
Entries(command->root, _S<ios::String>() << base << command->path); |
19 |
} |
20 |
|
21 |
void Wiki::Entries(const api::Path &directory, const cse::String &base) |
22 |
{ |
23 |
{ |
24 |
cse::String wiki(client.GetProperty(_B("GoogleTron:Wiki"), directory.GetPath())); |
25 |
|
26 |
if (wiki != _B("PmWiki")) |
27 |
throw ext::NotImplementedException(_S<ios::String>(_B("unknown wiki ")) << wiki); |
28 |
} |
29 |
|
30 |
api::Path wikiDirectory(directory.GetChild(_B("wiki.d"))); |
31 |
ext::RedBlackSet<cse::String> excludes(GetProperties<ext::RedBlackSet<cse::String> >(_B("GoogleTron:Exclude"), wikiDirectory.GetPath())); |
32 |
ext::RedBlackSet<cse::String> sections(GetProperties<ext::RedBlackSet<cse::String> >(_B("GoogleTron:Section"), wikiDirectory.GetPath())); |
33 |
api::Pcre::RegEx wikiEntry(_B("^([^a-z].*)\\.([^a-z].*)$")); |
34 |
|
35 |
_foreach (const _L<Subversion::Entry>, entry, client.GetEntries(wikiDirectory.GetPath())) |
36 |
{ |
37 |
api::Pcre::RegEx::Match match; |
38 |
|
39 |
if (!entry->GetName().StartsWith('.') && !excludes.Contains(entry->GetName()) && (match = wikiEntry(entry->GetName())) && sections.Contains(match[1])) |
40 |
Entry(wikiDirectory.GetChild(entry->GetName()), base, *entry, match[1], match[2]); |
41 |
} |
42 |
} |
43 |
|
44 |
void Wiki::Entry(const api::Path &file, const cse::String &base, const Subversion::Entry &entry, const cse::String §ion, const cse::String &page) |
45 |
{ |
46 |
std::time_t modified(entry.GetModified()); |
47 |
|
48 |
try |
49 |
{ |
50 |
_S<api::FileReader> reader(file.GetPath()); |
51 |
ext::Buffer key, value; |
52 |
api::Pcre::RegEx redirect(_B("^\\(:redirect .*:\\)$")); |
53 |
|
54 |
while (key = ios::ReadUntil(reader, '='), ios::ReadLine(reader, value)) |
55 |
if (key == _B("time")) |
56 |
{ |
57 |
modified = lexical_cast<std::time_t>(cse::String(value)); |
58 |
|
59 |
break; |
60 |
} |
61 |
else if (key == _B("text") && redirect(value)) |
62 |
return; |
63 |
} |
64 |
catch (ext::EosException) {} |
65 |
|
66 |
Url url(_S<ios::String>() << base << section << _B("/") << page, modified, always, GetPriority(client.GetProperty(_B("GoogleTron:Priority"), file.GetPath()))); |
67 |
|
68 |
_synchronized (queueLock) |
69 |
queue.Push(url); |
70 |
} |