diff options
author | zotlabs <mike@macgirvin.com> | 2016-12-01 02:51:27 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2016-12-01 02:51:27 -0800 |
commit | 6c5795b519bb2ace29d8361fcad45b8d4a530035 (patch) | |
tree | 4667f6c140e892e3c60bf41a451ad6d8db88b1cc | |
parent | 6552ccc47758b0f85af785a324289796cc459eb0 (diff) | |
parent | adb9f318038f4e0f54c8b3aacb2ed821b251500a (diff) | |
download | volse-hubzilla-6c5795b519bb2ace29d8361fcad45b8d4a530035.tar.gz volse-hubzilla-6c5795b519bb2ace29d8361fcad45b8d4a530035.tar.bz2 volse-hubzilla-6c5795b519bb2ace29d8361fcad45b8d4a530035.zip |
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge
-rw-r--r-- | Zotlabs/Module/Wiki.php | 29 | ||||
-rw-r--r-- | view/tpl/wiki.tpl | 69 |
2 files changed, 48 insertions, 50 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 5cf62d2fb..5b3c4c1d8 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -44,8 +44,6 @@ class Wiki extends \Zotlabs\Web\Controller { // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...) $wiki_owner = false; $showNewWikiButton = false; - $showCommitMsg = false; - $hidePageHistory = false; $pageHistory = array(); $local_observer = null; $resource_id = ''; @@ -173,10 +171,12 @@ class Wiki extends \Zotlabs\Web\Controller { // Fetch the wiki info and determine observer permissions $wikiUrlName = urlencode(argv(2)); $pageUrlName = urlencode(argv(3)); + $w = wiki_exists_by_name($owner['channel_id'], $wikiUrlName); if(!$w['resource_id']) { notice(t('Wiki not found') . EOL); goaway('/'.argv(0).'/'.argv(1)); + return; //not reached } $resource_id = $w['resource_id']; @@ -187,6 +187,7 @@ class Wiki extends \Zotlabs\Web\Controller { if(!$perms['read']) { notice(t('Permission denied.') . EOL); goaway('/'.argv(0).'/'.argv(1)); + return; //not reached } if($perms['write']) { $wiki_editor = true; @@ -198,15 +199,18 @@ class Wiki extends \Zotlabs\Web\Controller { } $wikiheaderName = urldecode($wikiUrlName); $wikiheaderPage = urldecode($pageUrlName); + $renamePage = (($wikiheaderPage === 'Home') ? '' : t('Rename page')); + $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); if(!$p['success']) { notice(t('Error retrieving page content') . EOL); goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName); + return; //not reached } $mimeType = $p['mimeType']; - $rawContent = $p['mimeType'] == 'text/bbcode' ? htmlspecialchars_decode(json_decode($p['content']),ENT_COMPAT) : htmlspecialchars_decode($p['content'],ENT_COMPAT); + $rawContent = (($p['mimeType'] == 'text/bbcode') ? htmlspecialchars_decode(json_decode($p['content']),ENT_COMPAT) : htmlspecialchars_decode($p['content'],ENT_COMPAT)); $content = ($p['content'] !== '' ? $rawContent : '"# New page\n"'); // Render the Markdown-formatted page content in HTML if($mimeType == 'text/bbcode') { @@ -221,12 +225,11 @@ class Wiki extends \Zotlabs\Web\Controller { $showPageControls = $wiki_editor; $showNewWikiButton = $wiki_owner; $showNewPageButton = $wiki_editor; - $hidePageHistory = false; - $showCommitMsg = true; $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); break; default: // Strip the extraneous URL components - goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName); + goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName); + return; //not reached } $wikiModalID = random_string(3); @@ -241,15 +244,14 @@ class Wiki extends \Zotlabs\Web\Controller { $o .= replace_macros(get_markup_template('wiki.tpl'),array( '$wikiheaderName' => $wikiheaderName, '$wikiheaderPage' => $wikiheaderPage, + '$renamePage' => $renamePage, '$hideEditor' => $hide_editor, // True will completely hide the content section and is used for the case of no wiki selected '$chooseWikiMessage' => t('Choose an available wiki from the list on the left.'), '$showPageControls' => $showPageControls, '$editOrSourceLabel' => (($showPageControls) ? t('Edit') : t('Source')), - '$tools_label' => 'Wiki Tools', + '$tools_label' => 'Page Tools', '$showNewWikiButton'=> $showNewWikiButton, '$showNewPageButton'=> $showNewPageButton, - '$hidePageHistory' => $hidePageHistory, - '$showCommitMsg' => $showCommitMsg, '$channel' => $owner['channel_address'], '$resource_id' => $resource_id, '$page' => $pageUrlName, @@ -263,9 +265,7 @@ class Wiki extends \Zotlabs\Web\Controller { '$mimeType' => $mimeType, '$content' => $content, '$renderedContent' => $renderedContent, - '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), - '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), - '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''), + '$pageRename' => array('pageRename', t('New page name'), '', ''), '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="Short description of your changes (optional)"'), '$pageHistory' => $pageHistory['history'], '$wikiModal' => $wikiModal, @@ -282,7 +282,10 @@ class Wiki extends \Zotlabs\Web\Controller { '$modalerrorlink' => t('Error getting photo link'), '$modalerroralbum' => t('Error getting album'), )); - head_add_js('library/ace/ace.js'); // Ace Code Editor + + if($p['mimeType'] != 'text/bbcode') + head_add_js('library/ace/ace.js'); // Ace Code Editor + return $o; } diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index 726494883..33bb3c449 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -2,14 +2,16 @@ <div class="section-title-wrapper"> <div class="pull-right"> {{if $showPageControls}} - <div class="btn-group"> + <div id="page-tools" class="btn-group" style="display: none;"> <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-caret-down"></i> {{$tools_label}} </button> <ul class="dropdown-menu dropdown-menu-right"> + {{if $renamePage}} <li class="nav-item"> - <a id="rename-page" class="nav-link" href="#"><i class="fa fa-edit"></i> Rename Page</a> + <a class="nav-link rename-page" href="#"><i class="fa fa-edit"></i> {{$renamePage}}</a> </li> + {{/if}} <li class="nav-item"> <a id="embed-image" class="nav-link" href="#"><i class="fa fa-picture-o"></i> Embed Image</a> </li> @@ -28,17 +30,22 @@ <div id="rename-page-form-wrapper" class="section-content-tools-wrapper" style="display:none;"> <form id="rename-page-form" action="wiki/rename/page" method="post" > {{include file="field_input.tpl" field=$pageRename}} - <div class="btn-group pull-right"> - <button id="rename-page-submit" class="btn btn-warning" type="submit" name="submit" >Rename Page</button> + <div class="form-group"> + <div class="pull-right"> + <button id="rename-page-submit" class="btn btn-primary" type="submit" name="submit">Submit</button> + </div> + <div> + <button class="btn btn-default rename-page" type="button">Cancel</button> + </div> + <div class="clear"></div> </div> </form> - <div class="clear"></div> </div> <div id="wiki-content-container" class="section-content-wrapper" {{if $hideEditor}}style="display: none;"{{/if}}> <ul class="nav nav-tabs" id="wiki-nav-tabs"> <li id="edit-pane-tab"><a data-toggle="tab" href="#edit-pane">{{$editOrSourceLabel}}</a></li> <li class="active"><a data-toggle="tab" href="#preview-pane" id="wiki-get-preview">View</a></li> - <li {{if $hidePageHistory}}style="display: none;"{{/if}}><a data-toggle="tab" href="#page-history-pane" id="wiki-get-history">History</a></li> + <li><a data-toggle="tab" href="#page-history-pane" id="wiki-get-history">History</a></li> </ul> <div class="tab-content" id="wiki-page-tabs"> <div id="edit-pane" class="tab-pane fade"> @@ -47,7 +54,6 @@ {{else}} <textarea id="editor">{{$content}}</textarea> {{/if}} - {{if $showCommitMsg}} {{if $showPageControls}} <div> <div id="id_{{$commitMsg.0}}_wrapper" class="form-group field input"> @@ -60,14 +66,13 @@ </div> </div> {{/if}} - {{/if}} </div> <div id="preview-pane" class="tab-pane fade in active"> <div id="wiki-preview"> {{$renderedContent}} </div> </div> - <div id="page-history-pane" class="tab-pane fade" {{if $hidePageHistory}}style="display: none;"{{/if}}> + <div id="page-history-pane" class="tab-pane fade"> <div id="page-history-list"></div> </div> </div> @@ -105,17 +110,12 @@ window.wiki_page_content = {{if !$mimeType || $mimeType == 'text/markdown'}}{{$content}}{{else}}`{{$content}}`{{/if}}; window.wiki_page_commit = '{{$commit}}'; - if (window.wiki_page_name === 'Home') { - $('#delete-page').hide(); - $('#rename-page').hide(); - } - $("#generic-modal-ok-{{$wikiModalID}}").removeClass('btn-primary'); $("#generic-modal-ok-{{$wikiModalID}}").addClass('btn-danger'); - $('#rename-page').click(function (ev) { - $('#rename-page-form-wrapper').show(); - ev.preventDefault(); + $('.rename-page').click(function (ev) { + $('#rename-page-form-wrapper').toggle(); + ev.preventDefault(); }); $( "#rename-page-form" ).submit(function( event ) { @@ -155,17 +155,23 @@ editor.getSession().setValue(window.wiki_page_content); window.editor = editor; // Store the editor in the window object so the anonymous function can use it. - {{if !$showPageControls}} - editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission - {{/if}} {{else}} window.editor = editor = $('#editor'); {{/if}} + {{if !$showPageControls}} + {{if !$mimeType || $mimeType == 'text/markdown'}} + editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission + {{else}} + editor.prop('readonly', true); + {{/if}} + {{/if}} + $('#edit-pane-tab').click(function (ev) { setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry + $('#page-tools').show(); }); $('#wiki-get-preview').click(function (ev) { @@ -181,6 +187,7 @@ if (data.success) { $('#wiki-preview').html(data.html); $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); + $('#page-tools').hide(); } else { window.console.log('Error previewing page.'); } @@ -192,6 +199,7 @@ $.post("wiki/{{$channel}}/history/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id}, function (data) { if (data.success) { $('#page-history-list').html(data.historyHTML); + $('#page-tools').hide(); } else { window.console.log('Error getting page history.'); } @@ -407,27 +415,14 @@ 'json'); }; - function wiki_show_edit_wiki_form(wiki_title, wiki_resource_id) { - window.wiki_resource_id = wiki_resource_id; - window.wiki_title = wiki_title; - $('div[id^=\'edit-wiki-form-wrapper\']').hide(); - $('#new-page-form-wrapper').hide(); - $('#new-wiki-form-wrapper').hide(); - $('#edit-wiki-form-wrapper').toggle(); - return false; - } - $(document).ready(function () { wiki_refresh_page_list(); $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); + + // This seems obsolete // Show Edit tab first. Otherwise the Ace editor does not load. - $("#wiki-nav-tabs li:eq(1) a").tab('show'); - {{if $showNewWikiButton}} - $('#new-wiki-button').show(); - {{else}} - $('#new-wiki-button').hide(); - {{/if}} - // using input event instead of change since it's called with some timeout + //$("#wiki-nav-tabs li:eq(1) a").tab('show'); + {{if !$mimeType || $mimeType == 'text/markdown'}} window.editor.on("input", function() { if(window.editor.getSession().getUndoManager().isClean()) { |