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, $wgExportAllowListContributors;
57 global $wgExportAllowHistory, $wgExportMaxHistory;
63 if ( $wgRequest->getCheck( 'addcat' ) ) {
64 $page = $wgRequest->getText( 'pages' );
65 $catname = $wgRequest->getText( 'catname' );
67 if ( $catname !== '' && $catname !== NULL && $catname !== false ) {
68 $t = Title
::makeTitleSafe( NS_CATEGORY
, $catname );
70 $catpages = wfExportGetPagesFromCategory( $t );
71 if ( $catpages ) $page .= "\n" . implode( "\n", $catpages );
75 else if( $wgRequest->wasPosted() ) {
76 $page = $wgRequest->getText( 'pages' );
77 $curonly = $wgRequest->getCheck( 'curonly' );
78 $rawOffset = $wgRequest->getVal( 'offset' );
80 $offset = wfTimestamp( TS_MW
, $rawOffset );
84 $limit = $wgRequest->getInt( 'limit' );
85 $dir = $wgRequest->getVal( 'dir' );
89 'limit' => $wgExportMaxHistory,
91 $historyCheck = $wgRequest->getCheck( 'history' );
93 $history = WikiExporter
::CURRENT
;
94 } elseif ( !$historyCheck ) {
95 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
96 $history['limit'] = $limit;
98 if ( !is_null( $offset ) ) {
99 $history['offset'] = $offset;
101 if ( strtolower( $dir ) == 'desc' ) {
102 $history['dir'] = 'desc';
106 if( $page != '' ) $doexport = true;
108 // Default to current-only for GET requests
109 $page = $wgRequest->getText( 'pages', $page );
110 $historyCheck = $wgRequest->getCheck( 'history' );
111 if( $historyCheck ) {
112 $history = WikiExporter
::FULL
;
114 $history = WikiExporter
::CURRENT
;
117 if( $page != '' ) $doexport = true;
120 if( !$wgExportAllowHistory ) {
122 $history = WikiExporter
::CURRENT
;
125 $list_authors = $wgRequest->getCheck( 'listauthors' );
126 if ( !$curonly ||
!$wgExportAllowListContributors ) $list_authors = false ;
131 // Cancel output buffering and gzipping if set
132 // This should provide safer streaming for pages with history
133 wfResetOutputBuffers();
134 header( "Content-type: application/xml; charset=utf-8" );
135 $pages = explode( "\n", $page );
137 $db = wfGetDB( DB_SLAVE
);
138 $exporter = new WikiExporter( $db, $history );
139 $exporter->list_authors
= $list_authors ;
140 $exporter->openStream();
142 foreach( $pages as $page ) {
144 if( $wgExportMaxHistory && !$curonly ) {
145 $title = Title::newFromText( $page );
147 $count = Revision::countByTitle( $db, $title );
148 if( $count > $wgExportMaxHistory ) {
149 wfDebug( __FUNCTION__ .
150 ": Skipped $page, $count revisions too big\n" );
156 #Bug 8824: Only export pages the user can read
157 $title = Title
::newFromText( $page );
158 if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something.
159 if( !$title->userCan( 'read' ) ) continue; #TODO: perhaps output an <error> tag or something.
161 $exporter->pageByTitle( $title );
164 $exporter->closeStream();
168 $wgOut->addWikiText( wfMsg( "exporttext" ) );
169 $titleObj = SpecialPage
::getTitleFor( "Export" );
171 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
173 $form .= wfInputLabel( wfMsg( 'export-addcattext' ), 'catname', 'catname', 40 ) . ' ';
174 $form .= wfSubmitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
176 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . htmlspecialchars($page). '</textarea><br />';
178 if( $wgExportAllowHistory ) {
179 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
180 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
182 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
184 $form .= wfHidden( 'action', 'submit' );
185 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
186 $wgOut->addHtml( $form );