r76049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76048‎ | r76049 | r76050 >
Date:22:06, 4 November 2010
Author:maxsem
Status:deferred
Tags:
Comment:
* Adapted Special:Gadgets to new code
* Fixed array merging
Modified paths:
  • /branches/Gadgets-work/Gadgets_body.php (modified) (history)
  • /branches/Gadgets-work/SpecialGadgets.php (modified) (history)

Diff [purge]

Index: branches/Gadgets-work/Gadgets_body.php
@@ -204,7 +204,7 @@
205205 }
206206
207207 public function getScriptsAndStyles() {
208 - return $this->scripts + $this->styles;
 208+ return array_merge( $this->scripts, $this->styles );
209209 }
210210
211211 public function getModule() {
Index: branches/Gadgets-work/SpecialGadgets.php
@@ -51,7 +51,7 @@
5252 $wgOut->setPagetitle( wfMsg( "gadgets-title" ) );
5353 $wgOut->addWikiMsg( 'gadgets-pagetext' );
5454
55 - $gadgets = wfLoadGadgetsStructured();
 55+ $gadgets = Gadget::loadStructuredList();
5656 if ( !$gadgets ) return;
5757
5858 $lang = "";
@@ -84,17 +84,17 @@
8585 $wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
8686 }
8787
88 - foreach ( $entries as $gname => $code ) {
89 - $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
 88+ foreach ( $entries as $gadget ) {
 89+ $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$lang" );
9090 if ( !$t ) continue;
9191
9292 $links = array();
9393 if ( $editInterfaceAllowed ) {
9494 $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
9595 }
96 - $links[] = $skin->link( $this->getTitle( "export/$gname" ), wfMsgHtml( 'gadgets-export' ) );
 96+ $links[] = $skin->link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
9797
98 - $ttext = wfMsgExt( "gadget-$gname", $msgOpt );
 98+ $ttext = wfMsgExt( "gadget-{$gadget->getName()}", $msgOpt );
9999
100100 if( !$listOpen ) {
101101 $listOpen = true;
@@ -107,8 +107,8 @@
108108 );
109109
110110 $lnk = array();
111 - foreach ( $code as $codePage ) {
112 - $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$codePage" );
 111+ foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
 112+ $t = Title::makeTitleSafe( NS_MEDIAWIKI, $codePage );
113113 if ( !$t ) continue;
114114
115115 $lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
@@ -123,6 +123,10 @@
124124 }
125125 }
126126
 127+ private static function stripName( $name ) {
 128+ return preg_replace( '/Gadget-/i', '', $name );
 129+ }
 130+
127131 /**
128132 * Exports a gadget with its dependencies in a serialized form
129133 * @param $gadget String Name of gadget to export
@@ -130,20 +134,23 @@
131135 public function showExportForm( $gadget ) {
132136 global $wgOut, $wgScript;
133137
134 - $gadgets = wfLoadGadgets();
 138+ $gadgets = Gadget::loadList();
135139 if ( !isset( $gadgets[$gadget] ) ) {
136140 $wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) );
137141 return;
138142 }
139143
140 - $ourDefinition = "* $gadget|" . implode('|', $gadgets[$gadget] );
 144+ $g = $gadgets[$gadget];
 145+ $pages = $g->getScriptsAndStyles();
 146+ $pages = array_map( 'SpecialGadgets::stripName', $pages );
 147+ $ourDefinition = "* $gadget|" . implode('|', $pages );
141148 $this->setHeaders();
142149 $wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) );
143150 $wgOut->addWikiMsg( 'gadgets-export-text', $gadget, $ourDefinition );
144151
145152 $exportList = "MediaWiki:gadget-$gadget\n";
146 - foreach ( $gadgets[$gadget] as $page ) {
147 - $exportList .= "MediaWiki:gadget-$page\n";
 153+ foreach ( $g->getScriptsAndStyles() as $page ) {
 154+ $exportList .= "MediaWiki:$page\n";
148155 }
149156
150157 $wgOut->addHTML( Html::openElement( 'form', array( 'method' => 'GET', 'action' => $wgScript ) )

Status & tagging log