diff options
author | intrigeri <intrigeri@boum.org> | 2008-11-06 12:28:31 +0100 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2008-11-06 12:28:31 +0100 |
commit | 1f54c13ec24977988a303f004f3fc08ee2e01abc (patch) | |
tree | 6e199ad04a48100286304ef53095e720ac72bca6 | |
parent | bd2dd8c60336ad7a03194d2a53f5409a620e484d (diff) | |
parent | 17bd930bc9f4192e084a223cf57af94680741853 (diff) |
Merge commit 'upstream/po' into prv/po
Conflicts:
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn
Signed-off-by: intrigeri <intrigeri@boum.org>
-rw-r--r-- | IkiWiki/Plugin/inline.pm | 4 | ||||
-rw-r--r-- | IkiWiki/Plugin/po.pm | 49 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | doc/ikiwiki/pagespec.mdwn | 2 | ||||
-rw-r--r-- | doc/ikiwiki/pagespec/po.mdwn | 2 | ||||
-rw-r--r-- | doc/plugins/img/discussion.mdwn | 3 | ||||
-rw-r--r-- | doc/plugins/po.mdwn | 49 | ||||
-rw-r--r-- | doc/plugins/relativedate.mdwn | 2 |
8 files changed, 77 insertions, 36 deletions
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 1b1ca2ce2..7fe5a4dcf 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -201,7 +201,7 @@ sub preprocess_inline (@) { #{{{ @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list; } else { - return sprintf(gettext("unknown sort type %s"), $params{sort}); + error sprintf(gettext("unknown sort type %s"), $params{sort}); } if (yesno($params{reverse})) { @@ -298,7 +298,7 @@ sub preprocess_inline (@) { #{{{ require HTML::Template; my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1); if (! @params) { - return sprintf(gettext("nonexistant template %s"), $params{template}); + error sprintf(gettext("nonexistant template %s"), $params{template}); } my $template=HTML::Template->new(@params) unless $raw; diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 38fc7527b..7861523da 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -28,11 +28,8 @@ memoize("percenttranslated"); # backup references to subs that will be overriden my %origsubs; -$origsubs{'bestlink'}=\&IkiWiki::bestlink; -$origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath; -$origsubs{'targetpage'}=\&IkiWiki::targetpage; -sub import { +sub import { #{{{ hook(type => "getsetup", id => "po", call => \&getsetup); hook(type => "checkconfig", id => "po", call => \&checkconfig); hook(type => "needsbuild", id => "po", call => \&needsbuild); @@ -40,16 +37,20 @@ sub import { hook(type => "htmlize", id => "po", call => \&htmlize); hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1); hook(type => "editcontent", id => "po", call => \&editcontent); + + $origsubs{'bestlink'}=\&IkiWiki::bestlink; inject(name => "IkiWiki::bestlink", call => \&mybestlink); + $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath; inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath); + $origsubs{'targetpage'}=\&IkiWiki::targetpage; inject(name => "IkiWiki::targetpage", call => \&mytargetpage); -} +} #}}} sub getsetup () { #{{{ return plugin => { safe => 0, - rebuild => 1, # format plugin + rebuild => 1, # format plugin & changes html filenames }, po_master_language => { type => "string", @@ -97,11 +98,11 @@ sub checkconfig () { #{{{ } if (! exists $config{po_link_to} || ! defined $config{po_link_to}) { - $config{po_link_to}="default"; + $config{po_link_to}="default"; } if (! exists $config{po_translatable_pages} || ! defined $config{po_translatable_pages}) { - $config{po_translatable_pages}=""; + $config{po_translatable_pages}=""; } if ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) { error(gettext("po_link_to=negotiated requires usedirs to be set")); @@ -111,6 +112,7 @@ sub checkconfig () { #{{{ sub potfile ($) { #{{{ my $masterfile=shift; + (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/); $dir='' if $dir eq './'; return File::Spec->catpath('', $dir, $name . ".pot"); @@ -119,6 +121,7 @@ sub potfile ($) { #{{{ sub pofile ($$) { #{{{ my $masterfile=shift; my $lang=shift; + (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/); $dir='' if $dir eq './'; return File::Spec->catpath('', $dir, $name . "." . $lang . ".po"); @@ -126,6 +129,7 @@ sub pofile ($$) { #{{{ sub refreshpot ($) { #{{{ my $masterfile=shift; + my $potfile=potfile($masterfile); my %options = ("markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0); my $doc=Locale::Po4a::Chooser::new('text',%options); @@ -153,8 +157,7 @@ sub refreshpofiles ($@) { #{{{ foreach my $pofile (@pofiles) { if (-e $pofile) { - my $cmd = "msgmerge -U --backup=none $pofile $potfile"; - system ($cmd) == 0 + system("msgmerge", "-U", "--backup=none", $pofile, $potfile) == 0 or error("[po/refreshpofiles:$pofile] failed to update"); } else { @@ -252,9 +255,10 @@ sub mytargetpage ($$) { #{{{ sub mybeautify_urlpath ($) { #{{{ my $url=shift; + my $res=$origsubs{'beautify_urlpath'}->($url); if ($config{po_link_to} eq "negotiated") { - $res =~ s!/index.$config{po_master_language}{code}.$config{htmlext}$!/!; + $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!; } return $res; } #}}} @@ -273,6 +277,7 @@ sub urlto_with_orig_beautiful_urlpath($$) { #{{{ sub mybestlink ($$) { #{{{ my $page=shift; my $link=shift; + my $res=$origsubs{'bestlink'}->($page, $link); if (length $res) { if ($config{po_link_to} eq "current" @@ -292,6 +297,7 @@ sub mybestlink ($$) { #{{{ # since the rest of ikiwiki should not work on PO files. sub filter (@) { #{{{ my %params = @_; + my $page = $params{page}; my $destpage = $params{destpage}; my $content = decode_utf8(encode_utf8($params{content})); @@ -329,8 +335,8 @@ sub filter (@) { #{{{ push @pos,$infile; push @masters,$masterfile; my %options = ( - "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0, - ); + "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0, + ); my $doc=Locale::Po4a::Chooser::new('text',%options); $doc->process( 'po_in_name' => \@pos, @@ -352,6 +358,7 @@ sub filter (@) { #{{{ sub htmlize (@) { #{{{ my %params=@_; + my $page = $params{page}; my $content = $params{content}; my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); @@ -363,7 +370,8 @@ sub htmlize (@) { #{{{ sub percenttranslated ($) { #{{{ my $page=shift; - return "N/A" unless (istranslation($page)); + + return gettext("N/A") unless (istranslation($page)); my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); my $file=srcfile($pagesources{$page}); my $masterfile = srcfile($pagesources{$masterpage}); @@ -371,8 +379,8 @@ sub percenttranslated ($) { #{{{ push @pos,$file; push @masters,$masterfile; my %options = ( - "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0, - ); + "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0, + ); my $doc=Locale::Po4a::Chooser::new('text',%options); $doc->process( 'po_in_name' => \@pos, @@ -386,6 +394,7 @@ sub percenttranslated ($) { #{{{ sub otherlanguages ($) { #{{{ my $page=shift; + my @ret; if (istranslatable($page)) { foreach my $lang (sort keys %{$translations{$page}}) { @@ -423,6 +432,7 @@ sub pagetemplate (@) { #{{{ my $page=$params{page}; my $destpage=$params{destpage}; my $template=$params{template}; + my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/) if istranslation($page); if (istranslation($page) && $template->query(name => "percenttranslated")) { @@ -485,6 +495,7 @@ sub editcontent () { #{{{ sub istranslatable ($) { #{{{ my $page=shift; + my $file=$pagesources{$page}; if (! defined $file @@ -497,6 +508,7 @@ sub istranslatable ($) { #{{{ sub _istranslation ($) { #{{{ my $page=shift; + my $file=$pagesources{$page}; if (! defined $file) { return IkiWiki::FailReason->new("no file specified"); @@ -522,6 +534,7 @@ sub _istranslation ($) { #{{{ sub istranslation ($) { #{{{ my $page=shift; + if (_istranslation($page)) { my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang}; @@ -537,6 +550,7 @@ use IkiWiki 2.00; sub match_istranslation ($;@) { #{{{ my $page=shift; + if (IkiWiki::Plugin::po::istranslation($page)) { return IkiWiki::SuccessReason->new("is a translation page"); } @@ -547,6 +561,7 @@ sub match_istranslation ($;@) { #{{{ sub match_istranslatable ($;@) { #{{{ my $page=shift; + if (IkiWiki::Plugin::po::istranslatable($page)) { return IkiWiki::SuccessReason->new("is set as translatable in po_translatable_pages"); } @@ -558,6 +573,7 @@ sub match_istranslatable ($;@) { #{{{ sub match_lang ($$;@) { #{{{ my $page=shift; my $wanted=shift; + my $regexp=IkiWiki::glob2re($wanted); my $lang; my $masterpage; @@ -579,6 +595,7 @@ sub match_lang ($$;@) { #{{{ sub match_currentlang ($$;@) { #{{{ my $page=shift; + shift; my %params=@_; my ($currentmasterpage, $currentlang, $masterpage, $lang); diff --git a/debian/control b/debian/control index fdf2a3a36..04283532b 100644 --- a/debian/control +++ b/debian/control @@ -14,7 +14,7 @@ Package: ikiwiki Architecture: all Depends: ${perl:Depends}, markdown | libtext-markdown-perl, libhtml-scrubber-perl, libhtml-template-perl, libhtml-parser-perl, liburi-perl Recommends: gcc | c-compiler, libc6-dev | libc-dev, subversion | git-core (>= 1:1.5.0) | tla | bzr (>= 0.91) | mercurial | monotone (>= 0.38), libxml-simple-perl, libnet-openid-consumer-perl, liblwpx-paranoidagent-perl, libtimedate-perl, libcgi-formbuilder-perl (>= 3.05), libcgi-session-perl (>= 4.14-1), libmail-sendmail-perl, libauthen-passphrase-perl -Suggests: viewvc | gitweb | viewcvs, libsearch-xapian-perl, xapian-omega (>= 1.0.5), librpc-xml-perl, libtext-wikiformat-perl, python, python-docutils, polygen, tidy, libxml-feed-perl, libmailtools-perl, perlmagick, libfile-mimeinfo-perl, libcrypt-ssleay-perl, liblocale-gettext-perl (>= 1.05-1), libtext-typography-perl, libtext-csv-perl, libdigest-sha1-perl, graphviz, libnet-amazon-s3-perl, sparkline-php, texlive, dvipng +Suggests: viewvc | gitweb | viewcvs, libsearch-xapian-perl, xapian-omega (>= 1.0.5), librpc-xml-perl, libtext-wikiformat-perl, python, python-docutils, polygen, tidy, libxml-feed-perl, libmailtools-perl, perlmagick, libfile-mimeinfo-perl, libcrypt-ssleay-perl, liblocale-gettext-perl (>= 1.05-1), libtext-typography-perl, libtext-csv-perl, libdigest-sha1-perl, graphviz, libnet-amazon-s3-perl, sparkline-php, texlive, dvipng, po4a Conflicts: ikiwiki-plugin-table Replaces: ikiwiki-plugin-table Provides: ikiwiki-plugin-table diff --git a/doc/ikiwiki/pagespec.mdwn b/doc/ikiwiki/pagespec.mdwn index c78666c40..176228e4b 100644 --- a/doc/ikiwiki/pagespec.mdwn +++ b/doc/ikiwiki/pagespec.mdwn @@ -47,6 +47,8 @@ Some more elaborate limits can be added to what matches using these functions: wiki admins. * "`ip(address)`" - tests whether a modification is being made from the specified IP address. +* Some additional special-purpose limits may be enabled, for matching + [[attachments|attachment]] and [[translations|po]]. For example, to match all pages in a blog that link to the page about music and were written in 2005: diff --git a/doc/ikiwiki/pagespec/po.mdwn b/doc/ikiwiki/pagespec/po.mdwn index 2edfaa0c1..60c344689 100644 --- a/doc/ikiwiki/pagespec/po.mdwn +++ b/doc/ikiwiki/pagespec/po.mdwn @@ -12,5 +12,5 @@ wiki: * "`currentlang()`" - Tests whether a page is written in the same language as the current page. -Note: every non-PO page is considered to be written in +Note: every non-po page is considered to be written in `po_master_language`, as specified in `ikiwiki.setup`. diff --git a/doc/plugins/img/discussion.mdwn b/doc/plugins/img/discussion.mdwn index 5bf340c56..e1bb2d15b 100644 --- a/doc/plugins/img/discussion.mdwn +++ b/doc/plugins/img/discussion.mdwn @@ -7,3 +7,6 @@ instead of linking to the PNG image file. --[[tschwinge]] > Done, use link=somepage --[[Joey]] It would be handy if the `class` and `id` tags were passed through to the surrounding `table` in the case of `caption` being present. Would this break anything? --[[neale]] + +> Seems unlikely to break *too* much. I can imagine css that styles the img +> unexpectedly applying the table. --[[Joey]] diff --git a/doc/plugins/po.mdwn b/doc/plugins/po.mdwn index f9cd0ff03..0a8a77a3c 100644 --- a/doc/plugins/po.mdwn +++ b/doc/plugins/po.mdwn @@ -13,7 +13,7 @@ A language is chosen as the "master" one, and any other supported language is a "slave" one. A page written in the "master" language is a "master" page. It can be -of any page type supported by ikiwiki, but PO. It does not have to be +of any page type supported by ikiwiki, except `po`. It does not have to be named a special way: migration to this plugin does not imply any page renaming work. @@ -22,7 +22,7 @@ English; if `usedirs` is enabled, it is rendered as `bla/page/index.en.html`, else as `bla/page.en.html`. Any translation of a "master" page into a "slave" language is called -a "slave" page; it is written in the gettext PO format. PO is now +a "slave" page; it is written in the gettext PO format. `po` is now a page type supported by ikiwiki. Example: `bla/page.fr.po` is the PO "message catalog" used to @@ -56,9 +56,8 @@ The `po_translatable_pages` setting configures what pages are translatable. It is a [[ikiwiki/PageSpec]], so you have lots of control over what kind of pages are translatable. -The PO translations files are anyway not considered as being -translatable, so you don't need to worry about excluding them -explicitly from this [[ikiwiki/PageSpec]]. +The `.po` files are not considered as being translatable, so you don't need to +worry about excluding them explicitly from this [[ikiwiki/PageSpec]]. Internal links -------------- @@ -180,17 +179,14 @@ Additional PageSpec tests This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some additional tests that are documented [[here|ikiwiki/pagespec/po]]. -Automatic PO files update -------------------------- +Automatic PO file update +------------------------ Committing changes to a "master" page: -1. updates the POT file, as well as the PO files for the "slave" - languages (this is done in the `needsbuild` hook); the updated PO - files are then put under version control; -2. triggers a refresh of the corresponding HTML slave pages (this is - achieved by making any "slave" page dependent on the corresponding - "master" page, in the `needsbuild` hook). +1. updates the POT file and the PO files for the "slave" languages; + the updated PO files are then put under version control; +2. triggers a refresh of the corresponding HTML slave pages. Also, when the plugin has just been enabled, or when a page has just been declared as being translatable, the needed POT and PO files are @@ -210,8 +206,8 @@ Translating One can edit the PO files using ikiwiki's CGI (a message-by-message interface could also be implemented at some point). -If [[tips/untrusted_git_push]] is setup, one can edit the PO files in -her preferred `$EDITOR`, without needing to be online. +If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's +preferred `$EDITOR`, without needing to be online. TODO ==== @@ -221,8 +217,18 @@ Security checks - `refreshpofiles` uses `system()`, whose args have to be checked more thoroughly to prevent any security issue (command injection, etc.). + > Always pass `system()` a list of parameters to avoid the shell. + > I've checked in a change fixing that. --[[Joey]] - `refreshpofiles` and `refreshpot` create new files; this may need some checks, e.g. using `IkiWiki::prep_writefile()` + > Yes, it would be ideal to call `prep_writefile` on each file + > that they write, beforehand. This way you'd avoid symlink attacks etc to the + > generated po/pot files. I haven't done it, but it seems pretty trivial. + > --[[Joey]] +- Can any sort of directives be put in po files that will + cause mischief (ie, include other files, run commands, crash gettext, + whatever). +- Any security issues on running po4a on untrusted content? gettext/po4a rough corners -------------------------- @@ -253,6 +259,14 @@ be fixed by something like [[todo/using_meta_titles_for_parentlinks]]. Which configuration settings are safe enough for websetup? +> I see no problems with `po_master_language` and `po_slave_languages` +> (assuming websetup handles the hashes correctly). Would not hurt to check +> that the values of these are legal language codes, in `checkconfig`. +> `po_translatable_pages` seems entirely safe. `po_link_to` w/o usedirs +> causes ikiwiki to error out. If it were changed to fall back to a safe +> setting in this case rather than error, it would be safe. +> --[[Joey]] + ### backlinks `po_link_to = negotiated`: if a given translatable `sourcepage.mdwn` @@ -262,6 +276,11 @@ in the backlinks. `po_link_to = current`: seems to work nicely +### license + +> Could you please put a copyright and license on po.pm? I assume it's +> GPLed as it's based on po4a-translate. --[[Joey]] + Translation quality assurance ----------------------------- diff --git a/doc/plugins/relativedate.mdwn b/doc/plugins/relativedate.mdwn index 32f8c798b..3ada0864b 100644 --- a/doc/plugins/relativedate.mdwn +++ b/doc/plugins/relativedate.mdwn @@ -13,4 +13,4 @@ If this plugin is enabled, you may also add relative dates to pages in the wiki, by using html elements in the "relativedate" class. For example, this will display as a relative date: - <span class="relativedate">Fri Oct 17 18:36:13 EDT 2008</span> + <span class="relativedate">Tue Jan 20 12:00:00 EDT 2009</span> |