From 5b2926495100869f18741fbcae35f653dc893c09 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 6 Feb 2009 22:44:28 +0000 Subject: [PATCH] Add 'include pages linked to from these pages' to Special:Export and the corresponding transwiki interface. --- includes/Import.php | 3 ++- includes/specials/SpecialExport.php | 16 ++++++++++++++++ includes/specials/SpecialImport.php | 9 ++++++++- languages/messages/MessagesEn.php | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index 17560a7220..4daf73bc89 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1116,7 +1116,7 @@ class ImportStreamSource { } } - public static function newFromInterwiki( $interwiki, $page, $history = false, $templates = false ) { + public static function newFromInterwiki( $interwiki, $page, $history = false, $templates = false, $pageLinkDepth = 0 ) { if( $page == '' ) { return new WikiErrorMsg( 'import-noarticle' ); } @@ -1127,6 +1127,7 @@ class ImportStreamSource { $params = array(); if ( $history ) $params['history'] = 1; if ( $templates ) $params['templates'] = 1; + if ( $pageLinkDepth ) $params['pagelink-depth'] = $pageLinkDepth; $url = $link->getFullUrl( $params ); # For interwikis, use POST to avoid redirects. return ImportStreamSource::newFromURL( $url, "POST" ); diff --git a/includes/specials/SpecialExport.php b/includes/specials/SpecialExport.php index 898b5a7851..04f0d6b0f5 100644 --- a/includes/specials/SpecialExport.php +++ b/includes/specials/SpecialExport.php @@ -62,6 +62,17 @@ function wfExportGetTemplates( $inputPages, $pageSet ) { array( 'page_id=tl_from' ) ); } +/** Expand a list of pages to include pages linked to from that page. */ +function wfExportGetPageLinks( $inputPages, $pageSet, $depth ) { + for( $depth=$depth; $depth>0; --$depth ) { + $pageSet = wfExportGetLinks( $inputPages, $pageSet, 'pagelinks', + array( 'pl_namespace AS namespace', 'pl_title AS title' ), + array( 'page_id=pl_from' ) ); + } + + return $pageSet; +} + /** * Expand a list of pages to include images used in those pages. * @param $inputPages array, list of titles to look up @@ -211,6 +222,10 @@ function wfSpecialExport( $page = '' ) { if( $wgRequest->getCheck( 'templates' ) ) { $pageSet = wfExportGetTemplates( $inputPages, $pageSet ); } + + if( $linkDepth = $wgRequest->getIntOrNull( 'pagelink-depth' ) ) { + $pageSet = wfExportGetPageLinks( $inputPages, $pageSet, $linkDepth ); + } /* // Enable this when we can do something useful exporting/importing image information. :) @@ -292,6 +307,7 @@ function wfSpecialExport( $page = '' ) { $wgOut->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) ); } $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '
'; + $form .= Xml::inputLabel( wfMsg( 'export-pagelinks' ), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '
'; // Enable this when we can do something useful exporting/importing image information. :) //$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '
'; $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '
'; diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index b6318c66a9..6d9b2c8723 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -72,6 +72,7 @@ class SpecialImport extends SpecialPage { $sourceName = $wgRequest->getVal( "source" ); $this->logcomment = $wgRequest->getText( 'log-comment' ); + $this->pageLinkDepth = $wgRequest->getIntOrNull( 'pagelink-depth' ); if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) { $source = new WikiErrorMsg( 'import-token-mismatch' ); @@ -94,7 +95,8 @@ class SpecialImport extends SpecialPage { $this->interwiki, $this->frompage, $this->history, - $this->includeTemplates ); + $this->includeTemplates, + $this->pageLinkDepth ); } } else { $source = new WikiErrorMsg( "importunknownsource" ); @@ -221,6 +223,11 @@ class SpecialImport extends SpecialPage { " . Xml::checkLabel( wfMsg( 'import-interwiki-templates' ), 'interwikiTemplates', 'interwikiTemplates', $this->includeTemplates ) . " + + + ".wfMsgExt( 'export-pagelinks', 'parseinline' )." + " . Xml::input( 'pagelink-depth', 20, 0 ) . "
+ " . Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) . diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 8daccf3166..777068bb79 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2794,6 +2794,7 @@ In the latter case you can also use a link, e.g. [[{{ns:special}}:Export/{{Media 'export-addcat' => 'Add', 'export-download' => 'Save as file', 'export-templates' => 'Include templates', +'export-pagelinks' => 'Include linked pages to a depth of:', # Namespace 8 related 'allmessages' => 'System messages', -- 2.20.1