How can I implement a random page button in MediaWiki? - mediawiki

I made the random page button by adding the following code to the Template.php skin file.
Html::rawElement( 'a', [
'id' => 'random',
'class' => 'random',
'href' => './index.php?title=Special:Random'
] )
But I don't like the 'href' part. Is there a way to write it like 'href' => $this->data['nav_urls']['mainpage']['href']?

I'm not sure, for what exactly you want to use it, however, the easiest part to replace the static linking to index.php?title=Special:Random would be to use the title object and let it generate a link for you. In your case something like this:
SpecialPage::getTitleFor( 'Random' )->getLinkURL()
in your full example:
Html::rawElement( 'a', [
'id' => 'random',
'class' => 'random',
'href' => SpecialPage::getTitleFor( 'Random' )->getLinkURL()
] );

Related

How to add a dot(.) in the url in yii2?

I was trying to add a dot in my URL in yii2. I am using Url rules for this.
Right now my URL looks like this.
http://localhost:8000/user/auth_key
But i want to change it to this
http://localhost:8000/.user/auth_key
My url-rules.php file looks like this.
<?php
return [
'enablePrettyUrl' => true,
'rules' => [
'user/auth_key' => 'user/authentication'
]
];
?>
without the dot(.) the URL works fine. But I need a dot(.) in URL.
Does yii2 allow us to do this? How can I achieve this?
Any suggestions or help would be really appreciated.
Yes, Yii will treat the pattern '.user/auth_key' as plain text, you can use it directly.
The full rule would be:
return [
'enablePrettyUrl' => true,
'rules' => [
'.user/auth_key' => 'user/authentication'
]
];

Pass Data Directly to yii2-tree-manager

I have a tree node in my form. I am using kartik-v's Tree Manager.
This is my view code:
echo TreeViewInput::widget([
'query' => Tree::find()->addOrderBy('root, lft'),
'headingOptions' => ['label' => 'Set Permission'],
'name' => 'name',
'value' => '1,2,3',
'asDropdown' => false,
'multiple' => true,
'fontAwesome' => true,
'rootOptions' => [
'label' => '<i class="fa fa-tree"></i>',
'class' => 'text-success'
]);
But, in this I have to follow the same table structure as mentioned in the widget. I have some extra fields and more permissions. So it is a bit complicated to use the same structure.
Is it possible to pass the value in an array directly to this widget? If possible let me know the array format.
Now I am stuck with this tree node implementation.
You can do this by doing some tricks, or by using another way:
1) you can add a condition to your query like this:
Tree::find()->andWhere(['not in','id',[2,3,4]])->addOrderBy('root, lft'),
by this solution you can ignore unwanted rows like you send data direct in array...
2) you can use another solution by using js lib/plugin direct like jsTree, in this case you can create and pass custom array direct...look at this example: jsTree Example

How to display values according to it's name in DetailView yii2?

I'm trying to display category values according to it's name, not id. I'm trying to do like so:
[
'attribute' => 'category_id',
'value' => 'category.name',
],
But then attribute doesn't get displayed. It displays: name instead of Category. Category name is displayed correctly.
Also tried 'category.name' ,but it's displaying same values, and 'category_id' is displaying label correctly, but the name - according to id's.
How should I solve that?
Are you define relation for category, like this?
public function getCategory()
{
return $this->hasOne(Category::className(),['id'=>'category_id']);
}
If you want to display in GridView, you can do it like you
[
'attribute' => 'category_id',
'value' => 'category.name',
],
If you want to display in DetailView, you can do it like this
[
'attribute' => 'category_id',
'value' => $model->category ? $model->category->name : '',
],
seems you need a label.
the simplest way is add the label direcly in the detail view item
[
'label' => 'Category',
'attribute' => 'category_id',
'value' => ....,
],

Multiple categories in Url

I want to create links something like that:
http://example.com/cat1/itemname-1
http://example.com/cat1/cat2/itemname-2
http://example.com/cat1/cat2/cat3/itemname-3
http://example.com/cat1/cat2/cat3/[..]/cat9/itemname-9
How rule looks like in yii2 UrlManager and how to create links for this?
Url::to([
'param1' => 'cat1',
'param2' => 'cat2',
'param3' => 'cat3',
'slug' => 'itemname',
'id' => 3
]);
Above code is really bad for multiple category params.
I add that important is only last param it means ID.
Controller looks like that:
public function actionProduct($id)
{
echo $id;
}
The below url rule would to this trick but you have to build the "slug" with the categories within your controller:
'rules' => [
['route' => 'module/controller/product', 'pattern' => '<slug:(.*)+>/<id:\d+>', 'encodeParams' => false],
]
Generate the Url:
yii\helpers\Url::toRoute(['/module/controller/product', 'slug' => 'cat1/cat2/cat3', 'id' => 1])
The output would be:
example.com/cat1/cat2/cat3/1

PHPStorm php-code indentation

I need these chunks of code to be indented properly like this:
$this->render('rights', array(
'admin' => $admin,
'editor' => $editor,
'author' => $author,
));
and widget snippet:
<?php $this->widget('zii.widgets.CMenu', array(
'items' => array(
array('label' => 'label', 'url' => 'url')
)
)); ?>
With default PHPStorm settings it indents this code like this:
$this->render('rights', array(
'admin' => $admin,
'editor' => $editor,
'author' => $author,
));
I went to Settings->Code Style->Wrapping and Braces and changed following options:
Array initializer -> Align when multiple (uncheck)
Method call arguments -> Align when multiple (uncheck)
The result is:
$this->render('rights', array(
'admin' => $admin,
'editor' => $editor,
'author' => $author,
));
Still not the style I want, but that's all I managed to accomplish. Can you please point me to the option I need to change?
Try selecting all the code and clicking :
Ctrl + Alt + I
It's auto indentation shortcut ...
It seems a to be a known issue. Please watch/vote or add your comments there.
I think this will help you in formatting
Your code
https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/8
I've found that unchecking the following option solves the issue for me:
Preferences > Editor > Code Style > PHP > Tab 'Wrapping and Braces' > Function/constructor call arguments > Align when multiline
This changes the following code:
var $numbers = $this->thing(array(
"one",
"two",
"three",
"four",
"five",
"six"
));
To be formatted like:
var $numbers = $this->thing(array(
"one",
"two",
"three",
"four",
"five",
"six"
));