MediaWiki, how to add filters to the SpecialPages:Categories page? - mediawiki

To better understand the code of MediaWiki, I'm trying to modify directly the source code without creating an extension.
In the page Special:Categories I'd like to show only the categories which are not created by a Template. How can I modify the query?
https://doc.wikimedia.org/mediawiki-core/1.28.0/php/classSpecialCategories.html
https://doc.wikimedia.org/mediawiki-core/1.28.0/php/classCategoryPager.html

I've found the solution
The source code for the Special Pages is inside the folder includes/specials. There are many scripts here about categories and by comparing some of those files I could find out the syntax used to manipulate queries in mediawiki which is defined through the method getQueryInfo() inside each file.
I'm posting the queries defined each in a different Special Page related to categories
public function getQueryInfo() {
return [
'tables' => [ 'category' ],
'fields' => [ 'title' => 'cat_title',
'namespace' => NS_CATEGORY,
'value' => 'cat_pages' ],
'conds' => [ 'cat_pages > 0' ],
];
}
public function getQueryInfo() {
return [
'tables' => [ 'categorylinks', 'page' ],
'fields' => [
'namespace' => 'page_namespace',
'title' => 'page_title',
'value' => 'COUNT(*)'
],
'conds' => [
'page_namespace' => $this->namespaceInfo->getContentNamespaces()
],
'options' => [
'HAVING' => 'COUNT(*) > 1',
'GROUP BY' => [ 'page_namespace', 'page_title' ]
],
'join_conds' => [
'page' => [
'LEFT JOIN',
'page_id = cl_from'
]
]
];
}

Related

How to also get custom fields of documents from Elasticsearch using Laravel Scout Elasticsearch Driver?

Below is the link to the Scout Elasticsearch Drive which I am using in my Laravel project.
https://github.com/babenkoivan/scout-elasticsearch-driver
I have database table users with the following columns:
id Integer
name String
created_at DateTime
Following the documentation on GitHub, my mapping in the User model looks like followings:
use Searchable; // using Searchable trait.
protected $mapping = [
'properties' => [
'name' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
'created_at' => [
'type' => 'date',
'format' => 'dd-MM-yyyy HH:mm',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
// Custom field...
'created_date' => [
'type' => 'date',
'format' => 'dd-MM-yyyy',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
// Custom field...
'created_time' => [
'type' => 'date',
'format' => 'HH:mm',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
]
]
Below is the implementation of the toSearchableArray() function.
public function toSearchableArray()
{
$array = $this->toArray();
// Pre-format the custom fields before inserting them into Elasticsearch.
$array['created_date'] = $this->created_at->format('d-m-Y');
$array['created_time'] = $this->created_at->format('h:i');
return $array;
}
When using curl -X GET command I get the following results and of course with the custom fields.
"hits" : [
{
"_source" : {
"id" : 3,
"name": "John Doe",
"created_at": "31-12-2018 23:59",
"created_date": "31-12-2018", // My custom field.
"created_time": "23:59" // My custom field.
}
]
In my index() action in my controller, I query the data using the following code.
public function index()
{
return User::search("*")->get();
}
I get the records with only the original attributes, matching those columns in the database table as following.
[
{
"id" : 3,
"name": "John Doe",
"created_at": "31-12-2018 23:59",
}
]
Note that this is a JSON response provided by default by Laravel, responding to API calls. My custom attributes created_date and created_time do exist in Elasticsearch as well. How can I get them too as result? The reason I created these custom fields is to format the date and time on the server side beforehands so that my client-side does not need to worry about formating the date and time in the for-loop.
When I use User::search("*")->explain(); I do get my custom fields as well in the hits.hits._source{} object.
This should give you results directly from Elastic Search without matching up with your related models. I think thats the reason why your custom fields get lost.
public function index()
{
return User::search("*")->raw();
}
Documentation

Use of condition in query builder in case of multiple association in cakephp 3.0?

I am facing trouble in multilevel association using query builder when i used conditions inside multiple contain in cakephp 3.0. Lets suppose i have to get a data of single store so i am trying to add the storeId in condition but its not working else rest of data is fetching correct from all store below are the query builder that i am using:-
// generate query
$bestSellingReportData = $this->ArticleMaster->find('all')->contain([
'Category' => [
'fields' => ['Cat_Id', 'Cat_Code']
],
'size_category' => [
'fields' => ['sizeCat_Id', 'sizeCat_Code']
],
'ItemMaster' => [
'Invoicedetaile' => [
'Invoice' => [
'Store' => [
'fields' => ['Store_Id', 'Store_Code']
],
'conditions' => ['Invoice.StoreId ='.$this->request->data['storeId']],
],
],
],
]);
$bestSellingReportData->select(['totalSoldItems' => $bestSellingReportData->func()->sum('Invoicedetaile.Qty')])
->matching('ItemMaster.Invoicedetaile', function ($q) {
return $q->where([
'AND' => [
'Invoicedetaile.ItemId = ItemMaster.Item_ID',
]
]);
})
->group(['ArticleMaster.Article_Code'])
->order(['totalSoldItems' => 'DESC'])
->autoFields(true);
I try to add the condition in both way using add condition and in where clause. But data is not filtering based on conditions i.e storeId
Work for me after doing R&D of many hours. Below is the query builder that work for me.
$bestSellingReportData = $this->ArticleMaster->find('all')->contain([
'Category' => [
'fields' => ['Cat_Id', 'Cat_Code']
],
'size_category' => [
'fields' => ['sizeCat_Id', 'sizeCat_Code']
],
'ItemMaster' => [
'Invoicedetaile' => [
'Invoice',
],
],
]);
$storeId = $this->request->data['storeId'];
$bestSellingReportData->select(['totalSoldItems' => $bestSellingReportData->func()->sum('Invoicedetaile.Qty')])
->matching('ItemMaster.Invoicedetaile.Invoice', function ($q) use ($storeId) {
return $q->where([
'AND' => [
'Invoicedetaile.ItemId = ItemMaster.Item_ID',
'Invoice.StoreId ='.$storeId,
]
]);
})
->group(['ArticleMaster.Article_Code'])
->order(['totalSoldItems' => 'DESC'])
->autoFields(true);

ZF3 zend-mvc generic route for many controllers in one module not working

I'm in ZF3, using the zend-mvc-skeleton and trying to configure a generic route that will match as many URLs as possible as I want to be able to create new controllers (including action methods of course), and have them immediately available.
The common approach described in the documentation is to write a route that matches the controller and action (same with ZF2).
Here is my module.config.php
namespace Application;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'default' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:controller[/:action]]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
'constraints' => [
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
],
],
],
],
],
'controllers' => [/* ... */],
'view_manager' => [/* ... */],
],
It works like a charm for http://localhost/ and http://localhost/application calling the indexAction() function of the IndexController class inside the /module/Application/src/IndexController.php file.
However, it's not working when I try to get the fooAction() function in the same Controller (i.e. IndexController). It's not resolving correctly http://localhost/application/foo. and I get the following error:
A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
foo (resolves to invalid controller class or alias: foo)
No Exception available
Same error if I try http://localhost/bar/foo to get the fooAction() in the barController.
Do you have any idea of what's wrong with this? Any help will be appreciated. Many thanks.
The route http://localhost/application/foo won't resolve to fooAction() in the index controller, since /foo in the URL will match the controller not the action. With that route setup you would need to visit http://localhost/application/index/foo.
To get it working you'll also need to make sure you have aliased your controller in the config, e.g. assuming you have:
'controllers' => [
'invokables' => [
'Application\Controller\Index' => \Application\Controller\IndexController::class
]
],
Then alias the controller so it matches the route parameter:
'controllers' => [
'invokables' => [
'Application\Controller\Index' => \Application\Controller\IndexController::class
],
'aliases' => [
'index' => 'Application\Controller\Index'
]
],
You'll need to add aliases that match the route parameter for each controller that isn't registered using the string you want for the route, e.g. a controller Namespace\Controller\BarController should be aliased to bar, etc.
I came here with similar problem. I have created two controllers in
"Application" module, and two in new module "Account" with the same name.
Application/Controller/IndexController
Application/Controller/OverviewController
Account/Controller/IndexController
Account/Controller/OverviewController
here are my modules.config.php
module/Account/config/module.config.php
return [
'router' => [
'routes' => [
'Account-account' => [
'type' => Segment::class,
'options' => [
'route' => '/account[/][:controller[/][:action][/]]',
'defaults' => [
'__NAMESPACE__' => 'Account\Controller',
'controller' => Account\Controller\IndexController::class,
'action' => 'index',
'locale' => 'en_us'
],
],
'may_terminate' => true,
'child_routes' => [
'wildcard' => [
'type' => 'Wildcard'
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => AccountControllerFactory::class,
Controller\OverviewController::class => AccountControllerFactory::class,
],
'aliases' => [
'index' => IndexController::class,
'overview' => OverviewController::class
]
],
and my
module/Application/config/module.config.php
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'Application-application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/][:controller[/][:action][/]]',
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => Application\Controller\IndexController::class,
'action' => 'index',
'locale' => 'en_US'
],
],
'may_terminate' => true,
'child_routes' => [
'wildcard' => [
'type' => 'Wildcard'
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => IndexControllerFactory::class,
Controller\OverviewController::class => IndexControllerFactory::class,
],
'aliases' => [
'index' => IndexController::class,
'overview' => OverviewController::class,
]
],
With this configuration if aliases sections are commented there is a error message which says that there is invalid controller or alias (index/overview).
If there are aliases
route: "application/overview/index" goes into Account module.

Edit content of export menu in yii2

I use export menu on my yii2 project. I download it from demos.krajee.com. I have been success to use it, but I want to edit content like in pdf, so it have title/header or footer or page number. How to make it?
There are at least two ways to do that.
For example you can set it as default setting in
Yii::$container->set('kartik\grid\GridView', [
'summary' => "Showing {begin} - {end} from {totalCount} records",
'captionOptions' => ['style' => 'font-size:0em;'],
'panel' => [
'heading' => false,
'before' => '{summary}',
'after' => '{pager}',
'footer' => false,
],
'hover' => true,
'toolbar' => [
'{export}',
'{toggleData}',
],
'export' =>[
'showConfirmAlert' => false,
],
'exportConfig' => [
kartik\grid\GridView::PDF => [
'label' => 'Save as PDF',
'config' => [
'methods' => [
'SetHeader' => ['Header'],
'SetFooter' => ['Footer whatever: ' . strftime("%c") . '||Page {PAGENO}'],
]
],
],
],
...
Or pass the settings individually to each widget in every view.
You can use methods in wrapper http://demos.krajee.com/mpdf#settings (look for methods) or directly from mpdf class if you need something more complicated.

Yii2 Apply a function to all requests

Is there any way to apply a function to all requests and queries in Yii2?
I want to replace specific characters for all of them.
I am using Yii2 advanced app
Thanks.
This is the config file:
$config = [
'language' => 'en',
'components' => [
'request' => [
'cookieValidationKey' => 'something',
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
'defaultRoles' => ['guest'],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
return $config;
Without extending custom code on each request can be exexuted like so (add this to your application config):
return [
'on beforeRequest' => function () {
if (!Yii::$app->get('user', false)) {
return;
}
$user = User::getCurrent();
if ($user) {
Yii::$app->setTimeZone($user->time_zone);
}
},
'on afterRequest' => function () {
...
},
];
Depending on when you need to execute code (before or after the request) use 'on beforeRequest' or 'on afterRequest' accordingly.
yii2 have a request component. You can extend yii\web\request and define your custom implementation.
[
...
'components' =>
'request' => [
'class' => '\common\MyRequest',
'addGeoLocationForExample' => true,
]
...