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
|
2007-11-16 20:13:25 +00:00
|
|
|
* @license GNU General Public License 2.0 or later
|
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
|
2012-02-17 21:23:46 +00:00
|
|
|
* @param $par array 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
|
|
|
|
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
|
|
|
global $wgContLang;
|
2008-02-04 08:40:17 +00:00
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$output = $this->getOutput();
|
2008-01-14 22:46:14 +00:00
|
|
|
$this->setHeaders();
|
2012-09-02 23:10:23 +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
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$lang = $this->getLanguage();
|
|
|
|
$langSuffix = "";
|
|
|
|
if ( $lang->getCode() != $wgContLang->getCode() ) {
|
|
|
|
$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
|
|
|
|
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
|
2012-09-02 23:10:23 +00:00
|
|
|
? Linker::link( $t, $this->msg( $editInterfaceMessage )->escaped(), array(), array( 'action' => 'edit' ) )
|
2012-05-18 09:49:15 +00:00
|
|
|
: htmlspecialchars( $section );
|
|
|
|
$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
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Html::rawElement( 'h2', array(), $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 ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$langSuffix" );
|
2011-09-23 06:48:37 +00:00
|
|
|
|
|
|
|
if ( !$t ) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2010-08-08 18:22:22 +00:00
|
|
|
$links = array();
|
2012-09-02 23:10:23 +00:00
|
|
|
$links[] = Linker::link(
|
|
|
|
$t,
|
|
|
|
$this->msg( $editInterfaceMessage )->escaped(),
|
|
|
|
array(),
|
|
|
|
array( 'action' => 'edit' )
|
|
|
|
);
|
|
|
|
$links[] = Linker::link(
|
2013-12-27 06:59:11 +00:00
|
|
|
$this->getPageTitle( "export/{$gadget->getName()}" ),
|
2012-09-02 23:10:23 +00:00
|
|
|
$this->msg( 'gadgets-export' )->escaped()
|
|
|
|
);
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2012-09-02 23:10:23 +00:00
|
|
|
$ttext = $this->msg( "gadget-{$gadget->getName()}" )->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
|
|
|
|
2015-02-07 13:31:19 +00:00
|
|
|
$lnk = '  ' .
|
|
|
|
$this->msg( 'parentheses' )->rawParams( $lang->pipeList( $links ) )->escaped();
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Xml::openElement( 'li' ) .
|
2010-01-12 19:45:49 +00:00
|
|
|
$ttext . $lnk . "<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
|
|
|
|
2010-01-12 19:45:49 +00:00
|
|
|
$lnk = array();
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
|
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, $codePage );
|
2011-09-23 06:48:37 +00:00
|
|
|
|
|
|
|
if ( !$t ) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2012-02-17 21:23:46 +00:00
|
|
|
$lnk[] = Linker::link( $t, htmlspecialchars( $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',
|
|
|
|
array( 'class' => 'mw-gadget-legacy errorbox' ),
|
|
|
|
$this->msg( 'gadgets-legacy' )->parse()
|
|
|
|
) );
|
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
|
2011-10-20 13:48:06 +00:00
|
|
|
$rights = array();
|
|
|
|
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
|
|
|
|
2011-10-22 19:09:25 +00:00
|
|
|
$skins = array();
|
2012-01-18 02:44:37 +00:00
|
|
|
$validskins = Skin::getSkinNames();
|
2011-10-22 19:09:25 +00:00
|
|
|
foreach ( $gadget->getRequiredSkins() as $skinid ) {
|
2012-01-18 02:44:37 +00:00
|
|
|
if ( isset( $validskins[$skinid] ) ) {
|
2012-09-02 23:10:23 +00:00
|
|
|
$skins[] = $this->msg( "skinname-$skinid" )->plain();
|
2012-01-18 02:44:37 +00:00
|
|
|
} else {
|
|
|
|
$skins[] = $skinid;
|
|
|
|
}
|
2011-10-22 19:09:25 +00:00
|
|
|
}
|
|
|
|
if ( count( $skins ) ) {
|
2012-09-02 23:10:23 +00:00
|
|
|
$output->addHTML(
|
|
|
|
'<br />' .
|
|
|
|
$this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
|
|
|
|
->numParams( count( $skins ) )->parse()
|
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
|
|
|
|
* @param $gadget String Name of gadget to export
|
|
|
|
*/
|
|
|
|
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 ) {
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->showErrorPage( 'error', 'gadgets-not-found', array( $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();
|
2012-09-02 23:10:23 +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 ) {
|
|
|
|
$exportList .= "MediaWiki:$page\n";
|
2010-08-08 18:22:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 22:18:10 +00:00
|
|
|
$output->addHTML( Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) )
|
2010-08-08 18:22:22 +00:00
|
|
|
. Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
|
|
|
|
. Html::hidden( 'pages', $exportList )
|
|
|
|
. Html::hidden( 'wpDownload', '1' )
|
2011-06-13 18:37:21 +00:00
|
|
|
. Html::hidden( 'templates', '1' )
|
2012-09-02 23:10:23 +00:00
|
|
|
. Xml::submitButton( $this->msg( 'gadgets-export-download' )->text() )
|
2010-08-08 18:22:22 +00:00
|
|
|
. Html::closeElement( 'form' )
|
|
|
|
);
|
|
|
|
}
|
2015-05-15 19:55:50 +00:00
|
|
|
|
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|