InstantCommons not working in MediaWiki 1.19 and SELinux - image

I am setting my own MediaWiki website locally, and am not able to get the InstantCommons feature to work (used to directly embed files from commons.wikimedia.org).
I get no error message, the files I try to load from Commons using the following syntax:
[[File:Cervus elaphus Luc Viatour 1.jpg|Cervus elaphus Luc Viatour 1]]
are just not loaded, and I end up with a red link on my page, referring to a non-existing file. It has been 2 days now that I am looking for a solution, but so far without any success.
I am running:
MediaWiki v.1.19.1
Fedora 16 (with SElinux)
PHP 5.3.15
MySQL Ver 14.14 Distrib 5.5.25a, for Linux (x86_64)
I have tried the following two configurations in my LocalSettings.php, without success:
$wgUseInstantCommons = true;
AND
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'shared',
'apibase' => 'http://commons.wikimedia.org/w/api.php',
'fetchDescription' => true, // Optional
'descriptionCacheExpiry' => 43200, // 12 hours, optional (values are seconds)
'apiThumbCacheExpiry' => 43200, // 12 hours, optional, but required for local thumb caching
);
Any suggestion is most welcome.

OK, this is not (yet) an answer, but a debugging suggestion. It looks to me like the HTTP request from your server to Commons is failing for some reason, but unfortunately ForeignAPIRepo doesn't indicate the cause of the error in any way.
This is really a bug in MediaWiki, and should be fixed, but in the mean time, could you please try applying the following diff (or just manually adding the line marked with the + sign) to your includes/filerepo/ForeignAPIRepo.php file:
Index: includes/filerepo/ForeignAPIRepo.php
===================================================================
--- includes/filerepo/ForeignAPIRepo.php (revision 97048)
+++ includes/filerepo/ForeignAPIRepo.php (working copy)
## -385,6 +385,7 ##
if ( $status->isOK() ) {
return $req->getContent();
} else {
+ wfDebug( "ForeignAPIRepo: HTTP GET failed: " . $status->getXML() );
return false;
}
}
After applying it, try loading the file description page for a Commons image and look at the MediaWiki debug log. There should now be a line starting with ForeignAPIRepo: HTTP GET failed: followed by a few lines of XML error dump. That error data should hopefully indicate what's going wrong; please copy and paste it here.

Mine is not a definitive answer either. Referring to Ilmari Karonen's post, I was unable to find or get the getXML() method to execute for my version of Mediawiki v1.23.0. I was looking at the reference documentation found here to try and find any other method calls on the Status class that would give me good troubleshooting info. I ended up finding the following and editing the same file as mentioned in Ilmari Karonen's post includes/filerepo/ForeignAPIRepo.php beginning at line #521:
if ( $status->isOK() ) {
return $req->getContent();
} else {
$error = $status->getErrorsArray();
$dump = print_r($error, true);
wfDebug("ForeignAPIRepo: HTTP GET failed: $dump\n");
return false;
}

The default InstantCommons configuration of older MediaWikis is a bit silly. Due to T114098 I recommend one of the following, which will hopefully fix your problems:
upgrade to MediaWiki 1.27 (when it's released), or
set your LocalSettings.php to hotlink images to save on server-side requests and processing.
$wgUseInstantCommons = false;
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'commonshotlink',
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'hashLevels' => 2,
'url' => 'https://upload.wikimedia.org/wikipedia/commons',
'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
'transformVia404' => true,
'fetchDescription' => true,
'descriptionCacheExpiry' => 43200,
'apiThumbCacheExpiry' => 24 * 3600,
);

Related

wkhtmltopdf, 0.12.6, Warning: Blocked access to file

When upgrade wkhtmltopdf to 0.12.6, it came to such messages and the image did not show in the target pdf:
Warning: Blocked access to file /path/to/bpa_product_layering.png
BTW, the same source html file works well with 0.12.5
This is caused by the change of default behavior in version 0.12.6 of wkhtmltopdf. wkhtmltopdf disables local file access by default now. It could be solved by adding the command line parameter
--enable-local-file-access
or the combination
--disable-local-file-access --allow <path>
For those that are using laravel-snappy, add the 'enable-local-file-access' option in the config\snappy.php:
'pdf' => [
'enabled' => true,
'binary' => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],
wkhtmltopdf disables local file access by default in the 0.12.6 version
Just bumping this thread with a correction in case you're still getting the same error in spite of using:
--enable-local-file-access
For some reason, this cmd line argument does not work when being specified after input/output files, you have to write this argument right after wkhtmltopdf.exe.
So
wkhtmltopdf.exe --enable-local-file-access input.html output.pdf
instead of other variants.
in my case, I put "enable-local-file-access": "", in options, it worked.
In Windows with Python, I came across a similar error as well when running code:
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries)
Error:
Warning: Blocked access to file C:/XXXXXX/background.A.jpg
Error: Failed to load about:blank, with network status code 301 and
http status code 0 - Protocol "about" is unknown
What I did to resolve this:
Add variable options
kitoptions = {
"enable-local-file-access": None
}
Add options to call
FROM
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries)
TO
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries, options=kitoptions)
Full Source:
import imgkit
#library path to kit
path_wkthmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'
wkhtmltoimage_binaries = imgkit.config(wkhtmltoimage=path_wkthmltopdf)
#OPTIONS
kitoptions = {
"enable-local-file-access": None
}
html_file_directory = r'C:\XXXX\template'
result = imgkit.from_file('postlayout.A.html', 'out.jpg', config=wkhtmltoimage_binaries, options=kitoptions)
if result:
print("successful")
else:
print("failed")
For the C API, contrary to what the documentation says, it's not load.blockLocalFileAccess but loadPage.blockLocalFileAccess that you must set to "false":
wkhtmltoimage_set_global_setting(settings, "loadPage.blockLocalFileAccess", "false");
Hopefully, the documentation will be updated soon; see issue #4763.
I confirm that the problem comes from the wkhtmltopdf version. For those on Symfony (3.4), just add an option in config.yml:
knp_snappy:
pdf:
options:
enable-local-file-access: true
I know am a bit late in party but just wanted to write clear example with c# here so one can understand clearly.
ProcessStartInfo proc = new ProcessStartInfo();
proc = new ProcessStartInfo();
proc.RedirectStandardError = true;
proc.UseShellExecute = false;
proc.WorkingDirectory = #"" + Config.WkhtmltopdfPath;
proc.FileName = #"" + Config.WkhtmltopdfPath + #"\wkhtmltopdf.exe";
proc.Arguments = #" --enable-local-file-access -T 0 -B 0 --page-width 210mm --page-height 450mm " + fileName + ".html " + fileName + ".pdf";
Process inkscape = Process.Start(proc);

How do I set the number of results return from completion/suggest?

Currently, I have the Elasticsearch service running on version 7.4.0 while my C# Windows Form application is using Elasticsearch.Net version 7.3.1.
I notice I could set the maximum number of results returned from highlight by setting NumberOfFragments which by default is five. However, I could not get the completion/suggestion to return more than five results when I set the following:
var tRes = client.Search<Words>(s => s
.SuggestSize(20) // How many suggestions to return in response
.Suggest(su => su
.Completion("name", cs => cs
.SkipDuplicates(true)
.Field(f => f.Suggest)
.Prefix(tbInput.Text)
.Regex("*")
.Size(20))
)
I received the following error message when I execute the above query.
{"The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: POST /docproperty/_search?typed_keys=true&suggest_size=20. ServerError: Type: illegal_argument_exception Reason: \"request [/docproperty/_search] contains unrecognized parameter: [suggest_size] -> did you mean [suggest_field]?\""}
Update
I manage to get more than 5 results by adding the following:
var tRes = client.Search<Words>(s => s
.Size(20)
.Suggest(su => su
.Completion("name", cs => cs
.SkipDuplicates(true)
.Field(f => f.Suggest)
.Prefix(tbInput.Text)
.Regex("*")
.Size(20))
.Term("", t=>t.ShardSize(20).Field(f=>f.Suggest).Text(tbInput.Text))
)
);
However, this time I notice that I could not get the completion to return words (a lot of missing ones) that could be found when I execute a MatchPhrase.
I think if you look at the documentation, I think it's not meant to be suggestSize. I think it should be size only.. not sure if this supports chaining.
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html

Laravel localization file format error: array() versus [] format

I am struggling a bit with localization in Laravel 5.3 (with php 7). The default localizaiton file format in Laravel 5.3 is using brackets, as in this example:
return [
'footer.contact.email' => 'Email:',
]
That's what I have been using in my app and it's working fine. But now I am trying to work with some packages to help with translations, for example:
https://github.com/potsky/laravel-localization-helpers
https://github.com/barryvdh/laravel-translation-manager
But both of those generate localization files in the "old" laravel 4.x array format. For example
return array(
'footer' => array(
'contact' => array(
'email' => 'Email:',
),
),
);
As I understand it I should have no issue with this localization file format in my laravel 5.3 app, however it's always throwing an exception:
[2016-12-02 13:26:01] local.ERROR: ErrorException: htmlspecialchars() expects parameter 1 to be string, array given in C:\100_source_code\consulting_platform_laravel\maingig\vendor\laravel\framework\src\Illuminate\Support\helpers.php:519
Stack trace:
#0 C:\100_source_code\consulting_platform_laravel\maingig\vendor\sentry\sentry\lib\Raven\Breadcrumbs\ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'htmlspecialchar...', 'C:\\100_source_c...', 519, Array)
I really cant understand why this format is not working with my app. I bet it is something trivial that I am missing, but any help would be very welcome!
Thanks,
Christian
After a few extra hours of stepping through the code I found the source of the problem.
For example, I got these in my original lang file:
'footer.subscribe' => 'SUBSCRIBE TO OUR NEWSLETTER',
'footer.subscribe.intro' => 'Be the first to know about our latest news...',
'footer.subscribe.privacy' => 'Privacy Policy',
'footer.subscribe.tos' => 'Terms of Service',
'footer.subscribe.tac' => 'Terms and Conditions',
As I tried to use both of the packages mentioned in my original question they produced the following output:
'footer' =>
array (
'subscribe' =>
array (
'intro' => 'TODO: intro',
'privacy' => 'TODO: privacy',
'tos' => 'TODO: tos',
'tac' => 'TODO: tac',
),
),
As you can see the generated file dropped the value for the text footer.subscribe and only kept the child element, intro, privacy, tos and tas in this case. Therefore a request for trans('footer.subscribe') returns an array and not the text.
Now that I know this I will change the format of my original translation file!
c.

How do I make puppet copy a file only if source exists?

I am trying to provision a vagrant VM to allow users to supply their own bash_profile.local but I don't want this file tracked in the vm's vcs repo. I have a tracked bash_profile.local.dist file that they can rename. How can I tell puppet to only create a file if the source file exists? It is currently working correctly but logs an error during provisioning and this is what I'm trying to avoid.
This is the manifest:
class local
{
file { '.bash_profile.local':
source => 'puppet:///modules/local/bash_profile.local',
path => '/home/vagrant/.bash_profile.local',
replace => false,
mode => 0644,
owner => 'vagrant',
group => 'vagrant',
}
}
You could abuse file in this way :
$a = file('/etc/puppet/modules/local/files/bash_profile.local','/dev/null')
if($a != '') {
file { '.bash_profile.local':
content => $a,
...
}
}
This is not exactly what you asked but you can supply multiple paths in the source, so you can have a default empty file if the user didn't supplied his own.
class local
{
file { '.bash_profile.local':
source => [
'puppet:///modules/local/bash_profile.local',
'puppet:///modules/local/bash_profile.local.default'
],
path => '/home/vagrant/.bash_profile.local',
replace => false,
mode => 0644,
owner => 'vagrant',
group => 'vagrant',
}
}
You can try something like this:
file { 'bash_profile.local':
ensure => present,
source => ['puppet:///modules/local/bash_profile.local', '/dev/null'],
path => '/home/vagrant/.bash_profile.local',
before => Exec['clean-useless-file'],
}
exec { 'clean-useless-file':
command => 'rm .bash_profile.local',
onlyif => 'test -s .bash_profile.local',
cwd => '/home/vagrant',
path => '/bin:/usr/bin',
}
If the admin don't make a copy of ".bash_profile.local" available in "modules/local/bash_profile.local", the file resource will use the second source and then create a blank file. Then, the "onlyif" test fails and the exec will remove the useless blank file.
Used this way this code can be a little cumbersome, but it's better than a provisioning failure. You may evaluate if retaining a blank .bash_profile.local file can be okay in your case. I normally use a variation of this, with wget instead of rm, to get a fresh copy of the file from the internet if it was not already made available as a source.
If you're using puppetmaster, be aware you can use it to provision the own server, presenting two versions of the catalog, according to the .bash_profile.local is present or not.

Magento: Headers already sent, Am Debugging, trying to understand output

I am aware of a number of posts on this topic - the most comprehensive of which is here.
My particular gremlin looks like this: (without further logging)
2012-04-17T00:28:50+00:00 DEBUG (7): HEADERS ALREADY SENT: <pre>[0] /domains/bodhi.uk.com/subdomains/dev/app/code/core/Mage/Core/Controller/Response/Http.php:51
[1] /domains/bodhi.uk.com/subdomains/dev/lib/Zend/Controller/Response/Abstract.php:766
[2] /domains/bodhi.uk.com/subdomains/dev/app/code/core/Mage/Core/Controller/Response/Http.php:89
[3] /domains/bodhi.uk.com/subdomains/dev/app/code/core/Mage/Core/Controller/Varien/Front.php:188
[4] /domains/bodhi.uk.com/subdomains/dev/app/code/core/Mage/Core/Model/App.php:349
[5] /domains/bodhi.uk.com/subdomains/dev/app/Mage.php:640
[6] /domains/bodhi.uk.com/subdomains/dev/index.php:80
This can occur loading the homepage on dev.bodhi.uk.com
Following the accepted answer in the linked post, creates a list of around 500 files, that are being included - not a practical method for debugging (especially when I may not recognise the issue when looking at it - I am currently assuming that I am looking for whitespace prior to a
For reference the output of the above is here on pastebin
Using the advice in the last comment (that appeared to work for the OP), and adding:
$headers = array();
foreach ($this->_headers as $i => $header) {
$headers[$header['name']] = $header;
}
$this->_headers = array_values($headers);
Mage::Log(array_values($headers));
Gives the unexpected responce:
2012-04-17T00:28:50+00:00 DEBUG (7): Array
(
[0] => Array
(
[name] => Content-Type
[value] => text/html; charset=UTF-8
[replace] =>
)
)
Ultimately I need to prevent this error, and I am struggling for a next step!
PS: I have also tried Alan's responce in comment 1, however the format of Abstract.php has changed (I am using version 1.6.2), and as I get no further output, I suspect I am not logging things correctly.
Thanks in advance!
Try ob_start() it may be helpful to you just put this code at the top of your file

Resources