r77835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77834‎ | r77835 | r77836 >
Date:22:36, 5 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Some more clean-up
Modified paths:
  • /trunk/extensions/DSMW/DSMW.hooks.php (modified) (history)
  • /trunk/extensions/DSMW/DSMW.php (modified) (history)
  • /trunk/extensions/DSMW/includes/DSMW_RevisionManager.php (added) (history)
  • /trunk/extensions/DSMW/includes/IntegrationFunctions.php (modified) (history)
  • /trunk/extensions/DSMW/jobs/DSMWUpdateJob.php (modified) (history)
  • /trunk/extensions/DSMW/logootModel/boModel.php (deleted) (history)
  • /trunk/extensions/DSMW/logootModel/dao.php (deleted) (history)
  • /trunk/extensions/DSMW/logootModel/manager.php (deleted) (history)
  • /trunk/extensions/DSMW/specialPage/DSMWAdmin.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DSMW/DSMW.hooks.php
@@ -372,6 +372,7 @@
373373 $title = Title::newFromText( 'Special:ArticleAdminPage' );
374374 $article = new Article( $title );
375375 $article->doRedirect();
 376+
376377 return false;
377378 }
378379
@@ -381,12 +382,17 @@
382383 // wfDebugLog('p2p','Create pull '.$_POST['pullname'].' with pushName '.$_POST['pushname'].' on '.$_POST['url']);
383384 // $url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one
384385 $urlTmp = $_POST['url'];
385 - if ( utils::isValidURL( $urlTmp ) == false )
386 - throw new MWException( __METHOD__ . ': ' . $urlTmp . ' seems not to be an url' ); // throws an exception if $url is invalid
387 -
388 - $res = utils::parsePushURL( $urlTmp );
389 - if ( $res === false || empty( $res ) )
390 - throw new MWException( __METHOD__ . ': URL format problem' );
 386+ if ( utils::isValidURL( $urlTmp ) == false ) {
 387+ // throws an exception if $url is invalid
 388+ throw new MWException( __METHOD__ . ': ' . $urlTmp . ' seems not to be an url' );
 389+ }
 390+
 391+ $res = utils::parsePushURL( $urlTmp );
 392+
 393+ if ( $res === false || empty( $res ) ) {
 394+ throw new MWException( __METHOD__ . ': URL format problem' );
 395+ }
 396+
391397 $pushname = $res[0];
392398 $url = $res[1];
393399
@@ -489,12 +495,15 @@
490496 if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) {
491497 $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' );
492498 }
 499+
493500 if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) {
494501 $cs = false;
495502 }
496503
497 - if ( $cs === false )
498 - throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' );
 504+ if ( $cs === false ) {
 505+ throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' );
 506+ }
 507+
499508 $cs = trim( $cs );
500509 $dom = new DOMDocument();
501510 $dom->loadXML( $cs );
@@ -627,7 +636,7 @@
628637 return true;
629638 }
630639
631 - $model = manager::loadModel( $rev_id );
 640+ $model = DSMWRevisionManager::loadModel( $rev_id );
632641 $logoot = new logootEngine( $model );
633642
634643 // get the revision with the edittime==>V0
@@ -641,10 +650,7 @@
642651 }
643652
644653 if ( $conctext != $text ) {// if last revision is not V0, there is editing conflict
645 - // wfDebugLog('testlog',' -> CONCURRENCE: ');
646 - // wfDebugLog('testlog',' -> +'.$conctext.'+('.$rev_id.') ts '.$lastRevision->getTimestamp());
647 - // wfDebugLog('testlog',' -> +'.$text.'+('.$rev_id1.') ts '.$editpage->edittime.' '.$rev->getTimestamp());
648 - $model1 = manager::loadModel( $rev_id1 );
 654+ $model1 = DSMWRevisionManager::loadModel( $rev_id1 );
649655 $logoot1 = new logootEngine( $model1 );
650656 $listOp1 = $logoot1->generate( $text, $actualtext );
651657 // creation Patch P2
@@ -675,7 +681,7 @@
676682
677683 $revId = utils::getNewArticleRevId();
678684 wfDebugLog( 'p2p', ' -> store model rev : ' . $revId . ' session ' . session_id() . ' model ' . $modelAfterIntegrate->getText() );
679 - manager::storeModel( $revId + 1, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
 685+ DSMWRevisionManager::storeModel( $revId + 1, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
680686
681687 $patch->storePage( $title, $revId + 1 ); // stores the patch in a wikipage
682688 $editpage->textbox1 = $modelAfterIntegrate->getText();
@@ -713,10 +719,10 @@
714720 }
715721
716722 $revID = $lastRevision->getId();
717 - $model = manager::loadModel( $rev_id );
 723+ $model = DSMWRevisionManager::loadModel( $rev_id );
718724 $patch = new Patch( false, true, null, $urlServer, $rev_id, null, null, null, $localfile->mime, $localfile->size, urldecode( $localfile->url ), null );
719725 $patch->storePage( $localfile->getTitle(), $revID ); // stores the patch in a wikipage
720 - manager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 );
 726+ DSMWRevisionManager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 );
721727 }
722728
723729 return true;
Index: trunk/extensions/DSMW/logootModel/manager.php
@@ -1,53 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Used to seperated the data access layer
6 - *
7 - * @copyright INRIA-LORIA-ECOO project
8 - *
9 - * @author CUCUTEANU
10 - */
11 -class manager {
12 -
13 - /**
14 - *
15 - * @param <String> $rev_id Revision id
16 - * @return boModel
17 - */
18 - static function loadModel( $rev_id ) {
19 - try {
20 - if ( $rev_id != 0 ) {
21 - $dao = new dao();
22 - return $dao->loadModel( $rev_id );
23 - }
24 - else {
25 - return new boModel();
26 - }
27 - } catch ( Exception $e ) {
28 - die($e->getMessage());
29 - throw new MWException( __METHOD__ . ' db access problems,
30 -if this page existed before the DSMW installation,
31 -maybe it has not been processed by DSMW' );
32 - }
33 -
34 - }
35 -
36 - /**
37 - *
38 - * @param <String> $rev_id
39 - * @param <String> $sessionId
40 - * @param <Object> $model boModel
41 - * @param <Object> $blobCB=0 (should have been a causal barrier object but
42 - * not used yet)
43 - */
44 - static function storeModel( $rev_id, $sessionId, $model, $blobCB ) {
45 - wfDebugLog( 'p2p', ' -> store model into revid : ' . $rev_id . ' sessionid : ' . $sessionId . ' model : ' . $model->getText() );
46 - try {
47 - $dao = new dao();
48 - $dao->storeModel( $rev_id, $sessionId, $model, $blobCB );
49 - } catch ( Exception $e ) {
50 - throw new MWException( __METHOD__ . ' db access problems' );
51 - }
52 - }
53 -
54 -}
Index: trunk/extensions/DSMW/logootModel/boModel.php
@@ -1,48 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Model of a wiki page.
6 - * Represented by a list of page's lines and a list of the logootPositions
7 - * associated to each line
8 - *
9 - * @copyright INRIA-LORIA-ECOO project
10 - * @author Muller Jean-Philippe
11 - */
12 -class boModel {
13 - private $positionList = array();
14 - private $lineList = array();
15 -
16 - public function setPositionlist( $positionList ) {
17 - $this->positionList = $positionList;
18 - }
19 -
20 - public function setLinelist( $lineList ) {
21 - $this->lineList = $lineList;
22 - }
23 -
24 - public function getPositionlist() {
25 - return $this->positionList;
26 - }
27 -
28 - public function getLinelist() {
29 - return $this->lineList;
30 - }
31 -
32 - /**
33 - * transforms the text array into a string
34 - * @return <String>
35 - */
36 - public function getText() {
37 - $textImage = "";
38 - $tmp = $this->lineList;
39 - $nb = 0;
40 -
41 - $nb = sizeof( $tmp );
42 - for ( $i = 1; $i <= $nb; $i++ ) {
43 -
44 - if ( $i == 1 ) $textImage = $tmp[$i];
45 - else $textImage = $textImage . "\n" . $tmp[$i];
46 - }
47 - return $textImage;
48 - }
49 -}
Index: trunk/extensions/DSMW/logootModel/dao.php
@@ -1,54 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * DAO used to load and store the boModel
6 - *
7 - * @copyright INRIA-LORIA-ECOO project
8 - * @author Jean-Philippe Muller
9 - */
10 -class dao {
11 -
12 - /**
13 - * To get the model of the given revision
14 - * --> A model is the logootPosition array corresponding to this revision
15 - * @param <Integer> $rev_id
16 - * @return <Object> model object
17 - */
18 - function loadModel( $rev_id ) {
19 - wfProfileIn( __METHOD__ );
20 - $dbr = wfGetDB( DB_SLAVE );
21 - $model1 = $dbr->selectField( 'model', 'blob_info', array(
22 - 'rev_id' => $rev_id ), __METHOD__ );
23 - if ( $model1 === false )
24 - throw new MWException( __METHOD__ . ': This page has not been processed by DSMW' );
25 - wfProfileOut( __METHOD__ );
26 - $model = unserialize( $model1 );
27 - return $model;
28 - }
29 -
30 -/**
31 - * integrate model to DB
32 - * @param <Integer> $rev_id
33 - * @param <String> $sessionId
34 - * @param <object> $model
35 - * @param <Object> $blobCB (should have been a causal barrier object but
36 - * not used yet)
37 - */
38 - function storeModel( $rev_id, $sessionId, $model, $blobCB ) {
39 -
40 - $model1 = serialize( $model );
41 -
42 - wfProfileIn( __METHOD__ );
43 - $dbw = wfGetDB( DB_MASTER );
44 - $dbw->insert( 'model', array(
45 - 'rev_id' => $rev_id,
46 - 'session_id' => $sessionId,
47 - 'blob_info' => $model1,
48 - 'causal_barrier' => $blobCB,
49 - ), __METHOD__ );
50 -
51 -
52 - wfProfileOut( __METHOD__ );
53 - }
54 -
55 -}
Index: trunk/extensions/DSMW/jobs/DSMWUpdateJob.php
@@ -83,7 +83,7 @@
8484 $pageText = $lastRev->getText();
8585
8686 // load an empty model
87 - $model = manager::loadModel( 0 );
 87+ $model = DSMWRevisionManager::loadModel( 0 );
8888 $logoot = new logootEngine( $model );
8989
9090 $listOp = $logoot->generate( "", $pageText );
@@ -111,7 +111,7 @@
112112 $patch->storePage( $lastRev->getTitle()->getText(), $lastRev->getId() );
113113 }
114114
115 - manager::storeModel( $lastRev->getId(), $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
 115+ DSMWRevisionManager::storeModel( $lastRev->getId(), $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
116116 }
117117 }
118118
Index: trunk/extensions/DSMW/DSMW.php
@@ -72,9 +72,7 @@
7373
7474 $wgAutoloadClasses['LogootIns'] = "$wgDSMWIP/logootComponent/LogootIns.php";
7575 $wgAutoloadClasses['LogootDel'] = "$wgDSMWIP/logootComponent/LogootDel.php";
76 -$wgAutoloadClasses['boModel'] = "$wgDSMWIP/logootModel/boModel.php";
77 -$wgAutoloadClasses['dao'] = "$wgDSMWIP/logootModel/dao.php";
78 -$wgAutoloadClasses['manager'] = "$wgDSMWIP/logootModel/manager.php";
 76+$wgAutoloadClasses['DSMWRevisionManager'] = dirname( __FILE__ ) . '/includes/DSMW_RevisionManager.php';
7977
8078 $wgAutoloadClasses['Patch'] = "$wgDSMWIP/patch/Patch.php";
8179 $wgAutoloadClasses['persistentClock'] = "$wgDSMWIP/clockEngine/persistentClock.php";
Index: trunk/extensions/DSMW/includes/IntegrationFunctions.php
@@ -257,7 +257,7 @@
258258 }
259259 $listOp = array();
260260 // $blobInfo = BlobInfo::loadBlobInfo($rev_id);
261 - $model = manager::loadModel( $rev_id );
 261+ $model = DSMWRevisionManager::loadModel( $rev_id );
262262 if ( ( $model instanceof boModel ) == false )
263263 throw new MWException( __METHOD__ . ': model loading problem!' );
264264 $logoot = new logootEngine( $model );
@@ -282,7 +282,7 @@
283283 // $revId = utils::getNewArticleRevId();
284284 $status = $article->doEdit( $modelAfterIntegrate->getText(), $summary = "" );
285285 $revId = $status->value['revision']->getId();
286 - manager::storeModel( $revId, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
 286+ DSMWRevisionManager::storeModel( $revId, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 );
287287 return $revId;
288288 // sleep(4);
289289 if ( is_bool( $status ) ) return $status;
@@ -299,15 +299,18 @@
300300 $dbr->immediateBegin();
301301 $title = Title::newFromText( $article );
302302 $lastRevision = Revision::loadFromTitle( $dbr, $title );
 303+
303304 if ( $lastRevision->getPrevious() == null ) {
304305 $rev_id = 0;
305306 }
306307 else {
307308 $rev_id = $lastRevision->getPrevious()->getId();
308309 }
 310+
309311 $revID = $lastRevision->getId();
310 - $model = manager::loadModel( $rev_id );
311 - manager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 );
 312+ $model = DSMWRevisionManager::loadModel( $rev_id );
 313+ DSMWRevisionManager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 );
 314+
312315 if ( $edit ) {
313316 $article = new Article( $title );
314317 $status = $article->doEdit( $model->getText(), $summary = "" );
@@ -326,11 +329,13 @@
327330 $dom = new DOMDocument();
328331 $dom->loadXML( $edittoken );
329332 $edittoken = $dom->getElementsByTagName( 'page' );
 333+
330334 foreach ( $edittoken as $p ) {
331335 if ( $p->hasAttribute( "edittoken" ) ) {
332336 $token = $p->getAttribute( 'edittoken' );
333337 }
334338 }
 339+
335340 $token = str_replace( "+", "%2B", $token );
336341
337342 // $url = $patch->getUrl();
@@ -347,6 +352,7 @@
348353
349354 function newRev( $article ) {
350355 global $wgCanonicalNamespaceNames;
 356+
351357 $indexNS = 0;
352358 $dbr = wfGetDB( DB_SLAVE );
353359
@@ -354,13 +360,16 @@
355361 preg_match( "/^(.+?)_*:_*(.*)$/S", $article, $tmp );
356362 $articleWithoutNS = $tmp[2];
357363 $NS = $tmp[1];
 364+
358365 if ( in_array( $NS, $wgCanonicalNamespaceNames ) ) {
359366 foreach ( $wgCanonicalNamespaceNames as $key => $value ) {
360367 if ( $NS == $value )
361368 $indexNS = $key;
362369 }
363370 }
 371+
364372 $title = Title::newFromText( $article );
 373+
365374 if ( !$title->exists() ) {
366375 $article = new Article( $title );
367376 $article->doEdit( '', '' );
@@ -368,7 +377,7 @@
369378 $lastRevision = Revision::loadFromTitle( $dbr, $title );
370379 $rev_id = $lastRevision->getPrevious()->getId();
371380 $revID = $lastRevision->getId();
372 - $model = manager::loadModel( $rev_id );
 381+ $model = DSMWRevisionManager::loadModel( $rev_id );
373382 $article = new Article( $title );
374383 $article->quickEdit( $model->getText(), '' );
375384 }
Index: trunk/extensions/DSMW/includes/DSMW_RevisionManager.php
@@ -0,0 +1,161 @@
 2+<?php
 3+
 4+/**
 5+ * Used to seperated the data access layer
 6+ *
 7+ * @copyright INRIA-LORIA-ECOO project
 8+ *
 9+ * @author CUCUTEANU
 10+ */
 11+class DSMWRevisionManager {
 12+
 13+ /**
 14+ *
 15+ * @param <String> $rev_id Revision id
 16+ * @return boModel
 17+ */
 18+ static function loadModel( $rev_id ) {
 19+ try {
 20+ if ( $rev_id != 0 ) {
 21+ $dao = new dao();
 22+ return $dao->loadModel( $rev_id );
 23+ }
 24+ else {
 25+ return new boModel();
 26+ }
 27+ } catch ( Exception $e ) {
 28+ die($e->getMessage());
 29+ throw new MWException( __METHOD__ . ' db access problems,
 30+if this page existed before the DSMW installation,
 31+maybe it has not been processed by DSMW' );
 32+ }
 33+
 34+ }
 35+
 36+ /**
 37+ *
 38+ * @param <String> $rev_id
 39+ * @param <String> $sessionId
 40+ * @param <Object> $model boModel
 41+ * @param <Object> $blobCB=0 (should have been a causal barrier object but
 42+ * not used yet)
 43+ */
 44+ static function storeModel( $rev_id, $sessionId, $model, $blobCB ) {
 45+ wfDebugLog( 'p2p', ' -> store model into revid : ' . $rev_id . ' sessionid : ' . $sessionId . ' model : ' . $model->getText() );
 46+ try {
 47+ $dao = new dao();
 48+ $dao->storeModel( $rev_id, $sessionId, $model, $blobCB );
 49+ } catch ( Exception $e ) {
 50+ die($e->getMessage());
 51+ throw new MWException( __METHOD__ . ' db access problems' );
 52+ }
 53+ }
 54+
 55+}
 56+
 57+/**
 58+ * DAO used to load and store the boModel
 59+ *
 60+ * @copyright INRIA-LORIA-ECOO project
 61+ *
 62+ * @author Jean-Philippe Muller
 63+ */
 64+class dao {
 65+
 66+ /**
 67+ * To get the model of the given revision
 68+ * --> A model is the logootPosition array corresponding to this revision
 69+ * @param <Integer> $rev_id
 70+ * @return <Object> model object
 71+ */
 72+ function loadModel( $rev_id ) {
 73+ wfProfileIn( __METHOD__ );
 74+
 75+ $dbr = wfGetDB( DB_SLAVE );
 76+
 77+ $model1 = $dbr->selectField(
 78+ 'model',
 79+ 'blob_info',
 80+ array(
 81+ 'rev_id' => $rev_id
 82+ ),
 83+ __METHOD__
 84+ );
 85+
 86+ if ( $model1 === false ) {
 87+ throw new MWException( __METHOD__ . ': This page has not been processed by DSMW' );
 88+ }
 89+
 90+ $model = unserialize( $model1 );
 91+
 92+ wfProfileOut( __METHOD__ );
 93+
 94+ return $model;
 95+ }
 96+
 97+ /**
 98+ * integrate model to DB
 99+ * @param <Integer> $rev_id
 100+ * @param <String> $sessionId
 101+ * @param <object> $model
 102+ * @param <Object> $blobCB (should have been a causal barrier object but
 103+ * not used yet)
 104+ */
 105+ function storeModel( $rev_id, $sessionId, $model, $blobCB ) {
 106+ wfProfileIn( __METHOD__ );
 107+
 108+ $model1 = serialize( $model );
 109+
 110+ $dbw = wfGetDB( DB_MASTER );
 111+ $dbw->insert( 'model', array(
 112+ 'rev_id' => $rev_id,
 113+ 'session_id' => $sessionId,
 114+ 'blob_info' => $model1,
 115+ 'causal_barrier' => $blobCB,
 116+ ), __METHOD__ );
 117+
 118+
 119+ wfProfileOut( __METHOD__ );
 120+ }
 121+
 122+}
 123+
 124+/**
 125+ * Model of a wiki page.
 126+ * Represented by a list of page's lines and a list of the logootPositions
 127+ * associated to each line
 128+ *
 129+ * @copyright INRIA-LORIA-ECOO project
 130+ * @author Muller Jean-Philippe
 131+ */
 132+class boModel {
 133+
 134+ private $positionList = array();
 135+ private $lineList = array();
 136+
 137+ public function setPositionlist( $positionList ) {
 138+ $this->positionList = $positionList;
 139+ }
 140+
 141+ public function setLinelist( $lineList ) {
 142+ $this->lineList = $lineList;
 143+ }
 144+
 145+ public function getPositionlist() {
 146+ return $this->positionList;
 147+ }
 148+
 149+ public function getLinelist() {
 150+ return $this->lineList;
 151+ }
 152+
 153+ /**
 154+ * Transforms the text array into a string.
 155+ *
 156+ * @return string
 157+ */
 158+ public function getText() {
 159+ return implode( "\n", $this->lineList );
 160+ }
 161+
 162+}
Property changes on: trunk/extensions/DSMW/includes/DSMW_RevisionManager.php
___________________________________________________________________
Added: svn:eol-style
1163 + native
Index: trunk/extensions/DSMW/specialPage/DSMWAdmin.php
@@ -39,12 +39,14 @@
4040 /**** Get status of refresh job, if any ****/
4141 $dbr =& wfGetDB( DB_SLAVE );
4242 $row = $dbr->selectRow( 'job', '*', array( 'job_cmd' => 'DSMWUpdateJob' ), __METHOD__ );
 43+
4344 if ( $row !== false ) { // similar to Job::pop_type, but without deleting the job
4445 $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
4546 $updatejob = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id );
4647 } else {
4748 $updatejob = NULL;
4849 }
 50+
4951 $row1 = $dbr->selectRow( 'job', '*', array( 'job_cmd' => 'DSMWPropertyTypeJob' ), __METHOD__ );
5052 if ( $row1 !== false ) { // similar to Job::pop_type, but without deleting the job
5153 $title = Title::makeTitleSafe( $row1->job_namespace, $row1->job_title );
@@ -57,8 +59,6 @@
5860 $action = $wgRequest->getText( 'action' );
5961
6062 if ( $action == 'logootize' ) {
61 -
62 -
6363 if ( $updatejob === NULL ) { // careful, there might be race conditions here
6464 $title = Title::makeTitle( NS_SPECIAL, 'DSMWAdmin' );
6565 $newjob = new DSMWUpdateJob( $title );
@@ -67,7 +67,6 @@
6868 } else {
6969 $wgOut->addHTML( '<p><font color="red"><b>' . wfMsg( 'dsmw-special-admin-articleuprunning' ) . '</b></font></p>' );
7070 }
71 -
7271 }
7372
7473 elseif ( $action == 'addProperties' ) {

Status & tagging log