* Add option to include templates in Special:Export.
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 20 Jan 2008 07:14:12 +0000 (07:14 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 20 Jan 2008 07:14:12 +0000 (07:14 +0000)
(An option to *expand* templates might be helpful too.)

RELEASE-NOTES
includes/SpecialExport.php
languages/messages/MessagesEn.php

index 620bf87..cf1c3b4 100644 (file)
@@ -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 ===
index 71eb122..f6261e4 100644 (file)
@@ -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 ) . '<br />';
        $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
        
        $form .= Xml::submitButton( wfMsg( 'export-submit' ) );
index 3815912..b737bd4 100644 (file)
@@ -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',