2011-04-16 16:29:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2023-10-25 22:32:58 +00:00
|
|
|
*
|
|
|
|
* @file
|
2011-04-16 16:29:33 +00:00
|
|
|
*/
|
|
|
|
|
2023-10-25 22:32:58 +00:00
|
|
|
namespace MediaWiki\Extension\Gadgets\Api;
|
|
|
|
|
2024-10-19 23:15:50 +00:00
|
|
|
use MediaWiki\Api\ApiBase;
|
|
|
|
use MediaWiki\Api\ApiQuery;
|
|
|
|
use MediaWiki\Api\ApiQueryBase;
|
|
|
|
use MediaWiki\Api\ApiResult;
|
2023-10-25 22:32:58 +00:00
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
|
|
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
|
|
|
2011-04-16 16:29:33 +00:00
|
|
|
class ApiQueryGadgets extends ApiQueryBase {
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private array $props;
|
2015-06-17 18:21:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array|bool
|
|
|
|
*/
|
|
|
|
private $categories;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array|bool
|
|
|
|
*/
|
|
|
|
private $neededIds;
|
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private bool $listAllowed;
|
2015-06-17 18:21:27 +00:00
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private bool $listEnabled;
|
2015-06-17 18:21:27 +00:00
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
private GadgetRepo $gadgetRepo;
|
|
|
|
|
2024-10-25 17:49:08 +00:00
|
|
|
public function __construct(
|
|
|
|
ApiQuery $queryModule,
|
|
|
|
string $moduleName,
|
|
|
|
GadgetRepo $gadgetRepo
|
|
|
|
) {
|
2015-06-17 18:21:27 +00:00
|
|
|
parent::__construct( $queryModule, $moduleName, 'ga' );
|
2022-08-16 15:24:01 +00:00
|
|
|
$this->gadgetRepo = $gadgetRepo;
|
2011-04-16 16:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
$this->props = array_flip( $params['prop'] );
|
2011-04-16 18:39:36 +00:00
|
|
|
$this->categories = isset( $params['categories'] )
|
|
|
|
? array_flip( $params['categories'] )
|
|
|
|
: false;
|
2011-09-12 11:17:44 +00:00
|
|
|
$this->neededIds = isset( $params['ids'] )
|
|
|
|
? array_flip( $params['ids'] )
|
2011-04-16 18:39:36 +00:00
|
|
|
: false;
|
2011-07-25 16:01:52 +00:00
|
|
|
$this->listAllowed = isset( $params['allowedonly'] ) && $params['allowedonly'];
|
|
|
|
$this->listEnabled = isset( $params['enabledonly'] ) && $params['enabledonly'];
|
2011-04-16 18:39:36 +00:00
|
|
|
|
|
|
|
$this->getMain()->setCacheMode( $this->listAllowed || $this->listEnabled
|
|
|
|
? 'anon-public-user-private' : 'public' );
|
2011-04-16 16:29:33 +00:00
|
|
|
|
|
|
|
$this->applyList( $this->getList() );
|
|
|
|
}
|
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private function getList(): array {
|
2022-08-16 15:24:01 +00:00
|
|
|
$gadgets = $this->gadgetRepo->getStructuredList();
|
2011-04-16 16:29:33 +00:00
|
|
|
|
2019-03-17 23:39:02 +00:00
|
|
|
if ( !$gadgets ) {
|
2016-12-28 10:25:47 +00:00
|
|
|
return [];
|
2013-09-11 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 10:25:47 +00:00
|
|
|
$result = [];
|
2011-04-16 16:29:33 +00:00
|
|
|
foreach ( $gadgets as $category => $list ) {
|
2011-04-16 18:39:36 +00:00
|
|
|
if ( $this->categories && !isset( $this->categories[$category] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2011-04-16 16:29:33 +00:00
|
|
|
foreach ( $list as $g ) {
|
|
|
|
if ( $this->isNeeded( $g ) ) {
|
|
|
|
$result[] = $g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private function applyList( array $gadgets ): void {
|
2016-12-28 10:25:47 +00:00
|
|
|
$data = [];
|
2011-04-16 16:29:33 +00:00
|
|
|
$result = $this->getResult();
|
|
|
|
|
2012-02-17 21:23:46 +00:00
|
|
|
/**
|
|
|
|
* @var $g Gadget
|
|
|
|
*/
|
2011-04-16 16:29:33 +00:00
|
|
|
foreach ( $gadgets as $g ) {
|
2016-12-28 10:25:47 +00:00
|
|
|
$row = [];
|
2011-09-12 11:17:44 +00:00
|
|
|
if ( isset( $this->props['id'] ) ) {
|
|
|
|
$row['id'] = $g->getName();
|
2011-04-16 16:29:33 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2011-09-01 16:08:47 +00:00
|
|
|
if ( isset( $this->props['metadata'] ) ) {
|
|
|
|
$row['metadata'] = $this->fakeMetadata( $g );
|
|
|
|
$this->setIndexedTagNameForMetadata( $row['metadata'] );
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2011-04-16 16:29:33 +00:00
|
|
|
if ( isset( $this->props['desc'] ) ) {
|
|
|
|
$row['desc'] = $g->getDescription();
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2011-04-16 16:29:33 +00:00
|
|
|
$data[] = $row;
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2021-10-09 00:34:45 +00:00
|
|
|
ApiResult::setIndexedTagName( $data, 'gadget' );
|
2011-04-16 16:29:33 +00:00
|
|
|
$result->addValue( 'query', $this->getModuleName(), $data );
|
|
|
|
}
|
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private function isNeeded( Gadget $gadget ): bool {
|
2012-08-17 09:28:09 +00:00
|
|
|
$user = $this->getUser();
|
2011-04-16 18:39:36 +00:00
|
|
|
|
2011-09-12 11:17:44 +00:00
|
|
|
return ( $this->neededIds === false || isset( $this->neededIds[$gadget->getName()] ) )
|
2012-08-17 09:28:09 +00:00
|
|
|
&& ( !$this->listAllowed || $gadget->isAllowed( $user ) )
|
|
|
|
&& ( !$this->listEnabled || $gadget->isEnabled( $user ) );
|
2011-04-16 16:29:33 +00:00
|
|
|
}
|
2011-09-09 11:11:22 +00:00
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private function fakeMetadata( Gadget $g ): array {
|
2016-12-28 10:25:47 +00:00
|
|
|
return [
|
|
|
|
'settings' => [
|
2021-12-14 13:10:22 +00:00
|
|
|
'actions' => $g->getRequiredActions(),
|
2024-02-20 13:55:52 +00:00
|
|
|
'categories' => $g->getRequiredCategories(),
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
'category' => $g->getCategory(),
|
2023-05-22 08:41:15 +00:00
|
|
|
'contentModels' => $g->getRequiredContentModels(),
|
2011-09-01 16:08:47 +00:00
|
|
|
'default' => $g->isOnByDefault(),
|
2015-08-03 06:34:16 +00:00
|
|
|
'hidden' => $g->isHidden(),
|
2015-06-13 02:33:35 +00:00
|
|
|
'legacyscripts' => (bool)$g->getLegacyScripts(),
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
'namespaces' => $g->getRequiredNamespaces(),
|
|
|
|
'package' => $g->isPackaged(),
|
2022-01-30 13:15:25 +00:00
|
|
|
'requiresES6' => $g->requiresES6(),
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
'rights' => $g->getRequiredRights(),
|
|
|
|
'shared' => false,
|
|
|
|
'skins' => $g->getRequiredSkins(),
|
2022-01-11 09:03:44 +00:00
|
|
|
'supportsUrlLoad' => $g->supportsUrlLoad(),
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
'module' => [
|
2021-10-17 13:05:15 +00:00
|
|
|
'datas' => $g->getJSONs(),
|
2011-09-01 16:08:47 +00:00
|
|
|
'dependencies' => $g->getDependencies(),
|
2015-08-03 06:34:16 +00:00
|
|
|
'messages' => $g->getMessages(),
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
'peers' => $g->getPeers(),
|
|
|
|
'scripts' => $g->getScripts(),
|
|
|
|
'styles' => $g->getStyles(),
|
2016-12-28 10:25:47 +00:00
|
|
|
]
|
|
|
|
];
|
2011-09-01 16:08:47 +00:00
|
|
|
}
|
|
|
|
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
private function setIndexedTagNameForMetadata( array &$metadata ): void {
|
2016-12-28 10:25:47 +00:00
|
|
|
static $tagNames = [
|
2021-12-14 13:10:22 +00:00
|
|
|
'actions' => 'action',
|
2024-02-20 13:55:52 +00:00
|
|
|
'categories' => 'category',
|
2023-05-22 08:41:15 +00:00
|
|
|
'contentModels' => 'contentModel',
|
2021-10-17 13:05:15 +00:00
|
|
|
'datas' => 'data',
|
2011-09-01 16:08:47 +00:00
|
|
|
'dependencies' => 'dependency',
|
|
|
|
'messages' => 'message',
|
Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.
* Re-format "rights" as a sentence instead of a bullet list. It was
the only one using a bullet list, which made it feel a bit long.
* Re-format "actions" as `<code>` since they are not localised.
* Re-format "contentModels" as `<code>`, and add the localised display
name in a title attribute, same as we do with "rights" already.
ContentHandler::getLocalizedName() is also used already on
Special:ChangeContentModel.
* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
if a gadget also sets "supportsUrlLoad", then that sentence is
appended to the previous line.
Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.
In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).
Highlights:
* Fix namespace IDs type. These can be strings when they are parsed
from the gadget definition text, not always integers.
* Add explicit default for 'category'. In theory not needed because
MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
`category: ''` is part of both the initial page content, as well
as merged via getDefaultMetadata.
This default benefits simpler test cases, and static analysis,
since the Gadget class constructor does not (yet) require it.
Without this, getCategory() could TypeError due to returning null.
Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-16 23:32:44 +00:00
|
|
|
'namespaces' => 'namespace',
|
|
|
|
'peers' => 'peer',
|
|
|
|
'rights' => 'right',
|
|
|
|
'scripts' => 'script',
|
|
|
|
'skins' => 'skin',
|
|
|
|
'styles' => 'style',
|
2016-12-28 10:25:47 +00:00
|
|
|
];
|
2011-09-09 11:11:22 +00:00
|
|
|
|
2017-10-09 23:20:26 +00:00
|
|
|
foreach ( $metadata as $data ) {
|
|
|
|
foreach ( $data as $key => $value ) {
|
2011-09-01 16:08:47 +00:00
|
|
|
if ( is_array( $value ) ) {
|
2019-03-17 23:39:02 +00:00
|
|
|
$tag = $tagNames[$key] ?? $key;
|
2021-10-09 00:34:45 +00:00
|
|
|
ApiResult::setIndexedTagName( $value, $tag );
|
2011-09-01 16:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-16 16:29:33 +00:00
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2016-12-28 10:25:47 +00:00
|
|
|
return [
|
|
|
|
'prop' => [
|
2021-10-09 00:34:45 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 'id|metadata',
|
2022-04-03 23:27:06 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
ParamValidator::PARAM_TYPE => [
|
2011-09-12 11:17:44 +00:00
|
|
|
'id',
|
2011-09-01 16:08:47 +00:00
|
|
|
'metadata',
|
2011-04-16 16:29:33 +00:00
|
|
|
'desc',
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
2023-08-04 23:47:04 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
'categories' => [
|
2022-04-03 23:27:06 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
|
|
|
'ids' => [
|
2022-04-03 23:27:06 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2016-12-28 10:25:47 +00:00
|
|
|
],
|
2011-07-25 16:01:52 +00:00
|
|
|
'allowedonly' => false,
|
|
|
|
'enabledonly' => false,
|
2016-12-28 10:25:47 +00:00
|
|
|
];
|
2011-04-16 16:29:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:57:35 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-08-27 14:07:08 +00:00
|
|
|
* @return array
|
2014-10-29 15:57:35 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
|
|
|
$params = $this->getAllowedParams();
|
2022-04-03 23:27:06 +00:00
|
|
|
$allProps = implode( '|', $params['prop'][ParamValidator::PARAM_TYPE] );
|
2016-12-28 10:25:47 +00:00
|
|
|
return [
|
2014-10-29 15:57:35 +00:00
|
|
|
'action=query&list=gadgets&gaprop=id|desc'
|
|
|
|
=> 'apihelp-query+gadgets-example-1',
|
|
|
|
"action=query&list=gadgets&gaprop=$allProps"
|
|
|
|
=> 'apihelp-query+gadgets-example-2',
|
|
|
|
'action=query&list=gadgets&gacategories=foo'
|
|
|
|
=> 'apihelp-query+gadgets-example-3',
|
|
|
|
'action=query&list=gadgets&gaids=foo|bar&gaprop=id|desc|metadata'
|
|
|
|
=> 'apihelp-query+gadgets-example-4',
|
|
|
|
'action=query&list=gadgets&gaenabledonly'
|
|
|
|
=> 'apihelp-query+gadgets-example-5',
|
2016-12-28 10:25:47 +00:00
|
|
|
];
|
2011-04-16 16:29:33 +00:00
|
|
|
}
|
2011-04-16 18:39:36 +00:00
|
|
|
}
|