/** 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; }
/** 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; }