Extension talk:Flattr

Annotations to version 0.7
// Check sanity on $wgFlattrForceUserid if (!isset($wgFlattrForceUserid) || $wgFlattrForceUserid != true || $wgFlattrForceUserid != false) { $wgFlattrForceUserid = false; } No matter what value (and type of this value) you compare to both true or false, it always will result in one true and one false, so the result is always true. If you want a comparision that assures the type is boolean you have to use a type-safe comparion operator === or !==. But what are you afraid of to make such a check? Just use $wgFlattrForceUserid = !empty($wgFlattrForceUserid); instead of the code above to force a boolean value. results to true for both not existing variables and values evaluating to false, so the negation is necessary. if (isset($args['url']) && !isset($args['uid'])) { return ...; } else { ... } Because if the condition ist true you will leave the current scope, so you don't need to protect the otherwise-code from execution with an else block encapsulation. $out = ""; $out .= "". PHP_EOL; is the same but longer as $out = ''. PHP_EOL; if (isset($wgFlattrUserid) && $wgFlattrUserid > 0 && (true === $wgFlattrForceUserid || !isset($args['uid']))) { $out .= "var flattr_uid = '". $wgFlattrUserid. "';" . PHP_EOL; Maybe you trust the admin that the content of  is safe, but I wouldn't rely on it.
 * Concering:
 * The following is a useless use of.
 * Don't style errors yourself. There is a rule for .error in a common CSS file, so you only need a.
 * A wrong value for  should generate an error message, not change silently to  . Or even better: implement both an error message and a forceLanguage option (for single language wikis).
 * It doesn't cost a lot of execution time but it's not necessary to initialize $out if you unconditionally assign a value to it just in the next line.
 * If you use  to ensure   is boolean you can shorten the next line a bit
 * Do not apply  to input values. Typically you will operate in your script with raw values. Apply it just before or while creating the output. If you always place   to the output you won't miss lines like this:

In addition, Javascript as content of is not HTML, so you have to escape regarding the JS rules not the HTML rules. Quote from the HTML4.01 spec. : “Although the STYLE and SCRIPT elements use CDATA for their data model, for these elements, CDATA must be handled differently by user agents. Markup and entities must be treated as raw text and passed to the application as is.” - Due to this rule  applied to a URL containing an   in a JS context results in the string   and no HTML parser will resolve this to a raw , so the resulting URL ist broken.

Unfortunately there is no function to escape values for JS strings in PHP, but you can use this one:

function wgFlattrJsEscape($value) { return strtr((string)$value, array( "'"    => '\\\'',     '"'     => '\"',     '\\'    => '\\\\',     "\n"    => '\n', "\r"   => '\r', "\t"   => '\t', chr(12) => '\f', chr(11) => '\v', chr(8) => '\b', ' '\u003c\u002F', )); }

if (isset($args['url'])) { $out .= "var flattr_tag = '". $args['url']. "';" . PHP_EOL; } Should be  instead of ..._tag.
 * And a copy&paste error:

proposal of version 0.8
obsoleted by 0.9

Changes since 0.7
 * Fixed some security issues (inappropriate escaping)
 * Added some configuration variables

proposal of version 0.9
obsoleted by 0.9

Changes since 0.8
 * Added more configuration variables.
 * Added static flattr button

proposal of version 1.0
Changes since 1.0β1
 * Added option to auto-insert Flattr buttons before or after main content
 * Changed the extension init code (using a different init hook)
 * Bugfix: sidebar didn't work without any flattr buttons in the main content

Changes since 0.9
 * Now uses Flattr API 0.5.0
 * Added Sidebar option
 * Rewritten to a (static) class instead of a bunch of functions
 * Changed $wgFlattr(Forced)Userid to $wgFlattr(Forced)Uid and $wgFlattrHide to $wgFlattrHidden to harmonize with names used by Flattr API
 * Added short description as code comment

Installation

 * Create a directory called Flattr in the extensions directory
 * Download http://api.flattr.com/button/button-static-50x60.png save as flattr-50x60.png into extensions/Flattr
 * Download http://api.flattr.com/button/button-compact-static-100x17.png save as flattr-100x17.png into extensions/Flattr
 * Copy the code below into extensions/Flattr/Flattr.php and extensions/Flattr/Flattr.i18n.php respectively

New configuration options: --dedlfix 11:10, 23 August 2010 (UTC)
 * $wgFlattrUid - nothing new (but renamed)
 * $wgFlattrForceUid - nothing new (but renamed)
 * $wgFlattrXXX - default configuration value
 * $wgFlattrForceXXX - always use the default value
 * instead XXX use Url, Title, Description, Language, Category, Tags, or Button
 * $wgFlattrHidden - set to any value other than 0, '0', '', false to always create a hidden "thing"; i.e. $wgFlattrHide = true;
 * See Flattr API for the meaning of these values
 * For both $wgFlattrButton and the attribute  you can use both or one of   and   in any combination, i.e. 'static', 'compact', 'static compact', 'compact-static', even 'staticompact' will work.
 * For a static button use the flattr.com-URL for an already submitted thing, i.e. https://flattr.com/thing/0815/Name