r85638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85637‎ | r85638 | r85639 >
Date:21:04, 7 April 2011
Author:btongminh
Status:ok
Tags:
Comment:
Stylize Export.php
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Export.php
@@ -112,7 +112,7 @@
113113 */
114114 public function pagesByRange( $start, $end ) {
115115 $condition = 'page_id >= ' . intval( $start );
116 - if( $end ) {
 116+ if ( $end ) {
117117 $condition .= ' AND page_id < ' . intval( $end );
118118 }
119119 return $this->dumpFrom( $condition );
@@ -129,7 +129,7 @@
130130
131131 public function pageByName( $name ) {
132132 $title = Title::newFromText( $name );
133 - if( is_null( $title ) ) {
 133+ if ( is_null( $title ) ) {
134134 throw new MWException( "Can't export invalid title" );
135135 } else {
136136 return $this->pageByTitle( $title );
@@ -137,7 +137,7 @@
138138 }
139139
140140 public function pagesByName( $names ) {
141 - foreach( $names as $name ) {
 141+ foreach ( $names as $name ) {
142142 $this->pageByName( $name );
143143 }
144144 }
@@ -148,7 +148,7 @@
149149
150150 public function logsByRange( $start, $end ) {
151151 $condition = 'log_id >= ' . intval( $start );
152 - if( $end ) {
 152+ if ( $end ) {
153153 $condition .= ' AND log_id < ' . intval( $end );
154154 }
155155 return $this->dumpFrom( $condition );
@@ -160,10 +160,10 @@
161161 protected function do_list_authors( $page , $revision , $cond ) {
162162 wfProfileIn( __METHOD__ );
163163 $this->author_list = "<contributors>";
164 - //rev_deleted
165 - $nothidden = '('.$this->db->bitAnd('rev_deleted', Revision::DELETED_USER) . ') = 0';
 164+ // rev_deleted
 165+ $nothidden = '(' . $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ') = 0';
166166
167 - $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
 167+ $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
168168 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
169169 $result = $this->db->query( $sql, __METHOD__ );
170170 $resultset = $this->db->resultObject( $result );
@@ -184,27 +184,27 @@
185185 protected function dumpFrom( $cond = '' ) {
186186 wfProfileIn( __METHOD__ );
187187 # For logging dumps...
188 - if( $this->history & self::LOGS ) {
189 - if( $this->buffer == WikiExporter::STREAM ) {
 188+ if ( $this->history & self::LOGS ) {
 189+ if ( $this->buffer == WikiExporter::STREAM ) {
190190 $prev = $this->db->bufferResults( false );
191191 }
192192 $where = array( 'user_id = log_user' );
193193 # Hide private logs
194194 $hideLogs = LogEventsList::getExcludeClause( $this->db );
195 - if( $hideLogs ) $where[] = $hideLogs;
 195+ if ( $hideLogs ) $where[] = $hideLogs;
196196 # Add on any caller specified conditions
197 - if( $cond ) $where[] = $cond;
 197+ if ( $cond ) $where[] = $cond;
198198 # Get logging table name for logging.* clause
199 - $logging = $this->db->tableName('logging');
200 - $result = $this->db->select( array('logging','user'),
 199+ $logging = $this->db->tableName( 'logging' );
 200+ $result = $this->db->select( array( 'logging', 'user' ),
201201 array( "{$logging}.*", 'user_name' ), // grab the user name
202202 $where,
203203 __METHOD__,
204 - array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
 204+ array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
205205 );
206206 $wrapper = $this->db->resultObject( $result );
207207 $this->outputLogStream( $wrapper );
208 - if( $this->buffer == WikiExporter::STREAM ) {
 208+ if ( $this->buffer == WikiExporter::STREAM ) {
209209 $this->db->bufferResults( $prev );
210210 }
211211 # For page dumps...
@@ -213,11 +213,11 @@
214214 $opts = array( 'ORDER BY' => 'page_id ASC' );
215215 $opts['USE INDEX'] = array();
216216 $join = array();
217 - if( is_array( $this->history ) ) {
 217+ if ( is_array( $this->history ) ) {
218218 # Time offset/limit for all pages/history...
219219 $revJoin = 'page_id=rev_page';
220220 # Set time order
221 - if( $this->history['dir'] == 'asc' ) {
 221+ if ( $this->history['dir'] == 'asc' ) {
222222 $op = '>';
223223 $opts['ORDER BY'] = 'rev_timestamp ASC';
224224 } else {
@@ -225,54 +225,54 @@
226226 $opts['ORDER BY'] = 'rev_timestamp DESC';
227227 }
228228 # Set offset
229 - if( !empty( $this->history['offset'] ) ) {
 229+ if ( !empty( $this->history['offset'] ) ) {
230230 $revJoin .= " AND rev_timestamp $op " .
231231 $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
232232 }
233 - $join['revision'] = array('INNER JOIN',$revJoin);
 233+ $join['revision'] = array( 'INNER JOIN', $revJoin );
234234 # Set query limit
235 - if( !empty( $this->history['limit'] ) ) {
 235+ if ( !empty( $this->history['limit'] ) ) {
236236 $opts['LIMIT'] = intval( $this->history['limit'] );
237237 }
238 - } elseif( $this->history & WikiExporter::FULL ) {
 238+ } elseif ( $this->history & WikiExporter::FULL ) {
239239 # Full history dumps...
240 - $join['revision'] = array('INNER JOIN','page_id=rev_page');
241 - } elseif( $this->history & WikiExporter::CURRENT ) {
 240+ $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
 241+ } elseif ( $this->history & WikiExporter::CURRENT ) {
242242 # Latest revision dumps...
243 - if( $this->list_authors && $cond != '' ) { // List authors, if so desired
244 - list($page,$revision) = $this->db->tableNamesN('page','revision');
 243+ if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
 244+ list( $page, $revision ) = $this->db->tableNamesN( 'page', 'revision' );
245245 $this->do_list_authors( $page, $revision, $cond );
246246 }
247 - $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
248 - } elseif( $this->history & WikiExporter::STABLE ) {
 247+ $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
 248+ } elseif ( $this->history & WikiExporter::STABLE ) {
249249 # "Stable" revision dumps...
250250 # Default JOIN, to be overridden...
251 - $join['revision'] = array('INNER JOIN','page_id=rev_page AND page_latest=rev_id');
 251+ $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
252252 # One, and only one hook should set this, and return false
253 - if( wfRunHooks( 'WikiExporter::dumpStableQuery', array(&$tables,&$opts,&$join) ) ) {
 253+ if ( wfRunHooks( 'WikiExporter::dumpStableQuery', array( &$tables, &$opts, &$join ) ) ) {
254254 wfProfileOut( __METHOD__ );
255 - throw new MWException( __METHOD__." given invalid history dump type." );
 255+ throw new MWException( __METHOD__ . " given invalid history dump type." );
256256 }
257257 } else {
258258 # Uknown history specification parameter?
259259 wfProfileOut( __METHOD__ );
260 - throw new MWException( __METHOD__." given invalid history dump type." );
 260+ throw new MWException( __METHOD__ . " given invalid history dump type." );
261261 }
262262 # Query optimization hacks
263 - if( $cond == '' ) {
 263+ if ( $cond == '' ) {
264264 $opts[] = 'STRAIGHT_JOIN';
265265 $opts['USE INDEX']['page'] = 'PRIMARY';
266266 }
267267 # Build text join options
268 - if( $this->text != WikiExporter::STUB ) { // 1-pass
 268+ if ( $this->text != WikiExporter::STUB ) { // 1-pass
269269 $tables[] = 'text';
270 - $join['text'] = array('INNER JOIN','rev_text_id=old_id');
 270+ $join['text'] = array( 'INNER JOIN', 'rev_text_id=old_id' );
271271 }
272272
273 - if( $this->buffer == WikiExporter::STREAM ) {
 273+ if ( $this->buffer == WikiExporter::STREAM ) {
274274 $prev = $this->db->bufferResults( false );
275275 }
276 -
 276+
277277 wfRunHooks( 'ModifyExportQuery',
278278 array( $this->db, &$tables, &$cond, &$opts, &$join ) );
279279
@@ -281,11 +281,11 @@
282282 $wrapper = $this->db->resultObject( $result );
283283 # Output dump results
284284 $this->outputPageStream( $wrapper );
285 - if( $this->list_authors ) {
 285+ if ( $this->list_authors ) {
286286 $this->outputPageStream( $wrapper );
287287 }
288288
289 - if( $this->buffer == WikiExporter::STREAM ) {
 289+ if ( $this->buffer == WikiExporter::STREAM ) {
290290 $this->db->bufferResults( $prev );
291291 }
292292 }
@@ -307,12 +307,12 @@
308308 protected function outputPageStream( $resultset ) {
309309 $last = null;
310310 foreach ( $resultset as $row ) {
311 - if( is_null( $last ) ||
 311+ if ( is_null( $last ) ||
312312 $last->page_namespace != $row->page_namespace ||
313313 $last->page_title != $row->page_title ) {
314 - if( isset( $last ) ) {
 314+ if ( isset( $last ) ) {
315315 $output = '';
316 - if( $this->dumpUploads ) {
 316+ if ( $this->dumpUploads ) {
317317 $output .= $this->writer->writeUploads( $last );
318318 }
319319 $output .= $this->writer->closePage();
@@ -325,9 +325,9 @@
326326 $output = $this->writer->writeRevision( $row );
327327 $this->sink->writeRevision( $row, $output );
328328 }
329 - if( isset( $last ) ) {
 329+ if ( isset( $last ) ) {
330330 $output = '';
331 - if( $this->dumpUploads ) {
 331+ if ( $this->dumpUploads ) {
332332 $output .= $this->writer->writeUploads( $last );
333333 }
334334 $output .= $this->author_list;
@@ -335,7 +335,7 @@
336336 $this->sink->writeClosePage( $output );
337337 }
338338 }
339 -
 339+
340340 protected function outputLogStream( $resultset ) {
341341 foreach ( $resultset as $row ) {
342342 $output = $this->writer->writeLogItem( $row );
@@ -418,9 +418,9 @@
419419 function namespaces() {
420420 global $wgContLang;
421421 $spaces = "<namespaces>\n";
422 - foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
423 - $spaces .= ' ' .
424 - Xml::element( 'namespace',
 422+ foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
 423+ $spaces .= ' ' .
 424+ Xml::element( 'namespace',
425425 array( 'key' => $ns,
426426 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
427427 ), $title ) . "\n";
@@ -451,16 +451,16 @@
452452 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
453453 $out .= ' ' . Xml::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
454454 $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n";
455 - if( $row->page_is_redirect ) {
 455+ if ( $row->page_is_redirect ) {
456456 $out .= ' ' . Xml::element( 'redirect', array() ) . "\n";
457457 }
458 - if( $row->page_restrictions != '' ) {
 458+ if ( $row->page_restrictions != '' ) {
459459 $out .= ' ' . Xml::element( 'restrictions', array(),
460460 strval( $row->page_restrictions ) ) . "\n";
461461 }
462 -
 462+
463463 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
464 -
 464+
465465 return $out;
466466 }
467467
@@ -489,25 +489,25 @@
490490
491491 $out .= $this->writeTimestamp( $row->rev_timestamp );
492492
493 - if( $row->rev_deleted & Revision::DELETED_USER ) {
 493+ if ( $row->rev_deleted & Revision::DELETED_USER ) {
494494 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
495495 } else {
496496 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
497497 }
498498
499 - if( $row->rev_minor_edit ) {
 499+ if ( $row->rev_minor_edit ) {
500500 $out .= " <minor/>\n";
501501 }
502 - if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
 502+ if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
503503 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
504 - } elseif( $row->rev_comment != '' ) {
 504+ } elseif ( $row->rev_comment != '' ) {
505505 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
506506 }
507507
508508 $text = '';
509 - if( $row->rev_deleted & Revision::DELETED_TEXT ) {
 509+ if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
510510 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
511 - } elseif( isset( $row->old_text ) ) {
 511+ } elseif ( isset( $row->old_text ) ) {
512512 // Raw text from the database may have invalid chars
513513 $text = strval( Revision::getRevisionText( $row ) );
514514 $out .= " " . Xml::elementClean( 'text',
@@ -527,7 +527,7 @@
528528 wfProfileOut( __METHOD__ );
529529 return $out;
530530 }
531 -
 531+
532532 /**
533533 * Dumps a <logitem> section on the output stream, with
534534 * data filled in from the given database row.
@@ -544,22 +544,22 @@
545545
546546 $out .= $this->writeTimestamp( $row->log_timestamp );
547547
548 - if( $row->log_deleted & LogPage::DELETED_USER ) {
 548+ if ( $row->log_deleted & LogPage::DELETED_USER ) {
549549 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
550550 } else {
551551 $out .= $this->writeContributor( $row->log_user, $row->user_name );
552552 }
553553
554 - if( $row->log_deleted & LogPage::DELETED_COMMENT ) {
 554+ if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
555555 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
556 - } elseif( $row->log_comment != '' ) {
 556+ } elseif ( $row->log_comment != '' ) {
557557 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
558558 }
559 -
 559+
560560 $out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
561561 $out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
562562
563 - if( $row->log_deleted & LogPage::DELETED_ACTION ) {
 563+ if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
564564 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
565565 } else {
566566 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
@@ -582,7 +582,7 @@
583583
584584 function writeContributor( $id, $text ) {
585585 $out = " <contributor>\n";
586 - if( $id ) {
 586+ if ( $id ) {
587587 $out .= " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
588588 $out .= " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
589589 } else {
@@ -596,11 +596,11 @@
597597 * Warning! This data is potentially inconsistent. :(
598598 */
599599 function writeUploads( $row ) {
600 - if( $row->page_namespace == NS_IMAGE ) {
 600+ if ( $row->page_namespace == NS_IMAGE ) {
601601 $img = wfFindFile( $row->page_title );
602 - if( $img ) {
 602+ if ( $img ) {
603603 $out = '';
604 - foreach( array_reverse( $img->getHistory() ) as $ver ) {
 604+ foreach ( array_reverse( $img->getHistory() ) as $ver ) {
605605 $out .= $this->writeUpload( $ver );
606606 }
607607 $out .= $this->writeUpload( $img );
@@ -648,7 +648,7 @@
649649 function writeRevision( $rev, $string ) {
650650 $this->write( $string );
651651 }
652 -
 652+
653653 function writeLogItem( $rev, $string ) {
654654 $this->write( $string );
655655 }
@@ -686,7 +686,7 @@
687687 */
688688 class DumpPipeOutput extends DumpFileOutput {
689689 function __construct( $command, $file = null ) {
690 - if( !is_null( $file ) ) {
 690+ if ( !is_null( $file ) ) {
691691 $command .= " > " . wfEscapeShellArg( $file );
692692 }
693693 $this->handle = popen( $command, "w" );
@@ -750,27 +750,27 @@
751751
752752 function writeOpenPage( $page, $string ) {
753753 $this->sendingThisPage = $this->pass( $page, $string );
754 - if( $this->sendingThisPage ) {
 754+ if ( $this->sendingThisPage ) {
755755 $this->sink->writeOpenPage( $page, $string );
756756 }
757757 }
758758
759759 function writeClosePage( $string ) {
760 - if( $this->sendingThisPage ) {
 760+ if ( $this->sendingThisPage ) {
761761 $this->sink->writeClosePage( $string );
762762 $this->sendingThisPage = false;
763763 }
764764 }
765765
766766 function writeRevision( $rev, $string ) {
767 - if( $this->sendingThisPage ) {
 767+ if ( $this->sendingThisPage ) {
768768 $this->sink->writeRevision( $rev, $string );
769769 }
770770 }
771 -
 771+
772772 function writeLogItem( $rev, $string ) {
773773 $this->sink->writeRevision( $rev, $string );
774 - }
 774+ }
775775
776776 /**
777777 * Override for page-based filter types.
@@ -822,17 +822,17 @@
823823 "NS_CATEGORY" => NS_CATEGORY,
824824 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
825825
826 - if( $param{0} == '!' ) {
 826+ if ( $param { 0 } == '!' ) {
827827 $this->invert = true;
828828 $param = substr( $param, 1 );
829829 }
830830
831 - foreach( explode( ',', $param ) as $key ) {
 831+ foreach ( explode( ',', $param ) as $key ) {
832832 $key = trim( $key );
833 - if( isset( $constants[$key] ) ) {
 833+ if ( isset( $constants[$key] ) ) {
834834 $ns = $constants[$key];
835835 $this->namespaces[$ns] = true;
836 - } elseif( is_numeric( $key ) ) {
 836+ } elseif ( is_numeric( $key ) ) {
837837 $ns = intval( $key );
838838 $this->namespaces[$ns] = true;
839839 } else {
@@ -861,7 +861,7 @@
862862 }
863863
864864 function writeClosePage( $string ) {
865 - if( $this->rev ) {
 865+ if ( $this->rev ) {
866866 $this->sink->writeOpenPage( $this->page, $this->pageString );
867867 $this->sink->writeRevision( $this->rev, $this->revString );
868868 $this->sink->writeClosePage( $string );
@@ -873,7 +873,7 @@
874874 }
875875
876876 function writeRevision( $rev, $string ) {
877 - if( $rev->rev_id == $this->page->page_latest ) {
 877+ if ( $rev->rev_id == $this->page->page_latest ) {
878878 $this->rev = $rev;
879879 $this->revString = $string;
880880 }
@@ -891,31 +891,31 @@
892892 }
893893
894894 function writeOpenStream( $string ) {
895 - for( $i = 0; $i < $this->count; $i++ ) {
 895+ for ( $i = 0; $i < $this->count; $i++ ) {
896896 $this->sinks[$i]->writeOpenStream( $string );
897897 }
898898 }
899899
900900 function writeCloseStream( $string ) {
901 - for( $i = 0; $i < $this->count; $i++ ) {
 901+ for ( $i = 0; $i < $this->count; $i++ ) {
902902 $this->sinks[$i]->writeCloseStream( $string );
903903 }
904904 }
905905
906906 function writeOpenPage( $page, $string ) {
907 - for( $i = 0; $i < $this->count; $i++ ) {
 907+ for ( $i = 0; $i < $this->count; $i++ ) {
908908 $this->sinks[$i]->writeOpenPage( $page, $string );
909909 }
910910 }
911911
912912 function writeClosePage( $string ) {
913 - for( $i = 0; $i < $this->count; $i++ ) {
 913+ for ( $i = 0; $i < $this->count; $i++ ) {
914914 $this->sinks[$i]->writeClosePage( $string );
915915 }
916916 }
917917
918918 function writeRevision( $rev, $string ) {
919 - for( $i = 0; $i < $this->count; $i++ ) {
 919+ for ( $i = 0; $i < $this->count; $i++ ) {
920920 $this->sinks[$i]->writeRevision( $rev, $string );
921921 }
922922 }

Status & tagging log