Index: trunk/extensions/Gadgets/Gadgets.i18n.php |
— | — | @@ -33,6 +33,14 @@ |
34 | 34 | 'gadgets-pagetext' => "Below is a list of special gadgets users can enable on their [[Special:Preferences|preferences page]], as defined by the [[MediaWiki:Gadgets-definition|definitions]]. |
35 | 35 | This overview provides easy access to the system message pages that define each gadget's description and code.", |
36 | 36 | 'gadgets-uses' => 'Uses', |
| 37 | + 'gadgets-export' => 'Export', |
| 38 | + 'gadgets-export-title' => 'Gadget export', |
| 39 | + 'gadgets-not-found' => 'Gadget "$1" not found.', |
| 40 | + 'gadgets-export-text' => 'To export the $1 gadget, click on "{{int:gadgets-export-download}}" button, save the downloaded file, |
| 41 | +go to Special:Import on destination wiki and upload it. Then add the following to MediaWiki:Gadgets-definition page: |
| 42 | +<pre>$2</pre> |
| 43 | +You must have appropriate permissions on destination wiki (including the right to edit system messages) and import from file uploads must be enabled.', |
| 44 | + 'gadgets-export-download' => 'Download', |
37 | 45 | ); |
38 | 46 | |
39 | 47 | /** Message documentation (Message documentation) |
— | — | @@ -52,6 +60,7 @@ |
53 | 61 | 'gadgets-uses' => "This is used as a verb in third-person singular. It appears in front of a script name. Example: \"''Uses: Gadget-UTCLiveClock.js''\" |
54 | 62 | |
55 | 63 | See [http://meta.wikimedia.org/wiki/Special:Gadgets Gadgets page in meta.wikimedia.org]", |
| 64 | + 'gadgets-export' => 'This is a verb, not noun', |
56 | 65 | ); |
57 | 66 | |
58 | 67 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/Gadgets/Gadgets.php |
— | — | @@ -36,6 +36,9 @@ |
37 | 37 | $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; |
38 | 38 | $wgSpecialPageGroups['Gadgets'] = 'wiki'; |
39 | 39 | |
| 40 | +// to restrict bots and spiders from pegging the server, disable this right for anons |
| 41 | +$wgGroupPermissions['*']['exportgadgets'] = true; |
| 42 | + |
40 | 43 | function wfGadgetsArticleSaveComplete( $article, $user, $text ) { |
41 | 44 | //update cache if MediaWiki:Gadgets-definition was edited |
42 | 45 | $title = $article->mTitle; |
Index: trunk/extensions/Gadgets/SpecialGadgets.php |
— | — | @@ -31,9 +31,22 @@ |
32 | 32 | * @param $par Parameters passed to the page |
33 | 33 | */ |
34 | 34 | function execute( $par ) { |
| 35 | + global $wgRequest; |
| 36 | + |
| 37 | + $export = $wgRequest->getVal( 'export' ); |
| 38 | + if ( $export ) { |
| 39 | + $this->showExportForm( $export ); |
| 40 | + } else { |
| 41 | + $this->showMainForm(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Displays form showing the list of installed gadgets |
| 47 | + */ |
| 48 | + public function showMainForm() { |
35 | 49 | global $wgOut, $wgUser, $wgLang, $wgContLang; |
36 | 50 | |
37 | | - wfLoadExtensionMessages( 'Gadgets' ); |
38 | 51 | $skin = $wgUser->getSkin(); |
39 | 52 | |
40 | 53 | $this->setHeaders(); |
— | — | @@ -51,7 +64,8 @@ |
52 | 65 | $listOpen = false; |
53 | 66 | |
54 | 67 | $msgOpt = array( 'parseinline', 'parsemag' ); |
55 | | - $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ) ? true : false ; |
| 68 | + $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ); |
| 69 | + $exportAllowed = $wgUser->isAllowed( 'exportgadgets' ); |
56 | 70 | |
57 | 71 | foreach ( $gadgets as $section => $entries ) { |
58 | 72 | if ( $section !== false && $section !== '' ) { |
— | — | @@ -77,18 +91,27 @@ |
78 | 92 | $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" ); |
79 | 93 | if ( !$t ) continue; |
80 | 94 | |
| 95 | + $links = array(); |
81 | 96 | if ( $editInterfaceAllowed ) { |
82 | | - $lnkTarget = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) ); |
83 | | - $lnk = "    [$lnkTarget]"; |
84 | | - } else { |
85 | | - $lnk = ''; |
| 97 | + $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) ); |
86 | 98 | } |
| 99 | + if ( $exportAllowed ) { |
| 100 | + $links[] = $skin->link( $this->getTitle(), wfMsgHtml( 'gadgets-export' ), |
| 101 | + array(), array( 'export' => $gname ) |
| 102 | + ); |
| 103 | + } |
| 104 | + |
87 | 105 | $ttext = wfMsgExt( "gadget-$gname", $msgOpt ); |
88 | 106 | |
89 | 107 | if( !$listOpen ) { |
90 | 108 | $listOpen = true; |
91 | 109 | $wgOut->addHTML( Xml::openElement( 'ul' ) ); |
92 | 110 | } |
| 111 | + if ( !empty( $links ) ) { |
| 112 | + $lnk = '  ' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) ); |
| 113 | + } else { |
| 114 | + $lnk = ''; |
| 115 | + } |
93 | 116 | $wgOut->addHTML( Xml::openElement( 'li' ) . |
94 | 117 | $ttext . $lnk . "<br />" . |
95 | 118 | wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' ) |
— | — | @@ -110,4 +133,41 @@ |
111 | 134 | $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" ); |
112 | 135 | } |
113 | 136 | } |
| 137 | + |
| 138 | + /** |
| 139 | + * Exports a gadget with its dependencies in a serialized form |
| 140 | + * @param $gadget String Name of gadget to export |
| 141 | + */ |
| 142 | + public function showExportForm( $gadget ) { |
| 143 | + global $wgOut, $wgRequest, $wgUser, $wgScript; |
| 144 | + |
| 145 | + if ( !$wgUser->isAllowed( 'exportgadgets' ) ) { |
| 146 | + $wgOut->permissionRequired( 'exportgadgets' ); |
| 147 | + return; |
| 148 | + } |
| 149 | + |
| 150 | + $gadgets = wfLoadGadgets(); |
| 151 | + if ( !isset( $gadgets[$gadget] ) ) { |
| 152 | + $wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) ); |
| 153 | + return; |
| 154 | + } |
| 155 | + |
| 156 | + $ourDefinition = "* $gadget|" . implode('|', $gadgets[$gadget] ); |
| 157 | + $this->setHeaders(); |
| 158 | + $wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) ); |
| 159 | + $wgOut->addWikiMsg( 'gadgets-export-text', $gadget, $ourDefinition ); |
| 160 | + |
| 161 | + $exportList = "MediaWiki:gadget-$gadget\n"; |
| 162 | + foreach ( $gadgets[$gadget] as $page ) { |
| 163 | + $exportList .= "MediaWiki:gadget-$page\n"; |
| 164 | + } |
| 165 | + |
| 166 | + $wgOut->addHTML( Html::openElement( 'form', array( 'method' => 'GET', 'action' => $wgScript ) ) |
| 167 | + . Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() ) |
| 168 | + . Html::hidden( 'pages', $exportList ) |
| 169 | + . Html::hidden( 'wpDownload', '1' ) |
| 170 | + . Xml::submitButton( wfMsg( 'gadgets-export-download' ) ) |
| 171 | + . Html::closeElement( 'form' ) |
| 172 | + ); |
| 173 | + } |
114 | 174 | } |