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
21 * @addtogroup SpecialPage
24 function wfExportGetPagesFromCategory( $title ) {
27 $name = $title->getDBKey();
29 $dbr = wfGetDB( DB_SLAVE
);
31 list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
32 $sql = "SELECT page_namespace, page_title FROM $page " .
33 "JOIN $categorylinks ON cl_from = page_id " .
34 "WHERE cl_to = " . $dbr->addQuotes( $name );
37 $res = $dbr->query( $sql, 'wfExportGetPagesFromCategory' );
38 while ( $row = $dbr->fetchObject( $res ) ) {
39 $n = $row->page_title
;
40 if ($row->page_namespace
) {
41 $ns = $wgContLang->getNsText( $row->page_namespace
);
47 $dbr->freeResult($res);
55 function wfSpecialExport( $page = '' ) {
56 global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
57 global $wgExportAllowHistory, $wgExportMaxHistory;
62 if ( $wgRequest->getCheck( 'addcat' ) ) {
63 $page = $wgRequest->getText( 'pages' );
64 $catname = $wgRequest->getText( 'catname' );
66 if ( $catname !== '' && $catname !== NULL && $catname !== false ) {
67 $t = Title
::makeTitleSafe( NS_CATEGORY
, $catname );
69 $catpages = wfExportGetPagesFromCategory( $t );
70 if ( $catpages ) $page .= "\n" . implode( "\n", $catpages );
74 else if( $wgRequest->wasPosted() && $page == '' ) {
75 $page = $wgRequest->getText( 'pages' );
76 $curonly = $wgRequest->getCheck( 'curonly' );
77 $rawOffset = $wgRequest->getVal( 'offset' );
79 $offset = wfTimestamp( TS_MW
, $rawOffset );
83 $limit = $wgRequest->getInt( 'limit' );
84 $dir = $wgRequest->getVal( 'dir' );
88 'limit' => $wgExportMaxHistory,
90 $historyCheck = $wgRequest->getCheck( 'history' );
92 $history = WikiExporter
::CURRENT
;
93 } elseif ( !$historyCheck ) {
94 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
95 $history['limit'] = $limit;
97 if ( !is_null( $offset ) ) {
98 $history['offset'] = $offset;
100 if ( strtolower( $dir ) == 'desc' ) {
101 $history['dir'] = 'desc';
105 if( $page != '' ) $doexport = true;
107 // Default to current-only for GET requests
108 $page = $wgRequest->getText( 'pages', $page );
109 $historyCheck = $wgRequest->getCheck( 'history' );
110 if( $historyCheck ) {
111 $history = WikiExporter
::FULL
;
113 $history = WikiExporter
::CURRENT
;
116 if( $page != '' ) $doexport = true;
119 if( !$wgExportAllowHistory ) {
121 $history = WikiExporter
::CURRENT
;
124 $list_authors = $wgRequest->getCheck( 'listauthors' );
125 if ( !$curonly ||
!$wgExportAllowListContributors ) $list_authors = false ;
130 // Cancel output buffering and gzipping if set
131 // This should provide safer streaming for pages with history
132 wfResetOutputBuffers();
133 header( "Content-type: application/xml; charset=utf-8" );
134 if( $wgRequest->getCheck( 'wpDownload' ) ) {
135 // Provide a sane filename suggestion
136 $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' );
137 $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" );
139 $pages = explode( "\n", $page );
141 $db = wfGetDB( DB_SLAVE
);
142 $exporter = new WikiExporter( $db, $history );
143 $exporter->list_authors
= $list_authors ;
144 $exporter->openStream();
146 foreach( $pages as $page ) {
148 if( $wgExportMaxHistory && !$curonly ) {
149 $title = Title::newFromText( $page );
151 $count = Revision::countByTitle( $db, $title );
152 if( $count > $wgExportMaxHistory ) {
153 wfDebug( __FUNCTION__ .
154 ": Skipped $page, $count revisions too big\n" );
160 #Bug 8824: Only export pages the user can read
161 $title = Title
::newFromText( $page );
162 if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something.
163 if( !$title->userCan( 'read' ) ) continue; #TODO: perhaps output an <error> tag or something.
165 $exporter->pageByTitle( $title );
168 $exporter->closeStream();
172 $self = SpecialPage
::getTitleFor( 'Export' );
173 $wgOut->addHtml( wfMsgExt( 'exporttext', 'parse' ) );
175 $form = Xml
::openElement( 'form', array( 'method' => 'post',
176 'action' => $self->getLocalUrl( 'action=submit' ) ) );
178 $form .= Xml
::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' ';
179 $form .= Xml
::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
181 $form .= Xml
::openElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) );
182 $form .= htmlspecialchars( $page );
183 $form .= Xml
::closeElement( 'textarea' );
186 if( $wgExportAllowHistory ) {
187 $form .= Xml
::checkLabel( wfMsg( 'exportcuronly' ), 'curonly', 'curonly', true ) . '<br />';
189 $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) );
191 $form .= Xml
::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
193 $form .= Xml
::submitButton( wfMsg( 'export-submit' ) );
194 $form .= Xml
::closeElement( 'form' );
195 $wgOut->addHtml( $form );