* (bug 10242) Update Chinese translations
[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, $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 $pages = explode( "\n", $page );
135
136 $db = wfGetDB( DB_SLAVE );
137 $exporter = new WikiExporter( $db, $history );
138 $exporter->list_authors = $list_authors ;
139 $exporter->openStream();
140
141 foreach( $pages as $page ) {
142 /*
143 if( $wgExportMaxHistory && !$curonly ) {
144 $title = Title::newFromText( $page );
145 if( $title ) {
146 $count = Revision::countByTitle( $db, $title );
147 if( $count > $wgExportMaxHistory ) {
148 wfDebug( __FUNCTION__ .
149 ": Skipped $page, $count revisions too big\n" );
150 continue;
151 }
152 }
153 }*/
154
155 #Bug 8824: Only export pages the user can read
156 $title = Title::newFromText( $page );
157 if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something.
158 if( !$title->userCan( 'read' ) ) continue; #TODO: perhaps output an <error> tag or something.
159
160 $exporter->pageByTitle( $title );
161 }
162
163 $exporter->closeStream();
164 return;
165 }
166
167 $wgOut->addWikiText( wfMsg( "exporttext" ) );
168 $titleObj = SpecialPage::getTitleFor( "Export" );
169
170 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
171
172 $form .= wfInputLabel( wfMsg( 'export-addcattext' ), 'catname', 'catname', 40 ) . ' ';
173 $form .= wfSubmitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
174
175 $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . htmlspecialchars($page). '</textarea><br />';
176
177 if( $wgExportAllowHistory ) {
178 $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
179 $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
180 } else {
181 $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
182 }
183 $form .= wfHidden( 'action', 'submit' );
184 $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
185 $wgOut->addHtml( $form );
186 }
187
188 ?>