5e6d6d8ddaff23b635edb48a0393405d0735b9cf
[lhc/web/wiklou.git] / includes / SpecialExport.php
1 <?php
2 # Copyright (C) 2003 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
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.
9 #
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.
14 #
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 /**
20 *
21 * @package MediaWiki
22 * @subpackage SpecialPage
23 */
24
25 /**
26 *
27 */
28 function wfSpecialExport( $page = '' ) {
29 global $wgOut, $wgRequest, $wgExportAllowListContributors;
30 global $wgExportAllowHistory, $wgExportMaxHistory;
31
32 $curonly = true;
33 if( $wgRequest->wasPosted() ) {
34 $page = $wgRequest->getText( 'pages' );
35 $curonly = $wgRequest->getCheck( 'curonly' );
36 $rawOffset = $wgRequest->getVal( 'offset' );
37 if( $rawOffset ) {
38 $offset = wfTimestamp( TS_MW, $rawOffset );
39 } else {
40 $offset = null;
41 }
42 $limit = $wgRequest->getInt( 'limit' );
43 $dir = $wgRequest->getVal( 'dir' );
44 $history = array(
45 'dir' => 'asc',
46 'offset' => false,
47 'limit' => $wgExportMaxHistory,
48 );
49 $historyCheck = $wgRequest->getCheck( 'history' );
50 if ( $curonly ) {
51 $history = WikiExporter::CURRENT;
52 } elseif ( !$historyCheck ) {
53 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
54 $history['limit'] = $limit;
55 }
56 if ( !is_null( $offset ) ) {
57 $history['offset'] = $offset;
58 }
59 if ( strtolower( $dir ) == 'desc' ) {
60 $history['dir'] = 'desc';
61 }
62 }
63 } else {
64 // Default to current-only for GET requests
65 $page = $wgRequest->getText( 'pages', $page );
66 $historyCheck = $wgRequest->getCheck( 'history' );
67 if( $historyCheck ) {
68 $history = WikiExporter::FULL;
69 } else {
70 $history = WikiExporter::CURRENT;
71 }
72 }
73 if( !$wgExportAllowHistory ) {
74 // Override
75 $history = WikiExporter::CURRENT;
76 }
77
78 $list_authors = $wgRequest->getCheck( 'listauthors' );
79 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
80
81 if( $page != '' ) {
82 $wgOut->disable();
83
84 // Cancel output buffering and gzipping if set
85 // This should provide safer streaming for pages with history
86 wfResetOutputBuffers();
87 header( "Content-type: application/xml; charset=utf-8" );
88 $pages = explode( "\n", $page );
89
90 $db =& wfGetDB( DB_SLAVE );
91 $exporter = new WikiExporter( $db, $history );
92 $exporter->list_authors = $list_authors ;
93 $exporter->openStream();
94
95 foreach( $pages as $page ) {
96 /*
97 if( $wgExportMaxHistory && !$curonly ) {
98 $title = Title::newFromText( $page );
99 if( $title ) {
100 $count = Revision::countByTitle( $db, $title );
101 if( $count > $wgExportMaxHistory ) {
102 wfDebug( __FUNCTION__ .
103 ": Skipped $page, $count revisions too big\n" );
104 continue;
105 }
106 }
107 }*/
108 $exporter->pageByName( $page );
109 }
110
111 $exporter->closeStream();
112 return;
113 }
114
115 $wgOut->addWikiText( wfMsg( "exporttext" ) );
116 $titleObj = SpecialPage::getTitleFor( "Export" );
117
118 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
119 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
120 if( $wgExportAllowHistory ) {
121 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
122 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
123 } else {
124 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
125 }
126 $form .= wfHidden( 'action', 'submit' );
127 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
128 $wgOut->addHtml( $form );
129 }
130
131 ?>