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
|
|
|
*/
|
|
|
|
|
2018-08-04 22:47:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
class SpecialGadgets extends SpecialPage {
|
2015-06-17 18:21:27 +00:00
|
|
|
public function __construct() {
|
2010-08-30 17:18:13 +00:00
|
|
|
parent::__construct( 'Gadgets', '', true );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2008-02-04 08:08:43 +00:00
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
/**
|
|
|
|
* Main execution function
|
2018-02-25 02:41:50 +00:00
|
|
|
* @param string $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 ) {
|
2010-09-16 17:28:21 +00:00
|
|
|
$parts = 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
|
|
|
|
2016-11-18 04:54:17 +00:00
|
|
|
private function makeAnchor( $gadgetName ) {
|
|
|
|
return 'gadget-' . Sanitizer::escapeId( $gadgetName, [ 'noninitial' ] );
|
|
|
|
}
|
|
|
|
|
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();
|
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
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
$output->disallowUserJs();
|
2012-07-11 22:18:10 +00:00
|
|
|
$lang = $this->getLanguage();
|
|
|
|
$langSuffix = "";
|
2018-08-04 22:47:17 +00:00
|
|
|
if ( !$lang->equals( MediaWikiServices::getInstance()->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
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$editInterfaceMessage = $this->getUser()->isAllowed( 'editinterface' )
|
2012-05-18 09:49:15 +00:00
|
|
|
? 'edit'
|
|
|
|
: 'viewsource';
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2017-02-04 21:06:01 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
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 = [];
|
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
|
|
|
|
2016-11-18 04:54:17 +00:00
|
|
|
$ttext = $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;
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Xml::openElement( 'ul' ) );
|
2007-11-16 20:13:25 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2016-11-18 04:54:17 +00:00
|
|
|
$actions = '  ' .
|
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(
|
|
|
|
Xml::openElement( 'li', [ 'id' => $this->makeAnchor( $name ) ] ) .
|
|
|
|
$ttext . $actions . "<br />" .
|
2012-09-02 23:10:23 +00:00
|
|
|
$this->msg( 'gadgets-uses' )->escaped() .
|
|
|
|
$this->msg( 'colon-separator' )->escaped()
|
2010-01-12 19:45:49 +00:00
|
|
|
);
|
2007-07-31 10:21:34 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
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 ) );
|
2015-08-07 00:05:29 +00:00
|
|
|
if ( $gadget->getLegacyScripts() ) {
|
|
|
|
$output->addHTML( '<br />' . Html::rawElement(
|
|
|
|
'span',
|
2016-12-28 10:25:47 +00:00
|
|
|
[ 'class' => 'mw-gadget-legacy errorbox' ],
|
2015-08-07 00:05:29 +00:00
|
|
|
$this->msg( 'gadgets-legacy' )->parse()
|
|
|
|
) );
|
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
|
2016-12-28 10:25:47 +00:00
|
|
|
$rights = [];
|
2011-10-20 13:48:06 +00:00
|
|
|
foreach ( $gadget->getRequiredRights() as $right ) {
|
2012-09-02 23:10:23 +00:00
|
|
|
$rights[] = '* ' . $this->msg( "right-$right" )->plain();
|
2011-10-20 13:48:06 +00:00
|
|
|
}
|
2011-04-03 19:01:52 +00:00
|
|
|
if ( count( $rights ) ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( '<br />' .
|
2012-09-02 23:10:23 +00:00
|
|
|
$this->msg( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
|
2011-04-12 18:09:50 +00:00
|
|
|
);
|
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2015-08-03 06:37:32 +00:00
|
|
|
$requiredSkins = $gadget->getRequiredSkins();
|
|
|
|
// $requiredSkins can be an array or true (if all skins are supported)
|
|
|
|
if ( is_array( $requiredSkins ) ) {
|
2016-12-28 10:25:47 +00:00
|
|
|
$skins = [];
|
2015-08-03 06:37:32 +00:00
|
|
|
$validskins = Skin::getSkinNames();
|
|
|
|
foreach ( $requiredSkins as $skinid ) {
|
|
|
|
if ( isset( $validskins[$skinid] ) ) {
|
|
|
|
$skins[] = $this->msg( "skinname-$skinid" )->plain();
|
|
|
|
} else {
|
|
|
|
$skins[] = $skinid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count( $skins ) ) {
|
|
|
|
$output->addHTML(
|
|
|
|
'<br />' .
|
|
|
|
$this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
|
|
|
|
->numParams( count( $skins ) )->parse()
|
|
|
|
);
|
2012-01-18 02:44:37 +00:00
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 18:09:50 +00:00
|
|
|
if ( $gadget->isOnByDefault() ) {
|
2012-09-02 23:10:23 +00:00
|
|
|
$output->addHTML( '<br />' . $this->msg( 'gadgets-default' )->parse() );
|
2011-04-03 19:01:52 +00:00
|
|
|
}
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Xml::closeElement( 'li' ) . "\n" );
|
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
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
->addHiddenField( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
|
|
|
|
->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
|
|
|
|
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|