Committed a bunch of live hacks from Wikimedia servers
[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 require_once( 'Export.php' );
27
28 /**
29 *
30 */
31 function wfSpecialExport( $page = '' ) {
32 global $wgOut, $wgRequest, $wgExportAllowListContributors;
33 global $wgExportAllowHistory, $wgExportMaxHistory;
34
35 $curonly = true;
36 $fullHistory = array(
37 'dir' => 'asc',
38 'offset' => false,
39 'limit' => $wgExportMaxHistory,
40 );
41 if( $wgRequest->wasPosted() ) {
42 $page = $wgRequest->getText( 'pages' );
43 $curonly = $wgRequest->getCheck( 'curonly' );
44 $rawOffset = $wgRequest->getVal( 'offset' );
45 if( $rawOffset ) {
46 $offset = wfTimestamp( TS_MW, $rawOffset );
47 } else {
48 $offset = null;
49 }
50 $limit = $wgRequest->getInt( 'limit' );
51 $dir = $wgRequest->getVal( 'dir' );
52 $history = array(
53 'dir' => 'asc',
54 'offset' => false,
55 'limit' => $wgExportMaxHistory,
56 );
57 $historyCheck = $wgRequest->getCheck( 'history' );
58 if ( $curonly ) {
59 $history = MW_EXPORT_CURRENT;
60 } elseif ( !$historyCheck ) {
61 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
62 $history['limit'] = $limit;
63 }
64 if ( !is_null( $offset ) ) {
65 $history['offset'] = $offset;
66 }
67 if ( strtolower( $dir ) == 'desc' ) {
68 $history['dir'] = 'desc';
69 }
70 }
71 } else {
72 // Default to current-only for GET requests
73 $page = $wgRequest->getText( 'pages', $page );
74 $historyCheck = $wgRequest->getCheck( 'history' );
75 if( $historyCheck ) {
76 $history = MW_EXPORT_FULL;
77 } else {
78 $history = MW_EXPORT_CURRENT;
79 }
80 }
81 if( !$wgExportAllowHistory ) {
82 // Override
83 $history = MW_EXPORT_CURRENT;
84 }
85
86 $list_authors = $wgRequest->getCheck( 'listauthors' );
87 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
88
89 if( $page != '' ) {
90 $wgOut->disable();
91
92 // Cancel output buffering and gzipping if set
93 // This should provide safer streaming for pages with history
94 while( $status = ob_get_status() ) {
95 ob_end_clean();
96 if( $status['name'] == 'ob_gzhandler' ) {
97 header( 'Content-Encoding:' );
98 }
99 }
100 header( "Content-type: application/xml; charset=utf-8" );
101 $pages = explode( "\n", $page );
102
103 $db =& wfGetDB( DB_SLAVE );
104 $exporter = new WikiExporter( $db, $history );
105 $exporter->list_authors = $list_authors ;
106 $exporter->openStream();
107
108 foreach( $pages as $page ) {
109 /*
110 if( $wgExportMaxHistory && !$curonly ) {
111 $title = Title::newFromText( $page );
112 if( $title ) {
113 $count = Revision::countByTitle( $db, $title );
114 if( $count > $wgExportMaxHistory ) {
115 wfDebug( __FUNCTION__ .
116 ": Skipped $page, $count revisions too big\n" );
117 continue;
118 }
119 }
120 }*/
121 $exporter->pageByName( $page );
122 }
123
124 $exporter->closeStream();
125 return;
126 }
127
128 $wgOut->addWikiText( wfMsg( "exporttext" ) );
129 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
130
131 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
132 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
133 if( $wgExportAllowHistory ) {
134 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
135 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
136 } else {
137 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
138 }
139 $form .= wfHidden( 'action', 'submit' );
140 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
141 $wgOut->addHtml( $form );
142 }
143
144 ?>