XHTML clean-up. Started reformatting Preferences. Fixed some hard-coding
[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 function wfSpecialExport( $page = "" ) {
21 global $wgOut, $wgLang, $wgRequest;
22
23 if( $wgRequest->getVal( 'action' ) == 'submit') {
24 $page = $wgRequest->getText( 'pages' );
25 $curonly = $wgRequest->getCheck( 'curonly' );
26 } else {
27 # Pre-check the 'current version only' box in the UI
28 $curonly = true;
29 }
30
31 if( $page != "" ) {
32 header( "Content-type: application/xml; charset=utf-8" );
33 $pages = explode( "\n", $page );
34 $xml = pages2xml( $pages, $curonly );
35 echo $xml;
36 wfAbruptExit();
37 }
38
39 $wgOut->addWikiText( wfMsg( "exporttext" ) );
40 $titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
41 $action = $titleObj->escapeLocalURL();
42 $wgOut->addHTML( "
43 <form method='post' action=\"$action\">
44 <input type='hidden' name='action' value='submit' />
45 <textarea name='pages' cols='40' rows='10'></textarea><br />
46 <label><input type='checkbox' name='curonly' value='true' checked='checked' />
47 " . wfMsg( "exportcuronly" ) . "</label><br />
48 <input type='submit' />
49 </form>
50 " );
51 }
52
53 function pages2xml( $pages, $curonly = false ) {
54 global $wgLanguageCode, $wgInputEncoding, $wgLang;
55 $xml = "<" . "?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n" .
56 "<mediawiki version=\"0.1\" xml:lang=\"$wgLanguageCode\">\n";
57 foreach( $pages as $page ) {
58 $xml .= page2xml( $page, $curonly );
59 }
60 $xml .= "</mediawiki>\n";
61 if($wgInputEncoding != "utf-8")
62 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
63 return $xml;
64 }
65
66 function page2xml( $page, $curonly, $full = false ) {
67 global $wgInputCharset, $wgLang;
68 $title = Title::NewFromText( $page );
69 if( !$title ) return "";
70 $t = wfStrencode( $title->getDBKey() );
71 $ns = $title->getNamespace();
72 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
73 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
74 "WHERE cur_namespace=$ns AND cur_title='$t'";
75 $res = wfQuery( $sql, DB_READ );
76 if( $s = wfFetchObject( $res ) ) {
77 $tl = htmlspecialchars( $title->getPrefixedText() );
78 $xml = " <page>\n";
79 $xml .= " <title>$tl</title>\n";
80 if( $full ) {
81 $xml .= " <id>$s->id</id>\n";
82 }
83 if( $s->restrictions ) {
84 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
85 }
86 if( !$curonly ) {
87 $sql = "SELECT old_id as id,old_timestamp as timestamp, old_user as user, old_user_text as user_text," .
88 "old_comment as comment, old_text as text, old_flags as flags FROM old " .
89 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
90 $res = wfQuery( $sql, DB_READ );
91
92 while( $s2 = wfFetchObject( $res ) ) {
93 $xml .= revision2xml( $s2, $full, false );
94 }
95 }
96 $xml .= revision2xml( $s, $full, true );
97 $xml .= " </page>\n";
98 return $xml;
99 } else {
100 return "";
101 }
102 }
103
104 function revision2xml( $s, $full, $cur ) {
105 $ts = wfTimestamp2ISO8601( $s->timestamp );
106 $xml = " <revision>\n";
107 if($full && !$cur)
108 $xml .= " <id>$s->id</id>\n";
109 $xml .= " <timestamp>$ts</timestamp>\n";
110 if($s->user) {
111 $u = "<username>" . htmlspecialchars( $s->user_text ) . "</username>";
112 if($full)
113 $u .= "<id>$s->user</id>";
114 } else {
115 $u = "<ip>" . htmlspecialchars( $s->user_text ) . "</ip>";
116 }
117 $xml .= " <contributor>$u</contributor>\n";
118 if( !empty( $s->minor ) ) {
119 $xml .= " <minor/>\n";
120 }
121 if($s->comment != "") {
122 $c = htmlspecialchars( $s->comment );
123 $xml .= " <comment>$c</comment>\n";
124 }
125 $t = htmlspecialchars( Article::getRevisionText( $s, "" ) );
126 $xml .= " <text>$t</text>\n";
127 $xml .= " </revision>\n";
128 return $xml;
129 }
130
131 function wfTimestamp2ISO8601( $ts ) {
132 #2003-08-05T18:30:02Z
133 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );
134 }
135
136 ?>