Followup to r46951 and friends: add $wgExportMaxLinkDepth, defaulting to 0.
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 18 Feb 2009 00:48:39 +0000 (00:48 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 18 Feb 2009 00:48:39 +0000 (00:48 +0000)
If set to non-zero, this specifies the maximum link depth that will be followed for exports. Remember "6 degrees of separation", this could easily kill on a site like Wikipedia. :)

includes/DefaultSettings.php
includes/specials/SpecialExport.php

index 6d37c88..34adb07 100644 (file)
@@ -2269,6 +2269,15 @@ $wgExportMaxHistory = 0;
 
 $wgExportAllowListContributors = false ;
 
+/**
+ * If non-zero, Special:Export accepts a "pagelink-depth" parameter
+ * up to this specified level, which will cause it to include all
+ * pages linked to from the pages you specify. Since this number
+ * can become *insanely large* and could easily break your wiki,
+ * it's disabled by default for now.
+ */
+$wgExportMaxLinkDepth = 0;
+
 
 /**
  * Edits matching these regular expressions in body text or edit summary
index 9005cf7..4f0d186 100644 (file)
@@ -32,7 +32,7 @@ class SpecialExport extends SpecialPage {
        
        public function execute( $par ) {
                global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
-               global $wgExportAllowHistory, $wgExportMaxHistory;
+               global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth;
 
                $this->setHeaders();
                $this->outputHeader();
@@ -42,7 +42,8 @@ class SpecialExport extends SpecialPage {
                $this->doExport = false;
                $this->templates = $wgRequest->getCheck( 'templates' );
                $this->images = $wgRequest->getCheck( 'images' ); // Doesn't do anything yet
-               $this->pageLinkDepth = $wgRequest->getIntOrNull( 'pagelink-depth' );
+               $this->pageLinkDepth = $this->validateLinkDepth(
+                       $wgRequest->getIntOrNull( 'pagelink-depth' ) );
 
                if ( $wgRequest->getCheck( 'addcat' ) ) {
                        $page = $wgRequest->getText( 'pages' );
@@ -144,7 +145,9 @@ class SpecialExport extends SpecialPage {
                        $wgOut->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) );
                }
                $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />';
-               $form .= Xml::inputLabel( wfMsg( 'export-pagelinks' ), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '<br />';
+               if( $wgExportMaxLinkDepth ) {
+                       $form .= Xml::inputLabel( wfMsg( 'export-pagelinks' ), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '<br />';
+               }
                // Enable this when we can do something useful exporting/importing image information. :)
                //$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '<br />';
                $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
@@ -270,6 +273,20 @@ class SpecialExport extends SpecialPage {
                                        array( 'page_id=tl_from' ) );
        }
 
+       /**
+        * Validate link depth setting, if available.
+        */
+       private function validateLinkDepth( $depth ) {
+               global $wgExportMaxLinkDepth;
+               if( $depth < 0 ) {
+                       return 0;
+               }
+               if( $depth > $wgExportMaxLinkDepth ) {
+                       return $wgExportMaxLinkDepth;
+               }
+               return intval( $depth );
+       }
+
        /** Expand a list of pages to include pages linked to from that page. */
        private function getPageLinks( $inputPages, $pageSet, $depth ) {
                for( $depth=$depth; $depth>0; --$depth ) {