示例#1
0
 public function getPages()
 {
     $c = new Criteria();
     $c->addAscendingOrderByColumn(nahoWikiPagePeer::NAME);
     $c->add(nahoWikiPagePeer::WIKI_ID, $this->getId());
     return nahoWikiPagePeer::doSelect($c);
 }
 /**
  * remove the page related to the object (and all the revisione in cascade)
  *
  * @return void
  * @author Guglielmo Celata
  **/
 public function preDelete($object, $con)
 {
     $prefix = sfConfig::get(sprintf('propel_behavior_wikifiableBehavior_%s_prefix', get_class($object)));
     $wiki_page = nahoWikiPagePeer::retrieveByName($prefix . "_" . $object->getId());
     if (!is_null($wiki_page)) {
         $wiki_page->delete();
     }
 }
 public function executeShowContent()
 {
     // store the referer in the user's session
     $referer = $this->getRequest()->getUri();
     $this->getUser()->setAttribute('referer', $referer);
     // Retrieve page and revision
     $this->page = nahoWikiPagePeer::retrieveByName($this->page_name);
     if ($this->page) {
         $this->revision = $this->page->getRevision();
     }
 }
/**
 * Get link for a page in the wiki
 *
 * @param string $text text of the link (if null, we create it from the pagename+revision)
 * @param string $page_name
 * @param array $options params added to the link (you can add a 'revision' option to specifiy the revision of the page you want to link to)
 *
 * @return string
 */
function link_to_wiki($text, $page_name, $options = array())
{
    $url = 'nahoWiki/view?page=' . $page_name;
    if (isset($options['revision'])) {
        $url .= '&revision=' . $options['revision'];
    }
    if (is_null($text)) {
        $text = htmlspecialchars(nahoWikiPagePeer::getBasename($page_name));
        if (isset($options['revision'])) {
            $text .= ' rev. ' . $options['revision'];
        }
    }
    return link_to($text, $url, $options);
}
 protected function setPage($page_name = null)
 {
     // Get page from request if not given as parameter (default behaviour)
     if (is_null($page_name)) {
         $page_name = $this->getRequestParameter('page', $this->startPage);
     }
     // Handle case insensitivity
     $page_name = strtolower($page_name);
     // Support default page if not specified in namespace
     if (substr($page_name, -1) == ':') {
         $page_name .= $this->startPage;
     }
     // Retrieve the page, or start a new one if cannot be found
     $this->page = nahoWikiPagePeer::retrieveByName($page_name);
     if (!$this->page) {
         return;
     }
     // Retrieve the revision
     $revision = $this->getRequestParameter('revision', $this->page->getLatestRevision());
     $this->revision = $this->page->getRevision($revision);
     if (!$this->revision) {
         $this->initNewRevision();
     }
     // Generate the URI parameters to keep trace of the requested page
     $this->uriParams = 'page=' . $this->page->getName();
     if ($this->revision->getRevision() != $this->page->getLatestRevision()) {
         $this->uriParams .= '&revision=' . $this->revision->getRevision();
     }
     // Permissions management
     $this->canView = $this->page->canView($this->getUser());
     $this->canEdit = $this->page->canEdit($this->getUser());
     // Retriev item name and type of item (tab and breadcrumbs)
     list($tipo, $id) = split("_", $this->page->getName());
     switch ($tipo) {
         case 'atto':
             $this->item = OppAttoPeer::retrieveByPK($id);
             $this->item_name = Text::denominazioneAttoShort($this->item);
             break;
         case 'votazione':
             $this->item = OppVotazionePeer::retrieveByPK($id);
             $this->item_name = $this->item->getTitolo();
             break;
         case 'emendamento':
             $this->item = OppEmendamentoPeer::retrieveByPK($id);
             $attoPortante = $this->item->getAttoPortante();
             $this->item_name = "Emendamento " . $this->item->getTitolo() . " relativo a " . Text::denominazioneAttoShort($attoPortante) . " - " . $attoPortante->getTitolo();
             break;
     }
     $this->item_type = $tipo;
 }
示例#6
0
 public function executeContent()
 {
     if (!isset($this->hide_toc)) {
         $this->hide_toc = !sfConfig::get('app_nahoWikiPlugin_include_toc', true);
     }
     $start = sfConfig::get('app_nahoWikiPlugin_start_page', 'index');
     if (!($page_name = $this->pagename)) {
         $page_name = $start;
     }
     // Support default page if not specified in namespace
     if (substr($page_name, -1) == ':') {
         $page_name .= $start;
     }
     // Retrieve the page, or start a new one if cannot be found
     $this->page = nahoWikiPagePeer::retrieveByName($page_name);
     // Build page object
     if (!$this->page) {
         $this->page = new nahoWikiPage();
         $this->revision = null;
     } else {
         // Retrieve the revision
         if (!($revision = $this->revision)) {
             $revision = $this->page->getLatestRevision();
         }
         $this->revision = $this->page->getRevision($revision);
     }
     // Buil revision object
     if (!$this->revision) {
         $this->revision = new nahoWikiRevision();
         $this->revision->setnahoWikiPage($this->page);
     }
     // Generate the URI parameters to keep trace of the requested page
     $this->uriParams = 'page=' . urlencode($this->page->getName());
     if ($this->revision->getRevision() != $this->page->getLatestRevision()) {
         $this->uriParams .= '&revision=' . urlencode($this->revision->getRevision());
     }
     // Permissions
     $this->canView = $this->page->canView($this->getUser());
     $this->canEdit = $this->page->canEdit($this->getUser());
 }
示例#7
0
 public static function convertInterwikiLinks($content)
 {
     $masks = sfConfig::get('app_nahoWikiPlugin_interwiki_links', array('[[%name% %title%]]', '[[%name%]]'));
     $pcre_masks = array('name' => '[a-z]+>' . nahoWikiPagePeer::pageNameFormat() . '(?:#[A-Za-z0-9_\\-]+)?', 'title' => '.*?');
     $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks);
     // Complete the replacements array
     $interwiki = sfConfig::get('app_nahoWikiPlugin_interwiki', array());
     $web_root = sfContext::getInstance()->getRequest()->getRelativeUrlRoot();
     $dir_root = sfConfig::get('sf_web_dir');
     $plugin_dir = '/nahoWikiPlugin/images/';
     foreach ($replaces as &$replace) {
         list($key, $name) = explode('>', $replace['name'], 2);
         if (isset($interwiki[$key])) {
             $replace['link'] = $interwiki[$key] . rawurlencode($name);
             if ($replace['link']) {
                 $replace['alttext'] = $key;
                 $key = strtolower($key);
                 if (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.png'))) {
                     $replace['image'] = $web_root . $image;
                 } elseif (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.gif'))) {
                     $replace['image'] = $web_root . $image;
                 } elseif (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.jpg'))) {
                     $replace['image'] = $web_root . $image;
                 } else {
                     $replace['image'] = $web_root . $plugin_dir . 'interwiki.png';
                 }
             }
             if (!$replace['title']) {
                 $replace['title'] = $name;
             }
         }
     }
     $link_model = sfConfig::get('app_nahoWikiPlugin_interwiki_link_model', '[![%alttext%](%image%) %title%](%link%)');
     return self::makeLinkReplacements($content, $replaces, $link_model);
 }
 public static function doSelectJoinAllExceptnahoWikiContent(Criteria $c, $con = null)
 {
     foreach (sfMixer::getCallables('BasenahoWikiRevisionPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) {
         call_user_func($callable, 'BasenahoWikiRevisionPeer', $c, $con);
     }
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     nahoWikiRevisionPeer::addSelectColumns($c);
     $startcol2 = nahoWikiRevisionPeer::NUM_COLUMNS - nahoWikiRevisionPeer::NUM_LAZY_LOAD_COLUMNS + 1;
     nahoWikiPagePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + nahoWikiPagePeer::NUM_COLUMNS;
     $c->addJoin(nahoWikiRevisionPeer::PAGE_ID, nahoWikiPagePeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = nahoWikiRevisionPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         $omClass = nahoWikiPagePeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj2 = new $cls();
         $obj2->hydrate($rs, $startcol2);
         $newObject = true;
         for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
             $temp_obj1 = $results[$j];
             $temp_obj2 = $temp_obj1->getnahoWikiPage();
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addnahoWikiRevision($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj2->initnahoWikiRevisions();
             $obj2->addnahoWikiRevision($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
 public function getHasDescrizioneWiki()
 {
     $prefix = sfConfig::get(sprintf('propel_behavior_wikifiableBehavior_%s_prefix', get_class($this)));
     $default_description = sfConfig::get(sprintf('propel_behavior_wikifiableBehavior_%s_default_description', get_class($this)), 'Descrizione di default');
     $wiki_page = nahoWikiPagePeer::retrieveByName($prefix . "_" . $this->getId());
     if ($wiki_page) {
         $desc = $wiki_page->getRevision()->getContent();
         if ($desc != $default_description) {
             return "true";
         }
     }
     return "false";
 }
示例#10
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = nahoWikiPagePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setWikiId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setLatestRevision($arr[$keys[3]]);
     }
 }
示例#11
0
 public function getBasename($page_name = null)
 {
     return nahoWikiPagePeer::getBasename($this->getName());
 }
 public function executeBrowse()
 {
     $this->setPage();
     $path = $this->getRequestParameter('path');
     $tree = array();
     $c = new Criteria();
     $c->addAscendingOrderByColumn(nahoWikiPagePeer::NAME);
     $pages = nahoWikiPagePeer::doSelect($c);
     foreach ($pages as $page) {
         $this->buildIndexTree($tree, explode(':', $page->getName()), $page->getName(), explode(':', $path));
     }
     $this->tree = $tree;
     $this->uriParams = 'page=' . urlencode($this->getRequestParameter('page'));
     return sfView::SUCCESS;
 }
$prefix = sfConfig::get(sprintf('propel_behavior_wikifiableBehavior_%s_prefix', get_class($obj_votazione)));
$t->ok($prefix == 'votazione', 'The prefix was correctly read from the behavior configuration');
$wiki_page = nahoWikiPagePeer::retrieveByName($prefix . "_" . $obj_votazione->getId());
$t->ok($wiki_page instanceof nahoWikiPage, 'a wiki page was just created for this object');
$c = new Criteria();
$c->add(nahoWikiRevisionPeer::REVISION, 1);
$wiki_revisions = $wiki_page->getRevisions($c);
$wiki_revision = $wiki_revisions[0];
$t->ok(count($wiki_revisions) == 1 && $wiki_revision instanceof nahoWikiRevision, 'a wiki revision was added');
$wiki_content = $wiki_revision->getnahoWikiContent();
$t->ok($wiki_content instanceof nahoWikiContent, 'a wiki content was also added');
$t->ok($wiki_revision->getComment() == 'Creazione Automatica' && $wiki_revision->getContent() == 'Descrizione wiki, a cura degli utenti.', 'comment and content were correctly inserted');
$votazione_page_id = $wiki_page->getId();
$votazione_revision_num = $wiki_revision->getRevision();
$votazione_content_id = $wiki_content->getId();
$t->diag('Remove the act object');
$obj_atto->delete();
$wiki_page = nahoWikiPagePeer::retrieveByPK($atto_page_id);
$t->ok(!$wiki_page instanceof nahoWikiPage, 'the wiki page was removed');
$wiki_revision = nahoWikiRevisionPeer::retrieveByPK($atto_page_id, $atto_revision_num, $atto_content_id);
$t->ok(!$wiki_revision instanceof nahoWikiRevision, 'the wiki revision was removed');
$wiki_content = nahoWikiContentPeer::retrieveByPK($atto_content_id);
$t->ok($wiki_content instanceof nahoWikiContent, 'the wiki content was NOT removed');
$t->diag('Remove the votation object');
$obj_votazione->delete();
$wiki_page = nahoWikiPagePeer::retrieveByPK($votazione_page_id);
$t->ok(!$wiki_page instanceof nahoWikiPage, 'the wiki page was removed');
$wiki_revision = nahoWikiRevisionPeer::retrieveByPK($votazione_page_id, $votazione_revision_num, $votazione_content_id);
$t->ok(!$wiki_revision instanceof nahoWikiRevision, 'the wiki revision was removed');
$wiki_content = nahoWikiContentPeer::retrieveByPK($votazione_content_id);
$t->ok($wiki_content instanceof nahoWikiContent, 'the wiki content was NOT removed');
 *
 * (c) 2008 Guglielmo Celata <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Creates the initial wiki descriptions for Attos and Votaziones
 */
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
// clean all pages and content
nahoWikiPagePeer::doDeleteAll();
nahoWikiContentPeer::doDeleteAll();
// define all classes that needs descriptions and their prefix in the name field
$classes = array('OppAtto' => 'atto', 'OppVotazione' => 'votazione');
$tot_cnt = 0;
foreach ($classes as $model => $name_prefix) {
    echo "Processing {$model} ";
    $c = new Criteria();
    // extract the number of items to process for the generator
    $n_todo = call_user_func_array(array($model . 'Peer', 'doCount'), array($c));
    echo "({$n_todo}) ";
    // get table map and columns map for this generator
    $model_table = call_user_func($model . 'Peer::getTableMap');
    $model_columns = $model_table->getColumns();
    // find and store primary keys
    $pks = array();
示例#15
0
 public function getnahoWikiPage($con = null)
 {
     if ($this->anahoWikiPage === null && $this->page_id !== null) {
         include_once 'plugins/nahoWikiPlugin/lib/model/om/BasenahoWikiPagePeer.php';
         $this->anahoWikiPage = nahoWikiPagePeer::retrieveByPK($this->page_id, $con);
     }
     return $this->anahoWikiPage;
 }
示例#16
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(nahoWikiPagePeer::ID, $pks, Criteria::IN);
         $objs = nahoWikiPagePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
示例#17
0
 public function countnahoWikiPages($criteria = null, $distinct = false, $con = null)
 {
     include_once 'lib/model/om/BasenahoWikiPagePeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     $criteria->add(nahoWikiPagePeer::WIKI_ID, $this->getId());
     return nahoWikiPagePeer::doCount($criteria, $distinct, $con);
 }