Revert of r20085, breaks retrieval with GET and subpage syntax, which breaks transwik...
[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 * @addtogroup SpecialPage
22 */
23
24 /**
25 *
26 */
27 function wfSpecialExport( $page = '' ) {
28 global $wgOut, $wgRequest, $wgExportAllowListContributors;
29 global $wgExportAllowHistory, $wgExportMaxHistory;
30
31 $curonly = true;
32 if( $wgRequest->wasPosted() ) {
33 $page = $wgRequest->getText( 'pages' );
34 $curonly = $wgRequest->getCheck( 'curonly' );
35 $rawOffset = $wgRequest->getVal( 'offset' );
36 if( $rawOffset ) {
37 $offset = wfTimestamp( TS_MW, $rawOffset );
38 } else {
39 $offset = null;
40 }
41 $limit = $wgRequest->getInt( 'limit' );
42 $dir = $wgRequest->getVal( 'dir' );
43 $history = array(
44 'dir' => 'asc',
45 'offset' => false,
46 'limit' => $wgExportMaxHistory,
47 );
48 $historyCheck = $wgRequest->getCheck( 'history' );
49 if ( $curonly ) {
50 $history = WikiExporter::CURRENT;
51 } elseif ( !$historyCheck ) {
52 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
53 $history['limit'] = $limit;
54 }
55 if ( !is_null( $offset ) ) {
56 $history['offset'] = $offset;
57 }
58 if ( strtolower( $dir ) == 'desc' ) {
59 $history['dir'] = 'desc';
60 }
61 }
62 } else {
63 // Default to current-only for GET requests
64 $page = $wgRequest->getText( 'pages', $page );
65 $historyCheck = $wgRequest->getCheck( 'history' );
66 if( $historyCheck ) {
67 $history = WikiExporter::FULL;
68 } else {
69 $history = WikiExporter::CURRENT;
70 }
71 }
72 if( !$wgExportAllowHistory ) {
73 // Override
74 $history = WikiExporter::CURRENT;
75 }
76
77 $list_authors = $wgRequest->getCheck( 'listauthors' );
78 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
79
80 if( $page != '' ) {
81 $wgOut->disable();
82
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 );
88
89 $db = wfGetDB( DB_SLAVE );
90 $exporter = new WikiExporter( $db, $history );
91 $exporter->list_authors = $list_authors ;
92 $exporter->openStream();
93
94 foreach( $pages as $page ) {
95 /*
96 if( $wgExportMaxHistory && !$curonly ) {
97 $title = Title::newFromText( $page );
98 if( $title ) {
99 $count = Revision::countByTitle( $db, $title );
100 if( $count > $wgExportMaxHistory ) {
101 wfDebug( __FUNCTION__ .
102 ": Skipped $page, $count revisions too big\n" );
103 continue;
104 }
105 }
106 }*/
107
108 #Bug 8824: Only export pages the user can read
109 $title = Title::newFromText( $page );
110 if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something.
111 if( !$title->userCan( 'read' ) ) continue; #TODO: perhaps output an <error> tag or something.
112
113 $exporter->pageByTitle( $title );
114 }
115
116 $exporter->closeStream();
117 return;
118 }
119
120 $wgOut->addWikiText( wfMsg( "exporttext" ) );
121 $titleObj = SpecialPage::getTitleFor( "Export" );
122
123 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
124 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
125 if( $wgExportAllowHistory ) {
126 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
127 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
128 } else {
129 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
130 }
131 $form .= wfHidden( 'action', 'submit' );
132 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
133 $wgOut->addHtml( $form );
134 }
135
136 ?>