From 068394aec07661c893ff0dd1a45a2ba880067706 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 16 Jul 2007 17:04:39 +0000 Subject: [PATCH] (bug 3173) Option to offer exported pages as a download, rather than displaying inline, as in most browsers; set Content-disposition: attachment with a filename incorporating the site name and timestamp. Defaults to being checked. Also rewrote the Export form generator to use Xml class methods; tweaked spacing on the existing check box. Tweaked English default for "exporttext". --- RELEASE-NOTES | 2 ++ includes/SpecialExport.php | 44 ++++++++++++++++++------------- languages/messages/MessagesEn.php | 3 ++- maintenance/language/messages.inc | 1 + 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a2664fad02..72a1b92cde 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -148,6 +148,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN than good. Proper handheld support will be added at a future date. For now, display should be acceptable either with CSS turned off or when using a so- phisticated handheld browser. +* (bug 3173) Option to offer exported pages as a download, rather than displaying + inline, as in most browsers == Bugfixes since 1.10 == diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index d8e767b1cc..9822efa34c 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -53,7 +53,7 @@ function wfExportGetPagesFromCategory( $title ) { * */ function wfSpecialExport( $page = '' ) { - global $wgOut, $wgRequest, $wgExportAllowListContributors; + global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors; global $wgExportAllowHistory, $wgExportMaxHistory; $curonly = true; @@ -131,6 +131,11 @@ function wfSpecialExport( $page = '' ) { // This should provide safer streaming for pages with history wfResetOutputBuffers(); header( "Content-type: application/xml; charset=utf-8" ); + if( $wgRequest->getCheck( 'wpDownload' ) ) { + // Provide a sane filename suggestion + $filename = $wgSitename . '-' . wfTimestampNow() . '.xml'; + $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" ); + } $pages = explode( "\n", $page ); $db = wfGetDB( DB_SLAVE ); @@ -164,25 +169,28 @@ function wfSpecialExport( $page = '' ) { return; } - $wgOut->addWikiText( wfMsg( "exporttext" ) ); - $titleObj = SpecialPage::getTitleFor( "Export" ); + $self = SpecialPage::getTitleFor( 'Export' ); + $wgOut->addHtml( wfMsgExt( 'exporttext', 'parse' ) ); + + $form = Xml::openElement( 'form', array( 'method' => 'post', + 'action' => $self->getLocalUrl( 'action=submit' ) ) ); + + $form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' '; + $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '
'; + + $form .= Xml::openElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ); + $form .= htmlspecialchars( $page ); + $form .= Xml::closeElement( 'textarea' ); + $form .= '
'; - $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) ); - - $form .= wfInputLabel( wfMsg( 'export-addcattext' ), 'catname', 'catname', 40 ) . ' '; - $form .= wfSubmitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '
'; - - $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . htmlspecialchars($page). '
'; - if( $wgExportAllowHistory ) { - $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) ); - $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '
'; + $form .= Xml::checkLabel( wfMsg( 'exportcuronly' ), 'curonly', 'curonly', true ) . '
'; } else { - $wgOut->addWikiText( wfMsg( 'exportnohistory' ) ); + $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) ); } - $form .= wfHidden( 'action', 'submit' ); - $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . ''; + $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '
'; + + $form .= Xml::submitButton( wfMsg( 'export-submit' ) ); + $form .= Xml::closeElement( 'form' ); $wgOut->addHtml( $form ); -} - - +} \ No newline at end of file diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 5f7aa3e54b..7d43aad48e 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2110,13 +2110,14 @@ To export pages, enter the titles in the text box below, one title per line, and select whether you want the current version as well as all old versions, with the page history lines, or just the current version with the info about the last edit. -In the latter case you can also use a link, e.g. [[{{ns:Special}}:Export/{{MediaWiki:mainpage}}]] for the page {{MediaWiki:mainpage}}.', +In the latter case you can also use a link, e.g. [[{{ns:Special}}:Export/{{MediaWiki:mainpage}}]] for the page "[[{{MediaWiki:mainpage}}]]".', '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.", 'export-submit' => 'Export', 'export-addcattext' => 'Add pages from category:', 'export-addcat' => 'Add', +'export-download' => 'Offer to save as a file', # Namespace 8 related 'allmessages' => 'System messages', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 439ef53f15..fa0cfb8ed9 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1397,6 +1397,7 @@ $wgMessageStructure = array( 'export-submit', 'export-addcattext', 'export-addcat', + 'export-download', ), 'allmessages' => array( 'allmessages', -- 2.20.1