r29976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29975‎ | r29976 | r29977 >
Date:10:58, 20 January 2008
Author:brion
Status:old
Tags:
Comment:
A little refactoring of the input splitting/expansion:
* Trim duplicate input. If we ask for "Foo" three times, only export it once!
* Add a (disabled) option to export used images as well. No use for it right now since Special:Export doesn't export, and Special:Import doesn't import, any useful image information. Uncomment it when that happens. :D
Modified paths:
  • /trunk/phase3/includes/SpecialExport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialExport.php
@@ -51,34 +51,57 @@
5252
5353 /**
5454 * Expand a list of pages to include templates used in those pages.
55 - * @input $pages string newline-separated list of page titles
56 - * @output string newline-separated list of page titles
 55+ * @param $inputPages array, list of titles to look up
 56+ * @param $pageSet array, associative array indexed by titles for output
 57+ * @return array associative array index by titles
5758 */
58 -function wfExportGetTemplates( $pages ) {
59 - $pageList = array_unique( array_filter( explode( "\n", $pages ) ) );
60 - $output = array();
 59+function wfExportGetTemplates( $inputPages, $pageSet ) {
 60+ return wfExportGetLinks( $inputPages, $pageSet,
 61+ 'templatelinks',
 62+ array( 'tl_namespace AS namespace', 'tl_title AS title' ),
 63+ array( 'page_id=tl_from' ) );
 64+}
 65+
 66+/**
 67+ * Expand a list of pages to include images used in those pages.
 68+ * @param $inputPages array, list of titles to look up
 69+ * @param $pageSet array, associative array indexed by titles for output
 70+ * @return array associative array index by titles
 71+ */
 72+function wfExportGetImages( $inputPages, $pageSet ) {
 73+ return wfExportGetLinks( $inputPages, $pageSet,
 74+ 'imagelinks',
 75+ array( NS_IMAGE . ' AS namespace', 'il_to AS title' ),
 76+ array( 'page_id=il_from' ) );
 77+}
 78+
 79+/**
 80+ * Expand a list of pages to include items used in those pages.
 81+ * @private
 82+ */
 83+function wfExportGetLinks( $inputPages, $pageSet, $table, $fields, $join ) {
6184 $dbr = wfGetDB( DB_SLAVE );
62 - foreach( $pageList as $page ) {
 85+ foreach( $inputPages as $page ) {
6386 $title = Title::newFromText( $page );
64 - $output[$title->getPrefixedText()] = true;
 87+ $pageSet[$title->getPrefixedText()] = true;
6588 if( $title ) {
6689 /// @fixme May or may not be more efficient to batch these
6790 /// by namespace when given multiple input pages.
6891 $result = $dbr->select(
69 - array( 'page', 'templatelinks' ),
70 - array( 'tl_namespace', 'tl_title' ),
71 - array(
72 - 'page_namespace' => $title->getNamespace(),
73 - 'page_title' => $title->getDbKey(),
74 - 'page_id=tl_from' ),
 92+ array( 'page', $table ),
 93+ $fields,
 94+ array_merge( $join,
 95+ array(
 96+ 'page_namespace' => $title->getNamespace(),
 97+ 'page_title' => $title->getDbKey() ) ),
7598 __METHOD__ );
7699 foreach( $result as $row ) {
77 - $template = Title::makeTitle( $row->tl_namespace, $row->tl_title );
78 - $output[$template->getPrefixedText()] = true;
 100+ $template = Title::makeTitle( $row->namespace, $row->title );
 101+ $pageSet[$template->getPrefixedText()] = true;
79102 }
80103 }
81104 }
82 - return implode( "\n", array_keys( $output ) );
 105+ return $pageSet;
83106 }
84107
85108 /**
@@ -161,10 +184,6 @@
162185 $list_authors = $wgRequest->getCheck( 'listauthors' );
163186 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
164187
165 - if( $wgRequest->getCheck( 'templates' ) ) {
166 - $page = wfExportGetTemplates( $page );
167 - }
168 -
169188 if ( $doexport ) {
170189 $wgOut->disable();
171190
@@ -177,8 +196,26 @@
178197 $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' );
179198 $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" );
180199 }
181 - $pages = explode( "\n", $page );
 200+
 201+ /* Split up the input and look up linked pages */
 202+ $inputPages = array_filter( explode( "\n", $page ) );
 203+ $pageSet = array_flip( $inputPages );
182204
 205+ if( $wgRequest->getCheck( 'templates' ) ) {
 206+ $pageSet = wfExportGetTemplates( $inputPages, $pageSet );
 207+ }
 208+
 209+ /*
 210+ // Enable this when we can do something useful exporting/importing image information. :)
 211+ if( $wgRequest->getCheck( 'images' ) ) {
 212+ $pageSet = wfExportGetImages( $inputPages, $pageSet );
 213+ }
 214+ */
 215+
 216+ $pages = array_keys( $pageSet );
 217+
 218+ /* Ok, let's get to it... */
 219+
183220 $db = wfGetDB( DB_SLAVE );
184221 $exporter = new WikiExporter( $db, $history );
185222 $exporter->list_authors = $list_authors ;
@@ -230,6 +267,8 @@
231268 $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) );
232269 }
233270 $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />';
 271+ // Enable this when we can do something useful exporting/importing image information. :)
 272+ //$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '<br />';
234273 $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
235274
236275 $form .= Xml::submitButton( wfMsg( 'export-submit' ) );

Status & tagging log