r70719 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70718‎ | r70719 | r70720 >
Date:18:22, 8 August 2010
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
Gadgets: added export feature for easier reuse
Modified paths:
  • /trunk/extensions/Gadgets/Gadgets.i18n.php (modified) (history)
  • /trunk/extensions/Gadgets/Gadgets.php (modified) (history)
  • /trunk/extensions/Gadgets/SpecialGadgets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/Gadgets.i18n.php
@@ -33,6 +33,14 @@
3434 '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]].
3535 This overview provides easy access to the system message pages that define each gadget's description and code.",
3636 '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',
3745 );
3846
3947 /** Message documentation (Message documentation)
@@ -52,6 +60,7 @@
5361 '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''\"
5462
5563 See [http://meta.wikimedia.org/wiki/Special:Gadgets Gadgets page in meta.wikimedia.org]",
 64+ 'gadgets-export' => 'This is a verb, not noun',
5665 );
5766
5867 /** Afrikaans (Afrikaans)
Index: trunk/extensions/Gadgets/Gadgets.php
@@ -36,6 +36,9 @@
3737 $wgSpecialPages['Gadgets'] = 'SpecialGadgets';
3838 $wgSpecialPageGroups['Gadgets'] = 'wiki';
3939
 40+// to restrict bots and spiders from pegging the server, disable this right for anons
 41+$wgGroupPermissions['*']['exportgadgets'] = true;
 42+
4043 function wfGadgetsArticleSaveComplete( $article, $user, $text ) {
4144 //update cache if MediaWiki:Gadgets-definition was edited
4245 $title = $article->mTitle;
Index: trunk/extensions/Gadgets/SpecialGadgets.php
@@ -31,9 +31,22 @@
3232 * @param $par Parameters passed to the page
3333 */
3434 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() {
3549 global $wgOut, $wgUser, $wgLang, $wgContLang;
3650
37 - wfLoadExtensionMessages( 'Gadgets' );
3851 $skin = $wgUser->getSkin();
3952
4053 $this->setHeaders();
@@ -51,7 +64,8 @@
5265 $listOpen = false;
5366
5467 $msgOpt = array( 'parseinline', 'parsemag' );
55 - $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ) ? true : false ;
 68+ $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' );
 69+ $exportAllowed = $wgUser->isAllowed( 'exportgadgets' );
5670
5771 foreach ( $gadgets as $section => $entries ) {
5872 if ( $section !== false && $section !== '' ) {
@@ -77,18 +91,27 @@
7892 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
7993 if ( !$t ) continue;
8094
 95+ $links = array();
8196 if ( $editInterfaceAllowed ) {
82 - $lnkTarget = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
83 - $lnk = "&#160; &#160; [$lnkTarget]";
84 - } else {
85 - $lnk = '';
 97+ $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
8698 }
 99+ if ( $exportAllowed ) {
 100+ $links[] = $skin->link( $this->getTitle(), wfMsgHtml( 'gadgets-export' ),
 101+ array(), array( 'export' => $gname )
 102+ );
 103+ }
 104+
87105 $ttext = wfMsgExt( "gadget-$gname", $msgOpt );
88106
89107 if( !$listOpen ) {
90108 $listOpen = true;
91109 $wgOut->addHTML( Xml::openElement( 'ul' ) );
92110 }
 111+ if ( !empty( $links ) ) {
 112+ $lnk = '&#160;&#160;' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
 113+ } else {
 114+ $lnk = '';
 115+ }
93116 $wgOut->addHTML( Xml::openElement( 'li' ) .
94117 $ttext . $lnk . "<br />" .
95118 wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
@@ -110,4 +133,41 @@
111134 $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
112135 }
113136 }
 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+ }
114174 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r70721Follow-up r70719: Add message for the new user rightraymond18:50, 8 August 2010
r70722Follow-up r70719 and r70721: on the second thought, this permission reflects ...maxsem19:01, 8 August 2010
r73131Follow-up r70719: prettified gadget export linkmaxsem17:28, 16 September 2010

Comments

#Comment by Reedy (talk | contribs)   22:45, 7 January 2011

Tested, seem to work fine for me

Status & tagging log