2015-08-03 06:37:32 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-06 18:54:47 +00:00
|
|
|
namespace MediaWiki\Extension\Gadgets;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContent;
|
2017-11-07 19:36:44 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2020-04-02 00:38:28 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-08-19 04:15:51 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-02-06 18:54:47 +00:00
|
|
|
use WANObjectCache;
|
2018-02-25 02:41:50 +00:00
|
|
|
use Wikimedia\Rdbms\Database;
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
use Wikimedia\Rdbms\IExpression;
|
|
|
|
use Wikimedia\Rdbms\LikeValue;
|
2017-03-03 01:41:25 +00:00
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
* Gadgets repo powered by `MediaWiki:Gadgets/<id>.json` pages.
|
|
|
|
*
|
|
|
|
* Each gadget has its own gadget definition page, using GadgetDefinitionContent.
|
2015-08-03 06:37:32 +00:00
|
|
|
*/
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
class MediaWikiGadgetsJsonRepo extends GadgetRepo {
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
|
|
|
* How long in seconds the list of gadget ids and
|
|
|
|
* individual gadgets should be cached for (1 day)
|
|
|
|
*/
|
2020-05-20 00:10:09 +00:00
|
|
|
private const CACHE_TTL = 86400;
|
2015-08-03 06:37:32 +00:00
|
|
|
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
public const DEF_PREFIX = 'Gadgets/';
|
|
|
|
public const DEF_SUFFIX = '.json';
|
2021-10-17 13:05:15 +00:00
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
|
|
|
* @var WANObjectCache
|
|
|
|
*/
|
|
|
|
private $wanCache;
|
|
|
|
|
2020-04-02 00:38:28 +00:00
|
|
|
/**
|
|
|
|
* @var RevisionLookup
|
|
|
|
*/
|
|
|
|
private $revLookup;
|
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
public function __construct( WANObjectCache $wanCache, RevisionLookup $revLookup ) {
|
|
|
|
$this->wanCache = $wanCache;
|
|
|
|
$this->revLookup = $revLookup;
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of gadget ids from cache/database
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2022-04-05 17:47:47 +00:00
|
|
|
public function getGadgetIds(): array {
|
2017-03-03 01:41:25 +00:00
|
|
|
$key = $this->getGadgetIdsKey();
|
|
|
|
|
2018-09-30 11:38:44 +00:00
|
|
|
$fname = __METHOD__;
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
$titles = $this->wanCache->getWithSetCallback(
|
2017-03-03 01:41:25 +00:00
|
|
|
$key,
|
2015-08-03 06:37:32 +00:00
|
|
|
self::CACHE_TTL,
|
2021-05-04 07:24:31 +00:00
|
|
|
static function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
|
2017-09-24 05:26:03 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2015-08-03 06:37:32 +00:00
|
|
|
$setOpts += Database::getCacheSetOptions( $dbr );
|
2017-03-03 01:41:25 +00:00
|
|
|
|
2022-08-27 11:47:27 +00:00
|
|
|
return $dbr->newSelectQueryBuilder()
|
|
|
|
->select( 'page_title' )
|
|
|
|
->from( 'page' )
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
->where( [
|
|
|
|
'page_namespace' => NS_MEDIAWIKI,
|
|
|
|
'page_content_model' => 'GadgetDefinition',
|
|
|
|
$dbr->expr(
|
|
|
|
'page_title',
|
|
|
|
IExpression::LIKE,
|
|
|
|
new LikeValue( self::DEF_PREFIX, $dbr->anyString(), self::DEF_SUFFIX )
|
|
|
|
)
|
|
|
|
] )
|
2022-08-27 11:47:27 +00:00
|
|
|
->caller( $fname )
|
|
|
|
->fetchFieldValues();
|
2015-08-03 06:37:32 +00:00
|
|
|
},
|
2016-12-28 10:25:47 +00:00
|
|
|
[
|
2017-03-03 01:41:25 +00:00
|
|
|
'checkKeys' => [ $key ],
|
|
|
|
'pcTTL' => WANObjectCache::TTL_PROC_SHORT,
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
// Bump when changing the database query.
|
|
|
|
'version' => 2,
|
2017-03-03 01:41:25 +00:00
|
|
|
'lockTSE' => 30
|
2016-12-28 10:25:47 +00:00
|
|
|
]
|
2015-08-03 06:37:32 +00:00
|
|
|
);
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
|
|
|
|
$ids = [];
|
|
|
|
foreach ( $titles as $title ) {
|
|
|
|
$id = self::getGadgetId( $title );
|
|
|
|
if ( $id !== '' ) {
|
|
|
|
$ids[] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ids;
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 19:36:44 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2022-04-05 17:47:47 +00:00
|
|
|
public function handlePageUpdate( LinkTarget $target ): void {
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
if ( $this->isGadgetDefinitionTitle( $target ) ) {
|
2017-11-07 19:36:44 +00:00
|
|
|
$this->purgeGadgetIdsList();
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
$this->purgeGadgetEntry( self::getGadgetId( $target->getText() ) );
|
2017-11-07 19:36:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
2017-03-03 01:41:25 +00:00
|
|
|
* Purge the list of gadget ids when a page is deleted or if a new page is created
|
2015-08-03 06:37:32 +00:00
|
|
|
*/
|
2022-04-05 17:47:47 +00:00
|
|
|
public function purgeGadgetIdsList(): void {
|
2017-03-03 01:41:25 +00:00
|
|
|
$this->wanCache->touchCheckKey( $this->getGadgetIdsKey() );
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
|
|
|
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
/**
|
|
|
|
* @param string $title Gadget definition page title
|
|
|
|
* @return string Gadget ID
|
|
|
|
*/
|
|
|
|
private static function getGadgetId( string $title ): string {
|
|
|
|
if ( !str_starts_with( $title, self::DEF_PREFIX ) || !str_ends_with( $title, self::DEF_SUFFIX ) ) {
|
|
|
|
throw new InvalidArgumentException( 'Invalid definition page title' );
|
|
|
|
}
|
|
|
|
return substr( $title, strlen( self::DEF_PREFIX ), -strlen( self::DEF_SUFFIX ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param LinkTarget $target
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isGadgetDefinitionTitle( LinkTarget $target ): bool {
|
|
|
|
if ( !$target->inNamespace( NS_MEDIAWIKI ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$title = $target->getText();
|
|
|
|
try {
|
|
|
|
self::getGadgetId( $title );
|
|
|
|
return true;
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 21:23:06 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getGadgetDefinitionTitle( string $id ): ?Title {
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
return Title::makeTitleSafe( NS_MEDIAWIKI, self::DEF_PREFIX . $id . self::DEF_SUFFIX );
|
2021-12-26 21:23:06 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
/**
|
|
|
|
* @param string $id
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
* @return Gadget
|
|
|
|
*/
|
2022-04-05 17:47:47 +00:00
|
|
|
public function getGadget( string $id ): Gadget {
|
2015-08-03 06:37:32 +00:00
|
|
|
$key = $this->getGadgetCacheKey( $id );
|
|
|
|
$gadget = $this->wanCache->getWithSetCallback(
|
|
|
|
$key,
|
|
|
|
self::CACHE_TTL,
|
2017-03-03 01:41:25 +00:00
|
|
|
function ( $old, &$ttl, array &$setOpts ) use ( $id ) {
|
2017-09-24 05:26:03 +00:00
|
|
|
$setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
$title = $this->getGadgetDefinitionTitle( $id );
|
2015-08-03 06:37:32 +00:00
|
|
|
if ( !$title ) {
|
|
|
|
$ttl = WANObjectCache::TTL_UNCACHEABLE;
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-03 01:41:25 +00:00
|
|
|
|
2020-04-02 00:38:28 +00:00
|
|
|
$revRecord = $this->revLookup->getRevisionByTitle( $title );
|
|
|
|
if ( !$revRecord ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
$ttl = WANObjectCache::TTL_UNCACHEABLE;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-02 00:38:28 +00:00
|
|
|
$content = $revRecord->getContent( SlotRecord::MAIN );
|
2015-08-03 06:37:32 +00:00
|
|
|
if ( !$content instanceof GadgetDefinitionContent ) {
|
|
|
|
// Uhm...
|
|
|
|
$ttl = WANObjectCache::TTL_UNCACHEABLE;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-12-13 10:08:16 +00:00
|
|
|
$handler = $content->getContentHandler();
|
|
|
|
'@phan-var \MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContentHandler $handler';
|
|
|
|
$data = wfArrayPlus2d( $content->getAssocArray(), $handler->getDefaultMetadata() );
|
|
|
|
return Gadget::serializeDefinition( $id, $data );
|
2015-08-03 06:37:32 +00:00
|
|
|
},
|
2016-12-28 10:25:47 +00:00
|
|
|
[
|
|
|
|
'checkKeys' => [ $key ],
|
2017-03-03 01:41:25 +00:00
|
|
|
'pcTTL' => WANObjectCache::TTL_PROC_SHORT,
|
2022-08-27 10:54:28 +00:00
|
|
|
'lockTSE' => 30,
|
|
|
|
'version' => 2,
|
2016-12-28 10:25:47 +00:00
|
|
|
]
|
2015-08-03 06:37:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( $gadget === null ) {
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
throw new InvalidArgumentException( "Unknown gadget $id" );
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
|
|
|
|
2022-08-27 10:54:28 +00:00
|
|
|
return new Gadget( $gadget );
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
2017-03-03 01:41:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the cache for a specific Gadget whenever it is updated
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
*/
|
|
|
|
public function purgeGadgetEntry( $id ) {
|
|
|
|
$this->wanCache->touchCheckKey( $this->getGadgetCacheKey( $id ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getGadgetIdsKey() {
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
return $this->wanCache->makeKey( 'gadgets-jsonrepo-ids' );
|
2017-03-03 01:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-25 02:41:50 +00:00
|
|
|
* @param string $id
|
2017-03-03 01:41:25 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getGadgetCacheKey( $id ) {
|
Goodbye Gadget/Gadget_definition namespaces!
== What ==
* Remove the empty Gadget and Gadget_definition namespaces.
* Remove the "gadgets-definition-edit" user right.
* Remove need for custom namespace permissions that previously
had to extend editsitejs to apply to NS_GADGET.
== Why ==
Simplify the (unused) "GadgetDefinitionNamespaceRepo" backend for
Gadgets 2.0 by making it less radically different from the status quo.
The experimental 2.0 branch will now make use of the "gadget definition"
content model via "MediaWiki:Gadgets/<id>.json" pages, instead of
through a dedicated namespace.
When I first worked the Gadgets 2.0 branch, content models
were not a thing in MediaWiki, and interface-admin wasn't a thing yet
either. Now that we have per-page permissions and per-page content
models, we don't really need a separate namespace.
This follows the principle of least surprise, and fits well with other
interface admin and site configuration tools such as:
- Citoid, MediaWiki:Citoid-template-type-map.json,
- VisualEditor, MediaWiki:Visualeditor-template-tools-definition.json,
- AbuseFilter, MediaWiki:BlockedExternalDomains.json,
- the upcoming "Community Config" initiative.
If/when we develop the SpecialPage GUI for editing gadget definitions,
this can save its data to these pages the same as it would in
any other namespace. Similar to how Special:BlockedExternalDomains
operates on MediaWiki:BlockedExternalDomains.json.
See also bf1d6b3e93 (I6ffd5e9467), which recently removed the
gadgets-edit user right in favour of the editsite{css,js,json} rights.
Change-Id: I5b04ab251552e839087d0a8a6923d205adc7f771
2023-12-05 23:28:45 +00:00
|
|
|
return $this->wanCache->makeKey( 'gadgets-object', $id, Gadget::GADGET_CLASS_VERSION );
|
2017-03-03 01:41:25 +00:00
|
|
|
}
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|