mediawiki-extensions-Gadgets/SpecialGadgets.php

158 lines
4.3 KiB
PHP
Raw Normal View History

<?php
/**
* Special:Gadgets, provides a preview of MediaWiki:Gadgets.
2008-02-04 08:08:43 +00:00
*
* @file
* @ingroup SpecialPage
* @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler
* @license GNU General Public License 2.0 or later
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "not a valid entry point.\n" );
die( 1 );
}
/**
*
*/
class SpecialGadgets extends SpecialPage {
2008-02-04 08:08:43 +00:00
/**
* Constructor
*/
function __construct() {
parent::__construct( 'Gadgets', '', true );
}
2008-02-04 08:08:43 +00:00
/**
* Main execution function
* @param $par Parameters passed to the page
*/
function execute( $par ) {
$parts = explode( '/', $par );
if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
$this->showExportForm( $parts[1] );
} 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;
$skin = $wgUser->getSkin();
$this->setHeaders();
$wgOut->setPagetitle( wfMsg( "gadgets-title" ) );
2010-07-08 08:13:03 +00:00
$wgOut->addWikiMsg( 'gadgets-pagetext' );
$gadgets = wfLoadGadgetsStructured();
if ( !$gadgets ) return;
2008-08-17 15:42:26 +00:00
$lang = "";
if ( $wgLang->getCode() != $wgContLang->getCode() ) {
$lang = "/" . $wgLang->getCode();
}
$listOpen = false;
$msgOpt = array( 'parseinline', 'parsemag' );
$editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' );
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" );
if ( $editInterfaceAllowed ) {
$lnkTarget = $t
? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
: htmlspecialchars( $section );
Remove most named character references from output Recommit of r66254 to trunk. This was just find extensions phase3 -iname '*.php' \! -iname '*.i18n.php' \! -iname 'Messages*.php' \! -iname '*_Messages.php' -exec sed -i 's/&nbsp;/\&#160;/g;s/&mdash;/―/g;s/&bull;/•/g;s/&aacute;/á/g;s/&acute;/´/g;s/&agrave;/à/g;s/&alpha;/α/g;s/&auml;/ä/g;s/&ccedil;/ç/g;s/&copy;/©/g;s/&darr;/↓/g;s/&deg;/°/g;s/&eacute;/é/g;s/&ecirc;/ê/g;s/&euml;/ë/g;s/&egrave;/è/g;s/&euro;/€/g;s/&harr;//g;s/&hellip;/…/g;s/&iacute;/í/g;s/&igrave;/ì/g;s/&larr;/←/g;s/&ldquo;/“/g;s/&middot;/·/g;s/&minus;/−/g;s/&ndash;/–/g;s/&oacute;/ó/g;s/&ocirc;/ô/g;s/&oelig;/œ/g;s/&ograve;/ò/g;s/&otilde;/õ/g;s/&ouml;/ö/g;s/&pound;/£/g;s/&prime;/′/g;s/&Prime;/″/g;s/&raquo;/»/g;s/&rarr;/→/g;s/&rdquo;/”/g;s/&Sigma;/Σ/g;s/&times;/×/g;s/&uacute;/ú/g;s/&uarr;/↑/g;s/&uuml;/ü/g;s/&yen;/¥/g' {} + followed by reading over every single line of the resulting diff and fixing a whole bunch of false positives. The reason for this change is given in <http://lists.wikimedia.org/pipermail/wikitech-l/2010-April/047617.html>. I cleared it with Tim and Brion on IRC before committing. It might cause a few problems, but I tried to be careful; please report any issues. I skipped all messages files. I plan to make a follow-up commit that alters wfMsgExt() with 'escapenoentities' to sanitize all the entities. That way, the only messages that will be problems will be ones that output raw HTML, and we want to get rid of those anyway. This should get rid of all named entities everywhere except messages. I skipped a few things like &nbsp that I noticed in manual inspection, because they weren't well-formed XML anyway. Also, to everyone who uses non-breaking spaces when they could use a normal space, or nothing at all, or CSS padding: I still hate you. Die.
2010-05-30 17:33:59 +00:00
$lnk = "&#160; &#160; [$lnkTarget]";
} else {
$lnk = '';
}
$ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
if( $listOpen ) {
$wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
$listOpen = false;
}
$wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
}
2008-02-04 08:08:43 +00:00
foreach ( $entries as $gname => $code ) {
2008-08-17 15:42:26 +00:00
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
if ( !$t ) continue;
$links = array();
if ( $editInterfaceAllowed ) {
$links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
}
$links[] = $skin->link( $this->getTitle( "export/$gname" ), wfMsgHtml( 'gadgets-export' ) );
$ttext = wfMsgExt( "gadget-$gname", $msgOpt );
if( !$listOpen ) {
$listOpen = true;
$wgOut->addHTML( Xml::openElement( 'ul' ) );
}
$lnk = '&#160;&#160;' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
$wgOut->addHTML( Xml::openElement( 'li' ) .
$ttext . $lnk . "<br />" .
wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
);
$lnk = array();
foreach ( $code as $codePage ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$codePage" );
if ( !$t ) continue;
$lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
}
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
$wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
}
}
if( $listOpen ) {
$wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
}
}
/**
* Exports a gadget with its dependencies in a serialized form
* @param $gadget String Name of gadget to export
*/
public function showExportForm( $gadget ) {
global $wgOut, $wgScript;
$gadgets = wfLoadGadgets();
if ( !isset( $gadgets[$gadget] ) ) {
$wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) );
return;
}
$ourDefinition = "* $gadget|" . implode('|', $gadgets[$gadget] );
$this->setHeaders();
$wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) );
$wgOut->addWikiMsg( 'gadgets-export-text', $gadget, $ourDefinition );
$exportList = "MediaWiki:gadget-$gadget\n";
foreach ( $gadgets[$gadget] as $page ) {
$exportList .= "MediaWiki:gadget-$page\n";
}
$wgOut->addHTML( Html::openElement( 'form', array( 'method' => 'GET', 'action' => $wgScript ) )
. Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
. Html::hidden( 'pages', $exportList )
. Html::hidden( 'wpDownload', '1' )
. Xml::submitButton( wfMsg( 'gadgets-export-download' ) )
. Html::closeElement( 'form' )
);
}
}