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