Bladeren bron

#2304 Wiki functionality: history

Alex Trofimov 6 jaren geleden
bovenliggende
commit
c84954ea47

+ 5 - 0
inc/classes/BxDolLanguages.php

@@ -103,6 +103,11 @@ class BxDolLanguages extends BxDolFactory implements iBxDolSingleton
         return $this->oDb->getLanguageName($iLangId);
     }
 
+    function getLangTitle($iLangId)
+    {
+        return $this->oDb->getLanguageTitle($iLangId);
+    }
+
     function getLangFlag($sLang = '')
     {
         if (!$sLang)

+ 5 - 0
inc/classes/BxDolLanguagesQuery.php

@@ -47,6 +47,11 @@ class BxDolLanguagesQuery extends BxDolDb implements iBxDolSingleton
         return $this->getLanguageFieldById($iId, 'Name', $bFromCache);
     }
 
+    function getLanguageTitle($iId, $bFromCache = true)
+    {
+        return $this->getLanguageFieldById($iId, 'Title', $bFromCache);
+    }
+
     function getLanguageFlag($sName, $bFromCache = true)
     {
         return $this->getLanguageField($sName, 'Flag', $bFromCache);

+ 35 - 12
inc/classes/BxDolWiki.php

@@ -120,18 +120,22 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
      * @param $sLang optional language name
      * @return block content
      */
-    public function getBlockContent ($iBlockId, $sLang = false)
+    public function getBlockContent ($iBlockId, $sLang = false, $iRevision = false)
     {
         if (!$sLang)
             $sLang = bx_lang_name();
-        $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
+        $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLang, $iRevision);
+        if (!$aWikiVer) {
+            return _t('_sys_wiki_error_no_rev', $iRevision, $sLang);
+        }
+        $aWikiLatest = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
 
         require_once(BX_DIRECTORY_PATH_PLUGINS . "parsedown/Parsedown.php");
         $oParsedown = new Parsedown();
         $oParsedown->setSafeMode($aWikiVer['unsafe'] ? false : true);
         $s = $oParsedown->text($aWikiVer['content']);
 
-        $sControls = BxDolService::call('system', 'wiki_controls', array($this, $aWikiVer, $iBlockId), 'TemplServiceWiki');
+        $sControls = BxDolService::call('system', 'wiki_controls', array($this, $aWikiVer, $aWikiLatest, $iBlockId), 'TemplServiceWiki');
 
         return $s . $sControls;
     }
@@ -144,10 +148,13 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
      */
     public function isAllowed ($sType, $iProfileId = false)
     {
-        if (isAdmin())
-            return true;
+        if ('translate' == $sType) {
+            $aLangs = BxDolLanguages::getInstance()->getLanguages(false, true);
+            if (count($aLangs) < 2)
+                return false;
+        }
 
-        if ('history' == $sType)
+        if (isAdmin())
             return true;
 
         $aTypes = array(
@@ -170,12 +177,7 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
             return false;
 
         $oAcl = BxDolAcl::getInstance();
-        $bResult = $oAcl->isMemberLevelInSet($this->_aObject[$aTypes[$sType]], $iProfileId); 
-        if ($bResult && 'translate' == $sType) {
-            $aLangs = BxDolLanguages::getInstance()->getLanguages(false, true);
-            return count($aLangs) > 1;
-        }
-        return $bResult;
+        return $oAcl->isMemberLevelInSet($this->_aObject[$aTypes[$sType]], $iProfileId);
     }
 
     public function actionGetTranslation ()
@@ -187,6 +189,27 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
             return array('code' => 0, 'lang' => $aWikiVer['lang'], 'content' => $aWikiVer['content'], 'block_id' => $aWikiVer['block_id']);
     }
 
+    public function actionHistory ()
+    {
+        $iBlockId = (int)bx_get('block_id');
+        $sLang = bx_lang_name();
+        $oLang = BxDolLanguages::getInstance();
+
+        $a = $this->_oQuery->getBlockHistory($iBlockId, $sLang);
+
+        $aVars = array('lang' => $oLang->getLangTitle($oLang->getLangId($sLang)), 'bx_repeat:revisions' => array());
+        foreach ($a as $r) {
+            $oProfile = BxDolProfile::getInstanceMagic($r['profile_id']);
+            list($sPageLink, $aPageParams) = bx_get_base_url_popup(array($r['block_id'].'rev' => $r['revision']));
+            $r['author_url'] = $oProfile->getUrl();
+            $r['author_name'] = $oProfile->getDisplayName();
+            $r['timejs'] = bx_time_js($r['added']);
+            $r['rev_url'] = bx_append_url_params($sPageLink, $aPageParams);
+            $aVars['bx_repeat:revisions'][] = $r;
+        }
+        return BxDolTemplate::getInstance()->parseHtmlByName('wiki_history.html', $aVars);
+    }
+
     public function actionTranslate ()
     {
         return $this->actionEdit (true);

+ 8 - 2
inc/classes/BxDolWikiQuery.php

@@ -52,16 +52,22 @@ class BxDolWikiQuery extends BxDolDb
         }
 
         // get latest revision for specific language
-        $aRow = $this->getRow("SELECT `block_id`, `revision`, `lang`, `main_lang`, `content`, `unsafe`, `notes`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `lang` = :lang $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
+        $aRow = $this->getRow("SELECT `block_id`, `revision`, `profile_id`, `lang`, `main_lang`, `content`, `unsafe`, `notes`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `lang` = :lang $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
 
         // if translation isn't found for specific language then get latest revision for main language 
         if ($bAutoMainLang && !$aRow) {
             unset($aBind['lang']);
-            $aRow = $this->getRow("SELECT `block_id`, `revision`, `lang`, `main_lang`, `content`, `unsafe`, `notes`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `main_lang` = 1 $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
+            $aRow = $this->getRow("SELECT `block_id`, `revision`, `profile_id`, `lang`, `main_lang`, `content`, `unsafe`, `notes`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `main_lang` = 1 $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
         }
 
         return $aRow ? $aRow : false;
     }
+
+    public function getBlockHistory ($iBlockId, $sLang)
+    {
+        $aBind = array('block' => $iBlockId, 'lang' => $sLang);
+        return $this->getAll("SELECT `block_id`, `lang`, `revision`, `profile_id`, `notes`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `lang` = :lang ORDER BY `revision` DESC", $aBind);
+    }
 }
 
 /** @} */

+ 23 - 19
inc/js/classes/BxDolWiki.js

@@ -40,24 +40,6 @@ BxDolWiki.prototype.removePopup = function (iBlockId) {
     $("#bx-wiki-form-" + iBlockId).parents(".bx-popup-wrapper").remove(); 
 }
 
-BxDolWiki.prototype.onTranslate = function () {
-    this.onEdit('translate');
-};
-
-BxDolWiki.prototype.onEdit = function (sAction) {
-    
-    var self = this;
-    var sActionUrl = bx_append_url_params(this._sActionUrl + ('undefined' === typeof(sAction) ? 'edit' : sAction), {
-        block_id: this._oOptions.block_id
-    });
-
-    // remove previous popup
-    this.removePopup();
-
-    // show new popup
-    $(window).dolPopupAjax({url: sActionUrl});
-};
-
 BxDolWiki.prototype.getTranslations = function () {
     return this._oTranslations;
 }
@@ -101,6 +83,14 @@ BxDolWiki.prototype.onChangeLangSelector = function (e) {
     }
 };
 
+BxDolWiki.prototype.onTranslate = function () {
+    this.popup('translate');
+};
+
+BxDolWiki.prototype.onEdit = function () {
+    this.popup('edit');
+};
+
 BxDolWiki.prototype.onDeleteVersion = function () {
     console.log("onDeleteVersion:" + this._sObject);
 };
@@ -110,7 +100,7 @@ BxDolWiki.prototype.onDeleteBlock = function () {
 };
 
 BxDolWiki.prototype.onHistory = function () {
-    console.log("onHistory:" + this._sObject);
+    this.popup('history');
 };
 
 BxDolWiki.prototype.processResponce = function (oResponce) {
@@ -147,4 +137,18 @@ BxDolWiki.prototype.actionReload = function (oResponce) {
     loadDynamicBlock(oResponce.block_id, document.location.href);
 }
 
+BxDolWiki.prototype.popup = function (sAction) {
+    
+    var self = this;
+    var sActionUrl = bx_append_url_params(this._sActionUrl + sAction, {
+        block_id: this._oOptions.block_id
+    });
+
+    // remove previous popup
+    this.removePopup();
+
+    // show new popup
+    $(window).dolPopupAjax({url: sActionUrl});
+};
+
 /** @} */

+ 2 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -3111,8 +3111,10 @@ 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_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>
     <string name="_sys_wiki_lang_mask"><![CDATA[{0} {1} <span class="bx-def-font-grayed bx-def-font-small">{2}</span>]]></string>
     <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>

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

@@ -3091,8 +3091,10 @@
   <string name="_sys_javascript_requred"><![CDATA[Для корректной работы нужен включенный JavaScript! Пожалуйста, включите его в барузере!]]></string>
 	<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_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>
     <string name="_sys_wiki_lang_mask"><![CDATA[{0} {1} <span class="bx-def-font-grayed bx-def-font-small">{2}</span>]]></string>
     <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>

+ 11 - 0
template/css/wiki.css

@@ -18,3 +18,14 @@
     overflow:auto;
     margin:0;
 }
+.bx-wiki-history-title {
+    margin:0;
+}
+.bx-wiki-history {
+    border-collapse:collapse;
+}
+.bx-wiki-history-cell-profile,
+.bx-wiki-history-cell-time,
+.bx-wiki-history-cell-rev {
+    text-align:center;
+}

+ 1 - 1
template/scripts/BxBasePage.php

@@ -399,7 +399,7 @@ class BxBasePage extends BxDolPage
             $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
         } 
         else {
-            $sContent = $oWiki->getBlockContent($aBlock['id']);
+            $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
             $sContent = bx_process_macros($sContent);
         }
 

+ 11 - 2
template/scripts/BxBaseServiceWiki.php

@@ -119,7 +119,7 @@ class BxBaseServiceWiki extends BxDol
     /** 
      * @ref bx_system_general-wiki_page "wiki_page"
      */
-    public function serviceWikiControls ($oWikiObject, $aWikiVer, $sBlockId)
+    public function serviceWikiControls ($oWikiObject, $aWikiVer, $aWikiVerLatest, $sBlockId)
     {
         $this->_addCssJs ();
     
@@ -128,12 +128,21 @@ class BxBaseServiceWiki extends BxDol
 
         $oMenu->setMenuObject($oWikiObject);
 
+        if ($aWikiVerLatest['revision'] == $aWikiVer['revision']) {
+            $sInfo = bx_time_js($aWikiVer['added']);
+        } 
+        else {
+            $oProfile = BxDolProfile::getInstanceMagic($aWikiVer['profile_id']);
+            $sInfo = _t('_sys_wiki_view_rev', $aWikiVer['revision'], $oProfile->getUrl(), $oProfile->getDisplayName(), bx_time_js($aWikiVer['added']));
+        }
+
         $o = BxDolTemplate::getInstance();        
         return $o->parseHtmlByName('wiki_controls.html', array(
             'obj' => $oWikiObject->getObjectName(),
             'block_id' => $sBlockId,
             'menu' => $oMenu->getCode(),
-            'info' => bx_time_js($aWikiVer['added']), // 'TODO: On right - Last modified time and List of missing and outdated translations. History and Last modified time should be controlled by regular menu privacy, while other actions should have custom privacy for particular wiki object',
+            // 'TODO: On right - Last modified time and List of missing and outdated translations. History and Last modified time should be controlled by regular menu privacy, while other actions should have custom privacy for particular wiki object',
+            'info' => $sInfo,
             'options' => json_encode(array(
                 'block_id' => $sBlockId,
                 'lang' => $aWikiVer['lang'],

+ 11 - 0
template/wiki_history.html

@@ -0,0 +1,11 @@
+<h3 class="bx-wiki-history-title bx-def-h3">__lang__</h3>
+<table class="bx-wiki-history bx-def-margin-sec-top">
+<bx_repeat:revisions>
+    <tr>
+        <td class="bx-wiki-history-cell-rev bx-def-border bx-def-padding-thd"><a href="__rev_url__">__revision__</a></td>
+        <td class="bx-wiki-history-cell-time bx-def-border bx-def-padding-thd">__timejs__</td>
+        <td class="bx-wiki-history-cell-profile bx-def-border bx-def-padding-thd"><a href="__author_url__">__author_name__</a></td>
+        <td class="bx-wiki-history-cell-notes bx-def-border bx-def-padding-thd">__notes__</td>
+    </tr>
+</bx_repeat:revisions>
+</table>