r75554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75553‎ | r75554 | r75555 >
Date:15:42, 27 October 2010
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 25463) Export header should not be shown if no pages were requested, to reduce confusion

Patch by Umherirrender, with a tweak to inverse logic to reduce nesting
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -457,15 +457,27 @@
458458 $result->addValue( 'query', 'pages', $pages );
459459 }
460460 if ( $this->params['export'] ) {
 461+ $exportTitles = array();
 462+ $titles = $pageSet->getGoodTitles();
 463+ if( count( $titles ) ) {
 464+ foreach ( $titles as $title ) {
 465+ if ( $title->userCanRead() ) {
 466+ $exportTitles[] = $title;
 467+ }
 468+ }
 469+ }
 470+ //export, when there are titles
 471+ if ( !count( $exportTitles ) ) {
 472+ return;
 473+ }
 474+
461475 $exporter = new WikiExporter( $this->getDB() );
462476 // WikiExporter writes to stdout, so catch its
463477 // output with an ob
464478 ob_start();
465479 $exporter->openStream();
466 - foreach ( $pageSet->getGoodTitles() as $title ) {
467 - if ( $title->userCanRead() ) {
468 - $exporter->pageByTitle( $title );
469 - }
 480+ foreach ( $exportTitles as $title ) {
 481+ $exporter->pageByTitle( $title );
470482 }
471483 $exporter->closeStream();
472484 $exportxml = ob_get_contents();
Index: trunk/phase3/RELEASE-NOTES
@@ -449,6 +449,8 @@
450450 used, rvlimit is enforced to 1.
451451 * If a action=parse request provides an oldid that is actually the current revision
452452 id, try the parser cache, and save it to it if necessary
 453+* (bug 25463) Export header should not be shown if no pages were requested, to
 454+ reduce confusion
453455
454456 === Languages updated in 1.17 ===
455457

Follow-up revisions

RevisionCommit summaryAuthorDate
r75641Followup r75554, functionise Export code, allows for return to be used "non s...reedy12:20, 29 October 2010

Comments

#Comment by Catrope (talk | contribs)   15:48, 28 October 2010
+			if ( !count( $exportTitles ) ) {
+				return;
+			}

This works but is fragile. The only reason it works nicely is that there is no code after the if ( $this->params['export'] ) { block. Any code added there in the future won't be run for empty exports.

#Comment by Reedy (talk | contribs)   21:52, 28 October 2010

Rather I just nest it (as per the original patch)?

#Comment by Catrope (talk | contribs)   11:35, 29 October 2010

That'd be more robust, yeah. Or move the export code to its own function, if feasible.

Status & tagging log