Added experimental history paging API, subject to change
[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 $maxLimit = 200;
35
36 $curonly = true;
37 $fullHistory = array(
38 'dir' => 'asc',
39 'offset' => false,
40 'limit' => $maxLimit,
41 );
42 if( $wgRequest->getVal( 'action' ) == 'submit') {
43 $page = $wgRequest->getText( 'pages' );
44 $curonly = $wgRequest->getCheck( 'curonly' );
45 $offset = wfTimestamp( TS_MW, $wgRequest->getVal( 'offset' ) );
46 $limit = $wgRequest->getInt( 'limit' );
47 $dir = $wgRequest->getVal( 'dir' );
48 $history = array(
49 'dir' => 'asc',
50 'offset' => false,
51 'limit' => $maxLimit,
52 );
53 $historyCheck = $wgRequest->getCheck( 'history' );
54 if ( $curonly ) {
55 $history = MW_EXPORT_CURRENT;
56 } elseif ( !$historyCheck ) {
57 if ( $limit > 0 && $limit < $maxLimit ) {
58 $history['limit'] = $limit;
59 }
60 if ( !is_null( $offset ) ) {
61 $history['offset'] = $offset;
62 }
63 if ( strtolower( $dir ) == 'desc' ) {
64 $history['dir'] = 'desc';
65 }
66 }
67 }
68 if( !$wgExportAllowHistory ) {
69 // Override
70 $history = MW_EXPORT_CURRENT;
71 }
72
73 $list_authors = $wgRequest->getCheck( 'listauthors' );
74 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
75
76 if( $page != '' ) {
77 $wgOut->disable();
78
79 // Cancel output buffering and gzipping if set
80 // This should provide safer streaming for pages with history
81 while( $status = ob_get_status() ) {
82 ob_end_clean();
83 if( $status['name'] == 'ob_gzhandler' ) {
84 header( 'Content-Encoding:' );
85 }
86 }
87 header( "Content-type: application/xml; charset=utf-8" );
88 $pages = explode( "\n", $page );
89
90 $db =& wfGetDB( DB_SLAVE );
91 $exporter = new WikiExporter( $db, $history );
92 $exporter->list_authors = $list_authors ;
93 $exporter->openStream();
94
95 foreach( $pages as $page ) {
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 $exporter->pageByName( $page );
108 }
109
110 $exporter->closeStream();
111 return;
112 }
113
114 $wgOut->addWikiText( wfMsg( "exporttext" ) );
115 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
116
117 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
118 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
119 if( $wgExportAllowHistory ) {
120 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
121 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
122 } else {
123 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
124 }
125 $form .= wfHidden( 'action', 'submit' );
126 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
127 $wgOut->addHtml( $form );
128 }
129
130 ?>