示例#1
0
 public function getSourceText()
 {
     if ($this->getDiffSource() == false) {
         $c = new Criteria();
         $c->add("source_id", $this->getSourceId());
         $source = DB_PageSourcePeer::instance()->selectOne($c);
         return $source->getText();
     } else {
         // select last revisions and sources.
         $q = "SELECT page_source.* FROM page_source, page_revision WHERE " . "page_revision.page_id =" . $this->getPageId() . " " . "AND page_revision.revision_id <= " . $this->getRevisionId() . " " . "AND (page_revision.flag_text = TRUE OR page_revision.flag_new = TRUE) " . "AND page_revision.source_id = page_source.source_id " . "ORDER BY page_revision.revision_id DESC " . "LIMIT " . ($this->getSinceFullSource() + 1);
         $c = new Criteria();
         $c->setExplicitQuery($q);
         $sources = DB_PageSourcePeer::instance()->select($c);
         // original source...
         $s = end($sources);
         $s0 = $s->getText();
         $differ = new ODiff();
         while ($s = prev($sources)) {
             $s0 = $differ->patchString($s0, $s->getText());
             if ($differ->getErrors() != null) {
                 return "Error processing the source - please report the problem to the support";
             }
         }
         return trim($s0);
     }
 }
示例#2
0
 public function revertEvent($runData)
 {
     $pl = $runData->getParameterList();
     $pageId = $pl->getParameterValue("pageId");
     $revisionId = $pl->getParameterValue("revisionId");
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("page_id", $pageId);
     $c->setForUpdate(true);
     $page = DB_PagePeer::instance()->selectOne($c);
     if ($page == null || $page->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("Error getting page information."), "no_page");
     }
     // check for permissions again
     $category = $page->getCategory();
     $user = $runData->getUser();
     WDPermissionManager::instance()->hasPagePermission('edit', $user, $category, $page);
     // get the revision
     $toRevision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId);
     $toMeta = DB_PageMetadataPeer::instance()->selectByPrimaryKey($toRevision->getMetadataId());
     $currentRevision = $page->getCurrentRevision();
     $currentMeta = $currentRevision->getMetadata();
     // compare title and source (ids and contents)
     if ($toMeta->getTitle() === $currentMeta->getTitle() && $toRevision->getSourceId() === $currentRevision->getSourceId()) {
         throw new ProcessException(_("The title and content source of the current revision and the destination revision are identical. No change has been applied."), "no_change");
     }
     // check for locks first
     DB_PageEditLockPeer::instance()->deleteOutdated($pageId);
     $c = new Criteria();
     $c->add("page_id", $page->getPageId());
     if ($pl->getParameterValue("force") === "yes") {
         DB_PageEditLockPeer::instance()->delete($c);
     }
     $locks = DB_PageEditLockPeer::instance()->select($c);
     if (count($locks) > 0) {
         $runData->ajaxResponseAdd("locks", true);
         $runData->contextAdd("locks", $locks);
         $runData->setModuleTemplate("history/RevertPageLockedWin");
         $db->rollback();
         return;
     }
     // success so far...
     $titleChanged = false;
     if ($toMeta->getTitle() !== $currentMeta->getTitle()) {
         // change the title, need to create a new metadata...
         $metadata = clone $currentMeta;
         $metadata->setMetadataId(null);
         $metadata->setNew(true);
         $metadata->setTitle($toMeta->getTitle());
         $metadata->save();
         $titleChanged = true;
     }
     $userId = $runData->getUserId();
     if ($userId == null) {
         $userString = $runData->createIpString();
     }
     if ($toRevision->getSourceId() !== $currentRevision->getSourceId()) {
         $sourceChanged = true;
         $nSource = $toRevision->getSourceText();
         $oSource = $currentRevision->getSourceText();
         if ($nSource === $oSource) {
             $sourceChanged = false;
         }
     }
     if (!$sourceChanged && !$titleChanged) {
         throw new ProcessException(_("The title and content source of the current revision and the destination revision are identical. No change has been applied."), "no_change");
     }
     $revision = clone $currentRevision;
     $revision->setNew(true);
     $revision->setRevisionId(null);
     $revision->resetFlags();
     if ($sourceChanged) {
         $revision->setFlagText(true);
     }
     if ($titleChanged) {
         $revision->setFlagTitle(true);
         $revision->setMetadataId($metadata->getMetadataId());
         $page->setTitle($toMeta->getTitle());
     }
     $revision->setComments(_("Reverted to page revision number") . " " . $toRevision->getRevisionNumber());
     if ($userId) {
         $revision->setUserId($userId);
         $page->setLastEditUserId($userId);
     } else {
         $revision->setUserId(0);
         $page->setLastEditUserId(0);
         $revision->setUserString($userString);
         $page->setLastEditUserString($userString);
     }
     if ($sourceChanged) {
         $fullSource = false;
         // first check if store new source as a diff or as a full-source.
         if (true || $currentRevision->getSinceFullSource() > 9) {
             $fullSource = true;
         } else {
             // also compare size of diff against size of new source.
             // must be less than %50 to qualify
             $differ = new ODiff();
             $diff = $differ->diffString($oSource, $nSource);
             if (strlen($diff) > 0.5 * strlen($nSource)) {
                 $fullSource = true;
             }
         }
         $pageSource = new DB_PageSource();
         if ($fullSource) {
             $pageSource->setText($nSource);
             $revision->setSinceFullSource(0);
             $revision->setDiffSource(false);
         } else {
             $pageSource->setText($diff);
             $revision->setDiffSource(true);
             $revision->setSinceFullSource($currentRevision->getSinceFullSource() + 1);
         }
         $pageSource->save();
         $revision->setSourceId($pageSource->getSourceId());
     } else {
         // copy source id i.e. do nothing
     }
     $revision->setRevisionNumber($revision->getRevisionNumber() + 1);
     $now = new ODate();
     $revision->setDateLastEdited($now);
     $revision->save();
     $page->setRevisionId($revision->getRevisionId());
     $page->setDateLastEdited($now);
     $page->setRevisionNumber($revision->getRevisionNumber());
     $page->save();
     // outdate party!
     $outdater = new Outdater();
     if ($sourceChanged) {
         $outdater->pageEvent("source_changed", $page);
     }
     if ($titleChanged) {
         $outdater->pageEvent("title_changed", $page);
     }
     // index page
     EventLogger::instance()->logSavePage($page);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
示例#3
0
 public function fixLinks()
 {
     // get the current source. for sure check the lock.
     // also note that $page should be selected with "FOR UPDATE" clause
     $oldSourceText = $this->page->getSource();
     $sourceChanged = false;
     $source = $oldSourceText;
     $source = preg_replace_callback('/(\\[\\[\\[)([^\\]\\|]+?)((\\s*\\|[^\\]]*?)?\\]\\]\\])/i', array(&$this, 'fixLink'), $source);
     $source = preg_replace_callback('/^\\[\\[include ([a-zA-Z0-9\\s\\-]+?)(?:\\]\\])$/im', array(&$this, 'fixInclusion'), $source);
     if ($source != $oldSourceText) {
         $page = $this->page;
         $currentRevision = $page->getCurrentRevision();
         //save it! wooohaaa! should we not clean the page source saving a bit?
         $revision = clone $currentRevision;
         $revision->setNew(true);
         $revision->setRevisionId(null);
         $revision->resetFlags();
         $revision->setFlagText(true);
         $revision->setPageId($page->getPageId());
         $revision->setRevisionNumber($currentRevision->getRevisionNumber() + 1);
         $now = new ODate();
         $revision->setDateLastEdited($now);
         $fullSource = false;
         // first check if store new source as a diff or as a full-source.
         if ($currentRevision->getSinceFullSource() > 9) {
             $fullSource = true;
         } else {
             // also compare size of diff against size of new source.
             // must be less than %50 to qualify
             $differ = new ODiff();
             $diff = $differ->diffString($oldSourceText, $source);
             if (strlen($diff) > 0.5 * strlen($source)) {
                 $fullSource = true;
             }
         }
         $pageSource = new DB_PageSource();
         if ($fullSource) {
             $pageSource->setText($source);
             $revision->setDiffSource(false);
             $revision->setSinceFullSource(0);
         } else {
             $pageSource->setText($diff);
             $revision->setDiffSource(true);
             $revision->setSinceFullSource($currentRevision->getSinceFullSource() + 1);
         }
         $pageSource->save();
         $revision->setSourceId($pageSource->getSourceId());
         $revision->setComments(sprintf(_('Automatic update related to page rename: "%s" to "%s".'), $this->oldPageName, $this->newPageName));
         $userId = $this->user->getUserId();
         if ($userId) {
             $revision->setUserId($userId);
             $page->setLastEditUserId($userId);
         }
         $revision->save();
         $page->setRevisionId($revision->getRevisionId());
         $page->setDateLastEdited($now);
         $page->setRevisionNumber($revision->getRevisionNumber());
         $page->save();
         // force page compilation
     }
 }