5c27658af561f451f2a7ab768c658cd8842e9d40
[lhc/web/wiklou.git] / includes / export / DumpFilter.php
1 <?php
2 /**
3 * Dump output filter class.
4 * This just does output filtering and streaming; XML formatting is done
5 * higher up, so be careful in what you do.
6 *
7 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
8 * https://www.mediawiki.org/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 *
25 * @file
26 */
27
28 /**
29 * @ingroup Dump
30 */
31 class DumpFilter {
32 /**
33 * @var DumpOutput
34 * FIXME will need to be made protected whenever legacy code
35 * is updated.
36 */
37 public $sink;
38
39 /**
40 * @var bool
41 */
42 protected $sendingThisPage;
43
44 /**
45 * @param DumpOutput $sink
46 */
47 function __construct( &$sink ) {
48 $this->sink =& $sink;
49 }
50
51 /**
52 * @param string $string
53 */
54 function writeOpenStream( $string ) {
55 $this->sink->writeOpenStream( $string );
56 }
57
58 /**
59 * @param string $string
60 */
61 function writeCloseStream( $string ) {
62 $this->sink->writeCloseStream( $string );
63 }
64
65 /**
66 * @param object $page
67 * @param string $string
68 */
69 function writeOpenPage( $page, $string ) {
70 $this->sendingThisPage = $this->pass( $page, $string );
71 if ( $this->sendingThisPage ) {
72 $this->sink->writeOpenPage( $page, $string );
73 }
74 }
75
76 /**
77 * @param string $string
78 */
79 function writeClosePage( $string ) {
80 if ( $this->sendingThisPage ) {
81 $this->sink->writeClosePage( $string );
82 $this->sendingThisPage = false;
83 }
84 }
85
86 /**
87 * @param object $rev
88 * @param string $string
89 */
90 function writeRevision( $rev, $string ) {
91 if ( $this->sendingThisPage ) {
92 $this->sink->writeRevision( $rev, $string );
93 }
94 }
95
96 /**
97 * @param object $rev
98 * @param string $string
99 */
100 function writeLogItem( $rev, $string ) {
101 $this->sink->writeRevision( $rev, $string );
102 }
103
104 /**
105 * @param string $newname
106 */
107 function closeRenameAndReopen( $newname ) {
108 $this->sink->closeRenameAndReopen( $newname );
109 }
110
111 /**
112 * @param string $newname
113 * @param bool $open
114 */
115 function closeAndRename( $newname, $open = false ) {
116 $this->sink->closeAndRename( $newname, $open );
117 }
118
119 /**
120 * @return array
121 */
122 function getFilenames() {
123 return $this->sink->getFilenames();
124 }
125
126 /**
127 * Override for page-based filter types.
128 * @param object $page
129 * @return bool
130 */
131 function pass( $page ) {
132 return true;
133 }
134 }