* (bug 6976) Add namespace and direction classes to classic skins
[mediawiki.git] / includes / SpecialExport.php
bloba402b659abece1f991e15092ba8a93aae139b100
1 <?php
2 # Copyright (C) 2003 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
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.
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.
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 /**
21 * @package MediaWiki
22 * @subpackage SpecialPage
25 /** */
26 require_once( 'Export.php' );
28 /**
31 function wfSpecialExport( $page = '' ) {
32 global $wgOut, $wgRequest, $wgExportAllowListContributors;
33 global $wgExportAllowHistory, $wgExportMaxHistory;
34 $maxLimit = 200;
36 $curonly = true;
37 $fullHistory = array(
38 'dir' => 'asc',
39 'offset' => false,
40 'limit' => $maxLimit,
42 if( $wgRequest->wasPosted() ) {
43 $page = $wgRequest->getText( 'pages' );
44 $curonly = $wgRequest->getCheck( 'curonly' );
45 $rawOffset = $wgRequest->getVal( 'offset' );
46 if( $rawOffset ) {
47 $offset = wfTimestamp( TS_MW, $rawOffset );
48 } else {
49 $offset = null;
51 $limit = $wgRequest->getInt( 'limit' );
52 $dir = $wgRequest->getVal( 'dir' );
53 $history = array(
54 'dir' => 'asc',
55 'offset' => false,
56 'limit' => $maxLimit,
58 $historyCheck = $wgRequest->getCheck( 'history' );
59 if ( $curonly ) {
60 $history = MW_EXPORT_CURRENT;
61 } elseif ( !$historyCheck ) {
62 if ( $limit > 0 && $limit < $maxLimit ) {
63 $history['limit'] = $limit;
65 if ( !is_null( $offset ) ) {
66 $history['offset'] = $offset;
68 if ( strtolower( $dir ) == 'desc' ) {
69 $history['dir'] = 'desc';
72 } else {
73 // Default to current-only for GET requests
74 $page = $wgRequest->getText( 'pages', $page );
75 $historyCheck = $wgRequest->getCheck( 'history' );
76 if( $historyCheck ) {
77 $history = MW_EXPORT_FULL;
78 } else {
79 $history = MW_EXPORT_CURRENT;
82 if( !$wgExportAllowHistory ) {
83 // Override
84 $history = MW_EXPORT_CURRENT;
87 $list_authors = $wgRequest->getCheck( 'listauthors' );
88 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
90 if( $page != '' ) {
91 $wgOut->disable();
93 // Cancel output buffering and gzipping if set
94 // This should provide safer streaming for pages with history
95 while( $status = ob_get_status() ) {
96 ob_end_clean();
97 if( $status['name'] == 'ob_gzhandler' ) {
98 header( 'Content-Encoding:' );
101 header( "Content-type: application/xml; charset=utf-8" );
102 $pages = explode( "\n", $page );
104 $db =& wfGetDB( DB_SLAVE );
105 $exporter = new WikiExporter( $db, $history );
106 $exporter->list_authors = $list_authors ;
107 $exporter->openStream();
109 foreach( $pages as $page ) {
110 if( $wgExportMaxHistory && !$curonly ) {
111 $title = Title::newFromText( $page );
112 if( $title ) {
113 $count = Revision::countByTitle( $db, $title );
114 if( $count > $wgExportMaxHistory ) {
115 wfDebug( __FUNCTION__ .
116 ": Skipped $page, $count revisions too big\n" );
117 continue;
121 $exporter->pageByName( $page );
124 $exporter->closeStream();
125 return;
128 $wgOut->addWikiText( wfMsg( "exporttext" ) );
129 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
131 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
132 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
133 if( $wgExportAllowHistory ) {
134 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
135 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
136 } else {
137 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
139 $form .= wfHidden( 'action', 'submit' );
140 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
141 $wgOut->addHtml( $form );