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
|
|
|
*/
|
|
|
|
|
|
|
|
if( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
echo( "not a valid entry point.\n" );
|
|
|
|
die( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class SpecialGadgets extends SpecialPage {
|
2008-02-04 08:08:43 +00:00
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
* @param $par Parameters passed to the page
|
|
|
|
*/
|
|
|
|
function execute( $par ) {
|
2010-09-16 17:28:21 +00:00
|
|
|
$parts = explode( '/', $par );
|
|
|
|
if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
|
|
|
|
$this->showExportForm( $parts[1] );
|
2010-08-08 18:22:22 +00:00
|
|
|
} else {
|
|
|
|
$this->showMainForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays form showing the list of installed gadgets
|
|
|
|
*/
|
|
|
|
public function showMainForm() {
|
2008-08-17 15:42:26 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang, $wgContLang;
|
2008-02-04 08:40:17 +00:00
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
$skin = $wgUser->getSkin();
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2008-01-14 22:46:14 +00:00
|
|
|
$this->setHeaders();
|
2007-07-31 10:21:34 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( "gadgets-title" ) );
|
2010-07-08 08:13:03 +00:00
|
|
|
$wgOut->addWikiMsg( 'gadgets-pagetext' );
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
$gadgets = Gadget::loadStructuredList();
|
2007-07-31 10:21:34 +00:00
|
|
|
if ( !$gadgets ) return;
|
|
|
|
|
2008-08-17 15:42:26 +00:00
|
|
|
$lang = "";
|
|
|
|
if ( $wgLang->getCode() != $wgContLang->getCode() ) {
|
|
|
|
$lang = "/" . $wgLang->getCode();
|
|
|
|
}
|
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
$listOpen = false;
|
2007-07-31 10:21:34 +00:00
|
|
|
|
|
|
|
$msgOpt = array( 'parseinline', 'parsemag' );
|
2010-08-08 18:22:22 +00:00
|
|
|
$editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' );
|
2010-01-12 19:45:49 +00:00
|
|
|
|
2007-07-31 10:21:34 +00:00
|
|
|
foreach ( $gadgets as $section => $entries ) {
|
|
|
|
if ( $section !== false && $section !== '' ) {
|
2008-08-17 15:42:26 +00:00
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
|
2010-01-12 19:45:49 +00:00
|
|
|
if ( $editInterfaceAllowed ) {
|
|
|
|
$lnkTarget = $t
|
|
|
|
? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
|
|
|
|
: htmlspecialchars( $section );
|
2010-05-30 17:33:59 +00:00
|
|
|
$lnk = "    [$lnkTarget]";
|
2010-01-12 19:45:49 +00:00
|
|
|
} else {
|
|
|
|
$lnk = '';
|
|
|
|
}
|
2007-11-16 20:13:25 +00:00
|
|
|
$ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
|
2007-07-31 10:21:34 +00:00
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
if( $listOpen ) {
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
|
2007-11-16 20:13:25 +00:00
|
|
|
$listOpen = false;
|
|
|
|
}
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2008-02-04 08:08:43 +00:00
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
foreach ( $entries as $gadget ) {
|
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$lang" );
|
2007-07-31 10:21:34 +00:00
|
|
|
if ( !$t ) continue;
|
|
|
|
|
2010-08-08 18:22:22 +00:00
|
|
|
$links = array();
|
2010-01-12 19:45:49 +00:00
|
|
|
if ( $editInterfaceAllowed ) {
|
2010-08-08 18:22:22 +00:00
|
|
|
$links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
|
|
|
|
}
|
2010-11-11 18:19:57 +00:00
|
|
|
$links[] = $skin->link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
|
2010-08-08 18:22:22 +00:00
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
$ttext = wfMsgExt( "gadget-{$gadget->getName()}", $msgOpt );
|
2008-07-07 18:50:47 +00:00
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
if( !$listOpen ) {
|
|
|
|
$listOpen = true;
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'ul' ) );
|
2007-11-16 20:13:25 +00:00
|
|
|
}
|
2010-08-08 19:01:28 +00:00
|
|
|
$lnk = '  ' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'li' ) .
|
|
|
|
$ttext . $lnk . "<br />" .
|
|
|
|
wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
|
|
|
|
);
|
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 );
|
2007-07-31 10:21:34 +00:00
|
|
|
if ( !$t ) continue;
|
|
|
|
|
2010-01-12 19:45:49 +00:00
|
|
|
$lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
|
2011-04-03 19:01:52 +00:00
|
|
|
$rights = $gadget->getRequiredRights();
|
|
|
|
if ( count( $rights ) ) {
|
|
|
|
$wgOut->addHTML( '<br />' );
|
|
|
|
$wgOut->addWikiMsg( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) );
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-16 20:13:25 +00:00
|
|
|
if( $listOpen ) {
|
2010-01-12 19:45:49 +00:00
|
|
|
$wgOut->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 ) {
|
2010-08-19 11:53:41 +00:00
|
|
|
global $wgOut, $wgScript;
|
2010-08-08 18:22:22 +00:00
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
$gadgets = Gadget::loadList();
|
2010-08-08 18:22:22 +00:00
|
|
|
if ( !isset( $gadgets[$gadget] ) ) {
|
|
|
|
$wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
$g = $gadgets[$gadget];
|
2010-08-08 18:22:22 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
$wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) );
|
2010-11-11 18:19:57 +00:00
|
|
|
$wgOut->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
|
|
|
}
|
|
|
|
|
2011-02-08 13:39:50 +00:00
|
|
|
$wgOut->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' )
|
|
|
|
. Xml::submitButton( wfMsg( 'gadgets-export-download' ) )
|
|
|
|
. Html::closeElement( 'form' )
|
|
|
|
);
|
|
|
|
}
|
2007-07-31 10:21:34 +00:00
|
|
|
}
|