r92455 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92454‎ | r92455 | r92456 >
Date:18:09, 18 July 2011
Author:reedy
Status:ok
Tags:
Comment:
Trim trailing whitespace

Add a bit of documentation

Swap old constructor
Modified paths:
  • /trunk/extensions/DumpHTML/dumpHTML.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/DumpHTML/dumpHTML.inc
@@ -88,7 +88,7 @@
8989 # Extension version
9090 const VERSION = '2.0';
9191
92 - function DumpHTML( $settings = array() ) {
 92+ function __construct( $settings = array() ) {
9393 foreach ( $settings as $var => $value ) {
9494 $this->$var = $value;
9595 }
@@ -171,7 +171,7 @@
172172 $end = $this->endID;
173173 }
174174 $start = $this->startID;
175 -
 175+
176176 # Start from the checkpoint
177177 $cp = $this->getCheckpoint( 'article' );
178178 if ( $cp == 'done' ) {
@@ -204,7 +204,7 @@
205205 $title = Title::newFromID( $id );
206206 if ( $title ) {
207207 $ns = $title->getNamespace() ;
208 - if ( $ns != NS_CATEGORY && $ns != NS_MEDIAWIKI &&
 208+ if ( $ns != NS_CATEGORY && $ns != NS_MEDIAWIKI &&
209209 $title->getPrefixedDBkey() != $mainPage ) {
210210 $this->doArticle( $title );
211211 }
@@ -233,11 +233,11 @@
234234
235235 $title = Title::newMainPage();
236236 $text = $this->getArticleHTML( $title );
237 -
 237+
238238 # Parse the XHTML to find the images
239239 #$images = $this->findImages( $text );
240240 #$this->copyImages( $images );
241 -
 241+
242242 $file = fopen( "{$this->dest}/index.html", "w" );
243243 if ( !$file ) {
244244 print "\nCan't open index.html for writing\n";
@@ -263,7 +263,7 @@
264264 $chunkSize = 1000;
265265
266266 $dbr = wfGetDB( DB_SLAVE );
267 -
 267+
268268 $cp = $this->getCheckpoint( 'local image' );
269269 if ( $cp == 'done' ) {
270270 print "Local image descriptions already done\n";
@@ -272,7 +272,7 @@
273273 print "Writing image description pages starting from $cp\n";
274274 $conds = array( 'img_name >= ' . $dbr->addQuotes( $cp ) );
275275 } else {
276 - print "Writing image description pages for local images\n";
 276+ print "Writing image description pages for local images\n";
277277 $conds = false;
278278 }
279279
@@ -280,14 +280,14 @@
281281 $i = 0;
282282
283283 do {
284 - $res = $dbr->select( 'image', array( 'img_name' ), $conds, __METHOD__,
 284+ $res = $dbr->select( 'image', array( 'img_name' ), $conds, __METHOD__,
285285 array( 'ORDER BY' => 'img_name', 'LIMIT' => $chunkSize ) );
286286 $numRows = $dbr->numRows( $res );
287287
288 - while ( $row = $dbr->fetchObject( $res ) ) {
 288+ foreach( $res as $row ) {
289289 # Update conds for the next chunk query
290290 $conds = array( 'img_name > ' . $dbr->addQuotes( $row->img_name ) );
291 -
 291+
292292 // Slice the result set with a filter
293293 if ( !$this->sliceFilter( $row->img_name ) ) {
294294 continue;
@@ -307,9 +307,8 @@
308308 }
309309 $this->doArticle( $title );
310310 }
311 - $dbr->freeResult( $res );
312311 } while ( $numRows );
313 -
 312+
314313 $this->setCheckpoint( 'local image', 'done' );
315314 print "\n";
316315 }
@@ -367,10 +366,10 @@
368367
369368 function doCategories() {
370369 $chunkSize = 1000;
371 -
 370+
372371 $this->setupGlobals();
373372 $dbr = wfGetDB( DB_SLAVE );
374 -
 373+
375374 $cp = $this->getCheckpoint( 'category' );
376375 if ( $cp == 'done' ) {
377376 print "Category pages already done\n";
@@ -385,14 +384,14 @@
386385
387386 $i = 0;
388387 do {
389 - $res = $dbr->select( 'categorylinks', 'DISTINCT cl_to', $conds, __METHOD__,
 388+ $res = $dbr->select( 'categorylinks', 'DISTINCT cl_to', $conds, __METHOD__,
390389 array( 'ORDER BY' => 'cl_to', 'LIMIT' => $chunkSize ) );
391390 $numRows = $dbr->numRows( $res );
392 -
393 - while ( $row = $dbr->fetchObject( $res ) ) {
 391+
 392+ foreach( $res as $row ) {
394393 // Set conditions for next chunk
395394 $conds = array( 'cl_to > ' . $dbr->addQuotes( $row->cl_to ) );
396 -
 395+
397396 // Filter pages from other slices
398397 if ( !$this->sliceFilter( $row->cl_to ) ) {
399398 continue;
@@ -408,9 +407,8 @@
409408 $title = Title::makeTitle( NS_CATEGORY, $row->cl_to );
410409 $this->doArticle( $title );
411410 }
412 - $dbr->freeResult( $res );
413411 } while ( $numRows );
414 -
 412+
415413 $this->setCheckpoint( 'category', 'done' );
416414 print "\n";
417415 }
@@ -437,7 +435,7 @@
438436
439437 for ( $chunkStart = $start; $chunkStart <= $end; $chunkStart += $chunkSize ) {
440438 $chunkEnd = min( $end, $chunkStart + $chunkSize - 1 );
441 - $conds = array(
 439+ $conds = array(
442440 'page_is_redirect' => 1,
443441 "page_id BETWEEN $chunkStart AND $chunkEnd"
444442 );
@@ -449,8 +447,8 @@
450448 }
451449 $res = $dbr->select( 'page', array( 'page_id', 'page_namespace', 'page_title' ),
452450 $conds, __METHOD__ );
453 -
454 - while ( $row = $dbr->fetchObject( $res ) ) {
 451+
 452+ foreach( $res as $row ) {
455453 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
456454 if ( !(++$i % (self::REPORTING_INTERVAL*10) ) ) {
457455 printf( "Done %d redirects (%2.3f%%)\n", $i, $row->page_id / $end * 100 );
@@ -458,7 +456,6 @@
459457 }
460458 $this->doArticle( $title );
461459 }
462 - $dbr->freeResult( $res );
463460 }
464461 $this->setCheckpoint( 'redirect', 'done' );
465462 }
@@ -523,11 +520,11 @@
524521 wfProfileIn( __METHOD__ );
525522 $filename = $this->getHashedFilename( $title );
526523
527 - # Temporary hack for current dump, this should be moved to
 524+ # Temporary hack for current dump, this should be moved to
528525 # getFriendlyName() at the earliest opportunity.
529526 #
530527 # Limit filename length to 255 characters, so it works on ext3.
531 - # Titles are in fact limited to 255 characters, but dumpHTML
 528+ # Titles are in fact limited to 255 characters, but dumpHTML
532529 # adds a suffix which may put them over the limit.
533530 $length = strlen( $filename );
534531 if ( $length > 255 ) {
@@ -535,13 +532,13 @@
536533 wfProfileOut( __METHOD__ );
537534 return;
538535 }
539 -
 536+
540537 $fullName = "{$this->dest}/$filename";
541538 $fullDir = dirname( $fullName );
542539
543540 if ( $this->compress ) {
544541 $fullName .= ".gz";
545 - $text = gzencode( $text, 9 );
 542+ $text = gzencode( $text, 9 );
546543 }
547544
548545 if ( preg_match( '/[\x80-\xFF]/', $fullName ) && wfIsWindows() ) {
@@ -553,7 +550,7 @@
554551
555552 $success = file_put_contents( $tempName, $text );
556553 if ( $success ) {
557 - wfShellExec( "cscript /nologo " . wfEscapeShellArg(
 554+ wfShellExec( "cscript /nologo " . wfEscapeShellArg(
558555 dirname( __FILE__ ) . "\\rename-hack.vbs",
559556 $this->escapeForVBScript( $tempName ),
560557 $this->escapeForVBScript( $fullName ) ) );
@@ -699,7 +696,6 @@
700697
701698 $wgStylePath = "{$this->articleBaseUrl}/skins";
702699
703 -
704700 if ( $this->makeSnapshot ) {
705701 $this->destUploadUrl = "{$this->articleBaseUrl}/{$this->imageRel}";
706702 } else {
@@ -822,6 +818,10 @@
823819 return $text;
824820 }
825821
 822+ /**
 823+ * @param $rt Title
 824+ * @return string
 825+ */
826826 function getRedirect( $rt ) {
827827 $url = $rt->escapeLocalURL();
828828 $text = $rt->getPrefixedText();
@@ -865,7 +865,7 @@
866866
867867 /**
868868 * Copy a file specified by a URL to a given directory
869 - *
 869+ *
870870 * @param string $srcPath The source URL
871871 * @param string $srcPathBase The base directory of the source URL
872872 * @param string $srcDirBase The base filesystem directory of the source URL
@@ -905,14 +905,14 @@
906906 $this->relativeCopy( $newSrc, $srcPathBase, $srcDirBase, $destDirBase );
907907 }
908908 }
909 -
 909+
910910 /**
911911 * Copy images (or create symlinks) from commons to a static directory.
912912 * This is necessary even if you intend to distribute all of commons, because
913913 * the directory contents is used to work out which image description pages
914914 * are needed.
915915 *
916 - * Also copies math images, and full-sized images if the makeSnapshot option
 916+ * Also copies math images, and full-sized images if the makeSnapshot option
917917 * is specified.
918918 *
919919 */
@@ -932,6 +932,12 @@
933933 }
934934 }
935935
 936+ /**
 937+ * @param $title Title
 938+ * @param $url
 939+ * @param $query
 940+ * @return bool
 941+ */
936942 function onGetFullURL( &$title, &$url, $query ) {
937943 global $wgContLang, $wgArticlePath;
938944
@@ -950,6 +956,12 @@
951957 }
952958 }
953959
 960+ /**
 961+ * @param $title Title
 962+ * @param $url
 963+ * @param $query
 964+ * @return bool
 965+ */
954966 function onGetLocalURL( &$title, &$url, $query ) {
955967 global $wgArticlePath;
956968
@@ -984,6 +996,11 @@
985997 return false;
986998 }
987999
 1000+ /**
 1001+ * @throws MWException
 1002+ * @param $title Title
 1003+ * @return string
 1004+ */
9881005 function getHashedFilename( &$title ) {
9891006 if ( !$title ) {
9901007 throw new MWException( 'Invalid $title parameter to '.__METHOD__ );
@@ -1029,6 +1046,8 @@
10301047
10311048 /**
10321049 * Get a relative directory for putting a title into
 1050+ *
 1051+ * @param $title Title
10331052 */
10341053 function getHashedDirectory( &$title ) {
10351054 if ( '' != $title->getInterwiki() ) {
@@ -1117,6 +1136,7 @@
11181137 $text = '';
11191138 return false;
11201139 }
 1140+
11211141 function onSiteNoticeAfter( &$text ) {
11221142 $text = '';
11231143 return false;
@@ -1157,7 +1177,7 @@
11581178 function debug( $text ) {
11591179 print "$text\n";
11601180 }
1161 -
 1181+
11621182 function mkdir( $dir ) {
11631183 //if ( wfIsWindows() ) {
11641184 return wfMkdirParents( $dir, 0755 );
@@ -1206,7 +1226,7 @@
12071227 } else {
12081228 $foreignDest = "{$dump->destUploadDirectory}/$friendlyName";
12091229 }
1210 - $this->foreignRepos[] = new DumpHTML_ProxyRepo( $repo, $dump, $foreignDest,
 1230+ $this->foreignRepos[] = new DumpHTML_ProxyRepo( $repo, $dump, $foreignDest,
12111231 $dump->destUploadUrl . '/' . urlencode( $friendlyName ) );
12121232 }
12131233 }
@@ -1317,7 +1337,7 @@
13181338 $result = call_user_func_array( array( $this->backend, $name ), $args );
13191339 if ( is_string( $result ) ) {
13201340 $result = $this->fixURL( $result );
1321 - } elseif ( $result instanceof MediaTransformOutput ) {
 1341+ } elseif ( $result instanceof MediaTransformOutput ) {
13221342 $result = $this->fixMTO( $result );
13231343 }
13241344 return $result;

Status & tagging log