--- mediawiki-1.5beta4/includes/SpecialExport.php 2005-07-13 03:59:12.000000000 +0200 +++ mwMM/applic/includes/SpecialExport.php 2005-08-20 17:45:52.867577320 +0200 @@ -1,4 +1,18 @@ # http://www.mediawiki.org/ # @@ -22,64 +36,349 @@ * @subpackage SpecialPage */ +# This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined +if( !defined( 'MEDIAWIKI' ) ) { + die( "This file is part of MediaWiki and is not a valid entry point\n" ); +} + /** */ require_once( 'Revision.php' ); +/* +* ==== comment to be removed after patch acceptance ==== +* why not just boolean's for the related parameters ? +* do we expect other values ? +*/ +define( 'MW_EXPORT_FULL', 0 ); +define( 'MW_EXPORT_CURRENT', 1 ); + +define( 'MW_EXPORT_BUFFER', 0 ); +define( 'MW_EXPORT_STREAM', 1 ); + +/* +* ==== comment to be removed after patch acceptance === +* wfSpecialExport does 4 things : +* 1 - process the request and/or the config parameters +* 2 - send HTTP header(s) +* 3 - send the XML output +* 4 - build the form +* Because this patch increases a little bit tasks 1, 2 and 4, +* it seems more convenient to leave task 1 here, +* but to move tasks 2, 3 and 4 in separate functions. +* In order to avoid wfXxx name space pollution, these 3 functions +* are created as static function of class WikiExporter +* doHeaders() , doExport() , doForm +*/ + /** - * + * Entry point + * @param $page string */ function wfSpecialExport( $page = '' ) { - global $wgOut, $wgLang, $wgRequest; + global $wgRequest; + + // config parameters : + + $wgSpecialExportFilename = is_integer($wgSpecialExportFilename) ? + $wgSpecialExportFilename : MW_EXPORT_FILENAME_DEFAULT ; + $wgSpecialExportDownload = is_integer($wgSpecialExportDownload) ? + $wgSpecialExportDownload : MW_EXPORT_DISPO_DEFAULT ; + $wgSpecialExportPrefix = is_string($wgSpecialExportPrefix) ? + $wgSpecialExportPrefix : MW_EXPORT_DEFAULT_PREFIX ; + + // proceed/prepare request : if( $wgRequest->getVal( 'action' ) == 'submit') { $page = $wgRequest->getText( 'pages' ); $curonly = $wgRequest->getCheck( 'curonly' ); + $szRequesXmlFileName = $wgRequest->getText( 'szXmlFileName' ); + $zRequestDispo = $wgRequest->getCheck( 'zDispo' ); } else { # Pre-check the 'current version only' box in the UI $curonly = true; } if( $page != '' ) { + + // output HTTP header(s) : + + WikiExporter::doHeaders( + // $zXmlDisposition = true // shall we use Content-Disposition ? + (( $wgSpecialExportDownload == MW_EXPORT_DISPO_ALLWAYS) || $zRequestDispo ) + // , $szSuggestedPrefix = MW_EXPORT_DEFAULT_PREFIX + , $wgSpecialExportPrefix + // , $zDate = true + , (($wgSpecialExportFilename == MW_EXPORT_FILENAME_ASK_ELSE_TIMESTAMP) + || ($wgSpecialExportFilename == MW_EXPORT_FILENAME_TIMESTAMP)) + , $szXmlFileName + // , $zRelyOnFileName = false + // , $uMaxLength = 250 // RARELY USED ! + // , $zGerman = true // RARELY USED ! + ) ; + + // output XML : + + WikiExporter::doExport( + $page + // , $history = MW_EXPORT_CURRENT + , ( $curonly ? MW_EXPORT_CURRENT : MW_EXPORT_FULL ) + // , $buffer = MW_EXPORT_BUFFER + ) ; + + } else { + + // prepare the form : + + WikiExporter::doForm( + // $zCurOnly = true // preset value of the 'current v. all' checkbox + $curonly + // , $zDisposition = true // preset value for the 'download' checkbox + , (($wgSpecialExportDownload == MW_EXPORT_DISPO_SUGGESTED) || $zRequestDispo) + // , $szXmlDispositionFileName = '' // preset value for the file name + , $szXmlFileName + // , $zAskFilename = true // shall we prompt the user for a filename? + , (($wgSpecialExportFilename == MW_EXPORT_FILENAME_ASK_ELSE_TIMESTAMP) + || ($wgSpecialExportFilename == MW_EXPORT_FILENAME_ASK_ELSE_RANDOM)) + // , $zAskDisposition = true // shall we prompt the user for download? + , (($wgSpecialExportDownload == MW_EXPORT_DISPO_PERHAPS) + || ($wgSpecialExportDownload == MW_EXPORT_DISPO_SUGGESTED)) + // , $szSuggestedPrefix = MW_EXPORT_DEFAULT_PREFIX + , $wgSpecialExportPrefix + // , $zDate = true + , (($wgSpecialExportFilename == MW_EXPORT_FILENAME_ASK_ELSE_TIMESTAMP) + || ($wgSpecialExportFilename == MW_EXPORT_FILENAME_TIMESTAMP)) + // , $zRelyOnFileName = false + // , $uMaxLength = 250 // RARELY USED ! + // , $zGerman = true // RARELY USED ! + ) ; + } +} + +/** + * @package MediaWiki + * @subpackage SpecialPage + */ +class WikiExporter { + /**#@+ + * @access public + * @static + */ + + /** + * @param boolean $zXmlDisposition : shall we use Content-Disposition ? + * @param string $szSuggestedPrefix + * @param boolean $zDate : use a timestamp (otherwise use a random value) + * @param string $szXmlDispositionFileName + * @param boolean $zRelyOnFileName (turn on if you are sure file name is ok, probably beacause it was generated automatically) + * @param unsigned $uMaxLength (RARE) Maximum filename length. Default is 250 characters. + * @param boolean $zGerman (RARE) proceed also german characters + */ + function doHeaders( + $zXmlDisposition = true // shall we use Content-Disposition ? + , $szSuggestedPrefix = MW_EXPORT_DEFAULT_PREFIX + , $zDate = true + , $szXmlDispositionFileName = '' + , $zRelyOnFileName = false + , $uMaxLength = 250 // RARELY USED ! + , $zGerman = true // RARELY USED ! + ) + { + global $wgOut ; $wgOut->disable(); header( "Content-type: application/xml; charset=utf-8" ); - $pages = explode( "\n", $page ); + if($zXmlDisposition) + { + if( ! $zRelyOnFileName ) + { + $szXmlDispositionFileName = wfUnixFileName( + $szXmlDispositionFileName,$uMaxLength,$zGerman) ; + } + if(! $szXmlDispositionFileName) + { + $szXmlDispositionFileName = wfSuggestFileName( + $szSuggestedPrefix,$zDate,$uMaxLength) ; + } + header("Content-Disposition: attachment; filename=\"{$szXmlDispositionFileName}\"'"); + } + } + /** + * factorize and run... + * + * @param string $page + * @param unsigned $history one of MW_EXPORT_FULL or MW_EXPORT_CURRENT + * @param unsigned $buffer one of MW_EXPORT_BUFFER or MW_EXPORT_STREAM + */ + function doExport( + $page + /* + * ==== comment to be removed after patch acceptance ==== + * why not just boolean's for these 2 parameters ? + */ + , $history = MW_EXPORT_CURRENT + , $buffer = MW_EXPORT_BUFFER + ) + { + $pages = explode( "\n", $page ); $db =& wfGetDB( DB_SLAVE ); - $history = $curonly ? MW_EXPORT_CURRENT : MW_EXPORT_FULL; - $exporter = new WikiExporter( $db, $history ); + $exporter = new WikiExporter( + $db + , $history = MW_EXPORT_CURRENT + , $buffer = MW_EXPORT_BUFFER + ); + /* + * ==== comment to be removed after patch acceptance ==== + * Mind that openStream() and closeStream() are, in fact, static functions + */ $exporter->openStream(); + // WikiExporter::openStream(); //... $exporter->pagesByName( $pages ); $exporter->closeStream(); - return; + // WikiExporter::closeStream(); //... } + /** + * write down the Export form on $wgOut + * + * @param boolean $curonly ($zCurOnly) preset value of the 'current v. all' checkbox + * @param boolean $zDisposition preset value for the 'download' checkbox + * @param string $szXmlDispositionFileName preset value for the file name + * @param boolean $zAskFilename shall we prompt the user for a filename? + * @param boolean $zAskDisposition shall we prompt the user for download? + * @param boolean $zDate use time stamp if we need to generate a file name + * @param boolean $zRelyOnFileName (turn on if you are sure file name is ok, probably beacause it was generated automatically) + * @param unsigned $uMaxLength (rarely used) + * @param boolean $zGerman (rarely used) + */ + function doForm( + $zCurOnly = true // preset value of the 'current v. all' checkbox + , $zDisposition = true // preset value for the 'download' checkbox + , $szXmlDispositionFileName = '' // preset value for the file name + , $zAskFilename = true // shall we prompt the user for a filename? + , $zAskDisposition = true // shall we prompt the user for download? + , $szSuggestedPrefix = MW_EXPORT_DEFAULT_PREFIX + , $zDate = true + , $zRelyOnFileName = false + , $uMaxLength = 250 // RARELY USED ! + , $zGerman = true // RARELY USED ! + ) + { + global $wgOut ; + $wgOut->addWikiText( wfMsg( "exporttext" ) ); $titleObj = Title::makeTitle( NS_SPECIAL, "Export" ); $action = $titleObj->escapeLocalURL( 'action=submit' ); + /* + * === comment to be removed after patch acceptance : + * there was a minor bug here : $curonly was ignored + */ + $szCurOnlyChecked = $zCurOnly ? " checked='checked' " : '' ; + $szPromptCurOnly = wfMsg( "exportcuronly" ) ; $wgOut->addHTML( "
+