Allow new checkbox on Special::Export to export all pages. See bug 10574.
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 3 Jan 2012 21:08:32 +0000 (21:08 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 3 Jan 2012 21:08:32 +0000 (21:08 +0000)
includes/DefaultSettings.php
includes/specials/SpecialExport.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 545a780..55baab8 100644 (file)
@@ -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 }
 
 /*************************************************************************//**
index 49f6839..b0e89fa 100644 (file)
@@ -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' ) ) . '<br />';
                }
 
+               if ( $wgExportAllowAll ) {
+                       $form .= Xml::checkLabel(
+                               wfMsg( 'exportall' ),
+                               'exportall',
+                               'exportall',
+                               $request->wasPosted() ? $request->getCheck( 'exportall' ) : false
+                       ) . '<br />';
+               }
+
                $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
                $form .= '<br />';
 
@@ -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 <error> tag or something.
-                       }
-                       if( !$title->userCan( 'read', $this->getUser() ) ) {
-                               continue; #TODO: perhaps output an <error> tag or something.
-                       }
+                               $title = Title::newFromText( $page );
+                               if( is_null( $title ) ) {
+                                       continue; #TODO: perhaps output an <error> tag or something.
+                               }
+                               if( !$title->userCan( 'read', $this->getUser() ) ) {
+                                       continue; #TODO: perhaps output an <error> tag or something.
+                               }
 
-                       $exporter->pageByTitle( $title );
+                               $exporter->pageByTitle( $title );
+                       }
                }
 
                $exporter->closeStream();
index cd32d8d..0f243a7 100644 (file)
@@ -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.",
index 0b6c06f..3133d77 100644 (file)
@@ -2271,6 +2271,7 @@ $wgMessageStructure = array(
        'export' => array(
                'export',
                'exporttext',
+               'exportall',
                'exportcuronly',
                'exportnohistory',
                'exportlistauthors',