r70616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70615‎ | r70616 | r70617 >
Date:03:15, 7 August 2010
Author:jeroendedauw
Status:ok
Tags:
Comment:
Minor style and doc improvements
Modified paths:
  • /trunk/extensions/ExtensionDistributor/ExtensionDistributor_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor_body.php
@@ -1,13 +1,18 @@
22 <?php
33
 4+/**
 5+ * Special page that allows users to download extensions as tar archives.
 6+ *
 7+ * @author Tim Starling
 8+ */
49 class ExtensionDistributorPage extends SpecialPage {
5 - var $extensionList; // cached list of extensions
 10+ protected $extensionList; // cached list of extensions
611
7 - function __construct() {
 12+ public function __construct() {
813 parent::__construct( 'ExtensionDistributor' );
914 }
1015
11 - function execute( $subpage ) {
 16+ public function execute( $subpage ) {
1217 global $wgExtDistTarDir, $wgExtDistWorkingCopy, $wgOut, $wgRequest;
1318
1419 $this->setHeaders();
@@ -19,9 +24,11 @@
2025
2126 if ( $subpage ) {
2227 $parts = explode( '/', $subpage, 2 );
 28+
2329 if ( count( $parts ) == 1 ) {
2430 $parts[] = false;
2531 }
 32+
2633 list( $extension, $version ) = $parts;
2734 } else {
2835 $extension = $wgRequest->getVal( 'extdist_extension' );
@@ -53,7 +60,7 @@
5461 $this->doDownload( $extension, $version );
5562 }
5663
57 - function getExtensionList() {
 64+ protected function getExtensionList() {
5865 global $wgExtDistWorkingCopy, $wgExtDistBranches;
5966
6067 if ( isset( $this->extensionList ) ) {
@@ -61,36 +68,46 @@
6269 }
6370
6471 $this->extensionList = array();
 72+
6573 foreach ( $wgExtDistBranches as $branchPath => $branch ) {
6674 $wc = "$wgExtDistWorkingCopy/$branchPath/extensions";
6775 $dir = opendir( $wc );
 76+
6877 if ( !$dir ) {
6978 return false;
7079 }
7180
7281 $this->extensionList[$branchPath] = array();
 82+
7383 while ( false !== ( $file = readdir( $dir ) ) ) {
7484 if ( substr( $file, 0, 1 ) == '.' ) {
7585 continue;
7686 }
 87+
7788 if ( !is_dir( "$wc/$file" ) ) {
7889 continue;
7990 }
 91+
8092 if ( file_exists( "$wc/$file/NO-DIST" ) ) {
8193 continue;
8294 }
 95+
8396 $this->extensionList[$branchPath][] = $file;
8497 }
 98+
8599 natcasesort( $this->extensionList[$branchPath] );
86100 }
 101+
87102 return $this->extensionList;
88103 }
89104
90 - function getBranchName( $path ) {
 105+ protected function getBranchName( $path ) {
91106 global $wgExtDistBranches;
 107+
92108 if ( !isset( $wgExtDistBranches[$path] ) ) {
93109 return false;
94110 }
 111+
95112 if ( isset( $wgExtDistBranches[$path]['msgName'] ) ) {
96113 return wfMsg( $wgExtDistBranches[$path]['msgName'] );
97114 } else {
@@ -98,14 +115,16 @@
99116 }
100117 }
101118
102 - function showExtensionSelector() {
 119+ protected function showExtensionSelector() {
103120 global $wgOut;
104121
105122 $extensions = $this->getExtensionList();
 123+
106124 if ( $extensions === false ) {
107125 $wgOut->addWikiMsg( 'extdist-wc-missing' );
108126 return;
109127 }
 128+
110129 if ( !$extensions['trunk'] ) {
111130 $wgOut->addWikiMsg( 'extdist-wc-empty' );
112131 return;
@@ -131,11 +150,13 @@
132151 );
133152 }
134153
135 - function showVersionSelector( $extensionName ) {
 154+ protected function showVersionSelector( $extensionName ) {
136155 global $wgOut, $wgExtDistBranches;
 156+
137157 $extensions = $this->getExtensionList();
138158
139159 $versions = array();
 160+
140161 foreach ( $wgExtDistBranches as $branchPath => $branch ) {
141162 if ( !in_array( $extensionName, $extensions[$branchPath] ) ) {
142163 continue;
@@ -146,6 +167,7 @@
147168 } else {
148169 $branchName = $branch['name'];
149170 }
 171+
150172 $versions[$branchPath] = $branchName;
151173 }
152174
@@ -171,6 +193,7 @@
172194
173195 $selected++;
174196 }
 197+
175198 $wgOut->addHTML(
176199 Xml::closeElement( 'select' ) . ' ' .
177200 Xml::submitButton( wfMsg( 'extdist-submit-version' ), array( 'name' => 'extdist_submit' ) ) .
@@ -178,7 +201,7 @@
179202 );
180203 }
181204
182 - function doDownload( $extension, $version ) {
 205+ protected function doDownload( $extension, $version ) {
183206 global $wgExtDistWorkingCopy, $wgExtDistTarDir, $wgExtDistBranches,
184207 $wgOut, $wgExtDistTarUrl, $wgExtDistRemoteClient;
185208
@@ -187,18 +210,19 @@
188211 } else {
189212 $rev = $this->updateAndGetRevisionLocal( $extension, $version );
190213 }
 214+
191215 if ( $rev === false ) {
192216 // Error already displayed
193217 return;
194218 }
195219
196 - // Determine tar name
 220+ // Determine tar name.
197221 $cleanName = str_replace( '/', '_', $extension );
198222 $versionName = $wgExtDistBranches[$version]['tarLabel'];
199223 $tarName = "$cleanName-$versionName-r$rev.tar.gz";
200224 $tarFile = "$wgExtDistTarDir/$tarName";
201225
202 - // Create it if it doesn't exist
 226+ // Create the archive if it doesn't exist.
203227 if ( !file_exists( $tarFile ) ) {
204228 // Does the tar file need ExtensionFunctions.php?
205229 $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension";
@@ -207,15 +231,17 @@
208232 wfShellExec( "grep -q '\bExtensionFunctions' " . $files, $retval );
209233 $needEF = !$retval;
210234
211 - // Create the archive
 235+ // Create the archive.
212236 $cmd = 'tar -czf ' . wfEscapeShellArg( $tarFile ) .
213237 ' --exclude \'*/.svn*\'' .
214238 ' -C ' . wfEscapeShellArg( "$wgExtDistWorkingCopy/$version/extensions" ) .
215239 ' ' . wfEscapeShellArg( $extension ) .
216240 ( $needEF ? ' ExtensionFunctions.php' : '' ) .
217241 ' 2>&1';
 242+
218243 $retval = - 1;
219244 $result = wfShellExec( $cmd, $retval );
 245+
220246 if ( $retval ) {
221247 $wgOut->addWikiMsg( 'extdist-tar-error', $retval );
222248 $wgOut->addHTML( '<pre>' . htmlspecialchars( $result ) . '</pre>' );
@@ -236,13 +262,17 @@
237263 header( 'Refresh: 5;' . $url );
238264 }
239265
240 - function updateAndGetRevisionLocal( $extension, $version ) {
 266+ protected function updateAndGetRevisionLocal( $extension, $version ) {
241267 global $wgExtDistWorkingCopy, $wgOut;
 268+
242269 // svn up
243270 $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension";
 271+
244272 $cmd = "svn up --non-interactive " . wfEscapeShellArg( $dir ) . " 2>&1";
245273 $retval = - 1;
 274+
246275 $result = wfShellExec( $cmd, $retval );
 276+
247277 if ( $retval ) {
248278 $wgOut->addWikiMsg( 'extdist-svn-error', $result );
249279 return false;
@@ -252,6 +282,7 @@
253283 $cmd = "svn info --non-interactive --xml " . wfEscapeShellArg( $dir );
254284 $retval = - 1;
255285 $result = wfShellExec( $cmd, $retval );
 286+
256287 if ( $retval ) {
257288 $wgOut->addWikiMsg( 'extdist-svn-error', $result );
258289 return false;
@@ -259,6 +290,7 @@
260291
261292 $sx = new SimpleXMLElement( $result );
262293 $rev = $sx->entry->commit['revision'];
 294+
263295 if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) {
264296 $wgOut->addWikiMsg( 'extdist-svn-parse-error', $result );
265297 return false;
@@ -267,12 +299,16 @@
268300 return $rev;
269301 }
270302
271 - function updateAndGetRevisionRemote( $extension, $version ) {
 303+ protected function updateAndGetRevisionRemote( $extension, $version ) {
272304 global $wgExtDistRemoteClient, $wgOut;
 305+
273306 $cmd = json_encode( array( 'extension' => $extension, 'version' => $version ) );
274307 $cmd = str_replace( "\000", '', $cmd );
 308+
275309 list( $host, $port ) = explode( ':', $wgExtDistRemoteClient, 2 );
 310+
276311 $sock = fsockopen( $host, $port );
 312+
277313 if ( !$sock ) {
278314 $wgOut->addWikiMsg( 'extdist-no-remote' );
279315 return false;
@@ -285,15 +321,19 @@
286322 fclose( $sock );
287323
288324 $response = json_decode( $encResponse );
 325+
289326 if ( isset( $response->error ) ) {
290327 $info = isset( $response->errorInfo ) ? $response->errorInfo : '';
291328 $wgOut->addWikiMsg( $response->error, $info );
292329 return false;
293330 }
 331+
294332 if ( !isset( $response->revision ) ) {
295333 $wgOut->addWikiMsg( 'extdist-remote-invalid-response' );
296334 return false;
297335 }
 336+
298337 return $response->revision;
299338 }
300 -}
 339+
 340+}
\ No newline at end of file

Status & tagging log