Completing code housekeeping stuff for rest of includes/ directory: removing unused...
[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 while( $status = ob_get_status() ) {
87 ob_end_clean();
88 if( $status['name'] == 'ob_gzhandler' ) {
89 header( 'Content-Encoding:' );
90 }
91 }
92 header( "Content-type: application/xml; charset=utf-8" );
93 $pages = explode( "\n", $page );
94
95 $db =& wfGetDB( DB_SLAVE );
96 $exporter = new WikiExporter( $db, $history );
97 $exporter->list_authors = $list_authors ;
98 $exporter->openStream();
99
100 foreach( $pages as $page ) {
101 /*
102 if( $wgExportMaxHistory && !$curonly ) {
103 $title = Title::newFromText( $page );
104 if( $title ) {
105 $count = Revision::countByTitle( $db, $title );
106 if( $count > $wgExportMaxHistory ) {
107 wfDebug( __FUNCTION__ .
108 ": Skipped $page, $count revisions too big\n" );
109 continue;
110 }
111 }
112 }*/
113 $exporter->pageByName( $page );
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 ?>