* (bug 6971) Fix regression in Special:Export history view
[mediawiki.git] / includes / SpecialExport.php
blob39e1d26882a66ea46023e42a93b26aa19025f319
1 <?php
2 # Copyright (C) 2003 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19 /**
21 * @package MediaWiki
22 * @subpackage SpecialPage
25 /** */
26 require_once( 'Export.php' );
28 /**
31 function wfSpecialExport( $page = '' ) {
32 global $wgOut, $wgRequest, $wgExportAllowListContributors;
33 global $wgExportAllowHistory, $wgExportMaxHistory;
34 $maxLimit = 200;
36 $curonly = true;
37 $fullHistory = array(
38 'dir' => 'asc',
39 'offset' => false,
40 'limit' => $maxLimit,
42 if( $wgRequest->getVal( 'action' ) == 'submit') {
43 $page = $wgRequest->getText( 'pages' );
44 $curonly = $wgRequest->getCheck( 'curonly' );
45 $rawOffset = $wgRequest->getVal( 'offset' );
46 if( $rawOffset ) {
47 $offset = wfTimestamp( TS_MW, $rawOffset );
48 } else {
49 $offset = null;
51 $limit = $wgRequest->getInt( 'limit' );
52 $dir = $wgRequest->getVal( 'dir' );
53 $history = array(
54 'dir' => 'asc',
55 'offset' => false,
56 'limit' => $maxLimit,
58 $historyCheck = $wgRequest->getCheck( 'history' );
59 if ( $curonly ) {
60 $history = MW_EXPORT_CURRENT;
61 } elseif ( !$historyCheck ) {
62 if ( $limit > 0 && $limit < $maxLimit ) {
63 $history['limit'] = $limit;
65 if ( !is_null( $offset ) ) {
66 $history['offset'] = $offset;
68 if ( strtolower( $dir ) == 'desc' ) {
69 $history['dir'] = 'desc';
73 if( !$wgExportAllowHistory ) {
74 // Override
75 $history = MW_EXPORT_CURRENT;
78 $list_authors = $wgRequest->getCheck( 'listauthors' );
79 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
81 if( $page != '' ) {
82 $wgOut->disable();
84 // Cancel output buffering and gzipping if set
85 // This should provide safer streaming for pages with history
86 while( $status = ob_get_status() ) {
87 ob_end_clean();
88 if( $status['name'] == 'ob_gzhandler' ) {
89 header( 'Content-Encoding:' );
92 header( "Content-type: application/xml; charset=utf-8" );
93 $pages = explode( "\n", $page );
95 $db =& wfGetDB( DB_SLAVE );
96 $exporter = new WikiExporter( $db, $history );
97 $exporter->list_authors = $list_authors ;
98 $exporter->openStream();
100 foreach( $pages as $page ) {
101 if( $wgExportMaxHistory && !$curonly ) {
102 $title = Title::newFromText( $page );
103 if( $title ) {
104 $count = Revision::countByTitle( $db, $title );
105 if( $count > $wgExportMaxHistory ) {
106 wfDebug( __FUNCTION__ .
107 ": Skipped $page, $count revisions too big\n" );
108 continue;
112 $exporter->pageByName( $page );
115 $exporter->closeStream();
116 return;
119 $wgOut->addWikiText( wfMsg( "exporttext" ) );
120 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
122 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
123 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
124 if( $wgExportAllowHistory ) {
125 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
126 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
127 } else {
128 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
130 $form .= wfHidden( 'action', 'submit' );
131 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
132 $wgOut->addHtml( $form );