Просмотр исходного кода

#2304 Wiki functionality: delete block

Alex Trofimov 6 лет назад
Родитель
Сommit
5793e64326

+ 45 - 8
inc/classes/BxDolWiki.php

@@ -124,18 +124,29 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
     {
         if (!$sLang)
             $sLang = bx_lang_name();
+
+        $s = '';
+        $sControls = '';
         $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLang, $iRevision);
-        if (!$aWikiVer) {
-            return _t('_sys_wiki_error_no_rev', $iRevision, $sLang);
-        }
         $aWikiLatest = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
+        if ($aWikiVer) {             
+            require_once(BX_DIRECTORY_PATH_PLUGINS . "parsedown/Parsedown.php");
+            $oParsedown = new Parsedown();
+            $oParsedown->setSafeMode($aWikiVer['unsafe'] ? false : true);
+            $s = $oParsedown->text($aWikiVer['content']);
+        }
 
-        require_once(BX_DIRECTORY_PATH_PLUGINS . "parsedown/Parsedown.php");
-        $oParsedown = new Parsedown();
-        $oParsedown->setSafeMode($aWikiVer['unsafe'] ? false : true);
-        $s = $oParsedown->text($aWikiVer['content']);
+        if (!$aWikiVer && $aWikiLatest) {
+            return _t('_sys_wiki_error_no_rev', $iRevision ? $iRevision : 0, $sLang);
+        }
 
-        $sControls = BxDolService::call('system', 'wiki_controls', array($this, $aWikiVer, $aWikiLatest, $iBlockId), 'TemplServiceWiki');
+        if (!$aWikiVer && !$aWikiLatest && $this->isAllowed('edit')) {
+            $s = _t('_sys_wiki_error_no_revs');
+        }
+
+        if ($aWikiVer || (!$aWikiVer && $this->isAllowed('edit'))) {
+            $sControls = BxDolService::call('system', 'wiki_controls', array($this, $aWikiVer, $aWikiLatest, $iBlockId), 'TemplServiceWiki');
+        }
 
         return $s . $sControls;
     }
@@ -198,6 +209,12 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         $aVars = $this->getVarsForHistory($iBlockId, $sLang);
         $aVars['select_all'] = _t('_Select_all');
 
+        if (!$aVars['bx_repeat:revisions'])
+            return BxDolTemplate::getInstance()->parseHtmlByName('wiki_msg.html', array(
+                'close' => _t('_sys_close'),
+                'msg' => _t('_sys_wiki_error_no_revs'),
+            ));
+
         $aForm = array(
             'form_attrs' => array(
                 'name' => 'bx-wiki-del-rev',
@@ -262,6 +279,18 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         }
     }
 
+    public function actionDeleteBlock ()
+    {
+        $iBlockId = (int)bx_get('block_id');
+
+        $oQueryPageBuilder = new BxDolStudioBuilderPageQuery();
+        if (!$oQueryPageBuilder->deleteBlocks(array('type' => 'by_id', 'value' => $iBlockId)))
+            return array('code' => 3, 'actions' => array('ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_txt_error_occured'));
+
+        $this->_oQuery->deleteAllRevisions($iBlockId);
+
+        return array('code' => 0, 'actions' => array('Reload', 'ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_wiki_block_deleted'));
+    }
     public function actionHistory ()
     {
         $iBlockId = (int)bx_get('block_id');
@@ -271,6 +300,7 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         $aVars = $this->getVarsForHistory($iBlockId, $sLang);
         $aVars['lang'] = $oLang->getLangTitle($oLang->getLangId($sLang));
         $aVars['close'] = _t('_sys_close');
+        $aVars['msg'] = $aVars['bx_repeat:revisions'] ? '' : _t('_sys_wiki_error_no_revs');
         return BxDolTemplate::getInstance()->parseHtmlByName('wiki_history.html', $aVars);
     }
 
@@ -287,6 +317,13 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         $sLangForTranslate = '';
         $aLangsForInput = $this->getLangsForInput ($iBlockId, $bTranslate, $sMainLangLabel, $aWikiVerMain, $sLangForTranslate);
 
+        // don't allow to translate empty blocks
+        if (!$aWikiVerMain && $bTranslate)
+            return BxDolTemplate::getInstance()->parseHtmlByName('wiki_msg.html', array(
+                'close' => _t('_sys_close'),
+                'msg' => _t('_sys_wiki_error_no_revs'),
+            ));
+
         // get latest revision for block with current lang
         if ($bTranslate) {
             $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLangForTranslate, false, false);

+ 6 - 0
inc/classes/BxDolWikiQuery.php

@@ -74,6 +74,12 @@ class BxDolWikiQuery extends BxDolDb
         $aBind = array('block' => $iBlockId, 'lang' => $sLang);
         return $this->query("DELETE FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `lang` = :lang AND `revision` IN(" . $this->implode_escape($aRevisions) . ")", $aBind);
     }
+
+    public function deleteAllRevisions ($iBlockId)
+    {
+        $aBind = array('block' => $iBlockId);
+        return $this->query("DELETE FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block", $aBind);
+    }
 }
 
 /** @} */

+ 8 - 2
inc/js/classes/BxDolWiki.js

@@ -98,7 +98,13 @@ BxDolWiki.prototype.onDeleteVersion = function () {
 };
 
 BxDolWiki.prototype.onDeleteBlock = function () {
-    console.log("onDeleteBlock:" + this._sObject);
+    if (!confirm(this._oOptions.t_confirm_block_deletion))
+        return;
+
+    var self = this;
+    $.post(this._sActionUrl + 'delete-block', {block_id: this._oOptions.block_id}, function (oData) {
+        self.processResponce(oData);
+    }, 'json');
 };
 
 BxDolWiki.prototype.onHistory = function () {
@@ -150,7 +156,7 @@ BxDolWiki.prototype.popup = function (sAction) {
     this.removePopup();
 
     // show new popup
-    $(window).dolPopupAjax({url: sActionUrl});
+    $(window).dolPopupAjax({url: sActionUrl, closeOnOuterClick: false});
 };
 
 /** @} */

+ 4 - 1
modules/boonex/english/data/langs/system/en.xml

@@ -3111,7 +3111,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_javascript_requred"><![CDATA[This site requires JavaScript! Please, enable it in the browser!]]></string>
 	<string name="_sys_wiki_system_title"><![CDATA[System WIKI]]></string>
 	<string name="_sys_wiki_error_page_exists"><![CDATA[Page with such name({0}) already exists]]></string>
-	<string name="_sys_wiki_error_no_rev"><![CDATA[There is no {0} revision exists for {1} language]]></string>
+	<string name="_sys_wiki_error_no_rev"><![CDATA[There is no {0} revision exist for {1} language]]></string>
+	<string name="_sys_wiki_error_no_revs"><![CDATA[There is no revisions available for this block]]></string>
 	<string name="_sys_wiki_error_missing_wiki_object"><![CDATA[Wiki object ({0}) wasn't found]]></string>
     <string name="_sys_wiki_error_action_not_allowed"><![CDATA[Wiki object ({1}) action ({0}) isn't allowed]]></string>
     <string name="_sys_wiki_view_rev"><![CDATA[Version <b>{0}</b> by <a href="{1}">{2}</a>, {3}]]></string>
@@ -3119,5 +3120,7 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_wiki_lang_mask_warn"><![CDATA[{0} {1} <span class="bx-def-font-small" style="color:red;">{2}</span>]]></string>
     <string name="_sys_wiki_lang_missing"><![CDATA[missing]]></string>
     <string name="_sys_wiki_revisions_deleted"><![CDATA[{0} revisions were deleted]]></string>
+    <string name="_sys_wiki_confirm_block_deletion"><![CDATA[Are you sure you want to permanently delete this block with all revisions and translations?]]></string>
+    <string name="_sys_wiki_block_deleted"><![CDATA[Block was successfully deleted]]></string>
 	
 </resources>

+ 3 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -3092,6 +3092,7 @@
 	<string name="_sys_wiki_system_title"><![CDATA[Системная Вики]]></string>
 	<string name="_sys_wiki_error_page_exists"><![CDATA[Страница с таким именем ({0}) уже существует]]></string>
     <string name="_sys_wiki_error_no_rev"><![CDATA[Ревизия {0} для {1} языка не существует]]></string>
+    <string name="_sys_wiki_error_no_revs"><![CDATA[Нет ревизий для данного блока]]></string>
     <string name="_sys_wiki_error_missing_wiki_object"><![CDATA[Вики объект ({0}) не найден]]></string>
     <string name="_sys_wiki_error_action_not_allowed"><![CDATA[Не разрешенное действие ({0}) для вики объекта ({1})]]></string>
     <string name="_sys_wiki_view_rev"><![CDATA[Версия <b>{0}</b> от <a href="{1}">{2}</a>, {3}]]></string>
@@ -3099,5 +3100,7 @@
     <string name="_sys_wiki_lang_mask_warn"><![CDATA[{0} {1} <span class="bx-def-font-small" style="color:red;">{2}</span>]]></string>
     <string name="_sys_wiki_lang_missing"><![CDATA[отсутствует]]></string>
     <string name="_sys_wiki_revisions_deleted"><![CDATA[{0} ревизий было удалено]]></string>
+    <string name="_sys_wiki_confirm_block_deletion"><![CDATA[Подтвердите удаление блока со всей историей и переводами?]]></string>
+    <string name="_sys_wiki_block_deleted"><![CDATA[Блок был успешно удален]]></string>
 
 </resources>

+ 2 - 1
template/scripts/BxBasePage.php

@@ -265,7 +265,8 @@ class BxBasePage extends BxDolPage
      */
     protected function _getBlockOnlyCode ($iBlockId)
     {
-        $aBlock = $this->_oQuery->getPageBlock((int)$iBlockId);
+        if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
+            return '';
         return $this->_getBlockCode($aBlock);
     }
 

+ 4 - 2
template/scripts/BxBaseServiceWiki.php

@@ -128,10 +128,11 @@ class BxBaseServiceWiki extends BxDol
 
         $oMenu->setMenuObject($oWikiObject);
 
-        if ($aWikiVerLatest['revision'] == $aWikiVer['revision']) {
+        $sInfo = '';
+        if ($aWikiVer && $aWikiVerLatest['revision'] == $aWikiVer['revision']) {
             $sInfo = bx_time_js($aWikiVer['added']);
         } 
-        else {
+        elseif ($aWikiVer) {
             $oProfile = BxDolProfile::getInstanceMagic($aWikiVer['profile_id']);
             $sInfo = _t('_sys_wiki_view_rev', $aWikiVer['revision'], $oProfile->getUrl(), $oProfile->getDisplayName(), bx_time_js($aWikiVer['added']));
         }
@@ -147,6 +148,7 @@ class BxBaseServiceWiki extends BxDol
                 'block_id' => $sBlockId,
                 'lang' => $aWikiVer['lang'],
                 'wiki_action_uri' => $oWikiObject->getWikiUri(),
+                't_confirm_block_deletion' => _t('_sys_wiki_confirm_block_deletion'),
             )),
         ));
     }

+ 1 - 0
template/wiki_history.html

@@ -9,4 +9,5 @@
     </tr>
 </bx_repeat:revisions>
 </table>
+<div>__msg__</div>
 <button class="bx-btn bx-def-margin-topbottom" onclick="$('.bx-popup-applied:visible').dolPopupHide();">__close__</button>

+ 2 - 0
template/wiki_msg.html

@@ -0,0 +1,2 @@
+<div class="bx-wiki-msg">__msg__</div>
+<button class="bx-btn bx-def-margin-topbottom" onclick="$('.bx-popup-applied:visible').dolPopupHide();">__close__</button>