Exemple #1
0
 public function calculate($user)
 {
     $c = new Criteria();
     $c->add('user_id', $user->getUserId());
     $count = DB_PageRevisionPeer::instance()->selectCount($c);
     return $count;
 }
Exemple #2
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $c = new Criteria();
     $c->addJoin("page_id", "page.page_id");
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->add("page.site_id", $site->getSiteId());
     $c->addOrderDescending("page_revision.revision_id");
     $c->setLimit(30);
     $revisions = DB_PageRevisionPeer::instance()->select($c);
     $channel['title'] = _('Recent page changes from site') . ' "' . htmlspecialchars($site->getName()) . '" (a Wikidot site)';
     $channel['link'] = "http://" . $site->getDomain();
     $items = array();
     foreach ($revisions as $rev) {
         $page = $rev->getPage();
         $item = array();
         $item['link'] = 'http://' . $site->getDomain() . '/' . $page->getUnixName();
         $desc = '';
         $flags = array();
         if ($rev->getFlagText()) {
             $flags[] = _("source change");
         }
         if ($rev->getFlagTitle()) {
             $flags[] = _("title change");
         }
         if ($rev->getFlagFile()) {
             $flags[] = _("file action");
         }
         if ($rev->getFlagRename()) {
             $flags[] = _("page move/rename");
         }
         if ($rev->getFlagMeta()) {
             $flags[] = _("metadata changed");
         }
         if ($rev->getFlagNew()) {
             $flags[] = _("new page");
         }
         $item['title'] = '"' . $page->getTitleOrUnixName() . '" - ' . implode(', ', $flags);
         $desc = '';
         $desc .= _('Page') . ': <a href="http://' . $site->getDomain() . '/' . $page->getUnixName() . '">' . htmlspecialchars($page->getTitle()) . '</a> (' . $page->getUnixName() . ')<br/>';
         $desc .= _('Current revision number') . ': ' . $rev->getRevisionNumber() . '<br/>';
         $desc .= _('Date changed') . ': ' . date('r', $rev->getDateLastEdited()->getTimestamp()) . '<br/>';
         $desc .= _('Change type') . ': ' . implode(', ', $flags) . '<br/>';
         if ($rev->getComments()) {
             $desc .= _('Change comments') . ': ' . htmlspecialchars($rev->getComments()) . '<br/>';
         }
         $desc .= _('By') . ': ' . WDRenderUtils::renderUser($rev->getUserOrString()) . '<br/>';
         $desc .= '<br/>' . _('Page content preview') . ': <br/>' . $page->getPreview();
         $item['description'] = $desc;
         $item['content'] = $desc;
         $item['guid'] = $item['link'] . "#revision-" . $rev->getRevisionId();
         $item['date'] = date('r', $rev->getDateLastEdited()->getTimestamp());
         $content = '';
         $items[] = $item;
     }
     $runData->contextAdd("channel", $channel);
     $runData->contextAdd("items", $items);
 }
Exemple #3
0
 public function build($runData)
 {
     $revisionId = $runData->getParameterList()->getParameterValue("revision_id");
     $revision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId);
     if ($revision == null) {
         throw new ProcessException(_("Revision error"), "revision_error");
     }
     $source = $revision->getSourceText();
     $runData->contextAdd("source", $source);
     $runData->contextAdd("revisionNo", $revision->getRevisionNumber());
 }
Exemple #4
0
 public function build($runData)
 {
     $pageId = $runData->getParameterList()->getParameterValue("page_id");
     if (!$pageId || !is_numeric($pageId)) {
         throw new ProcessException(_("The page can not be found or does not exist."), "no_page");
     }
     $c = new Criteria();
     $c->add('page_id', $pageId);
     $c->addOrderDescending('revision_id');
     $pageRevisions = DB_PageRevisionPeer::instance()->select($c);
     $runData->contextAdd("pageRevisions", $pageRevisions);
 }
Exemple #5
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $fromRevisionId = $pl->getParameterValue("from_revision_id");
     $toRevisionId = $pl->getParameterValue("to_revision_id");
     if ($fromRevisionId == $toRevisionId) {
         throw new ProcessException(_("What is the point in comparing the revision with itself? Please choose different revisions of the page."), "same_revision");
     }
     $fromRevision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($fromRevisionId);
     $toRevision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($toRevisionId);
     if ($fromRevision == null || $toRevision == null) {
         throw new ProcessException(_("Error selecting revisions to compare"), "no_revisions");
     }
     $fromMetadata = $fromRevision->getMetadata();
     $toMetadata = $toRevision->getMetadata();
     $changed = array();
     // compare titles and other things
     if ($fromMetadata->getTitle() !== $toMetadata->getTitle()) {
         $changed['title'] = true;
     }
     if ($fromMetadata->getUnixName() !== $toMetadata->getUnixName()) {
         $changed['unix_name'] = true;
     }
     if ($fromMetadata->getParentPageId() !== $toMetadata->getParentPageId()) {
         $changed['parent'] = true;
         if ($fromMetadata->getParentPageId()) {
             $fromParent = DB_PagePeer::instance()->selectByPrimaryKey($fromMetadata->getParentPageId())->getUnixName();
             $runData->contextAdd("fromParent", $fromParent);
         }
         if ($toMetadata->getParentPageId()) {
             $toParent = DB_PagePeer::instance()->selectByPrimaryKey($toMetadata->getParentPageId())->getUnixName();
             $runData->contextAdd("toParent", $toParent);
         }
     }
     //compare source now
     $fromPageSource = $fromRevision->getSourceText();
     $toPageSource = $toRevision->getSourceText();
     if ($fromPageSource !== $toPageSource) {
         $changed['source'] = true;
         // create page diff... wooo...
         $t1 = $fromPageSource;
         $t2 = $toPageSource;
         $inlineDiff = Wikidot_Util_Diff::generateInlineStringDiff($t1, $t2);
         $runData->contextAdd("inlineDiff", $inlineDiff);
     }
     $runData->contextAdd("fromPageSource", $fromPageSource);
     $runData->contextAdd("toPageSource", $toPageSource);
     $runData->contextAdd("fromRevision", $fromRevision);
     $runData->contextAdd("toRevision", $toRevision);
     $runData->contextAdd("fromMetadata", $fromMetadata);
     $runData->contextAdd("toMetadata", $toMetadata);
     $runData->contextAdd("changed", $changed);
 }
Exemple #6
0
 public function build($runData)
 {
     $revisionId = $runData->getParameterList()->getParameterValue("revision_id");
     $revision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId);
     if ($revision == null) {
         throw new ProcessException(_("Revision error"), "revision_error");
     }
     $metadata = $revision->getMetadata();
     $source = $revision->getSourceText();
     $tr = new WikiTransformation();
     $content = $tr->processSource($source);
     $runData->contextAdd("pageContent", $content);
     $runData->contextAdd("revision", $revision);
     $runData->contextAdd("metadata", $metadata);
     $runData->ajaxResponseAdd("title", $metadata->getTitle());
 }
 public function build($runData)
 {
     $user = $runData->getUser();
     $pl = $runData->getParameterList();
     $pageNumber = $pl->getParameterValue("page");
     if ($pageNumber === null) {
         $pageNumber = 1;
     }
     $limit = $pl->getParameterValue("limit");
     if ($limit == null || !is_numeric($limit)) {
         $limit = 20;
     }
     $perPage = $limit;
     $offset = ($pageNumber - 1) * $perPage;
     $count = $perPage * 2 + 1;
     // join the tables:
     // watched_page, page_revision, user, page, site. ???
     $c = new Criteria();
     $c->addJoin("page_id", "page.page_id");
     $c->addJoin("page_id", "watched_page.page_id");
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->add("watched_page.user_id", $user->getUserId());
     $c->addOrderDescending("page_revision.revision_id");
     $c->setLimit($count, $offset);
     $revisions = DB_PageRevisionPeer::instance()->select($c);
     $counted = count($revisions);
     $pagerData = array();
     $pagerData['currentPage'] = $pageNumber;
     if ($counted > $perPage * 2) {
         $knownPages = $pageNumber + 2;
         $pagerData['knownPages'] = $knownPages;
     } elseif ($counted > $perPage) {
         $knownPages = $pageNumber + 1;
         $pagerData['totalPages'] = $knownPages;
     } else {
         $totalPages = $pageNumber;
         $pagerData['totalPages'] = $totalPages;
     }
     $revisions = array_slice($revisions, 0, $perPage);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("revisions", $revisions);
 }
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $toPageSource = $pl->getParameterValue("source");
     $mode = $pl->getParameterValue("mode");
     $revisionId = $pl->getParameterValue("revision_id");
     $revision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId);
     $fromPageSource = $revision->getSourceText();
     if ($mode == "section") {
         // compare only a fragment...
         $rangeStart = $pl->getParameterValue("range_start");
         $rangeEnd = $pl->getParameterValue("range_end");
         $s2 = explode("\n", $fromPageSource);
         $fromPageSource = implode("\n", array_slice($s2, $rangeStart, $rangeEnd - $rangeStart + 1));
     }
     // create page diff... wooo...
     $t1 = $fromPageSource;
     $t2 = $toPageSource;
     $inlineDiff = Wikidot_Util_Diff::generateInlineStringDiff($t1, $t2);
     $runData->contextAdd("diff", $inlineDiff);
 }
 public function build($runData)
 {
     $user = $runData->getTemp("user");
     $userId = $user->getUserId();
     // set language for the user
     $lang = $user->getLanguage();
     $runData->setLanguage($lang);
     $GLOBALS['lang'] = $lang;
     // and for gettext too:
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     // now just get watched page changes for the user...
     $c = new Criteria();
     $c->addJoin("page_id", "page.page_id");
     $c->addJoin("page_id", "watched_page.page_id");
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->add("watched_page.user_id", $user->getUserId());
     $c->addOrderDescending("page_revision.revision_id");
     $c->setLimit(30);
     $revisions = DB_PageRevisionPeer::instance()->select($c);
     $channel['title'] = _('Wikidot.com watched pages changes for user') . ' "' . $user->getNickName() . '"';
     $channel['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/watched-changes";
     $items = array();
     foreach ($revisions as $rev) {
         $page = $rev->getPage();
         $site = $page->getSite();
         $item = array();
         $item['title'] = '"' . $page->getTitleOrUnixName() . '" ' . _('on site') . ' "' . $site->getName() . '"';
         $item['link'] = 'http://' . $site->getDomain() . '/' . $page->getUnixName();
         $desc = '';
         $flags = array();
         if ($rev->getFlagText()) {
             $flags[] = _("source change");
         }
         if ($rev->getFlagTitle()) {
             $flags[] = _("title change");
         }
         if ($rev->getFlagFile()) {
             $flags[] = _("file action");
         }
         if ($rev->getFlagRename()) {
             $flags[] = _("page move/rename");
         }
         if ($rev->getFlagMeta()) {
             $flags[] = _("metadata changed");
         }
         if ($rev->getFlagNew()) {
             $flags[] = _("new page");
         }
         $desc .= _('Site') . ': <a href="http://' . $site->getDomain() . '">' . htmlspecialchars($site->getName()) . '</a><br/>';
         $desc .= _('Page') . ': <a href="http://' . $site->getDomain() . '/' . $page->getUnixName() . '">' . htmlspecialchars($page->getTitle()) . '</a> (' . $page->getUnixName() . ')<br/>';
         $desc .= _('Current revision number') . ': ' . $rev->getRevisionNumber() . '<br/>';
         $desc .= _('Date changed') . ': ' . date('r', $rev->getDateLastEdited()->getTimestamp()) . '<br/>';
         $desc .= _('Change type') . ': ' . implode(', ', $flags) . '<br/>';
         if ($rev->getComments()) {
             $desc .= _('Change comments') . ': ' . htmlspecialchars($rev->getComments()) . '<br/>';
         }
         $desc .= _('By') . ': ' . WDRenderUtils::renderUser($rev->getUserOrString()) . '<br/>';
         $desc .= '<br/>' . _('Page content preview') . ': <br/>' . $page->getPreview();
         $item['description'] = $desc;
         $item['content'] = $desc;
         $item['guid'] = $channel['link'] . "#revision-" . $rev->getRevisionId();
         $item['date'] = date('r', $rev->getDateLastEdited()->getTimestamp());
         $content = '';
         $items[] = $item;
     }
     $runData->contextAdd("channel", $channel);
     $runData->contextAdd("items", $items);
 }
Exemple #10
0
 public function getCurrentRevision()
 {
     $c = new Criteria();
     $c->add("revision_id", $this->getRevisionId());
     return DB_PageRevisionPeer::instance()->selectOne($c);
 }
Exemple #11
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);
     }
 }
 public function build($runData)
 {
     // select recent revisions...
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     // get options
     $pageNumber = $pl->getParameterValue("page");
     $op = $pl->getParameterValue("options");
     if ($pageNumber === null) {
         $pageNumber = 1;
     }
     if ($op) {
         $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
         $o = $json->decode($op);
     }
     if (count($o) == 0) {
         $o['all'] == true;
     }
     $perPage = $pl->getParameterValue("perpage");
     if ($perPage == null) {
         $perPage = 20;
     }
     $offset = ($pageNumber - 1) * $perPage;
     $count = $perPage * 2 + 1;
     $c = new Criteria();
     $c->add("page_revision.site_id", $site->getSiteId());
     if (!$o['all'] && count($o) > 0) {
         $c2 = new Criteria();
         if ($o['new']) {
             $c2->addOr("flag_new", true);
         }
         if ($o['source']) {
             $c2->addOr("flag_text", true);
         }
         if ($o['title']) {
             $c2->addOr("flag_title", true);
         }
         if ($o['move']) {
             $c2->addOr("flag_rename", true);
         }
         if ($o['meta']) {
             $c2->addOr("flag_meta", true);
         }
         if ($o['files']) {
             $c2->addOr("flag_file", true);
         }
         $c->addCriteriaAnd($c2);
     }
     $categoryId = $pl->getParameterValue("categoryId");
     if ($categoryId && is_numeric($categoryId)) {
         $c->add("page.category_id", $categoryId);
     }
     $c->addJoin("page_id", "page.page_id");
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->addOrderDescending("page_revision.revision_id");
     $c->setLimit($count, $offset);
     $revisions = DB_PageRevisionPeer::instance()->select($c);
     $counted = count($revisions);
     $pagerData = array();
     $pagerData['currentPage'] = $pageNumber;
     if ($counted > $perPage * 2) {
         $knownPages = $pageNumber + 2;
         $pagerData['knownPages'] = $knownPages;
     } elseif ($counted > $perPage) {
         $knownPages = $pageNumber + 1;
         $pagerData['totalPages'] = $knownPages;
     } else {
         $totalPages = $pageNumber;
         $pagerData['totalPages'] = $totalPages;
     }
     $revisions = array_slice($revisions, 0, $perPage);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("revisions", $revisions);
     $runData->contextAdd("revisionsCount", count($revisions));
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $pageId = $pl->getParameterValue("page_id");
     $pageNumber = $pl->getParameterValue("page");
     $perPage = $pl->getParameterValue("perpage");
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $o = $json->decode($pl->getParameterValue("options"));
     $offset = ($pageNumber - 1) * $perPage;
     $count = $perPage * 2 + 1;
     // get the page
     $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId);
     if ($page == null || $page->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("Error selecting the page."), "no_page");
     }
     $c = new Criteria();
     $c->add('page_id', $pageId);
     // check options
     if (!$o['all'] && count($o) > 0) {
         $c2 = new Criteria();
         if ($o['new']) {
             $c2->addOr("flag_new", true);
         }
         if ($o['source']) {
             $c2->addOr("flag_text", true);
         }
         if ($o['title']) {
             $c2->addOr("flag_title", true);
         }
         if ($o['move']) {
             $c2->addOr("flag_rename", true);
         }
         if ($o['meta']) {
             $c2->addOr("flag_meta", true);
         }
         if ($o['files']) {
             $c2->addOr("flag_file", true);
         }
         $c->addCriteriaAnd($c2);
     }
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->addOrderDescending('revision_id');
     $c->setLimit($count, $offset);
     $pr = DB_PageRevisionPeer::instance()->select($c);
     // now see if number of selected is equal $perPage + 1. If so -
     // there is at least 1 more page to show...
     $counted = count($pr);
     $pagerData = array();
     $pagerData['current_page'] = $pageNumber;
     if ($counted > $perPage * 2) {
         $knownPages = $pageNumber + 2;
         $pagerData['known_pages'] = $knownPages;
     } elseif ($counted > $perPage) {
         $knownPages = $pageNumber + 1;
         $pagerData['total_pages'] = $knownPages;
     } else {
         $totalPages = $pageNumber;
         $pagerData['total_pages'] = $totalPages;
     }
     $pr = array_slice($pr, 0, $perPage);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("page", $page);
     $runData->contextAdd("currentRevision", $page->getCurrentRevision());
     $runData->contextAdd("revisions", $pr);
 }
 public function build($runData)
 {
     // select recent revisions...
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $userId = $pl->getParameterValue("userId");
     if ($runData->getUser() && $userId == $runData->getUser()->getUserId()) {
         $own = true;
     }
     // get user
     //if($userId
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     if ($user == null) {
         throw new ProcessException(_("Error selecting user."), "no_user");
     }
     // get options
     $pageNumber = $pl->getParameterValue("page");
     $op = $pl->getParameterValue("options");
     if ($pageNumber === null) {
         $pageNumber = 1;
     }
     if ($op) {
         $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
         $o = $json->decode($op);
     }
     if (count($o) == 0) {
         $o['all'] == true;
     }
     $perPage = $pl->getParameterValue("perpage");
     if ($perPage == null) {
         $perPage = 20;
     }
     $offset = ($pageNumber - 1) * $perPage;
     $count = $perPage * 2 + 1;
     $c = new Criteria();
     $c->add("page_revision.user_id", $user->getUserId());
     if (!$own) {
         $c->add("site.private", false);
     }
     if (!$o['all'] && count($o) > 0) {
         $c2 = new Criteria();
         if ($o['new']) {
             $c2->addOr("flag_new", true);
         }
         if ($o['source']) {
             $c2->addOr("flag_text", true);
         }
         if ($o['title']) {
             $c2->addOr("flag_title", true);
         }
         if ($o['move']) {
             $c2->addOr("flag_rename", true);
         }
         if ($o['meta']) {
             $c2->addOr("flag_meta", true);
         }
         if ($o['files']) {
             $c2->addOr("flag_file", true);
         }
         $c->addCriteriaAnd($c2);
     }
     $c->addJoin("page_revision.page_id", "page.page_id");
     $c->addJoin("page.site_id", "site.site_id");
     $c->add("site.deleted", false);
     $c->addOrderDescending("page_revision.revision_id");
     $c->setLimit($count, $offset);
     $revisions = DB_PageRevisionPeer::instance()->select($c);
     $counted = count($revisions);
     $pagerData = array();
     $pagerData['currentPage'] = $pageNumber;
     if ($counted > $perPage * 2) {
         $knownPages = $pageNumber + 2;
         $pagerData['knownPages'] = $knownPages;
     } elseif ($counted > $perPage) {
         $knownPages = $pageNumber + 1;
         $pagerData['totalPages'] = $knownPages;
     } else {
         $totalPages = $pageNumber;
         $pagerData['totalPages'] = $totalPages;
     }
     $revisions = array_slice($revisions, 0, $perPage);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("revisions", $revisions);
     $runData->contextAdd("revisionsCount", count($revisions));
 }
Exemple #15
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $categoryName = $this->_readParameter(array('category', 'categories'), false);
     $categoryName = strtolower($categoryName);
     $order = $this->_readParameter("order", true);
     $limit = $this->_readParameter("limit", true);
     $perPage = $this->_readParameter("perPage", true);
     $skipCurrent = $this->_readParameter('skipCurrent');
     if ($skipCurrent && ($skipCurrent == 'yes' || $skipCurrent == 'true')) {
         $skipCurrent = true;
     } else {
         $skipCurrent = false;
     }
     $pageUnixName = $runData->getTemp('pageUnixName');
     if (!$pageUnixName) {
         $pageUnixName = $pl->getParameterValue('page_unix_name');
         // from preview
     }
     $categories = array();
     $categoryNames = array();
     if ($categoryName != '*') {
         if (!$categoryName) {
             /* No category name specified, use the current category! */
             if (strpos($pageUnixName, ":") != false) {
                 $tmp0 = explode(':', $pageUnixName);
                 $categoryName = $tmp0[0];
             } else {
                 $categoryName = "_default";
             }
         }
         foreach (preg_split('/[,;\\s]+?/', $categoryName) as $cn) {
             $category = DB_CategoryPeer::instance()->selectByName($cn, $site->getSiteId());
             if ($category) {
                 $categories[] = $category;
                 $categoryNames[] = $category->getName();
             }
         }
         if (count($categories) == 0) {
             throw new ProcessException('The requested categories do not (yet) exist.');
         }
     }
     //if(count($categories) == 0){
     //	throw new ProcessException(_("The category can not be found."));
     //}
     // now select pages according to the specified criteria
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     if (count($categories) > 0) {
         $ccat = new Criteria();
         foreach ($categories as $cat) {
             $ccat->addOr('category_id', $cat->getCategoryId());
         }
         $c->addCriteriaAnd($ccat);
     }
     $c->add('unix_name', '(^|:)_', '!~');
     /* Handle magic previousBy/nextBy keywords */
     $previousBy = $this->_readParameter('previousBy', true);
     $nextBy = $this->_readParameter('nextBy', true);
     if ($previousBy || $nextBy) {
         if ($refPage = $runData->getTemp('page')) {
             $refPageId = $refPage->getPageId();
             $refPageTitle = $refPage->getTitle() . ' ... ' . $refPage->getUnixName();
             if ($previousBy == 'page_id') {
                 $c->add('page_id', $refPageId, '<');
             } elseif ($nextBy == 'page_id') {
                 $c->add('page_id', $refPageId, '>');
             } elseif ($previousBy == 'title') {
                 $c->add("title || ' ... ' || unix_name", $refPageTitle, '<');
             } elseif ($nextBy == 'title') {
                 $c->add("title || ' ... ' || unix_name", $refPageTitle, '>');
             }
         } else {
             $c->add('page_id', 0);
             // this should be simply never;
         }
     }
     /* Handle tags! */
     $tagString = $this->_readParameter(array('tag', 'tags'), true);
     if ($tagString) {
         /* Split tags. */
         $tags = preg_split(';[\\s,\\;]+;', $tagString);
         $tagsAny = array();
         $tagsAll = array();
         $tagsNone = array();
         foreach ($tags as $t) {
             if (substr($t, 0, 1) == '+') {
                 $tagsAll[] = substr($t, 1);
             } elseif (substr($t, 0, 1) == '-') {
                 $tagsNone[] = substr($t, 1);
             } elseif ($t == '=') {
                 /* It means: any tags of the current page. */
                 if ($runData->getTemp('page')) {
                     $pageId = $runData->getTemp('page')->getPageId();
                     $co = new Criteria();
                     $co->add("page_id", $pageId);
                     $co->addOrderAscending("tag");
                     $tagso = DB_PageTagPeer::instance()->select($co);
                     foreach ($tagso as $to) {
                         $tagsAny[] = $to->getTag();
                     }
                     if (count($tagsAny) == 0) {
                         /*
                          * If someone uses the '=' tag, the line below guarantees that
                          * only pages that DO have tags and share at least one similar tag with the 
                          * current page are listed.
                          */
                         $tagsAny[] = '   ';
                     }
                 }
             } else {
                 $tagsAny[] = $t;
             }
         }
         /*
          * One more condition: if $tagString is equal to "=" only (which means "similar pages by tags),
          * it is reasonable to drop current page from being displayed.
          */
         if ($tagString == '=') {
             $skipCurrent = true;
         }
         /* Create extra conditions to the SELECT */
         /* ANY */
         if (count($tagsAny) > 0) {
             $t = array();
             foreach ($tagsAny as $tag0) {
                 $t[] = 'tag = \'' . db_escape_string($tag0) . '\'';
             }
             $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")";
             $c->add('(' . $tagQuery . ')', 1, '>=');
         }
         /* ALL */
         if (count($tagsAll) > 0) {
             $t = array();
             foreach ($tagsAll as $tag0) {
                 $t[] = 'tag = \'' . db_escape_string($tag0) . '\'';
             }
             $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")";
             $c->add('(' . $tagQuery . ')', count($tagsAll));
         }
         /* NONE */
         if (count($tagsNone) > 0) {
             $t = array();
             foreach ($tagsNone as $tag0) {
                 $t[] = 'tag = \'' . db_escape_string($tag0) . '\'';
             }
             $tagQuery = "SELECT count(*) FROM page_tag " . "WHERE page_tag.page_id=page.page_id " . "AND (" . implode(' OR ', $t) . ")";
             $c->add('(' . $tagQuery . ')', 0);
         }
     }
     if ($skipCurrent && $runData->getTemp('page') && $runData->getTemp('page')->getPageId()) {
         $c->add('page_id', $runData->getTemp('page')->getPageId(), '!=');
     }
     /* Handle date ranges. */
     $date = $this->_readParameter("date", true);
     $dateA = array();
     if (preg_match(';^[0-9]{4}$;', $date)) {
         $dateA['year'] = $date;
     }
     if (preg_match(';^[0-9]{4}\\.[0-9]{1,2}$;', $date)) {
         $dateS = explode('.', $date);
         $dateA['year'] = $dateS[0];
         $dateA['month'] = $dateS[1];
     }
     if (isset($dateA['year'])) {
         $c->add('EXTRACT(YEAR FROM date_created)', $dateA['year']);
     }
     if (isset($dateA['month'])) {
         $c->add('EXTRACT(MONTH FROM date_created)', $dateA['month']);
     }
     /* Handle date "last X day(s)/week(s)/month(s)" */
     $m = array();
     if (preg_match(';^last (?:([1-9][0-9]*) )?(day|week|month)s?$;', $date, $m)) {
         $dateObj = new ODate();
         $n = $m[1];
         if (!$n) {
             $n = 1;
         }
         $unit = $m[2];
         $convarray = array('day' => 86400, 'week' => 604800, 'month' => 2592000);
         $dateObj->subtractSeconds($n * $convarray[$unit]);
         $c->add('date_created', $dateObj, '>');
     }
     /* Handle pagination. */
     if (!$perPage || !preg_match(';^[0-9]+$;', $perPage)) {
         $perPage = 20;
     }
     if ($limit && preg_match(';^[0-9]+$;', $limit)) {
         $c->setLimit($limit);
         // this limit has no effect on count(*) !!!
     } else {
         $limit = null;
     }
     $pageNo = $pl->getParameterValue(($this->_parameterUrlPrefix ? $this->_parameterUrlPrefix . '_' : '') . "p");
     if ($pageNo == null || !preg_match(';^[0-9]+$;', $pageNo)) {
         $pageNo = 1;
     }
     $co = DB_PagePeer::instance()->selectCount($c);
     if ($limit) {
         $co = min(array($co, $limit));
     }
     $totalPages = ceil($co / $perPage);
     if ($pageNo > $totalPages) {
         $pageNo = $totalPages;
     }
     $offset = ($pageNo - 1) * $perPage;
     if ($limit) {
         $newLimit = min(array($perPage, $limit - $offset));
     } else {
         $newLimit = $perPage;
     }
     $c->setLimit($newLimit, $offset);
     $runData->contextAdd("totalPages", $totalPages);
     $runData->contextAdd("currentPage", $pageNo);
     $runData->contextAdd("count", $co);
     $runData->contextAdd("totalPages", $totalPages);
     $runData->contextAdd('parameterUrlPrefix', $this->_parameterUrlPrefix);
     /* Pager's base url */
     $url = $_SERVER['REQUEST_URI'];
     if (($url == '' || $url == '/') && isset($pageUnixName)) {
         $url = '/' . $pageUnixName;
     }
     $pref = '';
     if ($this->_parameterUrlPrefix) {
         $pref = $this->_parameterUrlPrefix . '_';
     }
     $url = preg_replace(';(/' . $pref . 'p/[0-9]+)|$;', '/' . $pref . 'p/%d', $url, 1);
     $runData->contextAdd("pagerUrl", $url);
     switch ($order) {
         case 'dateCreatedAsc':
             $c->addOrderAscending('page_id');
             break;
         case 'dateEditedDesc':
             $c->addOrderDescending('date_last_edited');
             break;
         case 'dateEditedAsc':
             $c->addOrderAscending('date_last_edited');
             break;
         case 'titleDesc':
             $c->addOrderDescending("COALESCE(title, unix_name)");
             break;
         case 'titleAsc':
             $c->addOrderAscending("COALESCE(title, unix_name)");
             break;
         case 'ratingAsc':
             $c->addOrderAscending('rate');
             break;
         case 'ratingDesc':
             $c->addOrderDescending('rate');
             break;
             /*
                         case 'commentsAsc':
                         	$c->addJoin('thread_id', 'forum_thread.thread_id', 'LEFT');
                         	$c->addOrderAscending('number_posts');
                         	break;
                         case 'commentsDesc':
                         	$c->addOrderDescending('number_posts');
                         	break;
             */
         /*
                     case 'commentsAsc':
                     	$c->addJoin('thread_id', 'forum_thread.thread_id', 'LEFT');
                     	$c->addOrderAscending('number_posts');
                     	break;
                     case 'commentsDesc':
                     	$c->addOrderDescending('number_posts');
                     	break;
         */
         case 'pageLengthAsc':
             $c->addJoin('source_id', 'page_source.source_id');
             $c->addOrderAscending('char_length(page_source.text)');
             break;
         case 'pageLengthDesc':
             $c->addJoin('source_id', 'page_source.source_id');
             $c->addOrderDescending('char_length(page_source.text)');
             break;
         default:
         case 'dateCreatedDesc':
             $c->addOrderDescending('page_id');
             break;
     }
     $pages = DB_PagePeer::instance()->select($c);
     /* Process... */
     $format = $this->_readParameter("module_body");
     if (!$format) {
         $format = "" . "+ %%linked_title%%\n\n" . _("by") . " %%author%% %%date|%O ago (%e %b %Y, %H:%M %Z)%%\n\n" . "%%short%%";
     }
     //$wt = new WikiTransformation();
     //$wt->setMode("feed");
     //$template = $wt->processSource($format);
     //$template = preg_replace('/<p\s*>\s*(%%((?:short)|(?:description)|(?:summary)|(?:content)|(?:long)|(?:body)|(?:text))%%)\s*<\/\s*p>/smi',
     //			"<div>\\1</div>", $template);
     //$template = $format;
     $items = array();
     $separation = $this->_readParameter("separate");
     if ($separation == 'no' || $separation == 'false') {
         $separation = false;
     } else {
         $separation = true;
     }
     foreach ($pages as $page) {
         $this->_tmpPage = $page;
         $title = $page->getTitle();
         $source = $page->getSource();
         $title = str_replace(array('[', ']'), '', $title);
         $title = str_replace('%%', "ý", $title);
         $source = str_replace('%%', "ý", $source);
         $c = new Criteria();
         $c->add('revision_id', $page->getRevisionId());
         $lastRevision = DB_PageRevisionPeer::instance()->selectOne($c);
         //$c = new Criteria();
         //$c->add('page_id', $page->getPageId());
         //$c->addOrderAscending('revision_id');
         //$firstRevision = DB_PageRevisionPeer::instance()->selectOne($c);
         $b = $format;
         /* A series of substitutions. */
         $b = str_replace("ý", '', $b);
         /* %%title%% and similar */
         $b = str_replace('%%title%%', $title, $b);
         $b = preg_replace("/%%((linked_title)|(title_linked))%%/i", preg_quote_replacement('[[[' . $page->getUnixName() . ' | ' . $title . ']]]'), $b);
         /* %%author%% */
         if ($page->getOwnerUserId()) {
             $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($page->getOwnerUserId());
             if ($user->getUserId() > 0) {
                 $userString = '[[*user ' . $user->getNickName() . ']]';
             } else {
                 $userString = _('Anonymous user');
             }
         } else {
             $userString = _('Anonymous user');
         }
         $b = str_ireplace("%%author%%", $userString, $b);
         $b = str_ireplace("%%user%%", $userString, $b);
         if ($lastRevision->getUserId()) {
             $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($lastRevision->getUserId());
             if ($user->getUserId() > 0) {
                 $userString = '[[*user ' . $user->getNickName() . ']]';
             } else {
                 $userString = _('Anonymous user');
             }
         } else {
             $userString = _('Anonymous user');
         }
         $b = str_ireplace("%%author_edited%%", $userString, $b);
         $b = str_ireplace("%%user_edited%%", $userString, $b);
         /* %%date%% */
         $b = preg_replace(';%%date(\\|.*?)?%%;', '%%date|' . $page->getDateCreated()->getTimestamp() . '\\1%%', $b);
         $b = preg_replace(';%%date_edited(\\|.*?)?%%;', '%%date|' . $page->getDateLastEdited()->getTimestamp() . '\\1%%', $b);
         /* %%content%% */
         $b = preg_replace(';%%((body)|(text)|(long)|(content))%%;i', $source, $b);
         /* %%content{n}%% */
         /* Split the content first. */
         $this->_tmpSplitSource = preg_split('/^([=]{4,})$/m', $source);
         $this->_tmpSource = $source;
         $b = preg_replace_callback(';%%content{([0-9]+)}%%;', array($this, '_handleContentSubstitution'), $b);
         /* %%short%% */
         $b = preg_replace_callback("/%%((description)|(short)|(summary))%%/i", array($this, '_handleSummary'), $b);
         $b = preg_replace_callback("/%%first_paragraph%%/i", array($this, '_handleFirstParagraph'), $b);
         /* %%preview%% */
         $b = preg_replace_callback("/%%preview(?:\\(([0-9]+)\\))?%%/i", array($this, '_handlePreview'), $b);
         /* %%rating%% */
         $b = str_ireplace('%%rating%%', $page->getRate(), $b);
         /* %%comments%% */
         $b = preg_replace_callback("/%%comments%%/i", array($this, '_handleComementsCount'), $b);
         /* %%page_unix_name%% */
         $b = str_ireplace('%%page_unix_name%%', $page->getUnixName(), $b);
         /* %%category%% */
         if (strpos($page->getUnixName(), ":") != false) {
             $tmp0 = explode(':', $page->getUnixName());
             $categoryName00 = $tmp0[0];
         } else {
             $categoryName00 = "_default";
         }
         $b = str_ireplace('%%category%%', $categoryName00, $b);
         /* %%link%% */
         $b = str_ireplace('%%link%%', 'http://' . $site->getDomain() . '/' . $page->getUnixName(), $b);
         /* %%tags%% */
         $b = preg_replace_callback("/%%tags%%/i", array($this, '_handleTags'), $b);
         $b = str_replace("ý", '%%', $b);
         if ($separation) {
             $wt = new WikiTransformation();
             $wt->setMode("list");
             $wt->setPage($page);
             $b = $wt->processSource($b);
             $b = "<div class=\"list-pages-item\">\n" . $b . "</div>";
             //$b = "[[div class=\"list-pages-item\"]]\n".$b."\n[[/div]]";
         }
         $items[] = trim($b);
     }
     if (!$separation) {
         $prependLine = $this->_readParameter('prependLine');
         $appendLine = $this->_readParameter('appendLine');
         $wt = new WikiTransformation();
         $wt->setMode("list");
         $glue = "\n";
         $itemsContent = $wt->processSource(($prependLine ? $prependLine . "\n" : '') . implode($glue, $items) . ($appendLine ? "\n" . $appendLine : ''));
     } else {
         $itemsContent = implode("\n", $items);
     }
     /*
      * If separation is false, we are not separating the items with double-newlines but rather
      * with a single newline. This allows to create e.g. list of pages by creating a template:
      * * %%linked_title%%
      */
     /* Fix dates. */
     //$dateString = '<span class="odate">'.$thread->getDateStarted()->getTimestamp().'|%e %b %Y, %H:%M %Z|agohover</span>';
     $itemsContent = preg_replace_callback(';%%date\\|([0-9]+)(\\|.*?)?%%;', array($this, '_formatDate'), $itemsContent);
     $runData->contextAdd("items", $items);
     $runData->contextAdd("itemsContent", $itemsContent);
     $runData->contextAdd("details", $details);
     $runData->contextAdd("preview", $preview);
     /* Also build an URL for the feed. */
     $rssTitle = $this->_readParameter(array('rss', 'rssTitle'));
     if ($rssTitle !== null) {
         $url = 'http://' . $site->getDomain() . '/feed/pages';
         if (count($categoryNames) > 0) {
             $url .= '/category/' . urlencode(implode(',', $categoryNames));
         }
         if (isset($tags)) {
             $url .= '/tags/' . urlencode(implode(',', $tags));
         }
         /*
          * Ignore date in RSS generation.
          */
         /*
         	        if (isset($date)) {
         	            $url .= '/date/' . urlencode($date);
         	        }*/
         if ($order) {
             $url .= '/order/' . urlencode($order);
         }
         //$erss = $pl->getParameterValue('rssEmbed');
         //if ($erss == 'no' || $erss == 'false') {
         //    $erss = false;
         //} else {
         //    $erss = true;
         //}
         //$srss = $pl->getParameterValue('rssShow');
         //if ($srss == 'no' || $srss == 'false') {
         //    $srss = false;
         //} else {
         //    $srss = true;
         //}
         //$trss = $pl->getParameterValue('rssTitle');
         //if ($trss) {
         //    $url .= '/t/' . urlencode($trss);
         //}
         $url .= '/t/' . urlencode($rssTitle);
         //if ($erss) {
         $this->_vars['rssUrl'] = $url;
         $this->_vars['rssTitle'] = $rssTitle;
         //}
         //if ($srss) {
         $runData->contextAdd('rssUrl', $url);
         $runData->contextAdd('rssTitle', $rssTitle);
         //}
     }
 }