Added EditFilterMerged hook: like EditFilter but uses the text after section merging...
[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 * @addtogroup SpecialPage
22 */
23
24 function wfExportGetPagesFromCategory( $title ) {
25 global $wgContLang;
26
27 $name = $title->getDBKey();
28
29 $dbr = wfGetDB( DB_SLAVE );
30
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 );
35
36 $pages = array();
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 );
42 $n = $ns . ':' . $n;
43 }
44
45 $pages[] = $n;
46 }
47 $dbr->freeResult($res);
48
49 return $pages;
50 }
51
52 /**
53 *
54 */
55 function wfSpecialExport( $page = '' ) {
56 global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
57 global $wgExportAllowHistory, $wgExportMaxHistory;
58
59 $curonly = true;
60 $doexport = false;
61
62 if ( $wgRequest->getCheck( 'addcat' ) ) {
63 $page = $wgRequest->getText( 'pages' );
64 $catname = $wgRequest->getText( 'catname' );
65
66 if ( $catname !== '' && $catname !== NULL && $catname !== false ) {
67 $t = Title::makeTitleSafe( NS_CATEGORY, $catname );
68 if ( $t ) {
69 $catpages = wfExportGetPagesFromCategory( $t );
70 if ( $catpages ) $page .= "\n" . implode( "\n", $catpages );
71 }
72 }
73 }
74 else if( $wgRequest->wasPosted() && $page == '' ) {
75 $page = $wgRequest->getText( 'pages' );
76 $curonly = $wgRequest->getCheck( 'curonly' );
77 $rawOffset = $wgRequest->getVal( 'offset' );
78 if( $rawOffset ) {
79 $offset = wfTimestamp( TS_MW, $rawOffset );
80 } else {
81 $offset = null;
82 }
83 $limit = $wgRequest->getInt( 'limit' );
84 $dir = $wgRequest->getVal( 'dir' );
85 $history = array(
86 'dir' => 'asc',
87 'offset' => false,
88 'limit' => $wgExportMaxHistory,
89 );
90 $historyCheck = $wgRequest->getCheck( 'history' );
91 if ( $curonly ) {
92 $history = WikiExporter::CURRENT;
93 } elseif ( !$historyCheck ) {
94 if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
95 $history['limit'] = $limit;
96 }
97 if ( !is_null( $offset ) ) {
98 $history['offset'] = $offset;
99 }
100 if ( strtolower( $dir ) == 'desc' ) {
101 $history['dir'] = 'desc';
102 }
103 }
104
105 if( $page != '' ) $doexport = true;
106 } else {
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;
112 } else {
113 $history = WikiExporter::CURRENT;
114 }
115
116 if( $page != '' ) $doexport = true;
117 }
118
119 if( !$wgExportAllowHistory ) {
120 // Override
121 $history = WikiExporter::CURRENT;
122 }
123
124 $list_authors = $wgRequest->getCheck( 'listauthors' );
125 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
126
127 if ( $doexport ) {
128 $wgOut->disable();
129
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}" );
138 }
139 $pages = explode( "\n", $page );
140
141 $db = wfGetDB( DB_SLAVE );
142 $exporter = new WikiExporter( $db, $history );
143 $exporter->list_authors = $list_authors ;
144 $exporter->openStream();
145
146 foreach( $pages as $page ) {
147 /*
148 if( $wgExportMaxHistory && !$curonly ) {
149 $title = Title::newFromText( $page );
150 if( $title ) {
151 $count = Revision::countByTitle( $db, $title );
152 if( $count > $wgExportMaxHistory ) {
153 wfDebug( __FUNCTION__ .
154 ": Skipped $page, $count revisions too big\n" );
155 continue;
156 }
157 }
158 }*/
159
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.
164
165 $exporter->pageByTitle( $title );
166 }
167
168 $exporter->closeStream();
169 return;
170 }
171
172 $self = SpecialPage::getTitleFor( 'Export' );
173 $wgOut->addHtml( wfMsgExt( 'exporttext', 'parse' ) );
174
175 $form = Xml::openElement( 'form', array( 'method' => 'post',
176 'action' => $self->getLocalUrl( 'action=submit' ) ) );
177
178 $form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . '&nbsp;';
179 $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
180
181 $form .= Xml::openElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) );
182 $form .= htmlspecialchars( $page );
183 $form .= Xml::closeElement( 'textarea' );
184 $form .= '<br />';
185
186 if( $wgExportAllowHistory ) {
187 $form .= Xml::checkLabel( wfMsg( 'exportcuronly' ), 'curonly', 'curonly', true ) . '<br />';
188 } else {
189 $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) );
190 }
191 $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
192
193 $form .= Xml::submitButton( wfMsg( 'export-submit' ) );
194 $form .= Xml::closeElement( 'form' );
195 $wgOut->addHtml( $form );
196 }