Index: branches/RL2/extensions/Gadgets/SpecialGadgets.php |
— | — | @@ -0,0 +1,168 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special:Gadgets, provides a preview of MediaWiki:Gadgets. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup SpecialPage |
| 8 | + * @author Daniel Kinzler, brightbyte.de |
| 9 | + * @copyright © 2007 Daniel Kinzler |
| 10 | + * @license GNU General Public License 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + echo( "not a valid entry point.\n" ); |
| 15 | + die( 1 ); |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * |
| 20 | + */ |
| 21 | +class SpecialGadgets extends SpecialPage { |
| 22 | + |
| 23 | + /** |
| 24 | + * Constructor |
| 25 | + */ |
| 26 | + function __construct() { |
| 27 | + parent::__construct( 'Gadgets', '', true ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Main execution function |
| 32 | + * @param $par Parameters passed to the page |
| 33 | + */ |
| 34 | + function execute( $par ) { |
| 35 | + $parts = explode( '/', $par ); |
| 36 | + if ( count( $parts ) == 2 && $parts[0] == 'export' ) { |
| 37 | + $this->showExportForm( $parts[1] ); |
| 38 | + } else { |
| 39 | + $this->showMainForm(); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Displays form showing the list of installed gadgets |
| 45 | + */ |
| 46 | + public function showMainForm() { |
| 47 | + global $wgOut, $wgUser, $wgLang, $wgContLang; |
| 48 | + |
| 49 | + $skin = $wgUser->getSkin(); |
| 50 | + |
| 51 | + $this->setHeaders(); |
| 52 | + $wgOut->setPagetitle( wfMsg( "gadgets-title" ) ); |
| 53 | + $wgOut->addWikiMsg( 'gadgets-pagetext' ); |
| 54 | + |
| 55 | + $gadgets = Gadget::loadStructuredList(); |
| 56 | + if ( !$gadgets ) return; |
| 57 | + |
| 58 | + $lang = ""; |
| 59 | + if ( $wgLang->getCode() != $wgContLang->getCode() ) { |
| 60 | + $lang = "/" . $wgLang->getCode(); |
| 61 | + } |
| 62 | + |
| 63 | + $listOpen = false; |
| 64 | + |
| 65 | + $msgOpt = array( 'parseinline', 'parsemag' ); |
| 66 | + $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ); |
| 67 | + |
| 68 | + foreach ( $gadgets as $section => $entries ) { |
| 69 | + if ( $section !== false && $section !== '' ) { |
| 70 | + $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" ); |
| 71 | + if ( $editInterfaceAllowed ) { |
| 72 | + $lnkTarget = $t |
| 73 | + ? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) ) |
| 74 | + : htmlspecialchars( $section ); |
| 75 | + $lnk = "    [$lnkTarget]"; |
| 76 | + } else { |
| 77 | + $lnk = ''; |
| 78 | + } |
| 79 | + $ttext = wfMsgExt( "gadget-section-$section", $msgOpt ); |
| 80 | + |
| 81 | + if( $listOpen ) { |
| 82 | + $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" ); |
| 83 | + $listOpen = false; |
| 84 | + } |
| 85 | + $wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" ); |
| 86 | + } |
| 87 | + |
| 88 | + foreach ( $entries as $gadget ) { |
| 89 | + $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getId()}$lang" ); |
| 90 | + if ( !$t ) continue; |
| 91 | + |
| 92 | + $links = array(); |
| 93 | + if ( $editInterfaceAllowed ) { |
| 94 | + $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) ); |
| 95 | + } |
| 96 | + $links[] = $skin->link( $this->getTitle( "export/{$gadget->getId()}" ), wfMsgHtml( 'gadgets-export' ) ); |
| 97 | + |
| 98 | + $ttext = wfMsgExt( "gadget-{$gadget->getId()}", $msgOpt ); |
| 99 | + |
| 100 | + if( !$listOpen ) { |
| 101 | + $listOpen = true; |
| 102 | + $wgOut->addHTML( Xml::openElement( 'ul' ) ); |
| 103 | + } |
| 104 | + $lnk = '  ' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) ); |
| 105 | + $wgOut->addHTML( Xml::openElement( 'li' ) . |
| 106 | + $ttext . $lnk . "<br />" . |
| 107 | + wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' ) |
| 108 | + ); |
| 109 | + |
| 110 | + $lnk = array(); |
| 111 | + foreach ( $gadget->getScriptsAndStyles() as $codePage ) { |
| 112 | + $t = Title::makeTitleSafe( NS_MEDIAWIKI, $codePage ); |
| 113 | + if ( !$t ) continue; |
| 114 | + |
| 115 | + $lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) ); |
| 116 | + } |
| 117 | + $wgOut->addHTML( $wgLang->commaList( $lnk ) ); |
| 118 | + $rights = $gadget->getRequiredRights(); |
| 119 | + if ( count( $rights ) ) { |
| 120 | + $wgOut->addHTML( '<br />' . |
| 121 | + wfMessage( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) )->parse() |
| 122 | + ); |
| 123 | + } |
| 124 | + if ( $gadget->isOnByDefault() ) { |
| 125 | + $wgOut->addHTML( '<br />' . wfMessage( 'gadgets-default' )->parse() ); |
| 126 | + } |
| 127 | + |
| 128 | + $wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" ); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + if( $listOpen ) { |
| 133 | + $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" ); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Exports a gadget with its dependencies in a serialized form |
| 139 | + * @param $gadget String Name of gadget to export |
| 140 | + */ |
| 141 | + public function showExportForm( $gadget ) { |
| 142 | + global $wgOut, $wgScript; |
| 143 | + |
| 144 | + $gadgets = Gadget::loadList(); |
| 145 | + if ( !isset( $gadgets[$gadget] ) ) { |
| 146 | + $wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) ); |
| 147 | + return; |
| 148 | + } |
| 149 | + |
| 150 | + $g = $gadgets[$gadget]; |
| 151 | + $this->setHeaders(); |
| 152 | + $wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) ); |
| 153 | + $wgOut->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() ); |
| 154 | + |
| 155 | + $exportList = "MediaWiki:gadget-$gadget\n"; |
| 156 | + foreach ( $g->getScriptsAndStyles() as $page ) { |
| 157 | + $exportList .= "MediaWiki:$page\n"; |
| 158 | + } |
| 159 | + |
| 160 | + $wgOut->addHTML( Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) |
| 161 | + . Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() ) |
| 162 | + . Html::hidden( 'pages', $exportList ) |
| 163 | + . Html::hidden( 'wpDownload', '1' ) |
| 164 | + . Html::hidden( 'templates', '1' ) |
| 165 | + . Xml::submitButton( wfMsg( 'gadgets-export-download' ) ) |
| 166 | + . Html::closeElement( 'form' ) |
| 167 | + ); |
| 168 | + } |
| 169 | +} |
Property changes on: branches/RL2/extensions/Gadgets/SpecialGadgets.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 170 | + native |