r70034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70033‎ | r70034 | r70035 >
Date:20:11, 27 July 2010
Author:dfinzer
Status:deferred
Tags:
Comment:
Added column with page log data
Modified paths:
  • /trunk/tools/analysis/StreamingXMLHistory.php (modified) (history)

Diff [purge]

Index: trunk/tools/analysis/StreamingXMLHistory.php
@@ -77,7 +77,11 @@
7878 public $pagelog;
7979 public $pagelogFile;
8080 public $nextLog;
 81+ public $articleName;
8182
 83+ //page log reader
 84+ public $logreader;
 85+
8286 //md5 hashes of the revision texts
8387 public $md5History;
8488
@@ -95,7 +99,8 @@
96100 $this->revTypes = array();
97101 $this->pagelog = $pagelog;
98102 if($pagelog){
99 - $this->pagelogFile = fopen($this->pagelog, "r");
 103+ $this->logreader = new XMLReader();
 104+ $this->logreader->open($this->pagelog);
100105 }
101106 $this->oldSize = 0;
102107 }
@@ -140,7 +145,8 @@
141146 "new?",
142147 "edit size",
143148 "net size change",
144 - "anonymous?"
 149+ "anonymous?",
 150+ "log action"
145151 );
146152 fputcsv($this->outputFile, $csvData);
147153 }
@@ -150,9 +156,22 @@
151157 $reader->open($this->inputFileName);
152158 $this->writeCSVHeader();
153159 $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
154172 if($this->pagelog){
155173 $this->nextLog = $this->getNextLogDataLine();
156174 }
 175+
157176 //read each revision
158177 while ( $reader->read()){
159178 if ( $reader->nodeType == XMLREADER::ELEMENT
@@ -178,14 +197,36 @@
179198 }
180199
181200 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+ }
185221 }
186222
187223
188224 //foreach revision...
189225 public function parseRev($xmlTEXT){
 226+
 227+ if(!$xmlTEXT){
 228+ return;
 229+ }
 230+
190231 $revision = new SimpleXMLElement($xmlTEXT);
191232 $textSize = strlen($revision->text);
192233
@@ -194,17 +235,6 @@
195236
196237 $revertIndex = array_search($md5, $this->md5History);
197238
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 -
209239 $csvData = array(
210240 $revision->id,
211241 strtotime($revision->timestamp),
@@ -216,7 +246,8 @@
217247 $isNew,
218248 $textSize,
219249 $textSize - $this->oldSize,
220 - isset($revision->contributor->username)? "no":"yes"
 250+ isset($revision->contributor->username)? "no":"yes",
 251+ ""
221252 );
222253 $this->oldSize = $textSize;
223254
@@ -230,6 +261,18 @@
231262 }
232263 }
233264 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+
234277 }
235278
236279

Status & tagging log