Index: trunk/phase3/includes/SpecialExport.php |
— | — | @@ -50,6 +50,38 @@ |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
| 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 |
| 57 | + */ |
| 58 | +function wfExportGetTemplates( $pages ) { |
| 59 | + $pageList = array_unique( array_filter( explode( "\n", $pages ) ) ); |
| 60 | + $output = array(); |
| 61 | + $dbr = wfGetDB( DB_SLAVE ); |
| 62 | + foreach( $pageList as $page ) { |
| 63 | + $title = Title::newFromText( $page ); |
| 64 | + $output[$title->getPrefixedText()] = true; |
| 65 | + if( $title ) { |
| 66 | + /// @fixme May or may not be more efficient to batch these |
| 67 | + /// by namespace when given multiple input pages. |
| 68 | + $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' ), |
| 75 | + __METHOD__ ); |
| 76 | + foreach( $result as $row ) { |
| 77 | + $template = Title::makeTitle( $row->tl_namespace, $row->tl_title ); |
| 78 | + $output[$template->getPrefixedText()] = true; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + return implode( "\n", array_keys( $output ) ); |
| 83 | +} |
| 84 | + |
| 85 | +/** |
54 | 86 | * |
55 | 87 | */ |
56 | 88 | function wfSpecialExport( $page = '' ) { |
— | — | @@ -66,6 +98,11 @@ |
67 | 99 | if ( $catname !== '' && $catname !== NULL && $catname !== false ) { |
68 | 100 | $t = Title::makeTitleSafe( NS_CATEGORY, $catname ); |
69 | 101 | if ( $t ) { |
| 102 | + /** |
| 103 | + * @fixme This can lead to hitting memory limit for very large |
| 104 | + * categories. Ideally we would do the lookup synchronously |
| 105 | + * during the export in a single query. |
| 106 | + */ |
70 | 107 | $catpages = wfExportGetPagesFromCategory( $t ); |
71 | 108 | if ( $catpages ) $page .= "\n" . implode( "\n", $catpages ); |
72 | 109 | } |
— | — | @@ -123,6 +160,10 @@ |
124 | 161 | |
125 | 162 | $list_authors = $wgRequest->getCheck( 'listauthors' ); |
126 | 163 | if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ; |
| 164 | + |
| 165 | + if( $wgRequest->getCheck( 'templates' ) ) { |
| 166 | + $page = wfExportGetTemplates( $page ); |
| 167 | + } |
127 | 168 | |
128 | 169 | if ( $doexport ) { |
129 | 170 | $wgOut->disable(); |
— | — | @@ -188,6 +229,7 @@ |
189 | 230 | } else { |
190 | 231 | $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) ); |
191 | 232 | } |
| 233 | + $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />'; |
192 | 234 | $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />'; |
193 | 235 | |
194 | 236 | $form .= Xml::submitButton( wfMsg( 'export-submit' ) ); |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2261,6 +2261,7 @@ |
2262 | 2262 | 'export-addcattext' => 'Add pages from category:', |
2263 | 2263 | 'export-addcat' => 'Add', |
2264 | 2264 | 'export-download' => 'Save as file', |
| 2265 | +'export-templates' => 'Include templates', |
2265 | 2266 | |
2266 | 2267 | # Namespace 8 related |
2267 | 2268 | 'allmessages' => 'System messages', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -135,6 +135,7 @@ |
136 | 136 | * Support redirects in image namespace |
137 | 137 | * (bug 10049) Prefix index search and namespaces in Special:Withoutinterwiki |
138 | 138 | * (bug 12668) Support for custom iPhone bookmark icon via $wgAppleTouchIcon |
| 139 | +* Add option to include templates in Special:Export. |
139 | 140 | |
140 | 141 | |
141 | 142 | === Bug fixes in 1.12 === |