2007-07-31 10:21:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2007-11-16 20:13:25 +00:00
|
|
|
* Special:Gadgets, provides a preview of MediaWiki:Gadgets.
|
2008-02-04 08:08:43 +00:00
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup SpecialPage
|
2007-07-31 10:21:34 +00:00
|
|
|
* @author Daniel Kinzler, brightbyte.de
|
|
|
|
* @copyright © 2007 Daniel Kinzler
|
2018-04-07 01:25:09 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2007-07-31 10:21:34 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-06 18:54:47 +00:00
|
|
|
namespace MediaWiki\Extension\Gadgets;
|
|
|
|
|
|
|
|
use Html;
|
|
|
|
use HTMLForm;
|
|
|
|
use InvalidArgumentException;
|
2018-08-04 22:47:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2022-02-06 18:54:47 +00:00
|
|
|
use Sanitizer;
|
|
|
|
use SpecialPage;
|
|
|
|
use Title;
|
|
|
|
use Xml;
|
2018-08-04 22:47:17 +00:00
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
class SpecialGadgets extends SpecialPage {
|
2015-06-17 18:21:27 +00:00
|
|
|
public function __construct() {
|
2022-08-08 15:44:05 +00:00
|
|
|
parent::__construct( 'Gadgets' );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2008-02-04 08:08:43 +00:00
|
|
|
|
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
|
|
|
|
2010-09-16 17:28:21 +00:00
|
|
|
if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
|
|
|
|
$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' );
|
2016-12-28 10:41:50 +00:00
|
|
|
$output->setPageTitle( $this->msg( 'gadgets-title' ) );
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addWikiMsg( 'gadgets-pagetext' );
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2015-07-18 22:40:42 +00:00
|
|
|
$gadgets = GadgetRepo::singleton()->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
|
|
|
|
2021-12-26 21:23:06 +00:00
|
|
|
$editDefinitionMessage = $this->getUser()->isAllowed( 'gadgets-definition-edit' )
|
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 !== '' ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$langSuffix" );
|
2012-05-18 09:49:15 +00:00
|
|
|
$lnkTarget = $t
|
2017-02-04 21:06:01 +00:00
|
|
|
? $linkRenderer->makeLink( $t, $this->msg( $editInterfaceMessage )->text(),
|
|
|
|
[], [ 'action' => 'edit' ] )
|
2012-05-18 09:49:15 +00:00
|
|
|
: htmlspecialchars( $section );
|
2015-10-23 21:11:01 +00:00
|
|
|
$lnk = "    [$lnkTarget]";
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2012-09-02 23:10:23 +00:00
|
|
|
$ttext = $this->msg( "gadget-section-$section" )->parse();
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2011-09-23 06:48:37 +00:00
|
|
|
if ( $listOpen ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Xml::closeElement( 'ul' ) . "\n" );
|
2007-11-16 20:13:25 +00:00
|
|
|
$listOpen = false;
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2016-12-28 10:25:47 +00:00
|
|
|
$output->addHTML( Html::rawElement( 'h2', [], $ttext . $lnk ) . "\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
|
|
|
/**
|
|
|
|
* @var $gadget Gadget
|
|
|
|
*/
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $entries as $gadget ) {
|
2016-11-18 04:54:17 +00:00
|
|
|
$name = $gadget->getName();
|
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$name}$langSuffix" );
|
2011-09-23 06:48:37 +00:00
|
|
|
if ( !$t ) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2016-12-28 10:25:47 +00:00
|
|
|
$links = [];
|
2021-12-26 21:23:06 +00:00
|
|
|
$definitionTitle = GadgetRepo::singleton()->getGadgetDefinitionTitle( $name );
|
|
|
|
if ( $definitionTitle ) {
|
|
|
|
$links[] = $linkRenderer->makeLink(
|
|
|
|
$definitionTitle,
|
|
|
|
$this->msg( $editDefinitionMessage )->text(),
|
|
|
|
[],
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
);
|
|
|
|
}
|
2017-02-04 21:06:01 +00:00
|
|
|
$links[] = $linkRenderer->makeLink(
|
2012-09-02 23:10:23 +00:00
|
|
|
$t,
|
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()
|
|
|
|
);
|
2016-12-28 10:25:47 +00:00
|
|
|
$lnk = [];
|
2016-11-18 04:54:17 +00:00
|
|
|
foreach ( $gadget->getPeers() as $peer ) {
|
|
|
|
$lnk[] = Html::element(
|
|
|
|
'a',
|
|
|
|
[ 'href' => '#' . $this->makeAnchor( $peer ) ],
|
|
|
|
$peer
|
|
|
|
);
|
|
|
|
}
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
|
2015-12-10 20:05:18 +00:00
|
|
|
$t = Title::newFromText( $codePage );
|
2011-09-23 06:48:37 +00:00
|
|
|
if ( !$t ) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-04 21:06:01 +00:00
|
|
|
$lnk[] = $linkRenderer->makeLink( $t, $t->getText() );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( $lang->commaList( $lnk ) );
|
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',
|
|
|
|
GadgetRepo::singleton()->titleWithoutPrefix( $gadget->getScripts()[0] ) ) );
|
|
|
|
$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
|
|
|
|
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 ) {
|
2018-09-17 22:17:44 +00:00
|
|
|
$rights[] = '* ' . Html::element(
|
|
|
|
'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(
|
|
|
|
$this->msg( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
|
2011-04-12 18:09:50 +00:00
|
|
|
);
|
2018-09-17 22:28:15 +00:00
|
|
|
$needLineBreakAfter = false;
|
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();
|
2018-09-17 22:28:15 +00:00
|
|
|
// $requiredSkins can be an array, or true (if all skins are supported)
|
2015-08-03 06:37:32 +00:00
|
|
|
if ( is_array( $requiredSkins ) ) {
|
2016-12-28 10:25:47 +00:00
|
|
|
$skins = [];
|
2020-08-23 07:27:14 +00:00
|
|
|
$validskins = $skinFactory->getSkinNames();
|
2015-08-03 06:37:32 +00:00
|
|
|
foreach ( $requiredSkins as $skinid ) {
|
|
|
|
if ( isset( $validskins[$skinid] ) ) {
|
|
|
|
$skins[] = $this->msg( "skinname-$skinid" )->plain();
|
|
|
|
} else {
|
|
|
|
$skins[] = $skinid;
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 22:28:15 +00:00
|
|
|
if ( $skins ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
2015-08-03 06:37:32 +00:00
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
|
|
|
|
->numParams( count( $skins ) )->parse()
|
|
|
|
);
|
2018-09-17 22:28:15 +00:00
|
|
|
$needLineBreakAfter = true;
|
2012-01-18 02:44:37 +00:00
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:10:22 +00:00
|
|
|
// Portion: Show required actions (optional)
|
|
|
|
$actions = $gadget->getRequiredActions();
|
|
|
|
if ( $actions ) {
|
|
|
|
if ( $needLineBreakAfter ) {
|
|
|
|
$output->addHTML( '<br />' );
|
|
|
|
}
|
|
|
|
$output->addHTML(
|
|
|
|
$this->msg( 'gadgets-required-actions', $lang->commaList( $actions ) )
|
|
|
|
->numParams( count( $actions ) )->parse()
|
|
|
|
);
|
|
|
|
$needLineBreakAfter = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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 {
|
|
|
|
$g = GadgetRepo::singleton()->getGadget( $gadget );
|
|
|
|
} 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();
|
2016-12-28 10:41:50 +00:00
|
|
|
$output->setPageTitle( $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
|
|
|
}
|