wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / translations.pl
bloba35452c38769366e4c0cd958822784766031a81e
1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
2 # 2004 Tilmann Holst <spam@tholst.de>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/translations.pl">translations.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Translation_Extension">Translation Extension</a></p>';
22 push(@MyRules, \&TranslationRule);
24 sub TranslationRule {
25 if (m/\G(\&lt;translation +\[\[$FreeLinkPattern\]\] +(\d+)\&gt;[ \t]*)/gc) {
26 Dirty($1);
27 print GetTranslationLink($2, $3);
28 return '';
30 return undef;
33 sub GetCurrentPageRevision {
34 my $id = shift;
35 my %page = ParseData(ReadFileOrDie(GetPageFile($id)));
36 return $page{revision};
39 sub GetTranslationLink {
40 my ($id, $revision) = @_;
41 my $result = "";
42 my $currentRevision;
43 $id =~ s/^\s+//; # Trim extra spaces
44 $id =~ s/\s+$//;
45 $id = FreeToNormal($id);
46 $result = Ts('This page is a translation of %s. ', GetPageOrEditLink( $id, '', 0, 1));
47 $currentRevision = GetCurrentPageRevision($id);
49 if ($currentRevision == $revision) {
50 $result .= T("The translation is up to date.");
51 } elsif ( $currentRevision > $revision ) {
52 $result .= T("The translation is outdated.") . ' '
53 . ScriptLink("action=browse&diff=1&id=$id&revision=$currentRevision&diffrevision=$revision",
54 T("(diff)"));
55 } else {
56 $result .= T("The page does not exist.");
58 return $result;