[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Special:Gadgets, provides a preview of MediaWiki:Gadgets. 4 * 5 * @file 6 * @ingroup SpecialPage 7 * @author Daniel Kinzler, brightbyte.de 8 * @copyright © 2007 Daniel Kinzler 9 * @license GNU General Public License 2.0 or later 10 */ 11 12 class SpecialGadgets extends SpecialPage { 13 /** 14 * Constructor 15 */ 16 function __construct() { 17 parent::__construct( 'Gadgets', '', true ); 18 } 19 20 /** 21 * Main execution function 22 * @param $par array Parameters passed to the page 23 */ 24 function execute( $par ) { 25 $parts = explode( '/', $par ); 26 27 if ( count( $parts ) == 2 && $parts[0] == 'export' ) { 28 $this->showExportForm( $parts[1] ); 29 } else { 30 $this->showMainForm(); 31 } 32 } 33 34 /** 35 * Displays form showing the list of installed gadgets 36 */ 37 public function showMainForm() { 38 global $wgContLang; 39 40 $output = $this->getOutput(); 41 $this->setHeaders(); 42 $output->setPagetitle( $this->msg( 'gadgets-title' ) ); 43 $output->addWikiMsg( 'gadgets-pagetext' ); 44 45 $gadgets = Gadget::loadStructuredList(); 46 if ( !$gadgets ) { 47 return; 48 } 49 50 $lang = $this->getLanguage(); 51 $langSuffix = ""; 52 if ( $lang->getCode() != $wgContLang->getCode() ) { 53 $langSuffix = "/" . $lang->getCode(); 54 } 55 56 $listOpen = false; 57 58 $editInterfaceMessage = $this->getUser()->isAllowed( 'editinterface' ) 59 ? 'edit' 60 : 'viewsource'; 61 62 foreach ( $gadgets as $section => $entries ) { 63 if ( $section !== false && $section !== '' ) { 64 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$langSuffix" ); 65 $lnkTarget = $t 66 ? Linker::link( $t, $this->msg( $editInterfaceMessage )->escaped(), array(), array( 'action' => 'edit' ) ) 67 : htmlspecialchars( $section ); 68 $lnk = "    [$lnkTarget]"; 69 70 $ttext = $this->msg( "gadget-section-$section" )->parse(); 71 72 if ( $listOpen ) { 73 $output->addHTML( Xml::closeElement( 'ul' ) . "\n" ); 74 $listOpen = false; 75 } 76 77 $output->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" ); 78 } 79 80 /** 81 * @var $gadget Gadget 82 */ 83 foreach ( $entries as $gadget ) { 84 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$langSuffix" ); 85 86 if ( !$t ) { 87 continue; 88 } 89 90 $links = array(); 91 $links[] = Linker::link( 92 $t, 93 $this->msg( $editInterfaceMessage )->escaped(), 94 array(), 95 array( 'action' => 'edit' ) 96 ); 97 $links[] = Linker::link( 98 $this->getPageTitle( "export/{$gadget->getName()}" ), 99 $this->msg( 'gadgets-export' )->escaped() 100 ); 101 102 $ttext = $this->msg( "gadget-{$gadget->getName()}" )->parse(); 103 104 if ( !$listOpen ) { 105 $listOpen = true; 106 $output->addHTML( Xml::openElement( 'ul' ) ); 107 } 108 109 $lnk = '  ' . $this->msg( 'parentheses', $lang->pipeList( $links ) )->text(); 110 $output->addHTML( Xml::openElement( 'li' ) . 111 $ttext . $lnk . "<br />" . 112 $this->msg( 'gadgets-uses' )->escaped() . 113 $this->msg( 'colon-separator' )->escaped() 114 ); 115 116 $lnk = array(); 117 foreach ( $gadget->getScriptsAndStyles() as $codePage ) { 118 $t = Title::makeTitleSafe( NS_MEDIAWIKI, $codePage ); 119 120 if ( !$t ) { 121 continue; 122 } 123 124 $lnk[] = Linker::link( $t, htmlspecialchars( $t->getText() ) ); 125 } 126 $output->addHTML( $lang->commaList( $lnk ) ); 127 128 $rights = array(); 129 foreach ( $gadget->getRequiredRights() as $right ) { 130 $rights[] = '* ' . $this->msg( "right-$right" )->plain(); 131 } 132 if ( count( $rights ) ) { 133 $output->addHTML( '<br />' . 134 $this->msg( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse() 135 ); 136 } 137 138 $skins = array(); 139 $validskins = Skin::getSkinNames(); 140 foreach ( $gadget->getRequiredSkins() as $skinid ) { 141 if ( isset( $validskins[$skinid] ) ) { 142 $skins[] = $this->msg( "skinname-$skinid" )->plain(); 143 } else { 144 $skins[] = $skinid; 145 } 146 } 147 if ( count( $skins ) ) { 148 $output->addHTML( 149 '<br />' . 150 $this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) ) 151 ->numParams( count( $skins ) )->parse() 152 ); 153 } 154 155 if ( $gadget->isOnByDefault() ) { 156 $output->addHTML( '<br />' . $this->msg( 'gadgets-default' )->parse() ); 157 } 158 159 $output->addHTML( Xml::closeElement( 'li' ) . "\n" ); 160 } 161 } 162 163 if ( $listOpen ) { 164 $output->addHTML( Xml::closeElement( 'ul' ) . "\n" ); 165 } 166 } 167 168 /** 169 * Exports a gadget with its dependencies in a serialized form 170 * @param $gadget String Name of gadget to export 171 */ 172 public function showExportForm( $gadget ) { 173 global $wgScript; 174 175 $output = $this->getOutput(); 176 $gadgets = Gadget::loadList(); 177 if ( !isset( $gadgets[$gadget] ) ) { 178 $output->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) ); 179 return; 180 } 181 182 /** 183 * @var $g Gadget 184 */ 185 $g = $gadgets[$gadget]; 186 $this->setHeaders(); 187 $output->setPagetitle( $this->msg( 'gadgets-export-title' ) ); 188 $output->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() ); 189 190 $exportList = "MediaWiki:gadget-$gadget\n"; 191 foreach ( $g->getScriptsAndStyles() as $page ) { 192 $exportList .= "MediaWiki:$page\n"; 193 } 194 195 $output->addHTML( Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) 196 . Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() ) 197 . Html::hidden( 'pages', $exportList ) 198 . Html::hidden( 'wpDownload', '1' ) 199 . Html::hidden( 'templates', '1' ) 200 . Xml::submitButton( $this->msg( 'gadgets-export-download' )->text() ) 201 . Html::closeElement( 'form' ) 202 ); 203 } 204 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |