Index: trunk/tools/analysis/StreamingXMLHistory.php |
— | — | @@ -77,7 +77,11 @@ |
78 | 78 | public $pagelog; |
79 | 79 | public $pagelogFile; |
80 | 80 | public $nextLog; |
| 81 | + public $articleName; |
81 | 82 | |
| 83 | + //page log reader |
| 84 | + public $logreader; |
| 85 | + |
82 | 86 | //md5 hashes of the revision texts |
83 | 87 | public $md5History; |
84 | 88 | |
— | — | @@ -95,7 +99,8 @@ |
96 | 100 | $this->revTypes = array(); |
97 | 101 | $this->pagelog = $pagelog; |
98 | 102 | if($pagelog){ |
99 | | - $this->pagelogFile = fopen($this->pagelog, "r"); |
| 103 | + $this->logreader = new XMLReader(); |
| 104 | + $this->logreader->open($this->pagelog); |
100 | 105 | } |
101 | 106 | $this->oldSize = 0; |
102 | 107 | } |
— | — | @@ -140,7 +145,8 @@ |
141 | 146 | "new?", |
142 | 147 | "edit size", |
143 | 148 | "net size change", |
144 | | - "anonymous?" |
| 149 | + "anonymous?", |
| 150 | + "log action" |
145 | 151 | ); |
146 | 152 | fputcsv($this->outputFile, $csvData); |
147 | 153 | } |
— | — | @@ -150,9 +156,22 @@ |
151 | 157 | $reader->open($this->inputFileName); |
152 | 158 | $this->writeCSVHeader(); |
153 | 159 | $current_rev = 0; |
| 160 | + |
| 161 | + //get article title |
| 162 | + while($reader->read()){ |
| 163 | + if($reader->nodeType == XMLREADER::ELEMENT |
| 164 | + && $reader->localName == "title"){ |
| 165 | + $this->articleName = $reader->readInnerXml(); |
| 166 | + echo "Reading ".$this->articleName."\n"; |
| 167 | + break; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + //get first log |
154 | 172 | if($this->pagelog){ |
155 | 173 | $this->nextLog = $this->getNextLogDataLine(); |
156 | 174 | } |
| 175 | + |
157 | 176 | //read each revision |
158 | 177 | while ( $reader->read()){ |
159 | 178 | if ( $reader->nodeType == XMLREADER::ELEMENT |
— | — | @@ -178,14 +197,36 @@ |
179 | 198 | } |
180 | 199 | |
181 | 200 | public function getNextLogDataLine(){ |
182 | | - $csvArray = null; |
183 | | - // a CSV array for writing, make sure $csvArray[1] = timestamp |
184 | | - return $csvArray; |
| 201 | + while($this->logreader->read()){ |
| 202 | + if ($this->logreader->nodeType == XMLREADER::ELEMENT |
| 203 | + && $this->logreader->localName == "logitem") { |
| 204 | + $logitem = new SimpleXMLElement($this->logreader->readOuterXml()); |
| 205 | + if(strcmp($logitem->logtitle, $this->articleName)==0){ |
| 206 | + return array( |
| 207 | + $logitem->id, |
| 208 | + strtotime($logitem->timestamp), |
| 209 | + $logitem->contributor->username, |
| 210 | + "", |
| 211 | + "", |
| 212 | + "", |
| 213 | + "", |
| 214 | + "", |
| 215 | + "", |
| 216 | + $logitem->action |
| 217 | + ); |
| 218 | + } |
| 219 | + } |
| 220 | + } |
185 | 221 | } |
186 | 222 | |
187 | 223 | |
188 | 224 | //foreach revision... |
189 | 225 | public function parseRev($xmlTEXT){ |
| 226 | + |
| 227 | + if(!$xmlTEXT){ |
| 228 | + return; |
| 229 | + } |
| 230 | + |
190 | 231 | $revision = new SimpleXMLElement($xmlTEXT); |
191 | 232 | $textSize = strlen($revision->text); |
192 | 233 | |
— | — | @@ -194,17 +235,6 @@ |
195 | 236 | |
196 | 237 | $revertIndex = array_search($md5, $this->md5History); |
197 | 238 | |
198 | | - if($revertIndex === FALSE ){ |
199 | | - $isNew = 'yes'; |
200 | | - $this->revTypes[] = new Edit(true); |
201 | | - } |
202 | | - else{ |
203 | | - $revert = new Revert(count($this->revTypes), $this->revTypes, true, $revertIndex); |
204 | | - $this->revTypes[] = $revert; |
205 | | - $revert->updateHistory(); |
206 | | - } |
207 | | - $this->md5History[] = $md5; |
208 | | - |
209 | 239 | $csvData = array( |
210 | 240 | $revision->id, |
211 | 241 | strtotime($revision->timestamp), |
— | — | @@ -216,7 +246,8 @@ |
217 | 247 | $isNew, |
218 | 248 | $textSize, |
219 | 249 | $textSize - $this->oldSize, |
220 | | - isset($revision->contributor->username)? "no":"yes" |
| 250 | + isset($revision->contributor->username)? "no":"yes", |
| 251 | + "" |
221 | 252 | ); |
222 | 253 | $this->oldSize = $textSize; |
223 | 254 | |
— | — | @@ -230,6 +261,18 @@ |
231 | 262 | } |
232 | 263 | } |
233 | 264 | fputcsv($this->outputFile, $csvData); |
| 265 | + |
| 266 | + if($revertIndex === FALSE ){ |
| 267 | + $isNew = 'yes'; |
| 268 | + $this->revTypes[] = new Edit(true); |
| 269 | + } |
| 270 | + else{ |
| 271 | + $revert = new Revert(count($this->revTypes), $this->revTypes, true, $revertIndex); |
| 272 | + $this->revTypes[] = $revert; |
| 273 | + $revert->updateHistory(); |
| 274 | + } |
| 275 | + $this->md5History[] = $md5; |
| 276 | + |
234 | 277 | } |
235 | 278 | |
236 | 279 | |