* (bug 6618) Improve permissions/error detection in Special:Lockdb
[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 if( $wgRequest->getVal( 'action' ) == 'submit') {
37 $page = $wgRequest->getText( 'pages' );
38 $curonly = $wgRequest->getCheck( 'curonly' );
39 }
40 if( $wgRequest->getCheck( 'history' ) ) {
41 $curonly = false;
42 }
43 if( !$wgExportAllowHistory ) {
44 // Override
45 $curonly = true;
46 }
47
48 $list_authors = $wgRequest->getCheck( 'listauthors' );
49 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
50
51 if( $page != '' ) {
52 $wgOut->disable();
53
54 // Cancel output buffering and gzipping if set
55 // This should provide safer streaming for pages with history
56 while( $status = ob_get_status() ) {
57 ob_end_clean();
58 if( $status['name'] == 'ob_gzhandler' ) {
59 header( 'Content-Encoding:' );
60 }
61 }
62 header( "Content-type: application/xml; charset=utf-8" );
63 $pages = explode( "\n", $page );
64
65 $db =& wfGetDB( DB_SLAVE );
66 $history = $curonly ? MW_EXPORT_CURRENT : MW_EXPORT_FULL;
67 $exporter = new WikiExporter( $db, $history );
68 $exporter->list_authors = $list_authors ;
69 $exporter->openStream();
70
71 foreach( $pages as $page ) {
72 if( $wgExportMaxHistory && !$curonly ) {
73 $title = Title::newFromText( $page );
74 if( $title ) {
75 $count = Revision::countByTitle( $db, $title );
76 if( $count > $wgExportMaxHistory ) {
77 wfDebug( __FUNCTION__ .
78 ": Skipped $page, $count revisions too big\n" );
79 continue;
80 }
81 }
82 }
83 $exporter->pageByName( $page );
84 }
85
86 $exporter->closeStream();
87 return;
88 }
89
90 $wgOut->addWikiText( wfMsg( "exporttext" ) );
91 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
92
93 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
94 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
95 if( $wgExportAllowHistory ) {
96 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
97 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
98 } else {
99 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
100 }
101 $form .= wfHidden( 'action', 'submit' );
102 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
103 $wgOut->addHtml( $form );
104 }
105
106 ?>