From 51d5e546974405741e08ed27d0bf89958fa7366b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 9 Aug 2010 13:18:59 -0400 Subject: filecheck: Fall back to using the file command if the freedesktop magic file cannot identify a file. --- IkiWiki/Plugin/filecheck.pm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm index d00b6dfd3..a78058ffe 100644 --- a/IkiWiki/Plugin/filecheck.pm +++ b/IkiWiki/Plugin/filecheck.pm @@ -132,15 +132,28 @@ sub match_mimetype ($$;@) { return IkiWiki::ErrorReason->new("file does not exist"); } - # Use ::magic to get the mime type, the idea is to only trust - # data obtained by examining the actual file contents. + # Get the mime type. + # + # First, try File::Mimeinfo. This is fast, but doesn't recognise + # all files. eval q{use File::MimeInfo::Magic}; - if ($@) { - return IkiWiki::ErrorReason->new("failed to load File::MimeInfo::Magic ($@); cannot check MIME type"); + my $mimeinfo_ok=! $@; + my $mimetype; + if ($mimeinfo_ok) { + my $mimetype=File::MimeInfo::Magic::magic($file); } - my $mimetype=File::MimeInfo::Magic::magic($file); + + # Fall back to using file, which has a more complete + # magic database. if (! defined $mimetype) { - $mimetype=File::MimeInfo::Magic::default($file); + open(my $file_h, "-|", "file", "-bi", $file); + $mimetype=<$file_h>; + close $file_h; + } + if (! defined $mimetype || $mimetype !~s /;.*//) { + # Fall back to default value. + $mimetype=File::MimeInfo::Magic::default($file) + if $mimeinfo_ok; if (! defined $mimetype) { $mimetype="unknown"; } -- cgit v1.2.3 From a68241838b37cd40eaedb917330412c19491ca70 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 12 Aug 2010 14:29:22 -0400 Subject: correct comment; javascript is put after --- IkiWiki/Plugin/relativedate.pm | 2 +- IkiWiki/Plugin/toggle.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index c9280ef14..7296889ab 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -27,7 +27,7 @@ sub format (@) { my %params=@_; if (! ($params{content}=~s!^(]*>)!$1.include_javascript($params{page})!em)) { - # no tag, probably in preview mode + # no tag, probably in preview mode $params{content}=include_javascript($params{page}, 1).$params{content}; } return $params{content}; diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 20967d3fd..1f93f87fe 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -69,7 +69,7 @@ sub format (@) { if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; if (! ($params{content}=~s!^(]*>)!$1.include_javascript($params{page})!em)) { - # no tag, probably in preview mode + # no tag, probably in preview mode $params{content}=include_javascript($params{page}, 1).$params{content}; } } -- cgit v1.2.3 From 80102c042d0f2fd194222cd233a7bfd0e8bd467f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 12 Aug 2010 16:53:52 -0400 Subject: flattr: New plugin. Thanks to jaywalk for the initial implementation at a flattr plugin! This one is less configurable, but simpler. --- IkiWiki/Plugin/flattr.pm | 97 +++++++++++++++++++++++++++++++++++++++ debian/changelog | 2 + doc/ikiwiki/directive/flattr.mdwn | 45 ++++++++++++++++++ doc/plugins/contrib/flattr.mdwn | 3 ++ doc/plugins/flattr.mdwn | 9 ++++ doc/style.css | 4 ++ 6 files changed, 160 insertions(+) create mode 100644 IkiWiki/Plugin/flattr.pm create mode 100644 doc/ikiwiki/directive/flattr.mdwn create mode 100644 doc/plugins/flattr.mdwn (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/flattr.pm b/IkiWiki/Plugin/flattr.pm new file mode 100644 index 000000000..3aee1eb93 --- /dev/null +++ b/IkiWiki/Plugin/flattr.pm @@ -0,0 +1,97 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::flattr; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "flattr", call => \&getsetup); + hook(type => "preprocess", id => "flattr", call => \&preprocess); + hook(type => "format", id => "flattr", call => \&format); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => undef, + }, + flattr_userid => { + type => "string", + example => 'joeyh', + description => "userid or user name to use by default for Flattr buttons", + advanced => 0, + safe => 1, + rebuild => undef, + }, +} + +my %flattr_pages; + +sub preprocess (@) { + my %params=@_; + + $flattr_pages{$params{destpage}}=1; + + my $url=$params{url}; + if (! defined $url) { + $url=urlto($params{page}, "", 1); + } + + my @fields; + foreach my $field (qw{language uid button hidden category tags}) { + if (exists $params{$field}) { + push @fields, "$field:$params{$field}"; + } + } + + return ''. + (exists $params{description} ? $params{description} : ''). + ''; +} + +sub format (@) { + my %params=@_; + + # Add flattr's javascript to pages with flattr buttons. + if ($flattr_pages{$params{page}}) { + if (! ($params{content}=~s!^(]*>)!$1.flattrjs()!em)) { + # no tag, probably in preview mode + $params{content}=flattrjs().$params{content}; + } + } + return $params{content}; +} + +my $js_cached; +sub flattrjs { + return $js_cached if defined $js_cached; + + my $js_url='https://api.flattr.com/js/0.5.0/load.js?mode=auto'; + if (defined $config{flattr_userid}) { + my $userid=$config{flattr_userid}; + $userid=~s/[^-A-Za-z0-9_]//g; # sanitize for inclusion in javascript + $js_url.="&uid=$userid"; + } + + # This is Flattr's standard javascript snippet to include their + # external javascript file, asynchronously. + return $js_cached=<<"EOF"; + +EOF +} + +1 diff --git a/debian/changelog b/debian/changelog index 440bee34f..f90fd8855 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ ikiwiki (3.20100805) UNRELEASED; urgency=low * filecheck: Fall back to using the file command if the freedesktop magic file cannot identify a file. + * flattr: New plugin. (Thanks to jaywalk for the initial implementation + at a flattr plugin! This one is less configurable, but simpler.) -- Joey Hess Mon, 09 Aug 2010 13:18:28 -0400 diff --git a/doc/ikiwiki/directive/flattr.mdwn b/doc/ikiwiki/directive/flattr.mdwn new file mode 100644 index 000000000..5083005ce --- /dev/null +++ b/doc/ikiwiki/directive/flattr.mdwn @@ -0,0 +1,45 @@ +The `flattr` directive is supplied by the [[!iki plugins/flattr desc=flattr]] plugin. + +This directive allows easily inserting Flattr buttons onto wiki pages. + +Flattr supports both static buttons and javascript buttons. This directive +only creates dynamic javascript buttons. If you want to insert a static +Flattr button, you can simply copy the html code for it from Flattr, instead. +Note that this directive inserts javascript code into the page, that +loads more javascript code from Flattr.com. So only use it if you feel +comfortable with that. + +The directive can be used to display a button for a thing you have already +manually submitted to Flattr. In this mode, the only parameter you need to +include is the exact url to the thing that was submitted to Flattr. +(If the button is for the current page, you can leave that out.) For +example, this is the Flattr button for ikiwiki. Feel free to add it to all +your pages. ;) + + \[[!flattr url="http://ikiwiki.info/" button=compact]] + +The directive can also be used to create a button that automatically +submits a page to Flattr when a user clicks on it. In this mode you +need to include parameters to specify your uid, and a title, category, tags, +and description for the page. For example, this is a Flattr button for +a blog post: + + \[[!flattr uid=25634 title="my new blog post" category=text + tags="blog,example" description="This is a post on my blog."]] + +Here are all possible parameters you can pass to the Flattr directive. + +* `button` - Set to "compact" for a small button. +* `url` - The url to the thing to be Flattr'd. If omitted, defaults + to the url of the current page. +* `uid` - Your numeric Flattr userid. Not needed if the flattr plugin + has been configured with a global `flattr_userid`. +* `title` - A short title for the thing, to show on its Flattr page. +* `description` - A description of the thing, to show on its Flattr + page. +* `category` - One of: text, images, video, audio, software, rest. +* `tags` - A list of tags separated by a comma. +* `language` - A language code. +* `hidden` - Set to 1 to hide the button from listings on Flattr.com. + +[[!meta robots="noindex, follow"]] diff --git a/doc/plugins/contrib/flattr.mdwn b/doc/plugins/contrib/flattr.mdwn index f8f005c31..e9b4bf857 100644 --- a/doc/plugins/contrib/flattr.mdwn +++ b/doc/plugins/contrib/flattr.mdwn @@ -10,6 +10,9 @@ I wrote some notes on [jonatan.walck.se](http://jonatan.walck.se/software/ikiwik This plugin is licensed under [CC0](http://creativecommons.org/publicdomain/zero/1.0/) (public domain). +Note that there is now a [[plugins/flattr]] plugin bundled with ikiwiki. It +is less configurable, not supporting static buttons, but simpler to use. + # Usage # # [[!flattr args]] where args are in the form of arg=value. diff --git a/doc/plugins/flattr.mdwn b/doc/plugins/flattr.mdwn new file mode 100644 index 000000000..5da279518 --- /dev/null +++ b/doc/plugins/flattr.mdwn @@ -0,0 +1,9 @@ +[[!template id=plugin name=flattr author="[[Joey]]"]] +[[!tag type/web]] + +[Flattr](http://flattr.com/) is a social micropayment platform. +This plugin allows easily adding Flattr buttons to pages, +using the [[ikiwiki/directive/flattr]] directive. + +This plugin has a configuration setting. `flattr_userid` can be set +to either your numeric flatter userid, or your flattr username. diff --git a/doc/style.css b/doc/style.css index 8dd3b1c15..66d962bd6 100644 --- a/doc/style.css +++ b/doc/style.css @@ -449,6 +449,10 @@ li.L8 { list-style: upper-alpha; } background: #ff9900; } +.FlattrButton { + display: none; +} + /* openid selector */ #openid_choice { display: none; -- cgit v1.2.3 From 3ef8864122c2e665d41ed4d45baa50d4a5d21873 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 12 Aug 2010 17:19:20 -0400 Subject: insert flattr javascript via sanitize, not format hook This makes the javascript be added to rss feeds, which allows the buttons to be displayed by aggregators. At least, if the aggregator does not sanitize javascript. --- IkiWiki/Plugin/flattr.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/flattr.pm b/IkiWiki/Plugin/flattr.pm index 3aee1eb93..9cf9dfb13 100644 --- a/IkiWiki/Plugin/flattr.pm +++ b/IkiWiki/Plugin/flattr.pm @@ -8,7 +8,7 @@ use IkiWiki 3.00; sub import { hook(type => "getsetup", id => "flattr", call => \&getsetup); hook(type => "preprocess", id => "flattr", call => \&preprocess); - hook(type => "format", id => "flattr", call => \&format); + hook(type => "sanitize", id => "flattr", call => \&sanitize, last => 1); } sub getsetup () { @@ -54,17 +54,16 @@ sub preprocess (@) { ''; } -sub format (@) { +sub sanitize (@) { my %params=@_; # Add flattr's javascript to pages with flattr buttons. if ($flattr_pages{$params{page}}) { - if (! ($params{content}=~s!^(]*>)!$1.flattrjs()!em)) { - # no tag, probably in preview mode - $params{content}=flattrjs().$params{content}; - } + return flattrjs().$params{content}; + } + else { + return $params{content}; } - return $params{content}; } my $js_cached; -- cgit v1.2.3 From efd8e93c5be79b1df0b92b2b5aee91308e4343dc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 12 Aug 2010 18:18:35 -0400 Subject: Revert "insert flattr javascript via sanitize, not format hook" This reverts commit 3ef8864122c2e665d41ed4d45baa50d4a5d21873. Most aggregators block javascript and so it would display uglily. Need to find a way to fallback to static buttons instead. --- IkiWiki/Plugin/flattr.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/flattr.pm b/IkiWiki/Plugin/flattr.pm index 9cf9dfb13..3aee1eb93 100644 --- a/IkiWiki/Plugin/flattr.pm +++ b/IkiWiki/Plugin/flattr.pm @@ -8,7 +8,7 @@ use IkiWiki 3.00; sub import { hook(type => "getsetup", id => "flattr", call => \&getsetup); hook(type => "preprocess", id => "flattr", call => \&preprocess); - hook(type => "sanitize", id => "flattr", call => \&sanitize, last => 1); + hook(type => "format", id => "flattr", call => \&format); } sub getsetup () { @@ -54,16 +54,17 @@ sub preprocess (@) { ''; } -sub sanitize (@) { +sub format (@) { my %params=@_; # Add flattr's javascript to pages with flattr buttons. if ($flattr_pages{$params{page}}) { - return flattrjs().$params{content}; - } - else { - return $params{content}; + if (! ($params{content}=~s!^(]*>)!$1.flattrjs()!em)) { + # no tag, probably in preview mode + $params{content}=flattrjs().$params{content}; + } } + return $params{content}; } my $js_cached; -- cgit v1.2.3 From df5de5b967a1e6e14161fd1269efe5b17d33eec1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 13 Aug 2010 11:21:11 +0200 Subject: smiley: warn instead of error for missing smileys A missing smileys.mdwn caused the plugin to error out interrupting the building process. Instead, we check for the file presence and warn without erroring out in case it's missing, in a similar fashion as it's currently done for the shortcut plugin. --- IkiWiki/Plugin/smiley.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/smiley.pm b/IkiWiki/Plugin/smiley.pm index 0d77916d0..6f4f49d18 100644 --- a/IkiWiki/Plugin/smiley.pm +++ b/IkiWiki/Plugin/smiley.pm @@ -25,7 +25,14 @@ sub getsetup () { } sub build_regexp () { - my $list=readfile(srcfile("smileys.mdwn")); + my $srcfile = srcfile("smileys.mdwn", 1); + if (! defined $srcfile) { + print STDERR sprintf(gettext("smiley plugin will not work without %s"), + "smileys.mdwn")."\n"; + $smiley_regexp=''; + return; + } + my $list=readfile($srcfile); while ($list =~ m/^\s*\*\s+\\\\([^\s]+)\s+\[\[([^]]+)\]\]/mg) { my $smiley=$1; my $file=$2; -- cgit v1.2.3