예제 #1
0
파일: tikilib.php 프로젝트: rjsmelo/tiki
 /** Update a wiki page
 		@param array $hash- lock_it,contributions, contributors
 		@param int $saveLastModif - modification time - pass null for now, unless importing a Wiki page
 	 **/
 function update_page($pageName, $edit_data, $edit_comment, $edit_user, $edit_ip, $edit_description = null, $edit_minor = 0, $lang = '', $is_html = null, $hash = null, $saveLastModif = null, $wysiwyg = '', $wiki_authors_style = '')
 {
     global $prefs;
     $histlib = TikiLib::lib('hist');
     if (!$edit_user) {
         $edit_user = '******';
     }
     $this->invalidate_cache($pageName);
     // Collect pages before modifying edit_data (see update of links below)
     $pages = $this->get_pages($edit_data, true);
     $this->check_alias($edit_data, $pageName);
     if (!$this->page_exists($pageName)) {
         return false;
     }
     // Get this page information
     $info = $this->get_page_info($pageName);
     if ($edit_description === null) {
         $edit_description = $info['description'];
     }
     // Use largest version +1 in history table rather than tiki_page because versions used to be bugged
     // tiki_history is also bugged as not all changes get stored in the history, like minor changes
     // and changes that do not modify the body of the page. Both numbers are wrong, but the largest of
     // them both is right.
     $old_version = max($info["version"], $histlib->get_page_latest_version($pageName));
     $user = $info["user"] ? $info["user"] : '******';
     $data = $info["data"];
     $willDoHistory = $prefs['feature_wiki_history_full'] == 'y' || $data != $edit_data || $info['description'] != $edit_description || $info["comment"] != $edit_comment;
     $version = $old_version + ($willDoHistory ? 1 : 0);
     if ($is_html === null) {
         $html = $info['is_html'];
     } else {
         $html = $is_html ? 1 : 0;
     }
     if ($wysiwyg == '') {
         $wysiwyg = $info['wysiwyg'];
     }
     if ($wysiwyg == 'y' && $html != 1 && $prefs['wysiwyg_htmltowiki'] != 'y') {
         // correct for html only wysiwyg
         $html = 1;
     }
     $parserlib = TikiLib::lib('parser');
     $edit_data = $parserlib->process_save_plugins($edit_data, array('type' => 'wiki page', 'itemId' => $pageName, 'user' => $user));
     if ($html == 1 && $prefs['feature_purifier'] != 'n') {
         $parserlib->isHtmlPurifying = true;
         $parserlib->isEditMode = true;
         $noparsed = array();
         $parserlib->plugins_remove($edit_data, $noparsed);
         require_once 'lib/htmlpurifier_tiki/HTMLPurifier.tiki.php';
         $edit_data = HTMLPurifier($edit_data);
         $parserlib->plugins_replace($edit_data, $noparsed, true);
         $parserlib->isHtmlPurifying = false;
         $parserlib->isEditMode = false;
     }
     if (is_null($saveLastModif)) {
         $saveLastModif = $this->now;
     }
     $queryData = array('description' => $edit_description, 'data' => $edit_data, 'comment' => $edit_comment, 'lastModif' => (int) $saveLastModif, 'version' => $version, 'version_minor' => $edit_minor, 'user' => $edit_user, 'ip' => $edit_ip, 'page_size' => strlen($edit_data), 'is_html' => $html, 'wysiwyg' => $wysiwyg, 'wiki_authors_style' => $wiki_authors_style, 'lang' => $lang);
     if ($hash !== null) {
         if (!empty($hash['lock_it']) && ($hash['lock_it'] == 'y' || $hash['lock_it'] == 'on')) {
             $queryData['flag'] = 'L';
             $queryData['lockedby'] = $user;
         } else {
             if (empty($hash['lock_it']) || $hash['lock_it'] == 'n') {
                 $queryData['flag'] = '';
                 $queryData['lockedby'] = '';
             }
         }
     }
     if ($prefs['wiki_comments_allow_per_page'] != 'n') {
         if (!empty($hash['comments_enabled']) && $hash['comments_enabled'] == 'y') {
             $queryData['comments_enabled'] = 'y';
         } else {
             if (empty($hash['comments_enabled']) || $hash['comments_enabled'] == 'n') {
                 $queryData['comments_enabled'] = 'n';
             }
         }
     }
     if (empty($hash['contributions'])) {
         $hash['contributions'] = '';
     }
     if (empty($hash['contributors'])) {
         $hash2 = '';
     } else {
         foreach ($hash['contributors'] as $c) {
             $hash3['contributor'] = $c;
             $hash2[] = $hash3;
         }
     }
     $this->table('tiki_pages')->update($queryData, array('pageName' => $pageName));
     // Synchronize object comment
     if ($prefs['feature_wiki_description'] == 'y') {
         $query = 'update `tiki_objects` set `description`=? where `itemId`=? and `type`=?';
         $this->query($query, array($edit_description, $pageName, 'wiki page'));
     }
     //update status, page storage was updated in tiki 9 to be non html encoded
     $wikilib = TikiLib::lib('wiki');
     $converter = new convertToTiki9();
     $converter->saveObjectStatus($this->getOne("SELECT page_id FROM tiki_pages WHERE pageName = ?", array($pageName)), 'tiki_pages');
     // Parse edit_data updating the list of links from this page
     $this->clear_links($pageName);
     // Pages collected above
     foreach ($pages as $page => $types) {
         $this->replace_link($pageName, $page, $types);
     }
     if (strtolower($pageName) != 'sandbox' && !$edit_minor) {
         $maxversions = $prefs['maxVersions'];
         if ($maxversions && ($nb = $histlib->get_nb_history($pageName)) > $maxversions) {
             // Select only versions older than keep_versions days
             $keep = $prefs['keep_versions'];
             $oktodel = $saveLastModif - $keep * 24 * 3600 + 1;
             $history = $this->table('tiki_history');
             $result = $history->fetchColumn('version', array('pageName' => $pageName, 'lastModif' => $history->lesserThan($oktodel)), $nb - $maxversions, 0, array('lastModif' => 'ASC'));
             foreach ($result as $toRemove) {
                 $histlib->remove_version($pageName, $toRemove);
             }
         }
     }
     // This if no longer checks for minor-ness of the change; sendWikiEmailNotification does that.
     if ($willDoHistory) {
         $this->replicate_page_to_history($pageName);
         if (strtolower($pageName) != 'sandbox') {
             if ($prefs['feature_contribution'] == 'y') {
                 // transfer page contributions to the history
                 $contributionlib = TikiLib::lib('contribution');
                 $history = $this->table('tiki_history');
                 $historyId = $history->fetchOne($history->max('historyId'), array('pageName' => $pageName, 'version' => (int) $old_version));
                 $contributionlib->change_assigned_contributions($pageName, 'wiki page', $historyId, 'history', '', $pageName . '/' . $old_version, "tiki-pagehistory.php?page={$pageName}&preview={$old_version}");
             }
         }
         include_once 'lib/diff/difflib.php';
         if (strtolower($pageName) != 'sandbox') {
             $logslib = TikiLib::lib('logs');
             $bytes = diff2($data, $edit_data, 'bytes');
             $logslib->add_action('Updated', $pageName, 'wiki page', $bytes, $edit_user, $edit_ip, '', $this->now, $hash['contributions'], $hash2);
             if ($prefs['feature_contribution'] == 'y') {
                 $contributionlib = TikiLib::lib('contribution');
                 $contributionlib->assign_contributions($hash['contributions'], $pageName, 'wiki page', $edit_description, $pageName, "tiki-index.php?page=" . urlencode($pageName));
             }
         }
         if ($prefs['feature_multilingual'] == 'y' && $lang) {
             // Need to update the translated objects table when an object's language changes.
             $this->table('tiki_translated_objects')->update(array('lang' => $lang), array('type' => 'wiki page', 'objId' => $info['page_id']));
         }
         if ($prefs['wiki_watch_minor'] != 'n' || !$edit_minor) {
             //  Deal with mail notifications.
             include_once 'lib/notifications/notificationemaillib.php';
             $histlib = TikiLib::lib('hist');
             $old = $histlib->get_version($pageName, $old_version);
             $foo = parse_url($_SERVER["REQUEST_URI"]);
             $machine = self::httpPrefix(true) . dirname($foo["path"]);
             $diff = diff2($old["data"], $edit_data, "unidiff");
             sendWikiEmailNotification('wiki_page_changed', $pageName, $edit_user, $edit_comment, $old_version, $edit_data, $machine, $diff, $edit_minor, $hash['contributions'], 0, 0, $lang);
         }
     }
     $tx = $this->begin();
     TikiLib::events()->trigger('tiki.wiki.update', array('type' => 'wiki page', 'object' => $pageName, 'namespace' => $wikilib->get_namespace($pageName), 'reply_action' => 'comment', 'user' => $GLOBALS['user'], 'page_id' => $info['page_id'], 'version' => $version, 'data' => $edit_data, 'old_data' => $info['data']));
     $tx->commit();
 }
예제 #2
0
파일: wikilib.php 프로젝트: ameoba32/tiki
 public function wiki_attach_file($page, $name, $type, $size, $data, $comment, $user, $fhash, $date = '')
 {
     $comment = strip_tags($comment);
     $now = empty($date) ? $this->now : $date;
     $attId = $this->table('tiki_wiki_attachments')->insert(['page' => $page, 'filename' => $name, 'filesize' => (int) $size, 'filetype' => $type, 'data' => $data, 'created' => (int) $now, 'hits' => 0, 'user' => $user, 'comment' => $comment, 'path' => $fhash]);
     global $prefs;
     if ($prefs['feature_score'] == 'y') {
         $this->score_event($user, 'wiki_attach_file');
     }
     if ($prefs['feature_user_watches'] = 'y') {
         include_once 'lib/notifications/notificationemaillib.php';
         sendWikiEmailNotification('wiki_file_attached', $page, $user, $comment, '', $name, '', '', false, '', 0, $attId);
     }
     if ($prefs['feature_actionlog'] == 'y') {
         $logslib = TikiLib::lib('logs');
         $logslib->add_action('Created', $attId, 'wiki page attachment', '', $user);
     }
     return $attId;
 }
예제 #3
0
 /** Update a wiki page
 	 @param array $hash- lock_it,contributions, contributors
 	 **/
 function update_page($pageName, $edit_data, $edit_comment, $edit_user, $edit_ip, $description = '', $minor = false, $lang = '', $is_html = false, $hash = null, $saveLastModif = null, $wysiwyg = '', $wiki_authors_style)
 {
     global $smarty, $prefs, $dbTiki, $histlib, $quantifylib;
     include_once "lib/wiki/histlib.php";
     include_once "lib/commentslib.php";
     $commentslib = new Comments($dbTiki);
     if (!$edit_user) {
         $edit_user = '******';
     }
     $this->invalidate_cache($pageName);
     // Collect pages before modifying edit_data (see update of links below)
     $pages = $this->get_pages($edit_data);
     if (!$this->page_exists($pageName)) {
         return false;
     }
     // Get this page information
     $info = $this->get_page_info($pageName);
     // Use largest version +1 in history table rather than tiki_page because versions used to be bugged
     // tiki_history is also bugged as not all changes get stored in the history, like minor changes
     // and changes that do not modify the body of the page. Both numbers are wrong, but the largest of
     // them both is right.
     $old_version = max($info["version"], $histlib->get_page_latest_version($pageName) + 1);
     $lastModif = $info["lastModif"];
     $user = $info["user"];
     if (!$user) {
         $user = '******';
     }
     $ip = $info["ip"];
     $comment = $info["comment"];
     $data = $info["data"];
     // WARNING: POTENTIAL BUG
     // The line below is not consistent with the rest of Tiki
     // (I commented it out so it can be further examined by CVS change control)
     //$pageName=addslashes($pageName);
     // But this should work (comment added by redflo):
     $version = $old_version + 1;
     if ($prefs['quantify_changes'] == 'y' && $prefs['feature_multilingual'] == 'y') {
         include_once 'lib/wiki/quantifylib.php';
         $quantifylib->recordChangeSize($info['page_id'], $version, $info['data'], $edit_data);
     }
     $html = $is_html ? 1 : 0;
     if ($html && $prefs['feature_purifier'] != 'n') {
         require "HTMLPurifier.auto.php";
         $purifier = new HTMLPurifier();
         $edit_data = $purifier->purify($edit_data);
     }
     $mid = '';
     if (is_null($saveLastModif)) {
         $saveLastModif = $this->now;
     }
     $bindvars = array($description, $edit_data, $edit_comment, (int) $saveLastModif, $version, $edit_user, $edit_ip, (int) strlen($data), $html, $wysiwyg, $wiki_authors_style);
     if ($lang) {
         $mid .= ', `lang`=? ';
         $bindvars[] = $lang;
     }
     if (!empty($hash['lock_it']) && ($hash['lock_it'] == 'y' || $hash['lock_it'] == 'on')) {
         $mid .= ', `flag`=?, `lockedby`=? ';
         $bindvars[] = 'L';
         $bindvars[] = $user;
     } else {
         if (empty($hash['lock_it']) || $hash['lock_it'] == 'n') {
             $mid .= ', `flag`=?, `lockedby`=? ';
             $bindvars[] = '';
             $bindvars[] = '';
         }
     }
     if (empty($hash['contributions'])) {
         $hash['contributions'] = '';
     }
     if (empty($hash['contributors'])) {
         $hash2 = '';
     } else {
         foreach ($hash['contributors'] as $c) {
             $hash3['contributor'] = $c;
             $hash2[] = $hash3;
         }
     }
     $bindvars[] = $pageName;
     $query = "update `tiki_pages` set `description`=?, `data`=?, `comment`=?, `lastModif`=?, `version`=?, `user`=?, `ip`=?, `page_size`=?, `is_html`=?, `wysiwyg`=?, `wiki_authors_style`=?  {$mid} where `pageName`=?";
     $result = $this->query($query, $bindvars);
     // Parse edit_data updating the list of links from this page
     $this->clear_links($pageName);
     // Pages collected above
     foreach ($pages as $page) {
         $this->replace_link($pageName, $page);
     }
     if (strtolower($pageName) != 'sandbox' && !$minor) {
         $maxversions = $prefs['maxVersions'];
         if ($maxversions && ($nb = $histlib->get_nb_history($pageName)) > $maxversions) {
             // Select only versions older than keep_versions days
             $keep = $prefs['keep_versions'];
             $oktodel = $saveLastModif - $keep * 24 * 3600;
             $query = "select `pageName` ,`version`, `historyId` from `tiki_history` where `pageName`=? and `lastModif`<=? order by `lastModif` asc";
             $result = $this->query($query, array($pageName, $oktodel), $nb - $maxversions);
             $toelim = $result->numRows();
             while ($res = $result->fetchRow()) {
                 $page = $res["pageName"];
                 $version = $res["version"];
                 $query = "delete from `tiki_history` where `pageName`=? and `version`=?";
                 $this->query($query, array($pageName, $version));
                 if ($prefs['feature_contribution'] == 'y') {
                     global $contributionlib;
                     include_once 'lib/contribution/contributionlib.php';
                     $contributionlib->remove_history($res['historyId']);
                 }
             }
         }
     }
     // This if no longer checks for minor-ness of the change; sendWikiEmailNotification does that.
     if ($prefs['feature_wiki_history_full'] == 'y' || $data != $edit_data || $description != $info["description"] || $comment != $edit_comment) {
         if (strtolower($pageName) != 'sandbox') {
             $query = "insert into `tiki_history`(`pageName`, `version`, `lastModif`, `user`, `ip`, `comment`, `data`, `description`)\n\t\t    values(?,?,?,?,?,?,?,?)";
             # echo "<pre>";print_r(get_defined_vars());echo "</pre>";die();
             $result = $this->query($query, array($pageName, (int) $old_version, (int) $lastModif, $user, $ip, $comment, $data, $description));
             if ($prefs['feature_contribution'] == 'y') {
                 // transfer page contributions to the history
                 global $contributionlib;
                 include_once 'lib/contribution/contributionlib.php';
                 $query = 'select max(`historyId`) from `tiki_history`where `pageName`=? and `version`=?';
                 $historyId = $this->getOne($query, array($pageName, (int) $old_version));
                 $contributionlib->change_assigned_contributions($pageName, 'wiki page', $historyId, 'history', '', $pageName . '/' . $old_version, "tiki-pagehistory.php?page={$pageName}&preview={$old_version}");
             }
             /* the following doesn't work because tiki dies if the above query fails
             		if (!$result) {
             			$query2 = "delete from `tiki_history` where `pageName`=? and `version`=?";
             			$result = $this->query($query2,array($pageName,(int) $version));
             			$result = $this->query($query,array($pageName,(int) $version,(int) $lastModif,$user,$ip,$comment,$data,$description));
             		}
             		*/
         }
         if (strtolower($pageName) != 'sandbox') {
             global $logslib;
             include_once 'lib/logs/logslib.php';
             include_once 'lib/diff/difflib.php';
             $bytes = diff2($data, $edit_data, 'bytes');
             $logslib->add_action('Updated', $pageName, 'wiki page', $bytes, $edit_user, $edit_ip, '', $this->now, $hash['contributions'], $hash2);
             if ($prefs['feature_contribution'] == 'y') {
                 global $contributionlib;
                 include_once 'lib/contribution/contributionlib.php';
                 $contributionlib->assign_contributions($hash['contributions'], $pageName, 'wiki page', $description, $pageName, "tiki-index.php?page=" . urlencode($pageName));
             }
         }
         if ($prefs['feature_multilingual'] == 'y' && $lang) {
             // Need to update the translated objects table when an object's language changes.
             $this->query("UPDATE tiki_translated_objects SET lang = ? WHERE objId = ? AND type = 'wiki page'", array($lang, $info['page_id']));
         }
         if ($prefs['feature_user_watches'] == 'y' && $prefs['wiki_watch_minor'] != 'n') {
             //  Deal with mail notifications.
             include_once 'lib/notifications/notificationemaillib.php';
             global $histlib;
             include_once "lib/wiki/histlib.php";
             $old = $histlib->get_version($pageName, $old_version);
             $foo = parse_url($_SERVER["REQUEST_URI"]);
             $machine = $this->httpPrefix() . dirname($foo["path"]);
             require_once 'lib/diff/difflib.php';
             $diff = diff2($old["data"], $edit_data, "unidiff");
             sendWikiEmailNotification('wiki_page_changed', $pageName, $edit_user, $edit_comment, $old_version, $edit_data, $machine, $diff, $minor, $hash['contributions']);
         }
         $query = "delete from `tiki_page_drafts` where `user`=? and `pageName`=?";
         $this->query($query, array($GLOBALS['user'], $pageName));
         if ($prefs['feature_score'] == 'y') {
             $this->score_event($user, 'wiki_edit');
         }
     }
     if ($prefs['feature_search'] == 'y' && $prefs['feature_search_fulltext'] != 'y' && $prefs['search_refresh_index_mode'] == 'normal') {
         require_once 'lib/search/refresh-functions.php';
         refresh_index('pages', $pageName);
     }
 }
예제 #4
0
	function wiki_attach_file($page, $name, $type, $size, $data, $comment, $user, $fhash, $date='')
	{
		$comment = strip_tags($comment);
		$now = empty($date)? $this->now: $date;
		$query = 'insert into `tiki_wiki_attachments`' . 
						' (`page`,`filename`,`filesize`,`filetype`,`data`,`created`,`hits`,`user`,`comment`,`path`)' .
						' values(?,?,?,?,?,?,?,?,?,?)';
		$result = $this->query($query, array($page, $name, (int)$size, $type, $data, (int)$now, 0, $user, $comment, $fhash));

		global $prefs;
		if ($prefs['feature_score'] == 'y') {
			$this->score_event($user, 'wiki_attach_file');
		}
		if ($prefs['feature_user_watches'] = 'y') {
			include_once('lib/notifications/notificationemaillib.php');
			$query = 'select `attId` from `tiki_wiki_attachments` where `page`=? and `filename`=? and `created`=? and `user`=?';
			$attId = $this->getOne($query, array($page, $name, $now, $user));
			sendWikiEmailNotification('wiki_file_attached', $page, $user, $comment, '', $name, '', '', false, '', 0, $attId);
		}
		if ($prefs['feature_actionlog'] == 'y') {
			global $logslib; include_once('lib/logs/logslib.php');
			if (empty($attId)) {
				$query = 'select `attId` from `tiki_wiki_attachments` where `page`=? and `filename`=? and `created`=? and `user`=?';
				$attId = $this->getOne($query, array($page, $name, $now, $user));
			}
			$logslib->add_action('Created', $attId, 'wiki page attachment');
		}
	}