Index: trunk/phase3/includes/SpecialExport.php |
— | — | @@ -51,34 +51,57 @@ |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * 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 |
57 | 58 | */ |
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 ) { |
61 | 84 | $dbr = wfGetDB( DB_SLAVE ); |
62 | | - foreach( $pageList as $page ) { |
| 85 | + foreach( $inputPages as $page ) { |
63 | 86 | $title = Title::newFromText( $page ); |
64 | | - $output[$title->getPrefixedText()] = true; |
| 87 | + $pageSet[$title->getPrefixedText()] = true; |
65 | 88 | if( $title ) { |
66 | 89 | /// @fixme May or may not be more efficient to batch these |
67 | 90 | /// by namespace when given multiple input pages. |
68 | 91 | $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() ) ), |
75 | 98 | __METHOD__ ); |
76 | 99 | 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; |
79 | 102 | } |
80 | 103 | } |
81 | 104 | } |
82 | | - return implode( "\n", array_keys( $output ) ); |
| 105 | + return $pageSet; |
83 | 106 | } |
84 | 107 | |
85 | 108 | /** |
— | — | @@ -161,10 +184,6 @@ |
162 | 185 | $list_authors = $wgRequest->getCheck( 'listauthors' ); |
163 | 186 | if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ; |
164 | 187 | |
165 | | - if( $wgRequest->getCheck( 'templates' ) ) { |
166 | | - $page = wfExportGetTemplates( $page ); |
167 | | - } |
168 | | - |
169 | 188 | if ( $doexport ) { |
170 | 189 | $wgOut->disable(); |
171 | 190 | |
— | — | @@ -177,8 +196,26 @@ |
178 | 197 | $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' ); |
179 | 198 | $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" ); |
180 | 199 | } |
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 ); |
182 | 204 | |
| 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 | + |
183 | 220 | $db = wfGetDB( DB_SLAVE ); |
184 | 221 | $exporter = new WikiExporter( $db, $history ); |
185 | 222 | $exporter->list_authors = $list_authors ; |
— | — | @@ -230,6 +267,8 @@ |
231 | 268 | $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) ); |
232 | 269 | } |
233 | 270 | $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 />'; |
234 | 273 | $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />'; |
235 | 274 | |
236 | 275 | $form .= Xml::submitButton( wfMsg( 'export-submit' ) ); |