r69951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69950‎ | r69951 | r69952 >
Date:17:31, 26 July 2010
Author:jeroendedauw
Status:ok
Tags:
Comment:
Style improvements
Modified paths:
  • /trunk/phase3/includes/specials/SpecialExport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialExport.php
@@ -46,7 +46,8 @@
4747 $this->templates = $wgRequest->getCheck( 'templates' );
4848 $this->images = $wgRequest->getCheck( 'images' ); // Doesn't do anything yet
4949 $this->pageLinkDepth = $this->validateLinkDepth(
50 - $wgRequest->getIntOrNull( 'pagelink-depth' ) );
 50+ $wgRequest->getIntOrNull( 'pagelink-depth' )
 51+ );
5152 $nsindex = '';
5253
5354 if ( $wgRequest->getCheck( 'addcat' ) ) {
@@ -82,11 +83,13 @@
8384 $page = $wgRequest->getText( 'pages' );
8485 $this->curonly = $wgRequest->getCheck( 'curonly' );
8586 $rawOffset = $wgRequest->getVal( 'offset' );
 87+
8688 if( $rawOffset ) {
8789 $offset = wfTimestamp( TS_MW, $rawOffset );
8890 } else {
8991 $offset = null;
9092 }
 93+
9194 $limit = $wgRequest->getInt( 'limit' );
9295 $dir = $wgRequest->getVal( 'dir' );
9396 $history = array(
@@ -95,6 +98,7 @@
9699 'limit' => $wgExportMaxHistory,
97100 );
98101 $historyCheck = $wgRequest->getCheck( 'history' );
 102+
99103 if ( $this->curonly ) {
100104 $history = WikiExporter::CURRENT;
101105 } elseif ( !$historyCheck ) {
@@ -111,9 +115,10 @@
112116
113117 if( $page != '' ) $this->doExport = true;
114118 } else {
115 - // Default to current-only for GET requests
 119+ // Default to current-only for GET requests.
116120 $page = $wgRequest->getText( 'pages', $par );
117121 $historyCheck = $wgRequest->getCheck( 'history' );
 122+
118123 if( $historyCheck ) {
119124 $history = WikiExporter::FULL;
120125 } else {
@@ -133,16 +138,20 @@
134139
135140 if ( $this->doExport ) {
136141 $wgOut->disable();
 142+
137143 // Cancel output buffering and gzipping if set
138144 // This should provide safer streaming for pages with history
139145 wfResetOutputBuffers();
140146 $wgRequest->response()->header( "Content-type: application/xml; charset=utf-8" );
 147+
141148 if( $wgRequest->getCheck( 'wpDownload' ) ) {
142149 // Provide a sane filename suggestion
143150 $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' );
144151 $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" );
145152 }
 153+
146154 $this->doExport( $page, $history, $list_authors );
 155+
147156 return;
148157 }
149158
@@ -166,7 +175,9 @@
167176 } else {
168177 $wgOut->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) );
169178 }
 179+
170180 $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />';
 181+
171182 if( $wgExportMaxLinkDepth || $this->userCanOverrideExportDepth() ) {
172183 $form .= Xml::inputLabel( wfMsg( 'export-pagelinks' ), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '<br />';
173184 }
@@ -176,12 +187,12 @@
177188
178189 $form .= Xml::submitButton( wfMsg( 'export-submit' ), $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'export' ) );
179190 $form .= Xml::closeElement( 'form' );
 191+
180192 $wgOut->addHTML( $form );
181193 }
182194
183195 private function userCanOverrideExportDepth() {
184196 global $wgUser;
185 -
186197 return $wgUser->isAllowed( 'override-export-depth' );
187198 }
188199
@@ -231,6 +242,7 @@
232243 foreach( $pages as $k => $v ) {
233244 $pages[$k] = str_replace( " ", "_", $v );
234245 }
 246+
235247 $pages = array_unique( $pages );
236248
237249 /* Ok, let's get to it... */
@@ -249,9 +261,11 @@
250262 set_time_limit(0);
251263 wfRestoreWarnings();
252264 }
 265+
253266 $exporter = new WikiExporter( $db, $history, $buffer );
254267 $exporter->list_authors = $list_authors;
255268 $exporter->openStream();
 269+
256270 foreach( $pages as $page ) {
257271 /*
258272 if( $wgExportMaxHistory && !$this->curonly ) {
@@ -274,6 +288,7 @@
275289 }
276290
277291 $exporter->closeStream();
 292+
278293 if( $lb ) {
279294 $lb->closeAll();
280295 }
@@ -285,12 +300,16 @@
286301 $name = $title->getDBkey();
287302
288303 $dbr = wfGetDB( DB_SLAVE );
289 - $res = $dbr->select( array('page', 'categorylinks' ),
290 - array( 'page_namespace', 'page_title' ),
291 - array('cl_from=page_id', 'cl_to' => $name ),
292 - __METHOD__, array('LIMIT' => '5000'));
 304+ $res = $dbr->select(
 305+ array( 'page', 'categorylinks' ),
 306+ array( 'page_namespace', 'page_title' ),
 307+ array( 'cl_from=page_id', 'cl_to' => $name ),
 308+ __METHOD__,
 309+ array( 'LIMIT' => '5000' )
 310+ );
293311
294312 $pages = array();
 313+
295314 while ( $row = $dbr->fetchObject( $res ) ) {
296315 $n = $row->page_title;
297316 if ($row->page_namespace) {
@@ -300,6 +319,7 @@
301320
302321 $pages[] = $n;
303322 }
 323+
304324 $dbr->freeResult($res);
305325
306326 return $pages;
@@ -309,21 +329,28 @@
310330 global $wgContLang;
311331
312332 $dbr = wfGetDB( DB_SLAVE );
313 - $res = $dbr->select( 'page', array('page_namespace', 'page_title'),
314 - array('page_namespace' => $nsindex),
315 - __METHOD__, array('LIMIT' => '5000') );
 333+ $res = $dbr->select(
 334+ 'page',
 335+ array( 'page_namespace', 'page_title' ),
 336+ array( 'page_namespace' => $nsindex ),
 337+ __METHOD__,
 338+ array( 'LIMIT' => '5000' )
 339+ );
316340
317341 $pages = array();
 342+
318343 while ( $row = $dbr->fetchObject( $res ) ) {
319344 $n = $row->page_title;
320 - if ($row->page_namespace) {
 345+
 346+ if ( $row->page_namespace ) {
321347 $ns = $wgContLang->getNsText( $row->page_namespace );
322348 $n = $ns . ':' . $n;
323349 }
324350
325351 $pages[] = $n;
326352 }
327 - $dbr->freeResult($res);
 353+
 354+ $dbr->freeResult( $res );
328355
329356 return $pages;
330357 }
@@ -336,9 +363,10 @@
337364 */
338365 private function getTemplates( $inputPages, $pageSet ) {
339366 return $this->getLinks( $inputPages, $pageSet,
340 - 'templatelinks',
341 - array( 'tl_namespace AS namespace', 'tl_title AS title' ),
342 - array( 'page_id=tl_from' ) );
 367+ 'templatelinks',
 368+ array( 'tl_namespace AS namespace', 'tl_title AS title' ),
 369+ array( 'page_id=tl_from' )
 370+ );
343371 }
344372
345373 /**
@@ -346,14 +374,17 @@
347375 */
348376 private function validateLinkDepth( $depth ) {
349377 global $wgExportMaxLinkDepth;
 378+
350379 if( $depth < 0 ) {
351380 return 0;
352381 }
 382+
353383 if ( !$this->userCanOverrideExportDepth() ) {
354384 if( $depth > $wgExportMaxLinkDepth ) {
355385 return $wgExportMaxLinkDepth;
356386 }
357387 }
 388+
358389 /*
359390 * There's a HARD CODED limit of 5 levels of recursion here to prevent a
360391 * crazy-big export from being done by someone setting the depth
@@ -364,55 +395,70 @@
365396
366397 /** Expand a list of pages to include pages linked to from that page. */
367398 private function getPageLinks( $inputPages, $pageSet, $depth ) {
368 - for( $depth=$depth; $depth>0; --$depth ) {
369 - $pageSet = $this->getLinks( $inputPages, $pageSet, 'pagelinks',
370 - array( 'pl_namespace AS namespace', 'pl_title AS title' ),
371 - array( 'page_id=pl_from' ) );
 399+ for(; $depth > 0; --$depth ) {
 400+ $pageSet = $this->getLinks(
 401+ $inputPages, $pageSet, 'pagelinks',
 402+ array( 'pl_namespace AS namespace', 'pl_title AS title' ),
 403+ array( 'page_id=pl_from' )
 404+ );
372405 $inputPages = array_keys( $pageSet );
373406 }
 407+
374408 return $pageSet;
375409 }
376410
377411 /**
378412 * Expand a list of pages to include images used in those pages.
 413+ *
379414 * @param $inputPages array, list of titles to look up
380415 * @param $pageSet array, associative array indexed by titles for output
 416+ *
381417 * @return array associative array index by titles
382418 */
383419 private function getImages( $inputPages, $pageSet ) {
384 - return $this->getLinks( $inputPages, $pageSet,
385 - 'imagelinks',
386 - array( NS_FILE . ' AS namespace', 'il_to AS title' ),
387 - array( 'page_id=il_from' ) );
 420+ return $this->getLinks(
 421+ $inputPages,
 422+ $pageSet,
 423+ 'imagelinks',
 424+ array( NS_FILE . ' AS namespace', 'il_to AS title' ),
 425+ array( 'page_id=il_from' )
 426+ );
388427 }
389428
390429 /**
391430 * Expand a list of pages to include items used in those pages.
392 - * @private
393431 */
394432 private function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
395433 $dbr = wfGetDB( DB_SLAVE );
 434+
396435 foreach( $inputPages as $page ) {
397436 $title = Title::newFromText( $page );
 437+
398438 if( $title ) {
399439 $pageSet[$title->getPrefixedText()] = true;
400440 /// @todo Fixme: May or may not be more efficient to batch these
401441 /// by namespace when given multiple input pages.
402442 $result = $dbr->select(
403 - array( 'page', $table ),
404 - $fields,
405 - array_merge( $join,
406 - array(
407 - 'page_namespace' => $title->getNamespace(),
408 - 'page_title' => $title->getDBkey() ) ),
409 - __METHOD__ );
 443+ array( 'page', $table ),
 444+ $fields,
 445+ array_merge(
 446+ $join,
 447+ array(
 448+ 'page_namespace' => $title->getNamespace(),
 449+ 'page_title' => $title->getDBkey()
 450+ )
 451+ ),
 452+ __METHOD__
 453+ );
 454+
410455 foreach( $result as $row ) {
411456 $template = Title::makeTitle( $row->namespace, $row->title );
412457 $pageSet[$template->getPrefixedText()] = true;
413458 }
414459 }
415460 }
 461+
416462 return $pageSet;
417463 }
418 -}
419 -
 464+
 465+}
\ No newline at end of file

Status & tagging log