Setting default user option using the content language rather than the UI language
[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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 *
22 * @package MediaWiki
23 * @subpackage SpecialPage
24 */
25
26 /**
27 *
28 */
29 function wfSpecialExport( $page = '' ) {
30 global $wgOut, $wgLang, $wgRequest;
31
32 if( $wgRequest->getVal( 'action' ) == 'submit') {
33 $page = $wgRequest->getText( 'pages' );
34 $curonly = $wgRequest->getCheck( 'curonly' );
35 } else {
36 # Pre-check the 'current version only' box in the UI
37 $curonly = true;
38 }
39
40 if( $page != '' ) {
41 header( "Content-type: application/xml; charset=utf-8" );
42 $pages = explode( "\n", $page );
43 $xml = pages2xml( $pages, $curonly );
44 echo $xml;
45 wfAbruptExit();
46 }
47
48 $wgOut->addWikiText( wfMsg( "exporttext" ) );
49 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
50 $action = $titleObj->escapeLocalURL();
51 $wgOut->addHTML( "
52 <form method='post' action=\"$action\">
53 <input type='hidden' name='action' value='submit' />
54 <textarea name='pages' cols='40' rows='10'></textarea><br />
55 <label><input type='checkbox' name='curonly' value='true' checked='checked' />
56 " . wfMsg( "exportcuronly" ) . "</label><br />
57 <input type='submit' />
58 </form>
59 " );
60 }
61
62 function pages2xml( $pages, $curonly = false ) {
63 global $wgLanguageCode, $wgInputEncoding, $wgLang;
64 $xml = "<" . "?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n" .
65 "<mediawiki version=\"0.1\" xml:lang=\"$wgLanguageCode\">\n";
66 foreach( $pages as $page ) {
67 $xml .= page2xml( $page, $curonly );
68 }
69 $xml .= "</mediawiki>\n";
70 if($wgInputEncoding != "utf-8")
71 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
72 return $xml;
73 }
74
75 function page2xml( $page, $curonly, $full = false ) {
76 global $wgLang;
77 $fname = 'page2xml';
78
79 $title = Title::NewFromText( $page );
80 if( !$title ) return "";
81
82 $dbr =& wfGetDB( DB_SLAVE );
83 $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user',
84 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment',
85 'cur_text as text' ), $title->curCond(), $fname );
86 if( $s !== false ) {
87 $tl = xmlsafe( $title->getPrefixedText() );
88 $xml = " <page>\n";
89 $xml .= " <title>$tl</title>\n";
90 if( $full ) {
91 $xml .= " <id>$s->id</id>\n";
92 }
93 if( $s->restrictions ) {
94 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
95 }
96 if( !$curonly ) {
97 $res = $dbr->select( 'old', array( 'old_id as id','old_timestamp as timestamp',
98 'old_user as user', 'old_user_text as user_text', 'old_comment as comment',
99 'old_text as text', 'old_flags as flags' ), $title->oldCond(),
100 $fname, array( 'ORDER BY' => 'old_timestamp' )
101 );
102
103 while( $s2 = $dbr->fetchObject( $res ) ) {
104 $xml .= revision2xml( $s2, $full, false );
105 }
106 }
107 $xml .= revision2xml( $s, $full, true );
108 $xml .= " </page>\n";
109 return $xml;
110 } else {
111 return "";
112 }
113 }
114
115 function revision2xml( $s, $full, $cur ) {
116 $ts = wfTimestamp2ISO8601( $s->timestamp );
117 $xml = " <revision>\n";
118 if($full && !$cur)
119 $xml .= " <id>$s->id</id>\n";
120 $xml .= " <timestamp>$ts</timestamp>\n";
121 if($s->user) {
122 $u = "<username>" . xmlsafe( $s->user_text ) . "</username>";
123 if($full)
124 $u .= "<id>$s->user</id>";
125 } else {
126 $u = "<ip>" . xmlsafe( $s->user_text ) . "</ip>";
127 }
128 $xml .= " <contributor>$u</contributor>\n";
129 if( !empty( $s->minor ) ) {
130 $xml .= " <minor/>\n";
131 }
132 if($s->comment != "") {
133 $c = xmlsafe( $s->comment );
134 $xml .= " <comment>$c</comment>\n";
135 }
136 $t = xmlsafe( Article::getRevisionText( $s, "" ) );
137 $xml .= " <text>$t</text>\n";
138 $xml .= " </revision>\n";
139 return $xml;
140 }
141
142 function wfTimestamp2ISO8601( $ts ) {
143 #2003-08-05T18:30:02Z
144 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );
145 }
146
147 function xmlsafe( $string ) {
148 # May contain old data which has not been properly normalized.
149 global $wgUseLatin1;
150 if( $wgUseLatin1 ) {
151 $string = preg_replace( '/[\x00-\x08\x0b-\x1f]/', '', $string );
152 } else {
153 $string = UtfNormal::cleanUp( $string );
154 }
155 return htmlspecialchars( $string );
156 }
157
158 ?>