From a4c45fb2546ba5ea1a653f28d0c5bdfc9a790e80 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 20 Jan 2008 07:14:12 +0000 Subject: [PATCH] * Add option to include templates in Special:Export. (An option to *expand* templates might be helpful too.) --- RELEASE-NOTES | 1 + includes/SpecialExport.php | 42 +++++++++++++++++++++++++++++++ languages/messages/MessagesEn.php | 1 + 3 files changed, 44 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 620bf87ecf..cf1c3b4a3e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -135,6 +135,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Support redirects in image namespace * (bug 10049) Prefix index search and namespaces in Special:Withoutinterwiki * (bug 12668) Support for custom iPhone bookmark icon via $wgAppleTouchIcon +* Add option to include templates in Special:Export. === Bug fixes in 1.12 === diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index 71eb1221aa..f6261e49c4 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -49,6 +49,38 @@ function wfExportGetPagesFromCategory( $title ) { return $pages; } +/** + * Expand a list of pages to include templates used in those pages. + * @input $pages string newline-separated list of page titles + * @output string newline-separated list of page titles + */ +function wfExportGetTemplates( $pages ) { + $pageList = array_unique( array_filter( explode( "\n", $pages ) ) ); + $output = array(); + $dbr = wfGetDB( DB_SLAVE ); + foreach( $pageList as $page ) { + $title = Title::newFromText( $page ); + $output[$title->getPrefixedText()] = true; + if( $title ) { + /// @fixme May or may not be more efficient to batch these + /// by namespace when given multiple input pages. + $result = $dbr->select( + array( 'page', 'templatelinks' ), + array( 'tl_namespace', 'tl_title' ), + array( + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbKey(), + 'page_id=tl_from' ), + __METHOD__ ); + foreach( $result as $row ) { + $template = Title::makeTitle( $row->tl_namespace, $row->tl_title ); + $output[$template->getPrefixedText()] = true; + } + } + } + return implode( "\n", array_keys( $output ) ); +} + /** * */ @@ -66,6 +98,11 @@ function wfSpecialExport( $page = '' ) { if ( $catname !== '' && $catname !== NULL && $catname !== false ) { $t = Title::makeTitleSafe( NS_CATEGORY, $catname ); if ( $t ) { + /** + * @fixme This can lead to hitting memory limit for very large + * categories. Ideally we would do the lookup synchronously + * during the export in a single query. + */ $catpages = wfExportGetPagesFromCategory( $t ); if ( $catpages ) $page .= "\n" . implode( "\n", $catpages ); } @@ -123,6 +160,10 @@ function wfSpecialExport( $page = '' ) { $list_authors = $wgRequest->getCheck( 'listauthors' ); if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ; + + if( $wgRequest->getCheck( 'templates' ) ) { + $page = wfExportGetTemplates( $page ); + } if ( $doexport ) { $wgOut->disable(); @@ -188,6 +229,7 @@ function wfSpecialExport( $page = '' ) { } else { $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) ); } + $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '
'; $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '
'; $form .= Xml::submitButton( wfMsg( 'export-submit' ) ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 3815912aa8..b737bd49ac 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2261,6 +2261,7 @@ In the latter case you can also use a link, e.g. [[{{ns:special}}:Export/{{Media 'export-addcattext' => 'Add pages from category:', 'export-addcat' => 'Add', 'export-download' => 'Save as file', +'export-templates' => 'Include templates', # Namespace 8 related 'allmessages' => 'System messages', -- 2.20.1