* Allow fetching all revisions from transwiki Special:Import
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 27 Jun 2006 21:48:43 +0000 (21:48 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 27 Jun 2006 21:48:43 +0000 (21:48 +0000)
* Allow fetching all revisions from Special:Export GET request
* Disable output buffering on Special:Export; should help with streaming
  large numbers of history items.
* Allow setting a maximum number of revisions for history Special:Export;
  pages with more than $wgExportMaxHistory revisions are excluded from
  export when history is requested.
* Fix transwiki import of pages with space in name

RELEASE-NOTES
includes/DefaultSettings.php
includes/Revision.php
includes/SpecialExport.php
includes/SpecialImport.php
languages/Messages.php

index e73ee37..9379699 100644 (file)
@@ -576,6 +576,14 @@ Some default configuration options have changed:
 * (bug 2483) Run link updates on change via XML import
 * (bug 2481) List imported pages during Special:Import
 * (bug 2482) Log and RC entries for Special:Import events
+* Allow fetching all revisions from transwiki Special:Import
+* Allow fetching all revisions from Special:Export GET request
+* Disable output buffering on Special:Export; should help with streaming
+  large numbers of history items.
+* Allow setting a maximum number of revisions for history Special:Export;
+  pages with more than $wgExportMaxHistory revisions are excluded from
+  export when history is requested.
+* Fix transwiki import of pages with space in name
 
 
 == Compatibility ==
index eb2b07b..c4b2296 100644 (file)
@@ -1470,6 +1470,14 @@ $wgImportSources = array();
  * disabled on Wikimedia's sites.
  */
 $wgExportAllowHistory = true;
+
+/**
+ * If set nonzero, Special:Export requests for history of pages with
+ * more revisions than this will be rejected. On some big sites things
+ * could get bogged down by very very long pages.
+ */
+$wgExportMaxHistory = 0;
+
 $wgExportAllowListContributors = false ;
 
 
index 3139f24..653bacb 100644 (file)
@@ -768,6 +768,23 @@ class Revision {
                }
                return $timestamp;
        }
+       
+       static function countByPageId( $db, $id ) {
+               $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
+                       array( 'rev_page' => $id ), __METHOD__ );
+               if( $row ) {
+                       return $row->revCount;
+               }
+               return 0;
+       }
+       
+       static function countByTitle( $db, $title ) {
+               $id = $title->getArticleId();
+               if( $id ) {
+                       return Revision::countByPageId( $db, $id );
+               }
+               return 0;
+       }
 }
 
 /**
index 1f9a7f3..e589b57 100644 (file)
@@ -30,17 +30,18 @@ require_once( 'Export.php' );
  */
 function wfSpecialExport( $page = '' ) {
        global $wgOut, $wgRequest, $wgExportAllowListContributors;
-       global $wgExportAllowHistory;
+       global $wgExportAllowHistory, $wgExportMaxHistory;
 
+       $curonly = true;
        if( $wgRequest->getVal( 'action' ) == 'submit') {
                $page = $wgRequest->getText( 'pages' );
-               if( $wgExportAllowHistory ) {
-                       $curonly = $wgRequest->getCheck( 'curonly' );
-               } else {
-                       $curonly = true;
-               }
-       } else {
-               # Pre-check the 'current version only' box in the UI
+               $curonly = $wgRequest->getCheck( 'curonly' );
+       }
+       if( $wgRequest->getCheck( 'history' ) ) {
+               $curonly = false;
+       }
+       if( !$wgExportAllowHistory ) {
+               // Override
                $curonly = true;
        }
        
@@ -49,6 +50,15 @@ function wfSpecialExport( $page = '' ) {
 
        if( $page != '' ) {
                $wgOut->disable();
+               
+               // Cancel output buffering and gzipping if set
+               // This should provide safer streaming for pages with history
+               while( $status = ob_get_status() ) {
+                       ob_end_clean();
+                       if( $status['name'] == 'ob_gzhandler' ) {
+                               header( 'Content-Encoding:' );
+                       }
+               }
                header( "Content-type: application/xml; charset=utf-8" );
                $pages = explode( "\n", $page );
 
@@ -57,7 +67,22 @@ function wfSpecialExport( $page = '' ) {
                $exporter = new WikiExporter( $db, $history );
                $exporter->list_authors = $list_authors ;
                $exporter->openStream();
-               $exporter->pagesByName( $pages );
+               
+               foreach( $pages as $page ) {
+                       if( $wgExportMaxHistory && !$curonly ) {
+                               $title = Title::newFromText( $page );
+                               if( $title ) {
+                                       $count = Revision::countByTitle( $db, $title );
+                                       if( $count > $wgExportMaxHistory ) {
+                                               wfDebug( __FUNCTION__ .
+                                                       ": Skipped $page, $count revisions too big\n" );
+                                               continue;
+                                       }
+                               }
+                       }
+                       $exporter->pagesByName( $pages );
+               }
+               
                $exporter->closeStream();
                return;
        }
index 87fbd7e..65ae089 100644 (file)
@@ -48,10 +48,12 @@ function wfSpecialImport( $page = '' ) {
                        }
                        break;
                case "interwiki":
-                       $interwiki = $wgRequest->getVal( "interwiki" );
+                       $interwiki = $wgRequest->getVal( 'interwiki' );
+                       $history = $wgRequest->getCheck( 'interwikiHistory' );
                        $source = ImportStreamSource::newFromInterwiki(
                                $interwiki,
-                               $wgRequest->getText( "frompage" ) );
+                               $wgRequest->getText( "frompage" ),
+                               $history );
                        break;
                default:
                        $source = new WikiError( "Unknown import source type" );
@@ -105,19 +107,39 @@ function wfSpecialImport( $page = '' ) {
                $wgOut->addHTML( "
 <fieldset>
        <legend>" . wfMsgHtml('importinterwiki') . "</legend>
-       <form method='post' action=\"$action\">
+       <form method='post' action=\"$action\">" .
+               $wgOut->parse( wfMsg( 'import-interwiki-text' ) ) . "
                <input type='hidden' name='action' value='submit' />
                <input type='hidden' name='source' value='interwiki' />
-               <select name='interwiki'>
-" );
+               <table>
+                       <tr>
+                               <td>
+                                       <select name='interwiki'>" );
                foreach( $wgImportSources as $interwiki ) {
                        $iw = htmlspecialchars( $interwiki );
                        $wgOut->addHTML( "<option value=\"$iw\">$iw</option>\n" );
                }
                $wgOut->addHTML( "
-               </select>
-               <input name='frompage' />
-               <input type='submit' />
+                                       </select>
+                               </td>
+                               <td>" .
+                                       wfInput( 'frompage', 40 ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>" .
+                                       wfCheckLabel( wfMsg( 'import-interwiki-history' ),
+                                               'interwikiHistory', 'interwikiHistory', true ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>" .
+                                       wfSubmitButton( wfMsg( 'import-interwiki-submit' ) ) .
+                               "</td>
+                       </tr>
+               </table>
        </form>
 </fieldset>
 " );
@@ -705,6 +727,7 @@ class ImportStreamSource {
        }
 
        function newFromURL( $url ) {
+               wfDebug( __METHOD__ . ": opening $url\n" );
                # fopen-wrappers are normally turned off for security.
                ini_set( "allow_url_fopen", true );
                $ret = ImportStreamSource::newFromFile( $url );
@@ -712,13 +735,14 @@ class ImportStreamSource {
                return $ret;
        }
 
-       function newFromInterwiki( $interwiki, $page ) {
+       function newFromInterwiki( $interwiki, $page, $history=false ) {
                $base = Title::getInterwikiLink( $interwiki );
-               if( empty( $base ) ) {
+               $link = Title::newFromText( "$interwiki:Special:Export/$page" );
+               if( empty( $base ) || empty( $link ) ) {
                        return new WikiError( 'Bad interwiki link' );
                } else {
-                       $import = wfUrlencode( "Special:Export/$page" );
-                       $url = str_replace( "$1", $import, $base );
+                       $params = $history ? 'history=1' : '';
+                       $url = $link->getFullUrl( $params );
                        return ImportStreamSource::newFromURL( $url );
                }
        }
index 06c9aba..ce93b4b 100644 (file)
@@ -1457,6 +1457,11 @@ In the latter case you can also use a link, e.g. [[{{ns:Special}}:Export/{{int:m
 # Special:Import
 'import'       => 'Import pages',
 'importinterwiki' => 'Transwiki import',
+'import-interwiki-text' => 'Select a wiki and page title to import.
+Revision dates and editors\' names will be preserved.
+All transwiki import actions are logged at the [[Special:Log/import|import log]].',
+'import-interwiki-history' => 'Copy all history versions for this page',
+'import-interwiki-submit' => 'Import',
 'importtext'   => 'Please export the file from the source wiki using the Special:Export utility, save it to your disk and upload it here.',
 'importstart'  => "Importing pages...",
 'importnopages'        => "No pages to import.",