Make export depth > 1 actually work. :) Assuming it doesn't bomb and die using too...
[lhc/web/wiklou.git] / includes / specials / SpecialExport.php
index 83d0bbf..06bf34a 100644 (file)
@@ -33,6 +33,7 @@ class SpecialExport extends SpecialPage {
        public function execute( $par ) {
                global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
                global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth;
+               global $wgExportFromNamespaces;
                
                $this->setHeaders();
                $this->outputHeader();
@@ -44,6 +45,7 @@ class SpecialExport extends SpecialPage {
                $this->images = $wgRequest->getCheck( 'images' ); // Doesn't do anything yet
                $this->pageLinkDepth = $this->validateLinkDepth(
                                                                                                                $wgRequest->getIntOrNull( 'pagelink-depth' ) );
+               $nsindex = '';
                
                if ( $wgRequest->getCheck( 'addcat' ) ) {
                        $page = $wgRequest->getText( 'pages' );
@@ -62,11 +64,11 @@ class SpecialExport extends SpecialPage {
                                }
                        }
                }
-               else if( $wgRequest->getCheck( 'addns' ) ) {
+               else if( $wgRequest->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
                        $page = $wgRequest->getText( 'pages' );
-                       $nsindex = $wgRequest->getText( 'nsindex' );
+                       $nsindex = $wgRequest->getText( 'nsindex', '' );
                        
-                       if ( $nsindex !== '' && $nsindex !== NULL && $nsindex !== false ) {
+                       if ( $nsindex !== '' && $nsindex !== null && $nsindex !== false ) {
                                /**
                                 * Same implementation as above, so same @fixme
                                 */
@@ -149,8 +151,10 @@ class SpecialExport extends SpecialPage {
                $form .= Xml::inputLabel( wfMsg( 'export-addcattext' )    , 'catname', 'catname', 40 ) . ' ';
                $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
                
-               $form .= Xml::namespaceSelector( '', null, 'nsindex', wfMsg( 'export-addnstext' ) ) . '&nbsp;';
-               $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />';
+               if ( $wgExportFromNamespaces ) {
+                       $form .= Xml::namespaceSelector( $nsindex, null, 'nsindex', wfMsg( 'export-addnstext' ) ) . '&nbsp;';
+                       $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />';
+               }
                
                $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
                $form .= '<br />';
@@ -175,8 +179,8 @@ class SpecialExport extends SpecialPage {
        
        private function userCanOverrideExportDepth() {
                global $wgUser;   
-               
-               return in_array( 'override-export-depth', $wgUser->getRights());
+
+               return $wgUser->isAllowed( 'override-export-depth' );
        }
        
        /**
@@ -207,7 +211,13 @@ class SpecialExport extends SpecialPage {
                 */
                
                $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 );
+               }
+               $pages = array_unique( $pages );
+
                /* Ok, let's get to it... */
                if( $history == WikiExporter::CURRENT ) {
                        $lb = false;
@@ -343,6 +353,7 @@ class SpecialExport extends SpecialPage {
                        $pageSet = $this->getLinks( $inputPages, $pageSet, 'pagelinks',
                                                                           array( 'pl_namespace AS namespace', 'pl_title AS title' ),
                                                                           array( 'page_id=pl_from' ) );
+                       $inputPages = array_keys( $pageSet );
                }
                return $pageSet;
        }