2 # Copyright (C) 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
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.
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.
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
25 * @ingroup SpecialPage Dump
28 var $list_authors = false ; # Return distinct author list (when not returning full history)
29 var $author_list = "" ;
31 var $dumpUploads = false;
44 * If using WikiExporter::STREAM to stream a large amount of data,
45 * provide a database connection which is not managed by
46 * LoadBalancer to read from: some history blob types will
47 * make additional queries to pull source data while the
48 * main query is still running.
51 * @param $history Mixed: one of WikiExporter::FULL or WikiExporter::CURRENT,
52 * or an associative array:
53 * offset: non-inclusive offset at which to start the query
54 * limit: maximum number of rows to return
55 * dir: "asc" or "desc" timestamp order
56 * @param $buffer Int: one of WikiExporter::BUFFER or WikiExporter::STREAM
58 function __construct( &$db, $history = WikiExporter
::CURRENT
,
59 $buffer = WikiExporter
::BUFFER
, $text = WikiExporter
::TEXT
) {
61 $this->history
= $history;
62 $this->buffer
= $buffer;
63 $this->writer
= new XmlDumpWriter();
64 $this->sink
= new DumpOutput();
69 * Set the DumpOutput or DumpFilter object which will receive
70 * various row objects and XML output for filtering. Filters
71 * can be chained or used as callbacks.
75 public function setOutputSink( &$sink ) {
79 public function openStream() {
80 $output = $this->writer
->openStream();
81 $this->sink
->writeOpenStream( $output );
84 public function closeStream() {
85 $output = $this->writer
->closeStream();
86 $this->sink
->writeCloseStream( $output );
90 * Dumps a series of page and revision records for all pages
91 * in the database, either including complete history or only
92 * the most recent version.
94 public function allPages() {
95 return $this->dumpFrom( '' );
99 * Dumps a series of page and revision records for those pages
100 * in the database falling within the page_id range given.
101 * @param $start Int: inclusive lower limit (this id is included)
102 * @param $end Int: Exclusive upper limit (this id is not included)
103 * If 0, no upper limit.
105 public function pagesByRange( $start, $end ) {
106 $condition = 'page_id >= ' . intval( $start );
108 $condition .= ' AND page_id < ' . intval( $end );
110 return $this->dumpFrom( $condition );
114 * @param $title Title
116 public function pageByTitle( $title ) {
117 return $this->dumpFrom(
118 'page_namespace=' . $title->getNamespace() .
119 ' AND page_title=' . $this->db
->addQuotes( $title->getDBkey() ) );
122 public function pageByName( $name ) {
123 $title = Title
::newFromText( $name );
124 if( is_null( $title ) ) {
125 return new WikiError( "Can't export invalid title" );
127 return $this->pageByTitle( $title );
131 public function pagesByName( $names ) {
132 foreach( $names as $name ) {
133 $this->pageByName( $name );
137 public function allLogs() {
138 return $this->dumpFrom( '' );
141 public function logsByRange( $start, $end ) {
142 $condition = 'log_id >= ' . intval( $start );
144 $condition .= ' AND log_id < ' . intval( $end );
146 return $this->dumpFrom( $condition );
149 # Generates the distinct list of authors of an article
150 # Not called by default (depends on $this->list_authors)
151 # Can be set by Special:Export when not exporting whole history
152 protected function do_list_authors( $page , $revision , $cond ) {
153 $fname = "do_list_authors" ;
154 wfProfileIn( $fname );
155 $this->author_list
= "<contributors>";
157 $nothidden = '(rev_deleted & '.Revision
::DELETED_USER
.') = 0';
159 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
160 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
161 $result = $this->db
->query( $sql, $fname );
162 $resultset = $this->db
->resultObject( $result );
163 while( $row = $resultset->fetchObject() ) {
164 $this->author_list
.= "<contributor>" .
166 htmlentities( $row->rev_user_text
) .
173 wfProfileOut( $fname );
174 $this->author_list
.= "</contributors>";
177 protected function dumpFrom( $cond = '' ) {
178 $fname = 'WikiExporter::dumpFrom';
179 wfProfileIn( $fname );
182 if( $this->history
& self
::LOGS
) {
183 $where = array( 'user_id = log_user' );
185 $where[] = LogEventsList
::getExcludeClause( $this->db
);
186 if( $cond ) $where[] = $cond;
187 # Get logging table name for logging.* clause
188 $logging = $this->db
->tableName('logging');
189 $result = $this->db
->select( array('logging','user'),
190 array( "{$logging}.*", 'user_name' ), // grab the user name
193 array( 'ORDER BY' => 'log_id', 'USE INDEX' => array('logging' => 'PRIMARY') )
195 $wrapper = $this->db
->resultObject( $result );
196 $this->outputLogStream( $wrapper );
199 list($page,$revision,$text) = $this->db
->tableNamesN('page','revision','text');
201 $order = 'ORDER BY page_id';
204 if( $this->history
== WikiExporter
::FULL
) {
205 $join = 'page_id=rev_page';
206 } elseif( $this->history
== WikiExporter
::CURRENT
) {
207 if ( $this->list_authors
&& $cond != '' ) { // List authors, if so desired
208 $this->do_list_authors ( $page , $revision , $cond );
210 $join = 'page_id=rev_page AND page_latest=rev_id';
211 } elseif ( is_array( $this->history
) ) {
212 $join = 'page_id=rev_page';
213 if ( $this->history
['dir'] == 'asc' ) {
215 $order .= ', rev_timestamp';
218 $order .= ', rev_timestamp DESC';
220 if ( !empty( $this->history
['offset'] ) ) {
221 $join .= " AND rev_timestamp $op " . $this->db
->addQuotes(
222 $this->db
->timestamp( $this->history
['offset'] ) );
224 if ( !empty( $this->history
['limit'] ) ) {
225 $limitNum = intval( $this->history
['limit'] );
226 if ( $limitNum > 0 ) {
227 $limit = "LIMIT $limitNum";
231 wfProfileOut( $fname );
232 return new WikiError( "$fname given invalid history dump type." );
234 $where = ( $cond == '' ) ?
'' : "$cond AND";
236 if( $this->buffer
== WikiExporter
::STREAM
) {
237 $prev = $this->db
->bufferResults( false );
240 // Optimization hack for full-database dump
241 $revindex = $pageindex = $this->db
->useIndexClause("PRIMARY");
242 $straight = ' /*! STRAIGHT_JOIN */ ';
248 if( $this->text
== WikiExporter
::STUB
) {
249 $sql = "SELECT $straight * FROM
255 $sql = "SELECT $straight * FROM
259 WHERE $where $join AND rev_text_id=old_id
262 $result = $this->db
->query( $sql, $fname );
263 $wrapper = $this->db
->resultObject( $result );
264 $this->outputPageStream( $wrapper );
266 if ( $this->list_authors
) {
267 $this->outputPageStream( $wrapper );
270 if( $this->buffer
== WikiExporter
::STREAM
) {
271 $this->db
->bufferResults( $prev );
274 wfProfileOut( $fname );
278 * Runs through a query result set dumping page and revision records.
279 * The result set should be sorted/grouped by page to avoid duplicate
280 * page records in the output.
282 * The result set will be freed once complete. Should be safe for
283 * streaming (non-buffered) queries, as long as it was made on a
284 * separate database connection not managed by LoadBalancer; some
285 * blob storage types will make queries to pull source data.
287 * @param $resultset ResultWrapper
289 protected function outputPageStream( $resultset ) {
291 while( $row = $resultset->fetchObject() ) {
292 if( is_null( $last ) ||
293 $last->page_namespace
!= $row->page_namespace ||
294 $last->page_title
!= $row->page_title
) {
295 if( isset( $last ) ) {
297 if( $this->dumpUploads
) {
298 $output .= $this->writer
->writeUploads( $last );
300 $output .= $this->writer
->closePage();
301 $this->sink
->writeClosePage( $output );
303 $output = $this->writer
->openPage( $row );
304 $this->sink
->writeOpenPage( $row, $output );
307 $output = $this->writer
->writeRevision( $row );
308 $this->sink
->writeRevision( $row, $output );
310 if( isset( $last ) ) {
312 if( $this->dumpUploads
) {
313 $output .= $this->writer
->writeUploads( $last );
315 $output .= $this->author_list
;
316 $output .= $this->writer
->closePage();
317 $this->sink
->writeClosePage( $output );
322 protected function outputLogStream( $resultset ) {
323 while( $row = $resultset->fetchObject() ) {
324 $output = $this->writer
->writeLogItem( $row );
325 $this->sink
->writeLogItem( $row, $output );
334 class XmlDumpWriter
{
337 * Returns the export schema version.
340 function schemaVersion() {
341 return "0.3"; // FIXME: upgrade to 0.4 when updated XSD is ready, for the revision deletion bits
345 * Opens the XML output stream's root <mediawiki> element.
346 * This does not include an xml directive, so is safe to include
347 * as a subelement in a larger XML stream. Namespace and XML Schema
348 * references are included.
350 * Output will be encoded in UTF-8.
354 function openStream() {
355 global $wgContLanguageCode;
356 $ver = $this->schemaVersion();
357 return Xml
::element( 'mediawiki', array(
358 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
359 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
360 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
361 "http://www.mediawiki.org/xml/export-$ver.xsd",
363 'xml:lang' => $wgContLanguageCode ),
369 function siteInfo() {
374 $this->caseSetting(),
375 $this->namespaces() );
376 return " <siteinfo>\n " .
377 implode( "\n ", $info ) .
381 function sitename() {
383 return Xml
::element( 'sitename', array(), $wgSitename );
386 function generator() {
388 return Xml
::element( 'generator', array(), "MediaWiki $wgVersion" );
391 function homelink() {
392 return Xml
::element( 'base', array(), Title
::newMainPage()->getFullUrl() );
395 function caseSetting() {
396 global $wgCapitalLinks;
397 // "case-insensitive" option is reserved for future
398 $sensitivity = $wgCapitalLinks ?
'first-letter' : 'case-sensitive';
399 return Xml
::element( 'case', array(), $sensitivity );
402 function namespaces() {
404 $spaces = "<namespaces>\n";
405 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
406 $spaces .= ' ' . Xml
::element( 'namespace', array( 'key' => $ns ), $title ) . "\n";
408 $spaces .= " </namespaces>";
413 * Closes the output stream with the closing root element.
414 * Call when finished dumping things.
416 function closeStream() {
417 return "</mediawiki>\n";
422 * Opens a <page> section on the output stream, with data
423 * from the given database row.
429 function openPage( $row ) {
431 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
432 $out .= ' ' . Xml
::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n";
433 $out .= ' ' . Xml
::element( 'id', array(), strval( $row->page_id
) ) . "\n";
434 if( '' != $row->page_restrictions
) {
435 $out .= ' ' . Xml
::element( 'restrictions', array(),
436 strval( $row->page_restrictions
) ) . "\n";
442 * Closes a <page> section on the output stream.
446 function closePage() {
451 * Dumps a <revision> section on the output stream, with
452 * data filled in from the given database row.
458 function writeRevision( $row ) {
459 $fname = 'WikiExporter::dumpRev';
460 wfProfileIn( $fname );
462 $out = " <revision>\n";
463 $out .= " " . Xml
::element( 'id', null, strval( $row->rev_id
) ) . "\n";
465 $out .= $this->writeTimestamp( $row->rev_timestamp
);
467 if( $row->rev_deleted
& Revision
::DELETED_USER
) {
468 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
470 $out .= $this->writeContributor( $row->rev_user
, $row->rev_user_text
);
473 if( $row->rev_minor_edit
) {
474 $out .= " <minor/>\n";
476 if( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
477 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
478 } elseif( $row->rev_comment
!= '' ) {
479 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->rev_comment
) ) . "\n";
482 if( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
483 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
484 } elseif( isset( $row->old_text
) ) {
485 // Raw text from the database may have invalid chars
486 $text = strval( Revision
::getRevisionText( $row ) );
487 $out .= " " . Xml
::elementClean( 'text',
488 array( 'xml:space' => 'preserve' ),
489 strval( $text ) ) . "\n";
492 $out .= " " . Xml
::element( 'text',
493 array( 'id' => $row->rev_text_id
),
497 $out .= " </revision>\n";
499 wfProfileOut( $fname );
504 * Dumps a <logitem> section on the output stream, with
505 * data filled in from the given database row.
511 function writeLogItem( $row ) {
512 $fname = 'WikiExporter::writeLogItem';
513 wfProfileIn( $fname );
515 $out = " <logitem>\n";
516 $out .= " " . Xml
::element( 'id', null, strval( $row->log_id
) ) . "\n";
518 $out .= $this->writeTimestamp( $row->log_timestamp
);
520 if( $row->log_deleted
& LogPage
::DELETED_USER
) {
521 $out .= " " . Xml
::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
523 $out .= $this->writeContributor( $row->log_user
, $row->user_name
);
526 if( $row->log_deleted
& LogPage
::DELETED_COMMENT
) {
527 $out .= " " . Xml
::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
528 } elseif( $row->log_comment
!= '' ) {
529 $out .= " " . Xml
::elementClean( 'comment', null, strval( $row->log_comment
) ) . "\n";
532 $out .= " " . Xml
::element( 'type', null, strval( $row->log_type
) ) . "\n";
533 $out .= " " . Xml
::element( 'action', null, strval( $row->log_action
) ) . "\n";
535 if( $row->log_deleted
& LogPage
::DELETED_ACTION
) {
536 $out .= " " . Xml
::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
538 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
539 $out .= " " . Xml
::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n";
540 $out .= " " . Xml
::elementClean( 'params',
541 array( 'xml:space' => 'preserve' ),
542 strval( $row->log_params
) ) . "\n";
545 $out .= " </logitem>\n";
547 wfProfileOut( $fname );
551 function writeTimestamp( $timestamp ) {
552 $ts = wfTimestamp( TS_ISO_8601
, $timestamp );
553 return " " . Xml
::element( 'timestamp', null, $ts ) . "\n";
556 function writeContributor( $id, $text ) {
557 $out = " <contributor>\n";
559 $out .= " " . Xml
::elementClean( 'username', null, strval( $text ) ) . "\n";
560 $out .= " " . Xml
::element( 'id', null, strval( $id ) ) . "\n";
562 $out .= " " . Xml
::elementClean( 'ip', null, strval( $text ) ) . "\n";
564 $out .= " </contributor>\n";
569 * Warning! This data is potentially inconsistent. :(
571 function writeUploads( $row ) {
572 if( $row->page_namespace
== NS_IMAGE
) {
573 $img = wfFindFile( $row->page_title
);
576 foreach( array_reverse( $img->getHistory() ) as $ver ) {
577 $out .= $this->writeUpload( $ver );
579 $out .= $this->writeUpload( $img );
586 function writeUpload( $file ) {
587 return " <upload>\n" .
588 $this->writeTimestamp( $file->getTimestamp() ) .
589 $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
590 " " . Xml
::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
591 " " . Xml
::element( 'filename', null, $file->getName() ) . "\n" .
592 " " . Xml
::element( 'src', null, $file->getFullUrl() ) . "\n" .
593 " " . Xml
::element( 'size', null, $file->getSize() ) . "\n" .
601 * Base class for output stream; prints to stdout or buffer or whereever.
605 function writeOpenStream( $string ) {
606 $this->write( $string );
609 function writeCloseStream( $string ) {
610 $this->write( $string );
613 function writeOpenPage( $page, $string ) {
614 $this->write( $string );
617 function writeClosePage( $string ) {
618 $this->write( $string );
621 function writeRevision( $rev, $string ) {
622 $this->write( $string );
625 function writeLogItem( $rev, $string ) {
626 $this->write( $string );
630 * Override to write to a different stream type.
633 function write( $string ) {
639 * Stream outputter to send data to a file.
642 class DumpFileOutput
extends DumpOutput
{
645 function DumpFileOutput( $file ) {
646 $this->handle
= fopen( $file, "wt" );
649 function write( $string ) {
650 fputs( $this->handle
, $string );
655 * Stream outputter to send data to a file via some filter program.
656 * Even if compression is available in a library, using a separate
657 * program can allow us to make use of a multi-processor system.
660 class DumpPipeOutput
extends DumpFileOutput
{
661 function DumpPipeOutput( $command, $file = null ) {
662 if( !is_null( $file ) ) {
663 $command .= " > " . wfEscapeShellArg( $file );
665 $this->handle
= popen( $command, "w" );
670 * Sends dump output via the gzip compressor.
673 class DumpGZipOutput
extends DumpPipeOutput
{
674 function DumpGZipOutput( $file ) {
675 parent
::DumpPipeOutput( "gzip", $file );
680 * Sends dump output via the bgzip2 compressor.
683 class DumpBZip2Output
extends DumpPipeOutput
{
684 function DumpBZip2Output( $file ) {
685 parent
::DumpPipeOutput( "bzip2", $file );
690 * Sends dump output via the p7zip compressor.
693 class Dump7ZipOutput
extends DumpPipeOutput
{
694 function Dump7ZipOutput( $file ) {
695 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
696 // Suppress annoying useless crap from p7zip
697 // Unfortunately this could suppress real error messages too
698 $command .= ' >' . wfGetNull() . ' 2>&1';
699 parent
::DumpPipeOutput( $command );
706 * Dump output filter class.
707 * This just does output filtering and streaming; XML formatting is done
708 * higher up, so be careful in what you do.
712 function DumpFilter( &$sink ) {
713 $this->sink
=& $sink;
716 function writeOpenStream( $string ) {
717 $this->sink
->writeOpenStream( $string );
720 function writeCloseStream( $string ) {
721 $this->sink
->writeCloseStream( $string );
724 function writeOpenPage( $page, $string ) {
725 $this->sendingThisPage
= $this->pass( $page, $string );
726 if( $this->sendingThisPage
) {
727 $this->sink
->writeOpenPage( $page, $string );
731 function writeClosePage( $string ) {
732 if( $this->sendingThisPage
) {
733 $this->sink
->writeClosePage( $string );
734 $this->sendingThisPage
= false;
738 function writeRevision( $rev, $string ) {
739 if( $this->sendingThisPage
) {
740 $this->sink
->writeRevision( $rev, $string );
744 function writeLogItem( $rev, $string ) {
745 $this->sink
->writeRevision( $rev, $string );
749 * Override for page-based filter types.
752 function pass( $page ) {
758 * Simple dump output filter to exclude all talk pages.
761 class DumpNotalkFilter
extends DumpFilter
{
762 function pass( $page ) {
763 return !MWNamespace
::isTalk( $page->page_namespace
);
768 * Dump output filter to include or exclude pages in a given set of namespaces.
771 class DumpNamespaceFilter
extends DumpFilter
{
773 var $namespaces = array();
775 function DumpNamespaceFilter( &$sink, $param ) {
776 parent
::DumpFilter( $sink );
779 "NS_MAIN" => NS_MAIN
,
780 "NS_TALK" => NS_TALK
,
781 "NS_USER" => NS_USER
,
782 "NS_USER_TALK" => NS_USER_TALK
,
783 "NS_PROJECT" => NS_PROJECT
,
784 "NS_PROJECT_TALK" => NS_PROJECT_TALK
,
785 "NS_FILE" => NS_FILE
,
786 "NS_FILE_TALK" => NS_FILE_TALK
,
787 "NS_IMAGE" => NS_IMAGE
, // NS_IMAGE is an alias for NS_FILE
788 "NS_IMAGE_TALK" => NS_IMAGE_TALK
,
789 "NS_MEDIAWIKI" => NS_MEDIAWIKI
,
790 "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK
,
791 "NS_TEMPLATE" => NS_TEMPLATE
,
792 "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK
,
793 "NS_HELP" => NS_HELP
,
794 "NS_HELP_TALK" => NS_HELP_TALK
,
795 "NS_CATEGORY" => NS_CATEGORY
,
796 "NS_CATEGORY_TALK" => NS_CATEGORY_TALK
);
798 if( $param{0} == '!' ) {
799 $this->invert
= true;
800 $param = substr( $param, 1 );
803 foreach( explode( ',', $param ) as $key ) {
805 if( isset( $constants[$key] ) ) {
806 $ns = $constants[$key];
807 $this->namespaces
[$ns] = true;
808 } elseif( is_numeric( $key ) ) {
809 $ns = intval( $key );
810 $this->namespaces
[$ns] = true;
812 throw new MWException( "Unrecognized namespace key '$key'\n" );
817 function pass( $page ) {
818 $match = isset( $this->namespaces
[$page->page_namespace
] );
819 return $this->invert
xor $match;
825 * Dump output filter to include only the last revision in each page sequence.
828 class DumpLatestFilter
extends DumpFilter
{
829 var $page, $pageString, $rev, $revString;
831 function writeOpenPage( $page, $string ) {
833 $this->pageString
= $string;
836 function writeClosePage( $string ) {
838 $this->sink
->writeOpenPage( $this->page
, $this->pageString
);
839 $this->sink
->writeRevision( $this->rev
, $this->revString
);
840 $this->sink
->writeClosePage( $string );
843 $this->revString
= null;
845 $this->pageString
= null;
848 function writeRevision( $rev, $string ) {
849 if( $rev->rev_id
== $this->page
->page_latest
) {
851 $this->revString
= $string;
857 * Base class for output stream; prints to stdout or buffer or whereever.
860 class DumpMultiWriter
{
861 function DumpMultiWriter( $sinks ) {
862 $this->sinks
= $sinks;
863 $this->count
= count( $sinks );
866 function writeOpenStream( $string ) {
867 for( $i = 0; $i < $this->count
; $i++
) {
868 $this->sinks
[$i]->writeOpenStream( $string );
872 function writeCloseStream( $string ) {
873 for( $i = 0; $i < $this->count
; $i++
) {
874 $this->sinks
[$i]->writeCloseStream( $string );
878 function writeOpenPage( $page, $string ) {
879 for( $i = 0; $i < $this->count
; $i++
) {
880 $this->sinks
[$i]->writeOpenPage( $page, $string );
884 function writeClosePage( $string ) {
885 for( $i = 0; $i < $this->count
; $i++
) {
886 $this->sinks
[$i]->writeClosePage( $string );
890 function writeRevision( $rev, $string ) {
891 for( $i = 0; $i < $this->count
; $i++
) {
892 $this->sinks
[$i]->writeRevision( $rev, $string );
897 function xmlsafe( $string ) {
899 wfProfileIn( $fname );
902 * The page may contain old data which has not been properly normalized.
903 * Invalid UTF-8 sequences or forbidden control characters will make our
904 * XML output invalid, so be sure to strip them out.
906 $string = UtfNormal
::cleanUp( $string );
908 $string = htmlspecialchars( $string );
909 wfProfileOut( $fname );