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
21 * @addtogroup SpecialPage
27 function wfSpecialExport( $page = '' ) {
28 global $wgOut, $wgRequest, $wgExportAllowListContributors;
29 global $wgExportAllowHistory, $wgExportMaxHistory;
32 if( $wgRequest->wasPosted() ) {
33 $page = $wgRequest->getText( 'pages' );
34 $curonly = $wgRequest->getCheck( 'curonly' );
35 $rawOffset = $wgRequest->getVal( 'offset' );
37 $offset = wfTimestamp( TS_MW
, $rawOffset );
41 $limit = $wgRequest->getInt( 'limit' );
42 $dir = $wgRequest->getVal( 'dir' );
46 'limit' => $wgExportMaxHistory,
48 $historyCheck = $wgRequest->getCheck( 'history' );
50 $history = WikiExporter
::CURRENT
;
51 } elseif ( !$historyCheck ) {
52 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
53 $history['limit'] = $limit;
55 if ( !is_null( $offset ) ) {
56 $history['offset'] = $offset;
58 if ( strtolower( $dir ) == 'desc' ) {
59 $history['dir'] = 'desc';
63 // Default to current-only for GET requests
64 $page = $wgRequest->getText( 'pages', $page );
65 $historyCheck = $wgRequest->getCheck( 'history' );
67 $history = WikiExporter
::FULL
;
69 $history = WikiExporter
::CURRENT
;
72 if( !$wgExportAllowHistory ) {
74 $history = WikiExporter
::CURRENT
;
77 $list_authors = $wgRequest->getCheck( 'listauthors' );
78 if ( !$curonly ||
!$wgExportAllowListContributors ) $list_authors = false ;
83 // Cancel output buffering and gzipping if set
84 // This should provide safer streaming for pages with history
85 wfResetOutputBuffers();
86 header( "Content-type: application/xml; charset=utf-8" );
87 $pages = explode( "\n", $page );
89 $db =& wfGetDB( DB_SLAVE
);
90 $exporter = new WikiExporter( $db, $history );
91 $exporter->list_authors
= $list_authors ;
92 $exporter->openStream();
94 foreach( $pages as $page ) {
96 if( $wgExportMaxHistory && !$curonly ) {
97 $title = Title::newFromText( $page );
99 $count = Revision::countByTitle( $db, $title );
100 if( $count > $wgExportMaxHistory ) {
101 wfDebug( __FUNCTION__ .
102 ": Skipped $page, $count revisions too big\n" );
107 $exporter->pageByName( $page );
110 $exporter->closeStream();
114 $wgOut->addWikiText( wfMsg( "exporttext" ) );
115 $titleObj = SpecialPage
::getTitleFor( "Export" );
117 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
118 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
119 if( $wgExportAllowHistory ) {
120 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
121 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
123 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
125 $form .= wfHidden( 'action', 'submit' );
126 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
127 $wgOut->addHtml( $form );