Merge "Expose thumbnail file to extensions"
[lhc/web/wiklou.git] / includes / Export.php
1 <?php
2 /**
3 * Base classes for dumps and export
4 *
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 /**
27 * @defgroup Dump Dump
28 */
29
30 /**
31 * @ingroup SpecialPage Dump
32 */
33 class WikiExporter {
34 var $list_authors = false; # Return distinct author list (when not returning full history)
35 var $author_list = "";
36
37 var $dumpUploads = false;
38 var $dumpUploadFileContents = false;
39
40 const FULL = 1;
41 const CURRENT = 2;
42 const STABLE = 4; // extension defined
43 const LOGS = 8;
44 const RANGE = 16;
45
46 const BUFFER = 0;
47 const STREAM = 1;
48
49 const TEXT = 0;
50 const STUB = 1;
51
52 var $buffer;
53
54 var $text;
55
56 /**
57 * @var DumpOutput
58 */
59 var $sink;
60
61 /**
62 * Returns the export schema version.
63 * @return string
64 */
65 public static function schemaVersion() {
66 return "0.8";
67 }
68
69 /**
70 * If using WikiExporter::STREAM to stream a large amount of data,
71 * provide a database connection which is not managed by
72 * LoadBalancer to read from: some history blob types will
73 * make additional queries to pull source data while the
74 * main query is still running.
75 *
76 * @param $db DatabaseBase
77 * @param $history Mixed: one of WikiExporter::FULL, WikiExporter::CURRENT,
78 * WikiExporter::RANGE or WikiExporter::STABLE,
79 * or an associative array:
80 * offset: non-inclusive offset at which to start the query
81 * limit: maximum number of rows to return
82 * dir: "asc" or "desc" timestamp order
83 * @param int $buffer one of WikiExporter::BUFFER or WikiExporter::STREAM
84 * @param int $text one of WikiExporter::TEXT or WikiExporter::STUB
85 */
86 function __construct( $db, $history = WikiExporter::CURRENT,
87 $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
88 $this->db = $db;
89 $this->history = $history;
90 $this->buffer = $buffer;
91 $this->writer = new XmlDumpWriter();
92 $this->sink = new DumpOutput();
93 $this->text = $text;
94 }
95
96 /**
97 * Set the DumpOutput or DumpFilter object which will receive
98 * various row objects and XML output for filtering. Filters
99 * can be chained or used as callbacks.
100 *
101 * @param $sink mixed
102 */
103 public function setOutputSink( &$sink ) {
104 $this->sink =& $sink;
105 }
106
107 public function openStream() {
108 $output = $this->writer->openStream();
109 $this->sink->writeOpenStream( $output );
110 }
111
112 public function closeStream() {
113 $output = $this->writer->closeStream();
114 $this->sink->writeCloseStream( $output );
115 }
116
117 /**
118 * Dumps a series of page and revision records for all pages
119 * in the database, either including complete history or only
120 * the most recent version.
121 */
122 public function allPages() {
123 $this->dumpFrom( '' );
124 }
125
126 /**
127 * Dumps a series of page and revision records for those pages
128 * in the database falling within the page_id range given.
129 * @param int $start inclusive lower limit (this id is included)
130 * @param $end Int: Exclusive upper limit (this id is not included)
131 * If 0, no upper limit.
132 */
133 public function pagesByRange( $start, $end ) {
134 $condition = 'page_id >= ' . intval( $start );
135 if ( $end ) {
136 $condition .= ' AND page_id < ' . intval( $end );
137 }
138 $this->dumpFrom( $condition );
139 }
140
141 /**
142 * Dumps a series of page and revision records for those pages
143 * in the database with revisions falling within the rev_id range given.
144 * @param int $start inclusive lower limit (this id is included)
145 * @param $end Int: Exclusive upper limit (this id is not included)
146 * If 0, no upper limit.
147 */
148 public function revsByRange( $start, $end ) {
149 $condition = 'rev_id >= ' . intval( $start );
150 if ( $end ) {
151 $condition .= ' AND rev_id < ' . intval( $end );
152 }
153 $this->dumpFrom( $condition );
154 }
155
156 /**
157 * @param $title Title
158 */
159 public function pageByTitle( $title ) {
160 $this->dumpFrom(
161 'page_namespace=' . $title->getNamespace() .
162 ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
163 }
164
165 /**
166 * @param $name string
167 * @throws MWException
168 */
169 public function pageByName( $name ) {
170 $title = Title::newFromText( $name );
171 if ( is_null( $title ) ) {
172 throw new MWException( "Can't export invalid title" );
173 } else {
174 $this->pageByTitle( $title );
175 }
176 }
177
178 /**
179 * @param $names array
180 */
181 public function pagesByName( $names ) {
182 foreach ( $names as $name ) {
183 $this->pageByName( $name );
184 }
185 }
186
187 public function allLogs() {
188 $this->dumpFrom( '' );
189 }
190
191 /**
192 * @param $start int
193 * @param $end int
194 */
195 public function logsByRange( $start, $end ) {
196 $condition = 'log_id >= ' . intval( $start );
197 if ( $end ) {
198 $condition .= ' AND log_id < ' . intval( $end );
199 }
200 $this->dumpFrom( $condition );
201 }
202
203 /**
204 * Generates the distinct list of authors of an article
205 * Not called by default (depends on $this->list_authors)
206 * Can be set by Special:Export when not exporting whole history
207 *
208 * @param $cond
209 */
210 protected function do_list_authors( $cond ) {
211 wfProfileIn( __METHOD__ );
212 $this->author_list = "<contributors>";
213 // rev_deleted
214
215 $res = $this->db->select(
216 array( 'page', 'revision' ),
217 array( 'DISTINCT rev_user_text', 'rev_user' ),
218 array(
219 $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
220 $cond,
221 'page_id = rev_id',
222 ),
223 __METHOD__
224 );
225
226 foreach ( $res as $row ) {
227 $this->author_list .= "<contributor>" .
228 "<username>" .
229 htmlentities( $row->rev_user_text ) .
230 "</username>" .
231 "<id>" .
232 $row->rev_user .
233 "</id>" .
234 "</contributor>";
235 }
236 $this->author_list .= "</contributors>";
237 wfProfileOut( __METHOD__ );
238 }
239
240 /**
241 * @param $cond string
242 * @throws MWException
243 * @throws Exception
244 */
245 protected function dumpFrom( $cond = '' ) {
246 wfProfileIn( __METHOD__ );
247 # For logging dumps...
248 if ( $this->history & self::LOGS ) {
249 $where = array( 'user_id = log_user' );
250 # Hide private logs
251 $hideLogs = LogEventsList::getExcludeClause( $this->db );
252 if ( $hideLogs ) {
253 $where[] = $hideLogs;
254 }
255 # Add on any caller specified conditions
256 if ( $cond ) {
257 $where[] = $cond;
258 }
259 # Get logging table name for logging.* clause
260 $logging = $this->db->tableName( 'logging' );
261
262 if ( $this->buffer == WikiExporter::STREAM ) {
263 $prev = $this->db->bufferResults( false );
264 }
265 $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
266 try {
267 $result = $this->db->select( array( 'logging', 'user' ),
268 array( "{$logging}.*", 'user_name' ), // grab the user name
269 $where,
270 __METHOD__,
271 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
272 );
273 $wrapper = $this->db->resultObject( $result );
274 $this->outputLogStream( $wrapper );
275 if ( $this->buffer == WikiExporter::STREAM ) {
276 $this->db->bufferResults( $prev );
277 }
278 } catch ( Exception $e ) {
279 // Throwing the exception does not reliably free the resultset, and
280 // would also leave the connection in unbuffered mode.
281
282 // Freeing result
283 try {
284 if ( $wrapper ) {
285 $wrapper->free();
286 }
287 } catch ( Exception $e2 ) {
288 // Already in panic mode -> ignoring $e2 as $e has
289 // higher priority
290 }
291
292 // Putting database back in previous buffer mode
293 try {
294 if ( $this->buffer == WikiExporter::STREAM ) {
295 $this->db->bufferResults( $prev );
296 }
297 } catch ( Exception $e2 ) {
298 // Already in panic mode -> ignoring $e2 as $e has
299 // higher priority
300 }
301
302 // Inform caller about problem
303 wfProfileOut( __METHOD__ );
304 throw $e;
305 }
306 # For page dumps...
307 } else {
308 $tables = array( 'page', 'revision' );
309 $opts = array( 'ORDER BY' => 'page_id ASC' );
310 $opts['USE INDEX'] = array();
311 $join = array();
312 if ( is_array( $this->history ) ) {
313 # Time offset/limit for all pages/history...
314 $revJoin = 'page_id=rev_page';
315 # Set time order
316 if ( $this->history['dir'] == 'asc' ) {
317 $op = '>';
318 $opts['ORDER BY'] = 'rev_timestamp ASC';
319 } else {
320 $op = '<';
321 $opts['ORDER BY'] = 'rev_timestamp DESC';
322 }
323 # Set offset
324 if ( !empty( $this->history['offset'] ) ) {
325 $revJoin .= " AND rev_timestamp $op " .
326 $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
327 }
328 $join['revision'] = array( 'INNER JOIN', $revJoin );
329 # Set query limit
330 if ( !empty( $this->history['limit'] ) ) {
331 $opts['LIMIT'] = intval( $this->history['limit'] );
332 }
333 } elseif ( $this->history & WikiExporter::FULL ) {
334 # Full history dumps...
335 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
336 } elseif ( $this->history & WikiExporter::CURRENT ) {
337 # Latest revision dumps...
338 if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
339 $this->do_list_authors( $cond );
340 }
341 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
342 } elseif ( $this->history & WikiExporter::STABLE ) {
343 # "Stable" revision dumps...
344 # Default JOIN, to be overridden...
345 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
346 # One, and only one hook should set this, and return false
347 if ( wfRunHooks( 'WikiExporter::dumpStableQuery', array( &$tables, &$opts, &$join ) ) ) {
348 wfProfileOut( __METHOD__ );
349 throw new MWException( __METHOD__ . " given invalid history dump type." );
350 }
351 } elseif ( $this->history & WikiExporter::RANGE ) {
352 # Dump of revisions within a specified range
353 $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
354 $opts['ORDER BY'] = array( 'rev_page ASC', 'rev_id ASC' );
355 } else {
356 # Unknown history specification parameter?
357 wfProfileOut( __METHOD__ );
358 throw new MWException( __METHOD__ . " given invalid history dump type." );
359 }
360 # Query optimization hacks
361 if ( $cond == '' ) {
362 $opts[] = 'STRAIGHT_JOIN';
363 $opts['USE INDEX']['page'] = 'PRIMARY';
364 }
365 # Build text join options
366 if ( $this->text != WikiExporter::STUB ) { // 1-pass
367 $tables[] = 'text';
368 $join['text'] = array( 'INNER JOIN', 'rev_text_id=old_id' );
369 }
370
371 if ( $this->buffer == WikiExporter::STREAM ) {
372 $prev = $this->db->bufferResults( false );
373 }
374
375 $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
376 try {
377 wfRunHooks( 'ModifyExportQuery',
378 array( $this->db, &$tables, &$cond, &$opts, &$join ) );
379
380 # Do the query!
381 $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
382 $wrapper = $this->db->resultObject( $result );
383 # Output dump results
384 $this->outputPageStream( $wrapper );
385
386 if ( $this->buffer == WikiExporter::STREAM ) {
387 $this->db->bufferResults( $prev );
388 }
389 } catch ( Exception $e ) {
390 // Throwing the exception does not reliably free the resultset, and
391 // would also leave the connection in unbuffered mode.
392
393 // Freeing result
394 try {
395 if ( $wrapper ) {
396 $wrapper->free();
397 }
398 } catch ( Exception $e2 ) {
399 // Already in panic mode -> ignoring $e2 as $e has
400 // higher priority
401 }
402
403 // Putting database back in previous buffer mode
404 try {
405 if ( $this->buffer == WikiExporter::STREAM ) {
406 $this->db->bufferResults( $prev );
407 }
408 } catch ( Exception $e2 ) {
409 // Already in panic mode -> ignoring $e2 as $e has
410 // higher priority
411 }
412
413 // Inform caller about problem
414 throw $e;
415 }
416 }
417 wfProfileOut( __METHOD__ );
418 }
419
420 /**
421 * Runs through a query result set dumping page and revision records.
422 * The result set should be sorted/grouped by page to avoid duplicate
423 * page records in the output.
424 *
425 * Should be safe for
426 * streaming (non-buffered) queries, as long as it was made on a
427 * separate database connection not managed by LoadBalancer; some
428 * blob storage types will make queries to pull source data.
429 *
430 * @param $resultset ResultWrapper
431 */
432 protected function outputPageStream( $resultset ) {
433 $last = null;
434 foreach ( $resultset as $row ) {
435 if ( $last === null ||
436 $last->page_namespace != $row->page_namespace ||
437 $last->page_title != $row->page_title ) {
438 if ( $last !== null ) {
439 $output = '';
440 if ( $this->dumpUploads ) {
441 $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
442 }
443 $output .= $this->writer->closePage();
444 $this->sink->writeClosePage( $output );
445 }
446 $output = $this->writer->openPage( $row );
447 $this->sink->writeOpenPage( $row, $output );
448 $last = $row;
449 }
450 $output = $this->writer->writeRevision( $row );
451 $this->sink->writeRevision( $row, $output );
452 }
453 if ( $last !== null ) {
454 $output = '';
455 if ( $this->dumpUploads ) {
456 $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
457 }
458 $output .= $this->author_list;
459 $output .= $this->writer->closePage();
460 $this->sink->writeClosePage( $output );
461 }
462 }
463
464 /**
465 * @param $resultset array
466 */
467 protected function outputLogStream( $resultset ) {
468 foreach ( $resultset as $row ) {
469 $output = $this->writer->writeLogItem( $row );
470 $this->sink->writeLogItem( $row, $output );
471 }
472 }
473 }
474
475 /**
476 * @ingroup Dump
477 */
478 class XmlDumpWriter {
479 /**
480 * Returns the export schema version.
481 * @deprecated in 1.20; use WikiExporter::schemaVersion() instead
482 * @return string
483 */
484 function schemaVersion() {
485 wfDeprecated( __METHOD__, '1.20' );
486 return WikiExporter::schemaVersion();
487 }
488
489 /**
490 * Opens the XML output stream's root "<mediawiki>" element.
491 * This does not include an xml directive, so is safe to include
492 * as a subelement in a larger XML stream. Namespace and XML Schema
493 * references are included.
494 *
495 * Output will be encoded in UTF-8.
496 *
497 * @return string
498 */
499 function openStream() {
500 global $wgLanguageCode;
501 $ver = WikiExporter::schemaVersion();
502 return Xml::element( 'mediawiki', array(
503 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
504 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
505 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
506 #TODO: how do we get a new version up there?
507 "http://www.mediawiki.org/xml/export-$ver.xsd",
508 'version' => $ver,
509 'xml:lang' => $wgLanguageCode ),
510 null ) .
511 "\n" .
512 $this->siteInfo();
513 }
514
515 /**
516 * @return string
517 */
518 function siteInfo() {
519 $info = array(
520 $this->sitename(),
521 $this->homelink(),
522 $this->generator(),
523 $this->caseSetting(),
524 $this->namespaces() );
525 return " <siteinfo>\n " .
526 implode( "\n ", $info ) .
527 "\n </siteinfo>\n";
528 }
529
530 /**
531 * @return string
532 */
533 function sitename() {
534 global $wgSitename;
535 return Xml::element( 'sitename', array(), $wgSitename );
536 }
537
538 /**
539 * @return string
540 */
541 function generator() {
542 global $wgVersion;
543 return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
544 }
545
546 /**
547 * @return string
548 */
549 function homelink() {
550 return Xml::element( 'base', array(), Title::newMainPage()->getCanonicalURL() );
551 }
552
553 /**
554 * @return string
555 */
556 function caseSetting() {
557 global $wgCapitalLinks;
558 // "case-insensitive" option is reserved for future
559 $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
560 return Xml::element( 'case', array(), $sensitivity );
561 }
562
563 /**
564 * @return string
565 */
566 function namespaces() {
567 global $wgContLang;
568 $spaces = "<namespaces>\n";
569 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
570 $spaces .= ' ' .
571 Xml::element( 'namespace',
572 array(
573 'key' => $ns,
574 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
575 ), $title ) . "\n";
576 }
577 $spaces .= " </namespaces>";
578 return $spaces;
579 }
580
581 /**
582 * Closes the output stream with the closing root element.
583 * Call when finished dumping things.
584 *
585 * @return string
586 */
587 function closeStream() {
588 return "</mediawiki>\n";
589 }
590
591 /**
592 * Opens a "<page>" section on the output stream, with data
593 * from the given database row.
594 *
595 * @param $row object
596 * @return string
597 */
598 public function openPage( $row ) {
599 $out = " <page>\n";
600 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
601 $out .= ' ' . Xml::elementClean( 'title', array(), self::canonicalTitle( $title ) ) . "\n";
602 $out .= ' ' . Xml::element( 'ns', array(), strval( $row->page_namespace ) ) . "\n";
603 $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n";
604 if ( $row->page_is_redirect ) {
605 $page = WikiPage::factory( $title );
606 $redirect = $page->getRedirectTarget();
607 if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
608 $out .= ' ';
609 $out .= Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) );
610 $out .= "\n";
611 }
612 }
613
614 if ( $row->page_restrictions != '' ) {
615 $out .= ' ' . Xml::element( 'restrictions', array(),
616 strval( $row->page_restrictions ) ) . "\n";
617 }
618
619 wfRunHooks( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
620
621 return $out;
622 }
623
624 /**
625 * Closes a "<page>" section on the output stream.
626 *
627 * @access private
628 * @return string
629 */
630 function closePage() {
631 return " </page>\n";
632 }
633
634 /**
635 * Dumps a "<revision>" section on the output stream, with
636 * data filled in from the given database row.
637 *
638 * @param $row object
639 * @return string
640 * @access private
641 */
642 function writeRevision( $row ) {
643 wfProfileIn( __METHOD__ );
644
645 $out = " <revision>\n";
646 $out .= " " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
647 if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
648 $out .= " " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
649 }
650
651 $out .= $this->writeTimestamp( $row->rev_timestamp );
652
653 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_USER ) ) {
654 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
655 } else {
656 $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
657 }
658
659 if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
660 $out .= " <minor/>\n";
661 }
662 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_COMMENT ) ) {
663 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
664 } elseif ( $row->rev_comment != '' ) {
665 $out .= " " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
666 }
667
668 $text = '';
669 if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
670 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
671 } elseif ( isset( $row->old_text ) ) {
672 // Raw text from the database may have invalid chars
673 $text = strval( Revision::getRevisionText( $row ) );
674 $out .= " " . Xml::elementClean( 'text',
675 array( 'xml:space' => 'preserve', 'bytes' => intval( $row->rev_len ) ),
676 strval( $text ) ) . "\n";
677 } else {
678 // Stub output
679 $out .= " " . Xml::element( 'text',
680 array( 'id' => $row->rev_text_id, 'bytes' => intval( $row->rev_len ) ),
681 "" ) . "\n";
682 }
683
684 if ( isset( $row->rev_sha1 )
685 && $row->rev_sha1
686 && !( $row->rev_deleted & Revision::DELETED_TEXT )
687 ) {
688 $out .= " " . Xml::element( 'sha1', null, strval( $row->rev_sha1 ) ) . "\n";
689 } else {
690 $out .= " <sha1/>\n";
691 }
692
693 if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
694 $content_model = strval( $row->rev_content_model );
695 } else {
696 // probably using $wgContentHandlerUseDB = false;
697 // @todo test!
698 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
699 $content_model = ContentHandler::getDefaultModelFor( $title );
700 }
701
702 $out .= " " . Xml::element( 'model', null, strval( $content_model ) ) . "\n";
703
704 if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
705 $content_format = strval( $row->rev_content_format );
706 } else {
707 // probably using $wgContentHandlerUseDB = false;
708 // @todo test!
709 $content_handler = ContentHandler::getForModelID( $content_model );
710 $content_format = $content_handler->getDefaultFormat();
711 }
712
713 $out .= " " . Xml::element( 'format', null, strval( $content_format ) ) . "\n";
714
715 wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
716
717 $out .= " </revision>\n";
718
719 wfProfileOut( __METHOD__ );
720 return $out;
721 }
722
723 /**
724 * Dumps a "<logitem>" section on the output stream, with
725 * data filled in from the given database row.
726 *
727 * @param $row object
728 * @return string
729 * @access private
730 */
731 function writeLogItem( $row ) {
732 wfProfileIn( __METHOD__ );
733
734 $out = " <logitem>\n";
735 $out .= " " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
736
737 $out .= $this->writeTimestamp( $row->log_timestamp, " " );
738
739 if ( $row->log_deleted & LogPage::DELETED_USER ) {
740 $out .= " " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
741 } else {
742 $out .= $this->writeContributor( $row->log_user, $row->user_name, " " );
743 }
744
745 if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
746 $out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
747 } elseif ( $row->log_comment != '' ) {
748 $out .= " " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
749 }
750
751 $out .= " " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
752 $out .= " " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
753
754 if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
755 $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
756 } else {
757 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
758 $out .= " " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
759 $out .= " " . Xml::elementClean( 'params',
760 array( 'xml:space' => 'preserve' ),
761 strval( $row->log_params ) ) . "\n";
762 }
763
764 $out .= " </logitem>\n";
765
766 wfProfileOut( __METHOD__ );
767 return $out;
768 }
769
770 /**
771 * @param $timestamp string
772 * @param string $indent Default to six spaces
773 * @return string
774 */
775 function writeTimestamp( $timestamp, $indent = " " ) {
776 $ts = wfTimestamp( TS_ISO_8601, $timestamp );
777 return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
778 }
779
780 /**
781 * @param $id
782 * @param $text string
783 * @param string $indent Default to six spaces
784 * @return string
785 */
786 function writeContributor( $id, $text, $indent = " " ) {
787 $out = $indent . "<contributor>\n";
788 if ( $id || !IP::isValid( $text ) ) {
789 $out .= $indent . " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
790 $out .= $indent . " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
791 } else {
792 $out .= $indent . " " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
793 }
794 $out .= $indent . "</contributor>\n";
795 return $out;
796 }
797
798 /**
799 * Warning! This data is potentially inconsistent. :(
800 * @param $row
801 * @param $dumpContents bool
802 * @return string
803 */
804 function writeUploads( $row, $dumpContents = false ) {
805 if ( $row->page_namespace == NS_FILE ) {
806 $img = wfLocalFile( $row->page_title );
807 if ( $img && $img->exists() ) {
808 $out = '';
809 foreach ( array_reverse( $img->getHistory() ) as $ver ) {
810 $out .= $this->writeUpload( $ver, $dumpContents );
811 }
812 $out .= $this->writeUpload( $img, $dumpContents );
813 return $out;
814 }
815 }
816 return '';
817 }
818
819 /**
820 * @param File $file
821 * @param $dumpContents bool
822 * @return string
823 */
824 function writeUpload( $file, $dumpContents = false ) {
825 if ( $file->isOld() ) {
826 $archiveName = " " .
827 Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
828 } else {
829 $archiveName = '';
830 }
831 if ( $dumpContents ) {
832 $be = $file->getRepo()->getBackend();
833 # Dump file as base64
834 # Uses only XML-safe characters, so does not need escaping
835 # @todo Too bad this loads the contents into memory (script might swap)
836 $contents = ' <contents encoding="base64">' .
837 chunk_split( base64_encode(
838 $be->getFileContents( array( 'src' => $file->getPath() ) ) ) ) .
839 " </contents>\n";
840 } else {
841 $contents = '';
842 }
843 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
844 $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
845 } else {
846 $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
847 }
848 return " <upload>\n" .
849 $this->writeTimestamp( $file->getTimestamp() ) .
850 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
851 " " . $comment . "\n" .
852 " " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
853 $archiveName .
854 " " . Xml::element( 'src', null, $file->getCanonicalURL() ) . "\n" .
855 " " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
856 " " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
857 " " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
858 $contents .
859 " </upload>\n";
860 }
861
862 /**
863 * Return prefixed text form of title, but using the content language's
864 * canonical namespace. This skips any special-casing such as gendered
865 * user namespaces -- which while useful, are not yet listed in the
866 * XML "<siteinfo>" data so are unsafe in export.
867 *
868 * @param Title $title
869 * @return string
870 * @since 1.18
871 */
872 public static function canonicalTitle( Title $title ) {
873 if ( $title->isExternal() ) {
874 return $title->getPrefixedText();
875 }
876
877 global $wgContLang;
878 $prefix = str_replace( '_', ' ', $wgContLang->getNsText( $title->getNamespace() ) );
879
880 if ( $prefix !== '' ) {
881 $prefix .= ':';
882 }
883
884 return $prefix . $title->getText();
885 }
886 }
887
888 /**
889 * Base class for output stream; prints to stdout or buffer or wherever.
890 * @ingroup Dump
891 */
892 class DumpOutput {
893
894 /**
895 * @param $string string
896 */
897 function writeOpenStream( $string ) {
898 $this->write( $string );
899 }
900
901 /**
902 * @param $string string
903 */
904 function writeCloseStream( $string ) {
905 $this->write( $string );
906 }
907
908 /**
909 * @param $page
910 * @param $string string
911 */
912 function writeOpenPage( $page, $string ) {
913 $this->write( $string );
914 }
915
916 /**
917 * @param $string string
918 */
919 function writeClosePage( $string ) {
920 $this->write( $string );
921 }
922
923 /**
924 * @param $rev
925 * @param $string string
926 */
927 function writeRevision( $rev, $string ) {
928 $this->write( $string );
929 }
930
931 /**
932 * @param $rev
933 * @param $string string
934 */
935 function writeLogItem( $rev, $string ) {
936 $this->write( $string );
937 }
938
939 /**
940 * Override to write to a different stream type.
941 * @param $string string
942 * @return bool
943 */
944 function write( $string ) {
945 print $string;
946 }
947
948 /**
949 * Close the old file, move it to a specified name,
950 * and reopen new file with the old name. Use this
951 * for writing out a file in multiple pieces
952 * at specified checkpoints (e.g. every n hours).
953 * @param $newname mixed File name. May be a string or an array with one element
954 */
955 function closeRenameAndReopen( $newname ) {
956 }
957
958 /**
959 * Close the old file, and move it to a specified name.
960 * Use this for the last piece of a file written out
961 * at specified checkpoints (e.g. every n hours).
962 * @param $newname mixed File name. May be a string or an array with one element
963 * @param bool $open If true, a new file with the old filename will be opened
964 * again for writing (default: false)
965 */
966 function closeAndRename( $newname, $open = false ) {
967 }
968
969 /**
970 * Returns the name of the file or files which are
971 * being written to, if there are any.
972 * @return null
973 */
974 function getFilenames() {
975 return null;
976 }
977 }
978
979 /**
980 * Stream outputter to send data to a file.
981 * @ingroup Dump
982 */
983 class DumpFileOutput extends DumpOutput {
984 protected $handle = false, $filename;
985
986 /**
987 * @param $file
988 */
989 function __construct( $file ) {
990 $this->handle = fopen( $file, "wt" );
991 $this->filename = $file;
992 }
993
994 /**
995 * @param $string string
996 */
997 function writeCloseStream( $string ) {
998 parent::writeCloseStream( $string );
999 if ( $this->handle ) {
1000 fclose( $this->handle );
1001 $this->handle = false;
1002 }
1003 }
1004
1005 /**
1006 * @param $string string
1007 */
1008 function write( $string ) {
1009 fputs( $this->handle, $string );
1010 }
1011
1012 /**
1013 * @param $newname
1014 */
1015 function closeRenameAndReopen( $newname ) {
1016 $this->closeAndRename( $newname, true );
1017 }
1018
1019 /**
1020 * @param $newname
1021 * @throws MWException
1022 */
1023 function renameOrException( $newname ) {
1024 if ( !rename( $this->filename, $newname ) ) {
1025 throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
1026 }
1027 }
1028
1029 /**
1030 * @param $newname array
1031 * @return mixed
1032 * @throws MWException
1033 */
1034 function checkRenameArgCount( $newname ) {
1035 if ( is_array( $newname ) ) {
1036 if ( count( $newname ) > 1 ) {
1037 throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
1038 } else {
1039 $newname = $newname[0];
1040 }
1041 }
1042 return $newname;
1043 }
1044
1045 /**
1046 * @param $newname mixed
1047 * @param $open bool
1048 */
1049 function closeAndRename( $newname, $open = false ) {
1050 $newname = $this->checkRenameArgCount( $newname );
1051 if ( $newname ) {
1052 if ( $this->handle ) {
1053 fclose( $this->handle );
1054 $this->handle = false;
1055 }
1056 $this->renameOrException( $newname );
1057 if ( $open ) {
1058 $this->handle = fopen( $this->filename, "wt" );
1059 }
1060 }
1061 }
1062
1063 /**
1064 * @return string|null
1065 */
1066 function getFilenames() {
1067 return $this->filename;
1068 }
1069 }
1070
1071 /**
1072 * Stream outputter to send data to a file via some filter program.
1073 * Even if compression is available in a library, using a separate
1074 * program can allow us to make use of a multi-processor system.
1075 * @ingroup Dump
1076 */
1077 class DumpPipeOutput extends DumpFileOutput {
1078 protected $command, $filename;
1079 protected $procOpenResource = false;
1080
1081 /**
1082 * @param $command
1083 * @param $file null
1084 */
1085 function __construct( $command, $file = null ) {
1086 if ( !is_null( $file ) ) {
1087 $command .= " > " . wfEscapeShellArg( $file );
1088 }
1089
1090 $this->startCommand( $command );
1091 $this->command = $command;
1092 $this->filename = $file;
1093 }
1094
1095 /**
1096 * @param $string string
1097 */
1098 function writeCloseStream( $string ) {
1099 parent::writeCloseStream( $string );
1100 if ( $this->procOpenResource ) {
1101 proc_close( $this->procOpenResource );
1102 $this->procOpenResource = false;
1103 }
1104 }
1105
1106 /**
1107 * @param $command
1108 */
1109 function startCommand( $command ) {
1110 $spec = array(
1111 0 => array( "pipe", "r" ),
1112 );
1113 $pipes = array();
1114 $this->procOpenResource = proc_open( $command, $spec, $pipes );
1115 $this->handle = $pipes[0];
1116 }
1117
1118 /**
1119 * @param mixed $newname
1120 */
1121 function closeRenameAndReopen( $newname ) {
1122 $this->closeAndRename( $newname, true );
1123 }
1124
1125 /**
1126 * @param $newname mixed
1127 * @param $open bool
1128 */
1129 function closeAndRename( $newname, $open = false ) {
1130 $newname = $this->checkRenameArgCount( $newname );
1131 if ( $newname ) {
1132 if ( $this->handle ) {
1133 fclose( $this->handle );
1134 $this->handle = false;
1135 }
1136 if ( $this->procOpenResource ) {
1137 proc_close( $this->procOpenResource );
1138 $this->procOpenResource = false;
1139 }
1140 $this->renameOrException( $newname );
1141 if ( $open ) {
1142 $command = $this->command;
1143 $command .= " > " . wfEscapeShellArg( $this->filename );
1144 $this->startCommand( $command );
1145 }
1146 }
1147 }
1148
1149 }
1150
1151 /**
1152 * Sends dump output via the gzip compressor.
1153 * @ingroup Dump
1154 */
1155 class DumpGZipOutput extends DumpPipeOutput {
1156
1157 /**
1158 * @param $file string
1159 */
1160 function __construct( $file ) {
1161 parent::__construct( "gzip", $file );
1162 }
1163 }
1164
1165 /**
1166 * Sends dump output via the bgzip2 compressor.
1167 * @ingroup Dump
1168 */
1169 class DumpBZip2Output extends DumpPipeOutput {
1170
1171 /**
1172 * @param $file string
1173 */
1174 function __construct( $file ) {
1175 parent::__construct( "bzip2", $file );
1176 }
1177 }
1178
1179 /**
1180 * Sends dump output via the p7zip compressor.
1181 * @ingroup Dump
1182 */
1183 class Dump7ZipOutput extends DumpPipeOutput {
1184
1185 /**
1186 * @param $file string
1187 */
1188 function __construct( $file ) {
1189 $command = $this->setup7zCommand( $file );
1190 parent::__construct( $command );
1191 $this->filename = $file;
1192 }
1193
1194 /**
1195 * @param $file string
1196 * @return string
1197 */
1198 function setup7zCommand( $file ) {
1199 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
1200 // Suppress annoying useless crap from p7zip
1201 // Unfortunately this could suppress real error messages too
1202 $command .= ' >' . wfGetNull() . ' 2>&1';
1203 return $command;
1204 }
1205
1206 /**
1207 * @param $newname string
1208 * @param $open bool
1209 */
1210 function closeAndRename( $newname, $open = false ) {
1211 $newname = $this->checkRenameArgCount( $newname );
1212 if ( $newname ) {
1213 fclose( $this->handle );
1214 proc_close( $this->procOpenResource );
1215 $this->renameOrException( $newname );
1216 if ( $open ) {
1217 $command = $this->setup7zCommand( $this->filename );
1218 $this->startCommand( $command );
1219 }
1220 }
1221 }
1222 }
1223
1224 /**
1225 * Dump output filter class.
1226 * This just does output filtering and streaming; XML formatting is done
1227 * higher up, so be careful in what you do.
1228 * @ingroup Dump
1229 */
1230 class DumpFilter {
1231
1232 /**
1233 * @var DumpOutput
1234 * FIXME will need to be made protected whenever legacy code
1235 * is updated.
1236 */
1237 public $sink;
1238
1239 /**
1240 * @var bool
1241 */
1242 protected $sendingThisPage;
1243
1244 /**
1245 * @param $sink DumpOutput
1246 */
1247 function __construct( &$sink ) {
1248 $this->sink =& $sink;
1249 }
1250
1251 /**
1252 * @param $string string
1253 */
1254 function writeOpenStream( $string ) {
1255 $this->sink->writeOpenStream( $string );
1256 }
1257
1258 /**
1259 * @param $string string
1260 */
1261 function writeCloseStream( $string ) {
1262 $this->sink->writeCloseStream( $string );
1263 }
1264
1265 /**
1266 * @param $page
1267 * @param $string string
1268 */
1269 function writeOpenPage( $page, $string ) {
1270 $this->sendingThisPage = $this->pass( $page, $string );
1271 if ( $this->sendingThisPage ) {
1272 $this->sink->writeOpenPage( $page, $string );
1273 }
1274 }
1275
1276 /**
1277 * @param $string string
1278 */
1279 function writeClosePage( $string ) {
1280 if ( $this->sendingThisPage ) {
1281 $this->sink->writeClosePage( $string );
1282 $this->sendingThisPage = false;
1283 }
1284 }
1285
1286 /**
1287 * @param $rev
1288 * @param $string string
1289 */
1290 function writeRevision( $rev, $string ) {
1291 if ( $this->sendingThisPage ) {
1292 $this->sink->writeRevision( $rev, $string );
1293 }
1294 }
1295
1296 /**
1297 * @param $rev
1298 * @param $string string
1299 */
1300 function writeLogItem( $rev, $string ) {
1301 $this->sink->writeRevision( $rev, $string );
1302 }
1303
1304 /**
1305 * @param $newname string
1306 */
1307 function closeRenameAndReopen( $newname ) {
1308 $this->sink->closeRenameAndReopen( $newname );
1309 }
1310
1311 /**
1312 * @param $newname string
1313 * @param $open bool
1314 */
1315 function closeAndRename( $newname, $open = false ) {
1316 $this->sink->closeAndRename( $newname, $open );
1317 }
1318
1319 /**
1320 * @return array
1321 */
1322 function getFilenames() {
1323 return $this->sink->getFilenames();
1324 }
1325
1326 /**
1327 * Override for page-based filter types.
1328 * @param $page
1329 * @return bool
1330 */
1331 function pass( $page ) {
1332 return true;
1333 }
1334 }
1335
1336 /**
1337 * Simple dump output filter to exclude all talk pages.
1338 * @ingroup Dump
1339 */
1340 class DumpNotalkFilter extends DumpFilter {
1341
1342 /**
1343 * @param $page
1344 * @return bool
1345 */
1346 function pass( $page ) {
1347 return !MWNamespace::isTalk( $page->page_namespace );
1348 }
1349 }
1350
1351 /**
1352 * Dump output filter to include or exclude pages in a given set of namespaces.
1353 * @ingroup Dump
1354 */
1355 class DumpNamespaceFilter extends DumpFilter {
1356 var $invert = false;
1357 var $namespaces = array();
1358
1359 /**
1360 * @param $sink DumpOutput
1361 * @param $param
1362 * @throws MWException
1363 */
1364 function __construct( &$sink, $param ) {
1365 parent::__construct( $sink );
1366
1367 $constants = array(
1368 "NS_MAIN" => NS_MAIN,
1369 "NS_TALK" => NS_TALK,
1370 "NS_USER" => NS_USER,
1371 "NS_USER_TALK" => NS_USER_TALK,
1372 "NS_PROJECT" => NS_PROJECT,
1373 "NS_PROJECT_TALK" => NS_PROJECT_TALK,
1374 "NS_FILE" => NS_FILE,
1375 "NS_FILE_TALK" => NS_FILE_TALK,
1376 "NS_IMAGE" => NS_IMAGE, // NS_IMAGE is an alias for NS_FILE
1377 "NS_IMAGE_TALK" => NS_IMAGE_TALK,
1378 "NS_MEDIAWIKI" => NS_MEDIAWIKI,
1379 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK,
1380 "NS_TEMPLATE" => NS_TEMPLATE,
1381 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK,
1382 "NS_HELP" => NS_HELP,
1383 "NS_HELP_TALK" => NS_HELP_TALK,
1384 "NS_CATEGORY" => NS_CATEGORY,
1385 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK );
1386
1387 if ( $param { 0 } == '!' ) {
1388 $this->invert = true;
1389 $param = substr( $param, 1 );
1390 }
1391
1392 foreach ( explode( ',', $param ) as $key ) {
1393 $key = trim( $key );
1394 if ( isset( $constants[$key] ) ) {
1395 $ns = $constants[$key];
1396 $this->namespaces[$ns] = true;
1397 } elseif ( is_numeric( $key ) ) {
1398 $ns = intval( $key );
1399 $this->namespaces[$ns] = true;
1400 } else {
1401 throw new MWException( "Unrecognized namespace key '$key'\n" );
1402 }
1403 }
1404 }
1405
1406 /**
1407 * @param $page
1408 * @return bool
1409 */
1410 function pass( $page ) {
1411 $match = isset( $this->namespaces[$page->page_namespace] );
1412 return $this->invert xor $match;
1413 }
1414 }
1415
1416 /**
1417 * Dump output filter to include only the last revision in each page sequence.
1418 * @ingroup Dump
1419 */
1420 class DumpLatestFilter extends DumpFilter {
1421 var $page, $pageString, $rev, $revString;
1422
1423 /**
1424 * @param $page
1425 * @param $string string
1426 */
1427 function writeOpenPage( $page, $string ) {
1428 $this->page = $page;
1429 $this->pageString = $string;
1430 }
1431
1432 /**
1433 * @param $string string
1434 */
1435 function writeClosePage( $string ) {
1436 if ( $this->rev ) {
1437 $this->sink->writeOpenPage( $this->page, $this->pageString );
1438 $this->sink->writeRevision( $this->rev, $this->revString );
1439 $this->sink->writeClosePage( $string );
1440 }
1441 $this->rev = null;
1442 $this->revString = null;
1443 $this->page = null;
1444 $this->pageString = null;
1445 }
1446
1447 /**
1448 * @param $rev
1449 * @param $string string
1450 */
1451 function writeRevision( $rev, $string ) {
1452 if ( $rev->rev_id == $this->page->page_latest ) {
1453 $this->rev = $rev;
1454 $this->revString = $string;
1455 }
1456 }
1457 }
1458
1459 /**
1460 * Base class for output stream; prints to stdout or buffer or wherever.
1461 * @ingroup Dump
1462 */
1463 class DumpMultiWriter {
1464
1465 /**
1466 * @param $sinks
1467 */
1468 function __construct( $sinks ) {
1469 $this->sinks = $sinks;
1470 $this->count = count( $sinks );
1471 }
1472
1473 /**
1474 * @param $string string
1475 */
1476 function writeOpenStream( $string ) {
1477 for ( $i = 0; $i < $this->count; $i++ ) {
1478 $this->sinks[$i]->writeOpenStream( $string );
1479 }
1480 }
1481
1482 /**
1483 * @param $string string
1484 */
1485 function writeCloseStream( $string ) {
1486 for ( $i = 0; $i < $this->count; $i++ ) {
1487 $this->sinks[$i]->writeCloseStream( $string );
1488 }
1489 }
1490
1491 /**
1492 * @param $page
1493 * @param $string string
1494 */
1495 function writeOpenPage( $page, $string ) {
1496 for ( $i = 0; $i < $this->count; $i++ ) {
1497 $this->sinks[$i]->writeOpenPage( $page, $string );
1498 }
1499 }
1500
1501 /**
1502 * @param $string
1503 */
1504 function writeClosePage( $string ) {
1505 for ( $i = 0; $i < $this->count; $i++ ) {
1506 $this->sinks[$i]->writeClosePage( $string );
1507 }
1508 }
1509
1510 /**
1511 * @param $rev
1512 * @param $string
1513 */
1514 function writeRevision( $rev, $string ) {
1515 for ( $i = 0; $i < $this->count; $i++ ) {
1516 $this->sinks[$i]->writeRevision( $rev, $string );
1517 }
1518 }
1519
1520 /**
1521 * @param $newnames
1522 */
1523 function closeRenameAndReopen( $newnames ) {
1524 $this->closeAndRename( $newnames, true );
1525 }
1526
1527 /**
1528 * @param $newnames array
1529 * @param bool $open
1530 */
1531 function closeAndRename( $newnames, $open = false ) {
1532 for ( $i = 0; $i < $this->count; $i++ ) {
1533 $this->sinks[$i]->closeAndRename( $newnames[$i], $open );
1534 }
1535 }
1536
1537 /**
1538 * @return array
1539 */
1540 function getFilenames() {
1541 $filenames = array();
1542 for ( $i = 0; $i < $this->count; $i++ ) {
1543 $filenames[] = $this->sinks[$i]->getFilenames();
1544 }
1545 return $filenames;
1546 }
1547
1548 }
1549
1550 /**
1551 * @param $string string
1552 * @return string
1553 */
1554 function xmlsafe( $string ) {
1555 wfProfileIn( __FUNCTION__ );
1556
1557 /**
1558 * The page may contain old data which has not been properly normalized.
1559 * Invalid UTF-8 sequences or forbidden control characters will make our
1560 * XML output invalid, so be sure to strip them out.
1561 */
1562 $string = UtfNormal::cleanUp( $string );
1563
1564 $string = htmlspecialchars( $string );
1565 wfProfileOut( __FUNCTION__ );
1566 return $string;
1567 }