function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (empty($page)) { return ''; } $html = HTML(HTML::h3(fmt("Retransform page '%s'", $page))); // bypass WikiDB and cache, go directly through the backend. $backend =& $dbi->_backend; //$pagedata = $backend->get_pagedata($page); $version = $backend->get_latest_version($page); $vdata = $backend->get_versiondata($page, $version, true); include_once 'lib/PageType.php'; $formatted = new TransformedText($dbi->getPage($page), $vdata['%content'], $vdata); $content =& $formatted->_content; $html->pushContent($this->_DebugPrintArray($content)); $links = $formatted->getWikiPageLinks(); if (count($links) > 0) { $html->pushContent(HTML::h3("Links")); $html->pushContent($this->_DebugPrintArray($links)); } return $html; }
/** A higher-level interface to createRevision. * * This takes care of computing the links, and storing * a cached version of the transformed wiki-text. * * @param string $wikitext The page content. * * @param int $version Version number for new revision. * To ensure proper serialization of edits, $version must be * exactly one higher than the current latest version. * (You can defeat this check by setting $version to * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.) * * @param hash $meta Meta-data for new revision. */ function save($wikitext, $version, $meta) { $formatted = new TransformedText($this, $wikitext, $meta); $type = $formatted->getType(); $meta['pagetype'] = $type->getName(); $links = $formatted->getWikiPageLinks(); $backend =& $this->_wikidb->_backend; $newrevision = $this->createRevision($version, $wikitext, $meta, $links); if ($newrevision and !WIKIDB_NOCACHE_MARKUP) { $this->set('_cached_html', $formatted->pack()); } // FIXME: probably should have some global state information // in the backend to control when to optimize. // // We're doing this here rather than in createRevision because // postgres can't optimize while locked. if (DEBUG & _DEBUG_SQL or time() % 5 == 0) { if ($backend->optimize()) { // Codendi: don't show this message... //trigger_error(_("Optimizing database"), E_USER_NOTICE); } } /* Generate notification emails? */ if (ENABLE_EMAIL_NOTIFIFICATION && isa($newrevision, 'WikiDB_PageRevision')) { // Save didn't fail because of concurrent updates. $notify = $this->_wikidb->get('notify'); if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'], 'MockRequest')) { list($emails, $userids) = $this->getPageChangeEmails($notify); if (!empty($emails)) { $this->sendPageChangeNotification($wikitext, $version, $meta, $emails, $userids); } } $newrevision->_transformedContent = $formatted; } return $newrevision; }
/** * Put the database into a consistent state * by reparsing and restoring all pages. * * This should put the database into a consistent state. * (I.e. rebuild indexes, etc...) * * @return boolean True iff successful. */ function rebuild($args = false) { global $request; $dbh = $request->getDbh(); $iter = $dbh->getAllPages(false); while ($page = $iter->next()) { $current = $page->getCurrentRevision(true); $pagename = $page->getName(); $meta = $current->_data; $version = $current->getVersion(); $content =& $meta['%content']; $formatted = new TransformedText($page, $content, $current->getMetaData()); $type = $formatted->getType(); $meta['pagetype'] = $type->getName(); $links = $formatted->getWikiPageLinks(); // linkto => relation $this->lock(array('version', 'page', 'recent', 'link', 'nonempty')); $this->set_versiondata($pagename, $version, $meta); $this->set_links($pagename, $links); $this->unlock(array('version', 'page', 'recent', 'link', 'nonempty')); } }
/** A higher-level interface to createRevision. * * This takes care of computing the links, and storing * a cached version of the transformed wiki-text. * * @param string $wikitext The page content. * * @param int $version Version number for new revision. * To ensure proper serialization of edits, $version must be * exactly one higher than the current latest version. * (You can defeat this check by setting $version to * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.) * * @param hash $meta Meta-data for new revision. */ function save($wikitext, $version, $meta, $formatted = null) { if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; } if (is_null($formatted)) { $formatted = new TransformedText($this, $wikitext, $meta); } $type = $formatted->getType(); $meta['pagetype'] = $type->getName(); $links = $formatted->getWikiPageLinks(); // linkto => relation $attributes = array(); foreach ($links as $link) { if ($link['linkto'] === "" and !empty($link['relation'])) { $attributes[$link['relation']] = $this->getAttribute($link['relation']); } } $meta['attribute'] = $attributes; $backend =& $this->_wikidb->_backend; $newrevision = $this->createRevision($version, $wikitext, $meta, $links); if ($newrevision and !WIKIDB_NOCACHE_MARKUP) { $this->set('_cached_html', $formatted->pack()); } // FIXME: probably should have some global state information // in the backend to control when to optimize. // // We're doing this here rather than in createRevision because // postgresql can't optimize while locked. if ((int) DEBUG & _DEBUG_SQL or DATABASE_OPTIMISE_FREQUENCY > 0 and time() % DATABASE_OPTIMISE_FREQUENCY == 0) { if ($backend->optimize()) { if ((int) DEBUG) { trigger_error(_("Optimizing database"), E_USER_NOTICE); } } } /* Generate notification emails? */ if (ENABLE_MAILNOTIFY and isa($newrevision, 'WikiDB_PageRevision')) { // Save didn't fail because of concurrent updates. $notify = $this->_wikidb->get('notify'); if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'], 'MockRequest')) { include_once "lib/MailNotify.php"; $MailNotify = new MailNotify($newrevision->getName()); $MailNotify->onChangePage($this->_wikidb, $wikitext, $version, $meta); } $newrevision->_transformedContent = $formatted; } // more pagechange callbacks: (in a hackish manner for now) if (ENABLE_RECENTCHANGESBOX and empty($meta['is_minor_edit']) and !in_array($GLOBALS['request']->getArg('action'), array('loadfile', 'upgrade'))) { require_once "lib/WikiPlugin.php"; $w = new WikiPluginLoader(); $p = $w->getPlugin("RecentChangesCached", false); $p->box_update(false, $GLOBALS['request'], $this->_pagename); } return $newrevision; }