how to add "Portal" namespace? What code should I add? - mediawiki

I'm trying to create pages in my private wiki with the prefix "portal" without success, I understand that I have to add code in order for this to happen, what do I have to add?
Thank you

Something like this in LocalSettings.php:
define ('NS_PORTAL' , 198);
define ('NS_PORTAL_TALK', 199);
$wgExtraNamespaces [NS_PORTAL] = 'Portal';
$wgExtraNamespaces [NS_PORTAL_TALK]= 'Portal_talk';
Further reading: https://www.mediawiki.org/wiki/Manual:Using_custom_namespaces.

I actually added the following code:
define( 'Portal', 126 );
define( 'Portal_Talk', 127 );
$wgExtraNamespaces += [
126 => 'Portal',
127 => 'Portal_Talk',
];
$wgNonincludableNamespaces += [ 126, 127 ];
$wgNamespaceRobotPolicies += [
'Portal' => 'index, follow',
'Portal_Talk' => 'noindex, nofollow',
];
$wgNamespacesWithSubpages += [
'Portal' => true,
];
$wgContentNamespaces = [ 0, 126 ];

Related

How to use faker in yii2 in advance template

I am generating random data for project and for unit testing. So i want to use faker. But unable to how to use faker in yii2?
set this in your main config:
return [
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'templatePath' => '#common/tests/templates/fixtures',
'fixtureDataPath' => '#common/tests/fixtures/data',
],
// ...
],
// ...
];
use it like this:
$faker = Faker\Factory::create();
// generate data by accessing properties
echo $faker->name;
// 'Lucy Cechtelar';
echo $faker->address;
// "426 Jordy Lodge
// Cartwrightshire, SC 88120-6700"
echo $faker->text;
for more info check faker basic usage
and yii2 guide

Downloading an object from a bucket

I'm trying to write a function to download a file stored in a persistent bucket and I'm having some problems decoding the result.
I'm following the guide here to try and download the object shown here:
(int) 3 => object(stdClass) {
bucketKey => 'my-persistent-bucket'
objectKey => '11--test.dwg'
objectId => 'urn:adsk.objects:os.object:my-persistent-bucket/11--test.dwg'
sha1 => '477085439a60779064d91fd1971d53c77c7a163a'
size => (int) 188600
location => 'https://developer.api.autodesk.com/oss/v2/buckets/my-persistent-bucket/objects/11--test.dwg'
}
Using the following cURL function
$ch = curl_init();
$headers = [
"Authorization: Bearer " . $token->token,
"Accept: application/octet-stream"
];
$url = 'https://developer.api.autodesk.com/oss/v2/buckets/'.$this->persistent.'/objects/'.rawurlencode($file->object_key);
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
]);
$response = curl_exec($ch) ;
$http_header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE) ;
$http_header = substr($response, 0, $http_header_size) ;
$http_body = substr($response, $http_header_size) ;
$response_info = curl_getinfo($ch) ;
curl_close($ch) ;
curl_getinfo($ch); looks like everything has gone fine:
'url' => 'https://developer.api.autodesk.com/oss/v2/buckets/my-persistent-bucket/objects/11--test.dwg',
'content_type' => 'application/x-www-form-urlencoded',
'http_code' => (int) 200,
'header_size' => (int) 474,
'request_size' => (int) 199,
'filetime' => (int) -1,
'ssl_verify_result' => (int) 0,
'redirect_count' => (int) 0,
'total_time' => (float) 1.261261,
'namelookup_time' => (float) 0.029048,
'connect_time' => (float) 0.057444,
'pretransfer_time' => (float) 0.119675,
'size_upload' => (float) 0,
'size_download' => (float) 188600,
'speed_download' => (float) 149532,
'speed_upload' => (float) 0,
'download_content_length' => (float) 188600,
'upload_content_length' => (float) 0,
'starttransfer_time' => (float) 0.902231,
'redirect_time' => (float) 0,
'redirect_url' => '',
'primary_ip' => '52.210.137.76',
'certinfo' => [],
'primary_port' => (int) 443,
'local_ip' => '10.0.2.15',
'local_port' => (int) 50564
$http_body = '%C8B%BB%8B%A6%12%03Z%7D%29%E7%27%1F%5D%D4%CB%FC%DA%15G%3B%13%0D%89%0A%1C%DB%AE2%2C%9AP%EE%60x6%FD%92I2%F6%DE%7DI%DC%A0O%14%F2%84%9Ed%D0k%C40%B7%3E%3B%A1%22%...
The response is always what looks like a url encoded string but no matter how I try to decode it, I can't manage to get a working file, so far I've tried:
curl_unescape()
urldecode()
rawurldecode()
and none of these give me a useable file. It's worth noting that I can download a file from A360 no problem, but I've not managed to get one out of a Forge bucket.
Any ideas on what I'm doing wrong would be great.
Thanks
The bucketKey should match this regular expression '^[-_.a-z0-9]{3,128}$', and the objectKey should be URL encoded. However, the keys used to upload the file/object must match the ones used to download. Which means that if you choose to encode characters one way, they should be encoded the same way later.
I also noticed you did not specify how to encode the download. If you do not specify to download as octet, HTTP will use the default which is UTF8 text characters vs binary. You did specify CURLOPT_RETURNTRANSFER which will convert to binary, but you are missing the header for the server part.
The code below works fine for me, assuming bucketKey and objectKey were URL encoded with rawurlencode(); as well as when the file/object was uploaded with PUT.
```
$ch =curl_init () ;
$headers =[
"Authorization: Bearer {$token->token}",
"Accept: application/octet-stream",
"Content-Type: application/json"
] ;
$url ="https://developer.api.autodesk.com/oss/v2/buckets/{$bucket_key}/objects/{$object_key}" ;
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
]) ;
$response =curl_exec ($ch) ;
$http_header_size =curl_getinfo ($curl, CURLINFO_HEADER_SIZE) ;
$http_header =substr ($response, 0, $http_header_size) ;
$http_body =substr ($response, $http_header_size) ;
$response_info =curl_getinfo ($ch) ;
curl_close ($ch) ;
file_put_contents ('11--test.dwg', $http_body) ;
```
As you can see I split the response into 2 parts. The headers and the octet-stream. The file download is in the 2nd part and is the HTTP body response. The response contains both headers and body, hence you need to split this on your end.
Hope that helps,

Why memcache Yii2 not set value with duration parameter

I using Memcache to cache data in project yii2.
with config:
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => 'localhost',
'port' => 11211,
],
],
],
With code: return false
\Yii::$app->cache->set('abc', 'value of abc', 20); // 20 seconds
$data = \Yii::$app->cache->get('abc'); var_dump($data); // return false
But if i set:
\Yii::$app->cache->set('abc', 'value of abc', -20); // -20 seconds $data = \Yii::$app->cache->get('abc'); var_dump($data); // return "value of abc"
So why this? Thanks.
Can you increment the seconds?
Pls try this and let me know the results:
\Yii::$app->cache->set('abc', 'value of abc', 10000);
$data = \Yii::$app->cache->get('abc'); var_dump($data);
A bit late, but in case someone else have same problem, here are my thoughts...
It might depend on whether MemCached or MemCache is installed. If config uses MemCache (like in the question) but MemCached is installed, it will work using get() but set() is different after the two first parameters, ie duration.

How to parse this JSON object/string?

I am trying to parse the JSON written # http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js
Here is a quick snippet from above link:
{vers:0.01,config:{rate:"perhr",valueColumns:["vCPU","ECU","memoryGiB","storageGB","sles"],currencies:["USD"],regions:[{region:"us-east",instanceTypes:[{type:"generalCurrentGen",sizes:[{size:"t2.micro",vCPU:"1",ECU:"variable",
...
...
...
...
Please visit the aforementioned link to see the complete JSON.
As seen above, none of the keys of above JSON have Double Quotes around them.
This leads to malformed JSON string and my JSON parser is failing at it. I also tried putting this JSON in http://www.jsoneditoronline.org/ and it fails as well.
Now, this is the same link which is used by Amazon to display various prices of their EC2 instance. So I think I am missing something here. My Googling led me to believe that above thing is not JSON and is instead JSONP.. I don't understand what is that.
Could you help me understand how to parse this JSON. BTW, I am doing this work in perl using JSON Module.
Some background:
Amazon Web Services does not have an API to get Pricing info programmatically. Hence I am parsing these links which is what amazon is doing while displaying pricing information here. Besides, I am not from programming space and perl is all I know.
Like you said JSONP or "JSON with padding" can't be parsed by json parser because it is not json (it is a different format). But it is actually a json with the prefix (padding)
The padding is typically the name of a callback function that wraps json.
In this case, its default callback names 'callback' and we can do a bit hackiest way by using Regular Expression to capture json that is wrapped by 'callback()' like this
s/callback\((.*)\);$/$1/s;
Also, if you would like to use JSON library, you can enable allow_barekey which means you don't need those quotes around those keys.
Below is my working code. I use LWP::Simple to get the content for the given and Data::Dump to print the isolated data structure.
use strict;
use warnings;
use LWP::Simple;
use JSON;
my $jsonp = get("http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js")
or die "Couldn't get url";
( my $json = $jsonp ) =~ s/callback\((.*)\);$/$1/s; #grap the json from $jsonp and store in $json variable
my $hash = JSON->new->allow_barekey->decode ( $json );
use Data::Dump;
dd $hash;
Outputs:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 2,
size => "t2.small",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.056 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 4,
size => "t2.medium",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.152 } }],
vCPU => 2,
},
{
ECU => 3,
memoryGiB => 3.75,
size => "m3.medium",
storageGB => "1 x 4 SSD",
valueColumns => [{ name => "os", prices => { USD => "0.170" } }],
vCPU => 1,
},
....
As said in comments above, it is not JSON so it can't be parsed by JSON parser... But for an quick & (very)dirty work, you can try the JSON::DWIW module.
The next code:
use 5.014;
use warnings;
use WWW::Mechanize;
use Data::Dump;
use JSON::DWIW;
my $mech = WWW::Mechanize->new();
my $jsonstr = $mech->get('http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js')->content;
($jsonstr) = $jsonstr =~ /callback\((.*)\)/s;
my $json_obj = JSON::DWIW->new;
my $data = $json_obj->from_json( $jsonstr );
dd $data;
prints a structure what maybe is what you want, e.g.:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{

Perl Catalyst - Couldn't render template..........not found

The error I am getting in the development server:
[info] *** Request 2 (0.000/s) [681] [Thu Dec 12 21:05:39 2013] ***
[debug] Path is "homescreen"
[debug] "GET" request for "homescreen" from "192.168.1.100"
[debug] Rendering template "homescreen/homescreen.tt2"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[debug] Response Code: 500; Content-Type: text/html; charset=utf-8; Content-Length: 14312
[info] Request took 0.033915s (29.485/s)
.------------------------------------------------------------+-----------.
| Action | Time |
+------------------------------------------------------------+-----------+
| /homescreen | 0.000341s |
| /end | 0.014055s |
| -> Myproject::View::HTML->process | 0.013049s |
'------------------------------------------------------------+-----------'
What I am doing:
I have the following Controller/Homescreen.pm:
package Myproject::Controller::Homescreen;
use strict;
use warnings;
use parent 'Catalyst::Controller';
use Data::Dumper;
use JSON;
__PACKAGE__->config->{namespace} = '';
sub homescreen :Path('/homescreen') :Args(0) {
my ( $self, $c ) = #_;
print STDERR "IN THE HOMESCREEN ACTION\n";
$c->stash({template => 'homescreen/homescreen.tt2',
title => 'Home Screen'
});
}
I have the following View/HTML.pm:
package Myproject::View::HTML;
use Moose;
use namespace::autoclean;
extends 'Catalyst::View::TT';
__PACKAGE__->config({
#Changed default TT extension to TT2
TEMPLATE_EXTENSION => '.tt2',
render_die => 1,
});
I have the following lib/Myproject.pm:
__PACKAGE__->config(
name => 'Myproject',
# Disable deprecated behavior needed by old applications
disable_component_resolution_regex_fallback => 1,
#enable_catalyst_header => 1, # Send X-Catalyst header
);
__PACKAGE__->config(
#Configure the view
'View::HMTL' => {
#Set the location for TT files
INCLUDE_PATH => [
__PACKAGE__->path_to( 'root', 'src' ),
],
},
);
# Start the application
__PACKAGE__->setup();
I then have a root/src/homescreen/homescreen.tt2 withing my Catalyst directory that contains all my html code (eventually it will use the template toolkit,but at the moment it is purely html and javscript code which I know is fine).
The error I get on the application page in my browser is:
Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
I have tried using DEBUG => 'undef' in my HTML.pm View to help with debugging, but I don't seem to get any extra output.
There is probably something very obvious I am overlooking but I cannot work out what it is.
Update
I have just noticed the following in the Config section of my browser debug screen:
Config
do {
my $a = {
"Action::RenderView" => {
ignore_classes => [
"DBIx::Class::ResultSource::Table",
"DBIx::Class::ResultSourceHandle",
"DateTime",
],
scrubber_func => sub { ... },
},
"disable_component_resolution_regex_fallback" => 1,
"home" => "/home/fred/Myproject",
"name" => "Myproject",
"Plugin::ConfigLoader" => {},
"Plugin::Static::Simple" => {
debug => 1,
dirs => [],
ignore_dirs => [],
ignore_extensions => ["tmpl", "tt", "tt2", "html", "xhtml"], <---- IS THIS SIGNIFICANT AT ALL?
include_path => [
bless({
dirs => ["", "home", "fred", "Myproject", "root"],
file_spec_class => undef,
volume => "",
}, "Path::Class::Dir"),
],
mime_types => {},
mime_types_obj => bless({}, "MIME::Types"),
no_logs => 1,
},
"root" => 'fix',
"stacktrace" => { context => 3, verbose => 0 },
"static" => 'fix',
"View::HMTL" => {
INCLUDE_PATH => [
bless({
dirs => ["", "home", "fred", "Myproject", "root", "src"],
file_spec_class => undef,
volume => "",
}, "Path::Class::Dir"),
],
},
};
$a->{"root"} = $a->{"Plugin::Static::Simple"}{include_path}[0];
$a->{"static"} = $a->{"Plugin::Static::Simple"};
$a;
}
I take it this means it is ignoring my template file because it has the .tt2 file extension?
However, I am not setting this ignore_extensions attribute anywhere in my Catalyst project? Is this the cause of my problem or something totally unrelated?
It looks like your configuration isn't taking effect. Try putting your template in root/homescreen/homescreen.tt2 instead of root/src/homescreen/homescreen.tt2, and Catalyst finds it.
Ahh, you have a typo in your lib/Myproject.pm:
__PACKAGE__->config(
#Configure the view
'View::HMTL' => {
Try 'View::HTML' instead (notice you have HMTL - wrong spelling).