From 7f42601e818bed5dc07a126621fc0b3041bb1dd0 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Tue, 3 Jan 2012 21:08:32 +0000 Subject: [PATCH] Allow new checkbox on Special::Export to export all pages. See bug 10574. --- includes/DefaultSettings.php | 5 ++ includes/specials/SpecialExport.php | 114 +++++++++++++++++----------- languages/messages/MessagesEn.php | 1 + maintenance/language/messages.inc | 1 + 4 files changed, 77 insertions(+), 44 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 545a780ed6..55baab8a14 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4773,6 +4773,11 @@ $wgExportMaxLinkDepth = 0; */ $wgExportFromNamespaces = false; +/** +* Whether to allow exporting the entire wiki into a single file +*/ +$wgExportAllowAll = false; + /** @} */ # end of import/export } /*************************************************************************//** diff --git a/includes/specials/SpecialExport.php b/includes/specials/SpecialExport.php index 49f6839f2e..b0e89fa6ce 100644 --- a/includes/specials/SpecialExport.php +++ b/includes/specials/SpecialExport.php @@ -40,6 +40,7 @@ class SpecialExport extends SpecialPage { public function execute( $par ) { global $wgSitename, $wgExportAllowListContributors, $wgExportFromNamespaces; global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth; + global $wgExportAllowAll; $this->setHeaders(); $this->outputHeader(); @@ -88,6 +89,10 @@ class SpecialExport extends SpecialPage { } } } + elseif( $request->getCheck( 'exportall' ) && $wgExportAllowAll ) { + $this->doExport = true; + $exportall = true; + } elseif( $request->wasPosted() && $par == '' ) { $page = $request->getText( 'pages' ); $this->curonly = $request->getCheck( 'curonly' ); @@ -165,7 +170,7 @@ class SpecialExport extends SpecialPage { $request->response()->header( "Content-disposition: attachment;filename={$filename}" ); } - $this->doExport( $page, $history, $list_authors ); + $this->doExport( $page, $history, $list_authors, $exportall ); return; } @@ -183,6 +188,15 @@ class SpecialExport extends SpecialPage { $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '
'; } + if ( $wgExportAllowAll ) { + $form .= Xml::checkLabel( + wfMsg( 'exportall' ), + 'exportall', + 'exportall', + $request->wasPosted() ? $request->getCheck( 'exportall' ) : false + ) . '
'; + } + $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false ); $form .= '
'; @@ -245,50 +259,58 @@ class SpecialExport extends SpecialPage { * @param $history Mixed: one of the WikiExporter history export constants * @param $list_authors Boolean: Whether to add distinct author list (when * not returning full history) + * @param $exportall Boolean: Whether to export everything */ - private function doExport( $page, $history, $list_authors ) { - $pageSet = array(); // Inverted index of all pages to look up - - // Split up and normalize input - foreach( explode( "\n", $page ) as $pageName ) { - $pageName = trim( $pageName ); - $title = Title::newFromText( $pageName ); - if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) { - // Only record each page once! - $pageSet[$title->getPrefixedText()] = true; + private function doExport( $page, $history, $list_authors, $exportall ) { + + // If we are grabbing everything, enable full history and ignore the rest + if ($exportall) { + $history = WikiExporter::FULL; + } else { + + $pageSet = array(); // Inverted index of all pages to look up + + // Split up and normalize input + foreach( explode( "\n", $page ) as $pageName ) { + $pageName = trim( $pageName ); + $title = Title::newFromText( $pageName ); + if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) { + // Only record each page once! + $pageSet[$title->getPrefixedText()] = true; + } } - } - // Set of original pages to pass on to further manipulation... - $inputPages = array_keys( $pageSet ); + // Set of original pages to pass on to further manipulation... + $inputPages = array_keys( $pageSet ); - // Look up any linked pages if asked... - if( $this->templates ) { - $pageSet = $this->getTemplates( $inputPages, $pageSet ); - } - $linkDepth = $this->pageLinkDepth; - if( $linkDepth ) { - $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth ); - } + // Look up any linked pages if asked... + if( $this->templates ) { + $pageSet = $this->getTemplates( $inputPages, $pageSet ); + } + $linkDepth = $this->pageLinkDepth; + if( $linkDepth ) { + $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth ); + } - /* - // Enable this when we can do something useful exporting/importing image information. :) - if( $this->images ) ) { - $pageSet = $this->getImages( $inputPages, $pageSet ); - } - */ + /* + // Enable this when we can do something useful exporting/importing image information. :) + if( $this->images ) ) { + $pageSet = $this->getImages( $inputPages, $pageSet ); + } + */ - $pages = array_keys( $pageSet ); + $pages = array_keys( $pageSet ); - // Normalize titles to the same format and remove dupes, see bug 17374 - foreach( $pages as $k => $v ) { - $pages[$k] = str_replace( " ", "_", $v ); - } + // Normalize titles to the same format and remove dupes, see bug 17374 + foreach( $pages as $k => $v ) { + $pages[$k] = str_replace( " ", "_", $v ); + } - $pages = array_unique( $pages ); + $pages = array_unique( $pages ); + } /* Ok, let's get to it... */ - if( $history == WikiExporter::CURRENT ) { + if( $history == WikiExporter::CURRENT && ! $exportall ) { $lb = false; $db = wfGetDB( DB_SLAVE ); $buffer = WikiExporter::BUFFER; @@ -308,7 +330,10 @@ class SpecialExport extends SpecialPage { $exporter->list_authors = $list_authors; $exporter->openStream(); - foreach( $pages as $page ) { + if ( $exportall ) { + $exporter->allPages(); + } else { + foreach( $pages as $page ) { /* if( $wgExportMaxHistory && !$this->curonly ) { $title = Title::newFromText( $page ); @@ -322,15 +347,16 @@ class SpecialExport extends SpecialPage { } }*/ #Bug 8824: Only export pages the user can read - $title = Title::newFromText( $page ); - if( is_null( $title ) ) { - continue; #TODO: perhaps output an tag or something. - } - if( !$title->userCan( 'read', $this->getUser() ) ) { - continue; #TODO: perhaps output an tag or something. - } + $title = Title::newFromText( $page ); + if( is_null( $title ) ) { + continue; #TODO: perhaps output an tag or something. + } + if( !$title->userCan( 'read', $this->getUser() ) ) { + continue; #TODO: perhaps output an tag or something. + } - $exporter->pageByTitle( $title ); + $exporter->pageByTitle( $title ); + } } $exporter->closeStream(); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index cd32d8d02d..0f243a7428 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3310,6 +3310,7 @@ This can be imported into another wiki using MediaWiki via the [[Special:Import| To export pages, enter the titles in the text box below, one title per line, and select whether you want the current revision as well as all old revisions, with the page history lines, or the current revision with the info about the last edit. In the latter case you can also use a link, for example [[{{#Special:Export}}/{{MediaWiki:Mainpage}}]] for the page "[[{{MediaWiki:Mainpage}}]]".', +'exportall' => 'Export all pages', 'exportcuronly' => 'Include only the current revision, not the full history', 'exportnohistory' => "---- '''Note:''' Exporting the full history of pages through this form has been disabled due to performance reasons.", diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 0b6c06f26b..3133d779f4 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2271,6 +2271,7 @@ $wgMessageStructure = array( 'export' => array( 'export', 'exporttext', + 'exportall', 'exportcuronly', 'exportnohistory', 'exportlistauthors', -- 2.20.1