2007-07-31 10:21:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-10-25 22:32:58 +00:00
|
|
|
* 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
|
2008-02-04 08:08:43 +00:00
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
2007-07-31 10:21:34 +00:00
|
|
|
*/
|
|
|
|
|
2023-10-30 15:36:33 +00:00
|
|
|
namespace MediaWiki\Extension\Gadgets\Special;
|
2022-02-06 18:54: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
|
|
|
use ContentHandler;
|
2022-02-06 18:54:47 +00:00
|
|
|
use HTMLForm;
|
|
|
|
use InvalidArgumentException;
|
2023-10-30 15:36:33 +00:00
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
|
|
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
2024-01-06 16:45:07 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2018-08-04 22:47:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-01-06 16:45:07 +00:00
|
|
|
use MediaWiki\Parser\Sanitizer;
|
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-08-19 04:15:51 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2018-08-04 22:47:17 +00:00
|
|
|
|
2023-10-25 22:32:58 +00:00
|
|
|
/**
|
|
|
|
* Special:Gadgets renders the data of MediaWiki:Gadgets-definition.
|
|
|
|
*
|
|
|
|
* @copyright 2007 Daniel Kinzler
|
|
|
|
*/
|
2007-07-31 10:21:34 +00:00
|
|
|
class SpecialGadgets extends SpecialPage {
|
2022-08-16 15:24:01 +00:00
|
|
|
private GadgetRepo $gadgetRepo;
|
|
|
|
|
|
|
|
public function __construct( GadgetRepo $gadgetRepo ) {
|
2022-08-08 15:44:05 +00:00
|
|
|
parent::__construct( 'Gadgets' );
|
2022-08-16 15:24:01 +00:00
|
|
|
$this->gadgetRepo = $gadgetRepo;
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2008-02-04 08:08:43 +00:00
|
|
|
|
2024-02-07 13:04:41 +00:00
|
|
|
/**
|
|
|
|
* Return title for Special:Gadgets heading and Special:Specialpages link.
|
|
|
|
*
|
|
|
|
* @return \Message
|
|
|
|
*/
|
|
|
|
public function getDescription() {
|
|
|
|
return $this->msg( 'special-gadgets' );
|
|
|
|
}
|
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
/**
|
2019-06-04 15:32:42 +00:00
|
|
|
* @param string|null $par Parameters passed to the page
|
2007-07-31 10:21:34 +00:00
|
|
|
*/
|
2015-06-17 18:21:27 +00:00
|
|
|
public function execute( $par ) {
|
2022-06-29 00:37:36 +00:00
|
|
|
$parts = $par !== null ? explode( '/', $par ) : [];
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2023-07-01 13:26:33 +00:00
|
|
|
if ( count( $parts ) === 2 && $parts[0] === 'export' ) {
|
2010-09-16 17:28:21 +00:00
|
|
|
$this->showExportForm( $parts[1] );
|
2010-08-08 18:22:22 +00:00
|
|
|
} else {
|
|
|
|
$this->showMainForm();
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2020-10-12 09:32:09 +00:00
|
|
|
/**
|
|
|
|
* @param string $gadgetName
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-18 04:54:17 +00:00
|
|
|
private function makeAnchor( $gadgetName ) {
|
2019-02-22 20:25:45 +00:00
|
|
|
return 'gadget-' . Sanitizer::escapeIdForAttribute( $gadgetName );
|
2016-11-18 04:54:17 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 18:22:22 +00:00
|
|
|
/**
|
|
|
|
* Displays form showing the list of installed gadgets
|
|
|
|
*/
|
|
|
|
public function showMainForm() {
|
2012-07-11 22:18:10 +00:00
|
|
|
$output = $this->getOutput();
|
2008-01-14 22:46:14 +00:00
|
|
|
$this->setHeaders();
|
2019-07-17 19:39:36 +00:00
|
|
|
$this->addHelpLink( 'Extension:Gadgets' );
|
2024-02-17 01:57:11 +00:00
|
|
|
$output->setPageTitleMsg( $this->msg( 'gadgets-title' ) );
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addWikiMsg( 'gadgets-pagetext' );
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
$gadgets = $this->gadgetRepo->getStructuredList();
|
2012-07-11 22:18:10 +00:00
|
|
|
if ( !$gadgets ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2020-08-23 07:27:14 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
$output->disallowUserJs();
|
2012-07-11 22:18:10 +00:00
|
|
|
$lang = $this->getLanguage();
|
|
|
|
$langSuffix = "";
|
2020-08-23 07:27:14 +00:00
|
|
|
if ( !$lang->equals( $services->getContentLanguage() ) ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$langSuffix = "/" . $lang->getCode();
|
2008-08-17 15:42:26 +00:00
|
|
|
}
|
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
$listOpen = false;
|
2007-07-31 10:21:34 +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
|
|
|
$editDefinitionMessage = $this->getUser()->isAllowed( 'editsitejs' )
|
2012-05-18 09:49:15 +00:00
|
|
|
? 'edit'
|
|
|
|
: 'viewsource';
|
2021-12-26 21:23:06 +00:00
|
|
|
$editInterfaceMessage = $this->getUser()->isAllowed( 'editinterface' )
|
|
|
|
? 'gadgets-editdescription'
|
|
|
|
: 'gadgets-viewdescription';
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2017-02-04 21:06:01 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
2020-08-23 07:27:14 +00:00
|
|
|
$skinFactory = $services->getSkinFactory();
|
2007-07-31 10:21:34 +00:00
|
|
|
foreach ( $gadgets as $section => $entries ) {
|
|
|
|
if ( $section !== false && $section !== '' ) {
|
2024-01-17 16:09:14 +00:00
|
|
|
if ( $listOpen ) {
|
|
|
|
$output->addHTML( Html::closeElement( 'ul' ) . "\n" );
|
|
|
|
$listOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// H2 section heading
|
2024-01-17 16:18:01 +00:00
|
|
|
$headingText = Html::rawElement(
|
|
|
|
'span',
|
|
|
|
[ 'class' => 'mw-headline' ],
|
|
|
|
$this->msg( "gadget-section-$section" )->parse()
|
|
|
|
);
|
2024-01-17 15:59:17 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$langSuffix" );
|
2024-01-17 16:18:01 +00:00
|
|
|
$leftBracket = Html::rawElement(
|
|
|
|
'span',
|
|
|
|
[ 'class' => 'mw-editsection-bracket' ],
|
|
|
|
'['
|
|
|
|
);
|
2024-01-17 15:59:17 +00:00
|
|
|
$linkTarget = $title
|
|
|
|
? $linkRenderer->makeLink( $title, $this->msg( $editInterfaceMessage )->text(),
|
2017-02-04 21:06:01 +00:00
|
|
|
[], [ 'action' => 'edit' ] )
|
2012-05-18 09:49:15 +00:00
|
|
|
: htmlspecialchars( $section );
|
2024-01-17 16:18:01 +00:00
|
|
|
$rightBracket = Html::rawElement(
|
|
|
|
'span',
|
|
|
|
[ 'class' => 'mw-editsection-bracket' ],
|
|
|
|
']'
|
|
|
|
);
|
|
|
|
$editDescriptionLink = Html::rawElement(
|
|
|
|
'span',
|
|
|
|
[ 'class' => 'mw-editsection' ],
|
|
|
|
$leftBracket . $linkTarget . $rightBracket
|
|
|
|
);
|
|
|
|
$output->addHTML( Html::rawElement( 'h2', [], $headingText . $editDescriptionLink ) . "\n" );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2008-02-04 08:08:43 +00:00
|
|
|
|
2012-02-17 21:23:46 +00:00
|
|
|
/**
|
2024-01-17 15:52:04 +00:00
|
|
|
* @var Gadget $gadget
|
2012-02-17 21:23:46 +00:00
|
|
|
*/
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $entries as $gadget ) {
|
2016-11-18 04:54:17 +00:00
|
|
|
$name = $gadget->getName();
|
2024-01-17 15:59:17 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$name}$langSuffix" );
|
|
|
|
if ( !$title ) {
|
2011-09-23 06:48:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2016-12-28 10:25:47 +00:00
|
|
|
$links = [];
|
2022-08-16 15:24:01 +00:00
|
|
|
$definitionTitle = $this->gadgetRepo->getGadgetDefinitionTitle( $name );
|
2021-12-26 21:23:06 +00:00
|
|
|
if ( $definitionTitle ) {
|
|
|
|
$links[] = $linkRenderer->makeLink(
|
|
|
|
$definitionTitle,
|
|
|
|
$this->msg( $editDefinitionMessage )->text(),
|
|
|
|
[],
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
);
|
|
|
|
}
|
2017-02-04 21:06:01 +00:00
|
|
|
$links[] = $linkRenderer->makeLink(
|
2024-01-17 15:59:17 +00:00
|
|
|
$title,
|
2017-02-04 21:06:01 +00:00
|
|
|
$this->msg( $editInterfaceMessage )->text(),
|
2016-12-28 10:25:47 +00:00
|
|
|
[],
|
|
|
|
[ 'action' => 'edit' ]
|
2012-09-02 23:10:23 +00:00
|
|
|
);
|
2017-02-04 21:06:01 +00:00
|
|
|
$links[] = $linkRenderer->makeLink(
|
2016-11-18 04:54:17 +00:00
|
|
|
$this->getPageTitle( "export/{$name}" ),
|
2017-02-04 21:06:01 +00:00
|
|
|
$this->msg( 'gadgets-export' )->text()
|
2012-09-02 23:10:23 +00:00
|
|
|
);
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
$nameHtml = $this->msg( "gadget-{$name}" )->parse();
|
2008-07-07 18:50:47 +00:00
|
|
|
|
2011-09-23 06:48:37 +00:00
|
|
|
if ( !$listOpen ) {
|
2007-11-16 20:13:25 +00:00
|
|
|
$listOpen = true;
|
2018-09-17 22:28:15 +00:00
|
|
|
$output->addHTML( Html::openElement( 'ul' ) );
|
2007-11-16 20:13:25 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
$actionsHtml = '  ' .
|
2015-02-07 13:31:19 +00:00
|
|
|
$this->msg( 'parentheses' )->rawParams( $lang->pipeList( $links ) )->escaped();
|
2016-11-18 04:54:17 +00:00
|
|
|
$output->addHTML(
|
2018-09-17 22:28:15 +00:00
|
|
|
Html::openElement( 'li', [ 'id' => $this->makeAnchor( $name ) ] ) .
|
|
|
|
$nameHtml . $actionsHtml
|
2010-01-12 19:45:49 +00:00
|
|
|
);
|
2018-09-17 22:28:15 +00:00
|
|
|
// Whether the next portion of the list item contents needs
|
|
|
|
// a line break between it and the next portion.
|
|
|
|
// This is set to false after lists, but true after lines of text.
|
|
|
|
$needLineBreakAfter = true;
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
// Portion: Show files, dependencies, speers
|
2018-09-26 02:45:07 +00:00
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
2018-09-17 22:28:15 +00:00
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-uses' )->escaped() .
|
|
|
|
$this->msg( 'colon-separator' )->escaped()
|
|
|
|
);
|
2024-01-17 15:59:17 +00:00
|
|
|
$links = [];
|
2016-11-18 04:54:17 +00:00
|
|
|
foreach ( $gadget->getPeers() as $peer ) {
|
2024-01-17 15:59:17 +00:00
|
|
|
$links[] = Html::element(
|
2016-11-18 04:54:17 +00:00
|
|
|
'a',
|
|
|
|
[ 'href' => '#' . $this->makeAnchor( $peer ) ],
|
|
|
|
$peer
|
|
|
|
);
|
|
|
|
}
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
|
2024-01-17 15:59:17 +00:00
|
|
|
$title = Title::newFromText( $codePage );
|
|
|
|
if ( !$title ) {
|
2011-09-23 06:48:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2024-01-17 15:59:17 +00:00
|
|
|
$links[] = $linkRenderer->makeLink( $title, $title->getText() );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2024-01-17 15:59:17 +00:00
|
|
|
$output->addHTML( $lang->commaList( $links ) );
|
2018-09-26 02:45:07 +00:00
|
|
|
|
2021-10-17 13:05:15 +00:00
|
|
|
if ( $gadget->isPackaged() ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML( $this->msg( 'gadgets-packaged',
|
2023-12-08 21:33:19 +00:00
|
|
|
$this->gadgetRepo->titleWithoutPrefix( $gadget->getScripts()[0], $gadget->getName() ) ) );
|
2021-10-17 13:05:15 +00:00
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:45:07 +00:00
|
|
|
// Portion: Legacy scripts
|
2015-08-07 00:05:29 +00:00
|
|
|
if ( $gadget->getLegacyScripts() ) {
|
2018-09-17 22:28:15 +00:00
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
2022-03-24 14:22:40 +00:00
|
|
|
$output->addHTML( Html::errorBox(
|
|
|
|
$this->msg( 'gadgets-legacy' )->parse(),
|
|
|
|
'',
|
|
|
|
'mw-gadget-legacy'
|
2015-08-07 00:05:29 +00:00
|
|
|
) );
|
2022-03-24 14:22:40 +00:00
|
|
|
$needLineBreakAfter = false;
|
2015-08-07 00:05:29 +00:00
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
|
2022-01-30 13:15:25 +00:00
|
|
|
if ( $gadget->requiresES6() ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-requires-es6' )->parse()
|
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
// Portion: Show required rights (optional)
|
2016-12-28 10:25:47 +00:00
|
|
|
$rights = [];
|
2011-10-20 13:48:06 +00:00
|
|
|
foreach ( $gadget->getRequiredRights() as $right ) {
|
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[] = Html::element(
|
2018-09-17 22:17:44 +00:00
|
|
|
'code',
|
|
|
|
[ 'title' => $this->msg( "right-$right" )->plain() ],
|
|
|
|
$right
|
|
|
|
);
|
2011-10-20 13:48:06 +00:00
|
|
|
}
|
2018-09-17 22:28:15 +00:00
|
|
|
if ( $rights ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
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
|
|
|
$this->msg( 'gadgets-required-rights', $lang->commaList( $rights ), count( $rights ) )->parse()
|
2011-04-12 18:09:50 +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
|
|
|
$needLineBreakAfter = true;
|
2011-04-12 18:09:50 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
// Portion: Show required skins (optional)
|
2015-08-03 06:37:32 +00:00
|
|
|
$requiredSkins = $gadget->getRequiredSkins();
|
2023-07-24 12:36:59 +00:00
|
|
|
$skins = [];
|
|
|
|
$validskins = $skinFactory->getSkinNames();
|
|
|
|
foreach ( $requiredSkins as $skinid ) {
|
|
|
|
if ( isset( $validskins[$skinid] ) ) {
|
|
|
|
$skins[] = $this->msg( "skinname-$skinid" )->plain();
|
|
|
|
} else {
|
|
|
|
$skins[] = $skinid;
|
2015-08-03 06:37:32 +00:00
|
|
|
}
|
2023-07-24 12:36:59 +00:00
|
|
|
}
|
|
|
|
if ( $skins ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
2012-01-18 02:44:37 +00:00
|
|
|
}
|
2023-07-24 12:36:59 +00:00
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
|
|
|
|
->numParams( count( $skins ) )->parse()
|
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
2011-10-22 19:09:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:10:22 +00:00
|
|
|
// Portion: Show required actions (optional)
|
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
|
|
|
$actions = [];
|
|
|
|
foreach ( $gadget->getRequiredActions() as $action ) {
|
|
|
|
$actions[] = Html::element( 'code', [], $action );
|
|
|
|
}
|
2021-12-14 13:10:22 +00:00
|
|
|
if ( $actions ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-required-actions', $lang->commaList( $actions ) )
|
|
|
|
->numParams( count( $actions ) )->parse()
|
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
2020-09-04 03:42:31 +00:00
|
|
|
// Portion: Show required namespaces (optional)
|
|
|
|
$namespaces = $gadget->getRequiredNamespaces();
|
|
|
|
if ( $namespaces ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
|
|
|
$this->msg(
|
|
|
|
'gadgets-required-namespaces',
|
|
|
|
$lang->commaList( array_map( function ( int $ns ) use ( $lang ) {
|
|
|
|
return $ns == NS_MAIN
|
|
|
|
? $this->msg( 'blanknamespace' )->text()
|
|
|
|
: $lang->getFormattedNsText( $ns );
|
|
|
|
}, $namespaces ) )
|
|
|
|
)->numParams( count( $namespaces ) )->parse()
|
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Portion: Show required content models (optional)
|
|
|
|
$contentModels = [];
|
|
|
|
foreach ( $gadget->getRequiredContentModels() as $model ) {
|
|
|
|
$contentModels[] = Html::element(
|
|
|
|
'code',
|
|
|
|
[ 'title' => ContentHandler::getLocalizedName( $model, $lang ) ],
|
|
|
|
$model
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( $contentModels ) {
|
2024-02-20 13:55:52 +00:00
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
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
|
|
|
$this->msg( 'gadgets-required-contentmodels',
|
|
|
|
$lang->commaList( $contentModels ),
|
|
|
|
count( $contentModels )
|
|
|
|
)->parse()
|
2024-02-20 13:55:52 +00:00
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Portion: Show required categories (optional)
|
|
|
|
$categories = [];
|
|
|
|
foreach ( $gadget->getRequiredCategories() as $category ) {
|
|
|
|
$title = Title::makeTitleSafe( NS_CATEGORY, $category );
|
|
|
|
$categories[] = $title
|
|
|
|
? $linkRenderer->makeLink( $title, $category )
|
|
|
|
: htmlspecialchars( $category );
|
|
|
|
}
|
|
|
|
if ( $categories ) {
|
2023-05-22 08:41:15 +00:00
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
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
|
|
|
$this->msg( 'gadgets-required-categories' )
|
|
|
|
->rawParams( $lang->commaList( $categories ) )
|
|
|
|
->numParams( count( $categories ) )->parse()
|
2023-05-22 08:41:15 +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
|
|
|
$needLineBreakAfter = true;
|
2023-05-22 08:41:15 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 09:03:44 +00:00
|
|
|
if ( $gadget->supportsUrlLoad() ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML( $this->msg( 'gadgets-supports-urlload' )->parse() );
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
// Portion: Show on by default (optional)
|
2011-04-12 18:09:50 +00:00
|
|
|
if ( $gadget->isOnByDefault() ) {
|
2018-09-17 22:28:15 +00:00
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML( $this->msg( 'gadgets-default' )->parse() );
|
|
|
|
$needLineBreakAfter = true;
|
2011-04-03 19:01:52 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2021-12-28 21:29:05 +00:00
|
|
|
// Show warnings
|
|
|
|
$warnings = GadgetRepo::singleton()->validationWarnings( $gadget );
|
|
|
|
|
|
|
|
if ( count( $warnings ) > 0 ) {
|
|
|
|
$output->addHTML( Html::warningBox( implode( '<br/>', array_map( static function ( $msg ) {
|
|
|
|
return $msg->parse();
|
2024-03-10 18:23:46 +00:00
|
|
|
}, $warnings ) ) ) );
|
2021-12-28 21:29:05 +00:00
|
|
|
$needLineBreakAfter = false;
|
|
|
|
}
|
|
|
|
|
2018-09-17 22:28:15 +00:00
|
|
|
$output->addHTML( Html::closeElement( 'li' ) . "\n" );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-23 06:48:37 +00:00
|
|
|
if ( $listOpen ) {
|
2018-09-17 22:28:15 +00:00
|
|
|
$output->addHTML( Html::closeElement( 'ul' ) . "\n" );
|
2007-11-16 20:13:25 +00:00
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2010-08-08 18:22:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports a gadget with its dependencies in a serialized form
|
2017-08-27 14:07:08 +00:00
|
|
|
* @param string $gadget Name of gadget to export
|
2010-08-08 18:22:22 +00:00
|
|
|
*/
|
|
|
|
public function showExportForm( $gadget ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
global $wgScript;
|
2010-08-08 18:22:22 +00:00
|
|
|
|
2019-07-17 19:39:36 +00:00
|
|
|
$this->addHelpLink( 'Extension:Gadgets' );
|
2012-07-11 22:18:10 +00:00
|
|
|
$output = $this->getOutput();
|
2015-07-18 22:40:42 +00:00
|
|
|
try {
|
2022-08-16 15:24:01 +00:00
|
|
|
$g = $this->gadgetRepo->getGadget( $gadget );
|
2015-07-18 22:40:42 +00:00
|
|
|
} catch ( InvalidArgumentException $e ) {
|
2016-12-28 10:25:47 +00:00
|
|
|
$output->showErrorPage( 'error', 'gadgets-not-found', [ $gadget ] );
|
2010-08-08 18:22:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2010-08-08 18:22:22 +00:00
|
|
|
$this->setHeaders();
|
2024-02-17 01:57:11 +00:00
|
|
|
$output->setPageTitleMsg( $this->msg( 'gadgets-export-title' ) );
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() );
|
2010-08-08 18:22:22 +00:00
|
|
|
|
|
|
|
$exportList = "MediaWiki:gadget-$gadget\n";
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $g->getScriptsAndStyles() as $page ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
$exportList .= "$page\n";
|
2010-08-08 18:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 17:49:46 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', [], $this->getContext() );
|
|
|
|
$htmlForm
|
2022-03-20 14:07:38 +00:00
|
|
|
->setTitle( SpecialPage::getTitleFor( 'Export' ) )
|
2018-04-09 17:49:46 +00:00
|
|
|
->addHiddenField( 'pages', $exportList )
|
|
|
|
->addHiddenField( 'wpDownload', '1' )
|
|
|
|
->addHiddenField( 'templates', '1' )
|
|
|
|
->setAction( $wgScript )
|
|
|
|
->setMethod( 'get' )
|
|
|
|
->setSubmitText( $this->msg( 'gadgets-export-download' )->text() )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
2010-08-08 18:22:22 +00:00
|
|
|
}
|
2015-05-15 19:55:50 +00:00
|
|
|
|
2020-10-12 09:10:15 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2015-05-15 19:55:50 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|