implement wiki editing
This commit is contained in:
parent
663802e699
commit
373651c3db
@ -19,17 +19,17 @@ class NativeWiki {
|
|||||||
if($wikis) {
|
if($wikis) {
|
||||||
foreach($wikis as &$w) {
|
foreach($wikis as &$w) {
|
||||||
|
|
||||||
$w['allow_cid'] = acl2json($w['allow_cid']);
|
$w['json_allow_cid'] = acl2json($w['allow_cid']);
|
||||||
$w['allow_gid'] = acl2json($w['allow_gid']);
|
$w['json_allow_gid'] = acl2json($w['allow_gid']);
|
||||||
$w['deny_cid'] = acl2json($w['deny_cid']);
|
$w['json_deny_cid'] = acl2json($w['deny_cid']);
|
||||||
$w['deny_gid'] = acl2json($w['deny_gid']);
|
$w['json_deny_gid'] = acl2json($w['deny_gid']);
|
||||||
|
|
||||||
$w['rawName'] = get_iconfig($w, 'wiki', 'rawName');
|
$w['rawName'] = get_iconfig($w, 'wiki', 'rawName');
|
||||||
$w['htmlName'] = escape_tags($w['rawName']);
|
$w['htmlName'] = escape_tags($w['rawName']);
|
||||||
$w['urlName'] = urlencode(urlencode($w['rawName']));
|
$w['urlName'] = urlencode(urlencode($w['rawName']));
|
||||||
$w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType');
|
$w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType');
|
||||||
$w['typelock'] = get_iconfig($w, 'wiki', 'typelock');
|
$w['typelock'] = get_iconfig($w, 'wiki', 'typelock');
|
||||||
$w['lock'] = (($w['item_private'] || $w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? true : false);
|
$w['lockstate'] = (($w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? 'lock' : 'unlock');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: query db for wikis the observer can access. Return with two lists, for read and write access
|
// TODO: query db for wikis the observer can access. Return with two lists, for read and write access
|
||||||
@ -107,6 +107,47 @@ class NativeWiki {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_wiki($channel_id, $observer_hash, $arr, $acl) {
|
||||||
|
|
||||||
|
$w = self::get_wiki($channel_id, $observer_hash, $arr['resource_id']);
|
||||||
|
$item = $w['wiki'];
|
||||||
|
|
||||||
|
if(! $item) {
|
||||||
|
return array('item' => null, 'success' => false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$x = $acl->get();
|
||||||
|
|
||||||
|
$item['allow_cid'] = $x['allow_cid'];
|
||||||
|
$item['allow_gid'] = $x['allow_gid'];
|
||||||
|
$item['deny_cid'] = $x['deny_cid'];
|
||||||
|
$item['deny_gid'] = $x['deny_gid'];
|
||||||
|
$item['item_private'] = intval($acl->is_private());
|
||||||
|
|
||||||
|
if($item['title'] !== $arr['updateRawName']) {
|
||||||
|
$update_title = true;
|
||||||
|
$item['title'] = $arr['updateRawName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$update = item_store_update($item);
|
||||||
|
|
||||||
|
$item_id = $update['item_id'];
|
||||||
|
|
||||||
|
if($update['item_id']) {
|
||||||
|
info( t('Wiki updated successfully'));
|
||||||
|
if($update_title) {
|
||||||
|
// Update the wiki name information using iconfig.
|
||||||
|
if(! set_iconfig($update['item_id'], 'wiki', 'rawName', $arr['updateRawName'], true)) {
|
||||||
|
return array('item' => null, 'success' => false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array('item' => $update['item'], 'item_id' => $update['item_id'], 'success' => $update['success']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return array('item' => null, 'success' => false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static public function sync_a_wiki_item($uid,$id,$resource_id) {
|
static public function sync_a_wiki_item($uid,$id,$resource_id) {
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8');
|
$content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8');
|
||||||
}
|
}
|
||||||
elseif($iv['mimetype'] === 'text/markdown') {
|
elseif($iv['mimetype'] === 'text/markdown') {
|
||||||
$content = html_entity_decode(\Zlib\MarkdownSoap::unescape($iv['body']),ENT_COMPAT,'UTF-8');
|
$content = html_entity_decode(Zlib\MarkdownSoap::unescape($iv['body']),ENT_COMPAT,'UTF-8');
|
||||||
}
|
}
|
||||||
$fname = get_iconfig($iv['id'],'nwikipage','pagetitle') . Zlib\NativeWikiPage::get_file_ext($iv);
|
$fname = get_iconfig($iv['id'],'nwikipage','pagetitle') . Zlib\NativeWikiPage::get_file_ext($iv);
|
||||||
$zip->addFromString($fname,$content);
|
$zip->addFromString($fname,$content);
|
||||||
@ -185,6 +185,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
switch(argc()) {
|
switch(argc()) {
|
||||||
case 2:
|
case 2:
|
||||||
$wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
|
$wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
|
||||||
|
|
||||||
if($wikis) {
|
if($wikis) {
|
||||||
$o .= replace_macros(get_markup_template('wikilist.tpl'), array(
|
$o .= replace_macros(get_markup_template('wikilist.tpl'), array(
|
||||||
'$header' => t('Wikis'),
|
'$header' => t('Wikis'),
|
||||||
@ -473,36 +474,40 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
goaway('/' . argv(0) . '/' . $nick . '/');
|
goaway('/' . argv(0) . '/' . $nick . '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($wiki['urlName'] === '') {
|
$arr = [];
|
||||||
|
|
||||||
|
$arr['urlName'] = urlencode(urlencode($_POST['origRawName']));
|
||||||
|
|
||||||
|
if($_POST['updateRawName'])
|
||||||
|
$arr['updateRawName'] = $_POST['updateRawName'];
|
||||||
|
|
||||||
|
if(($arr['urlName'] || $arr['updateRawName']) === '') {
|
||||||
notice( t('Error updating wiki. Invalid name.') . EOL);
|
notice( t('Error updating wiki. Invalid name.') . EOL);
|
||||||
goaway('/wiki');
|
goaway('/wiki');
|
||||||
return; //not reached
|
return; //not reached
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = Zlib\NativeWiki::exists_by_name($owner['channel_id'], $wiki['urlName']);
|
$wiki = Zlib\NativeWiki::exists_by_name($owner['channel_id'], $arr['urlName']);
|
||||||
if($exists['id']) {
|
|
||||||
|
if($wiki['resource_id']) {
|
||||||
|
|
||||||
|
$arr['resource_id'] = $wiki['resource_id'];
|
||||||
|
|
||||||
// Get ACL for permissions
|
|
||||||
$acl = new \Zotlabs\Access\AccessList($owner);
|
$acl = new \Zotlabs\Access\AccessList($owner);
|
||||||
$acl->set_from_array($_POST);
|
$acl->set_from_array($_POST);
|
||||||
$r = Zlib\NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl);
|
|
||||||
|
$r = Zlib\NativeWiki::update_wiki($owner['channel_id'], $observer_hash, $arr, $acl);
|
||||||
if($r['success']) {
|
if($r['success']) {
|
||||||
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id'],$r['item']['resource_id']);
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id'],$r['item']['resource_id']);
|
||||||
$homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id'], $wiki['mimeType']);
|
goaway(z_root() . '/wiki/' . $nick);
|
||||||
if(! $homePage['success']) {
|
|
||||||
notice( t('Wiki created, but error creating Home page.'));
|
|
||||||
goaway(z_root() . '/wiki/' . $nick . '/' . $wiki['urlName']);
|
|
||||||
}
|
|
||||||
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$homePage['item_id'],$r['item']['resource_id']);
|
|
||||||
goaway(z_root() . '/wiki/' . $nick . '/' . $wiki['urlName'] . '/' . $homePage['page']['urlName']);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
notice( t('Error creating wiki'));
|
notice( t('Error updating wiki'));
|
||||||
goaway(z_root() . '/wiki');
|
goaway(z_root() . '/wiki');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
goaway(z_root() . '/wiki');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a wiki
|
// Delete a wiki
|
||||||
|
@ -38,14 +38,8 @@
|
|||||||
padding: 7px 3px 7px 10px;
|
padding: 7px 3px 7px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#wikis-index th:nth-child(3),
|
#wikis-index th:nth-child(6),
|
||||||
#wikis-index td:nth-child(3){
|
#wikis-index td:nth-child(6){
|
||||||
padding: 7px 10px 7px 7px;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
#wikis-index th:nth-child(4),
|
|
||||||
#wikis-index td:nth-child(4){
|
|
||||||
padding: 7px 10px 7px 7px;
|
padding: 7px 10px 7px 7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +262,14 @@ function openClose(theID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openCloseTR(theID) {
|
||||||
|
if(document.getElementById(theID).style.display == "table-row") {
|
||||||
|
document.getElementById(theID).style.display = "none";
|
||||||
|
} else {
|
||||||
|
document.getElementById(theID).style.display = "table-row";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function closeOpen(theID) {
|
function closeOpen(theID) {
|
||||||
if(document.getElementById(theID).style.display == "none") {
|
if(document.getElementById(theID).style.display == "none") {
|
||||||
document.getElementById(theID).style.display = "block";
|
document.getElementById(theID).style.display = "block";
|
||||||
|
@ -40,32 +40,34 @@
|
|||||||
<tr class="wikis-index-row">
|
<tr class="wikis-index-row">
|
||||||
<td><a href="/wiki/{{$channel}}/{{$wiki.urlName}}/Home" title="{{$view}}"{{if $wiki.active}} class="active"{{/if}}>{{$wiki.title}}</a></td>
|
<td><a href="/wiki/{{$channel}}/{{$wiki.urlName}}/Home" title="{{$view}}"{{if $wiki.active}} class="active"{{/if}}>{{$wiki.title}}</a></td>
|
||||||
<td>{{if $wiki.typelock}}{{$wiki.mimeType}}{{else}}{{$unlocked}}{{/if}}</td>
|
<td>{{if $wiki.typelock}}{{$wiki.mimeType}}{{else}}{{$unlocked}}{{/if}}</td>
|
||||||
<td class="wiki-index-tool dropdown">
|
<td class="wikis-index-tool"><i class="fa fa-pencil" onclick="openCloseTR('wikis-index-edit-{{$wiki.id}}')"></i></td>
|
||||||
{{if $wiki.lock}}
|
<td class="wikis-index-tool dropdown">
|
||||||
<button class="btn btn-default btn-sm" onclick="lockview('item',{{$wiki.id}});"><i class="fa fa-lock lockview" data-toggle="dropdown" ></i></button>
|
{{if $wiki.lockstate == 'lock'}}
|
||||||
|
<i class="fa fa-lock lockview" data-toggle="dropdown" onclick="lockview('item',{{$wiki.id}});"></i>
|
||||||
<ul id="panel-{{$wiki.id}}" class="lockview-panel dropdown-menu dropdown-menu-right"></ul>
|
<ul id="panel-{{$wiki.id}}" class="lockview-panel dropdown-menu dropdown-menu-right"></ul>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
<td class="wiki-index-tool"><button class="btn btn-default btn-sm" onclick="wiki_download_wiki('{{$wiki.resource_id}}'); return false;"><i class="fa fa-download fakelink" ></i></button></td>
|
<td class="wikis-index-tool"><i class="fa fa-download" onclick="wiki_download_wiki('{{$wiki.resource_id}}'); return false;"></i></td>
|
||||||
{{if $owner}}
|
{{if $owner}}
|
||||||
<td> </td>
|
<td><i class="fa fa-trash-o drop-icons" onclick="wiki_delete_wiki('{{$wiki.title}}', '{{$wiki.resource_id}}'); return false;"></i></td>
|
||||||
<td><button class="btn btn-default btn-sm" onclick="wiki_delete_wiki('{{$wiki.title}}', '{{$wiki.resource_id}}'); return false;"><i class="fa fa-trash-o drop-icons" ></i></button></td>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
{{if $owner}}
|
||||||
<td colspan="4">
|
<tr id="wikis-index-edit-{{$wiki.id}}" style="display:none">
|
||||||
<form id="edit-wiki-form-{{$wiki.id}}" method="post" action="wiki/{{$channel}}/update/wiki" class="acl-form" data-form_id="edit-wiki-form-{{$wiki.id}}" data-allow_cid='{{$wiki.allow_cid}}' data-allow_gid='{{$wiki.allow_gid}}' data-deny_cid='{{$wiki.deny_cid}}' data-deny_gid='{{$wiki.deny_gid}}'>
|
<td colspan="6">
|
||||||
|
<form id="edit-wiki-form-{{$wiki.id}}" method="post" action="wiki/{{$channel}}/update/wiki" class="acl-form" data-form_id="edit-wiki-form-{{$wiki.id}}" data-allow_cid='{{$wiki.json_allow_cid}}' data-allow_gid='{{$wiki.json_allow_gid}}' data-deny_cid='{{$wiki.json_deny_cid}}' data-deny_gid='{{$wiki.json_deny_gid}}'>
|
||||||
|
<input type="hidden" name="origRawName" value="{{$wiki.title}}">
|
||||||
|
{{include file="field_input.tpl" field=['updateRawName', 'Edit Wiki Name', $wiki.title]}}
|
||||||
<div class="btn-group float-right">
|
<div class="btn-group float-right">
|
||||||
{{if $lockstate}}
|
|
||||||
<button class="btn btn-outline-secondary btn-sm" data-toggle="modal" data-target="#aclModal" type="button">
|
<button class="btn btn-outline-secondary btn-sm" data-toggle="modal" data-target="#aclModal" type="button">
|
||||||
<i class="jot-perms-icon fa fa-{{$lockstate}}"></i>
|
<i class="jot-perms-icon fa fa-{{$wiki.lockstate}}"></i>
|
||||||
</button>
|
</button>
|
||||||
{{/if}}
|
|
||||||
<button class="btn btn-primary btn-sm" type="submit" value="edit">Submit</button>
|
<button class="btn btn-primary btn-sm" type="submit" value="edit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{/if}}
|
||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user