Fixed bug #1839: Broken Rootline when a Editor view a Page that is not online
authorDmitry Dulepov <dmitry.dulepov@gmail.com>
Fri, 20 Apr 2007 16:29:25 +0000 (16:29 +0000)
committerDmitry Dulepov <dmitry.dulepov@gmail.com>
Fri, 20 Apr 2007 16:29:25 +0000 (16:29 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2261 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_page.php
typo3/mod/user/ws/class.wslib_gui.php
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/version/cm1/index.php

index f478c9d..d560b56 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-04-18  Dmitry Dulepov  <dmitry@typo3.org>
+
+       * Fixed bug #1839: Broken Rootline when a Editor view a Page that is not online
+
 2007-04-19     Thomas Hempel   <thomas@work.de>
        
        * Implemented feature request #3894: Open module on startup
index 02ce152..4c2f5ac 100755 (executable)
@@ -115,7 +115,7 @@ class t3lib_pageSelect {
                // Versioning preview related:
        var $versioningPreview = FALSE;         // If true, preview of other record versions is allowed. THIS MUST ONLY BE SET IF the page is not cached and truely previewed by a backend user!!!
        var $versioningWorkspaceId = 0;         // Workspace ID for preview
-
+       var     $workspaceCache = array();
 
 
                // Internal, dynamic:
@@ -799,7 +799,9 @@ class t3lib_pageSelect {
                $uid = intval($uid);
                if (is_array($TCA[$table]) || $table=='pages') {        // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).$this->deleteClause($table));
-                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       if ($row) {
                                if (!$noWSOL)   {
                                        $this->versionOL($table,$row);
                                }
@@ -1068,8 +1070,8 @@ class t3lib_pageSelect {
                                }
                        }
 
-                               // If workspace ids matches and ID of current online version is found, look up the PID value of that:
-                       if ($oid && !strcmp((int)$wsid,$this->versioningWorkspaceId))   {
+                       // If workspace ids matches and ID of current online version is found, look up the PID value of that:
+                       if ($oid && (($this->versioningWorkspaceId == 0 && $this->checkWorkspaceAccess($wsid)) || !strcmp((int)$wsid,$this->versioningWorkspaceId)))    {
                                $oidRec = $this->getRawRecord($table,$oid,'pid',TRUE);
 
                                if (is_array($oidRec))  {
@@ -1199,6 +1201,38 @@ class t3lib_pageSelect {
 
                return FALSE;   // No look up in database because versioning not enabled / or workspace not offline
        }
+
+       /**
+        * Checks if user has access to workspace.
+        * 
+        * @param       int     $wsid   Workspace ID
+        * @return      boolean <code>true</code> if has access
+        */
+       function checkWorkspaceAccess($wsid) {
+               if (!$GLOBALS['BE_USER']) {
+                       return false;
+               }
+               if (isset($this->workspaceCache[$wsid])) {
+                       $ws = $this->workspaceCache[$wsid];
+               }
+               else {
+                       if ($wsid > 0) {
+                               $ws = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_workspace', 'uid='.intval($wsid).' AND deleted=0'); // No $TCA yet!
+                               if (count($ws)) {
+                                       $ws = $ws[0];
+                               }
+                               else {
+                                       return false;
+                               }
+                       }
+                       else {
+                               $ws = $wsid;
+                       }
+                       $ws = $GLOBALS['BE_USER']->checkWorkspace($ws);
+                       $this->workspaceCache[$wsid] = $ws;
+               }
+               return ($ws['_ACCESS'] != '');
+       }
 }
 
 
index 231cfff..19ba9f0 100644 (file)
@@ -381,10 +381,24 @@ class wslib_gui {
                                                                // Traverse the versions of the element
                                                                foreach($recs as $rec)  {
 
-                                                                       // Get the offline version record and icon:
+                                                                       // Get the offline version record:
                                                                        $rec_off = t3lib_BEfunc::getRecord($table,$rec['uid']);
+
+                                                                       // Prepare swap-mode values:
+                                                                       if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1) {
+                                                                               if ($rec_off['t3ver_swapmode']>0)       {
+                                                                                       $vType = 'branch';      // Do not translate!
+                                                                               } else {
+                                                                                       $vType = 'page';        // Do not translate!
+                                                                               }
+                                                                       } else {
+                                                                               $vType = 'element';     // Do not translate!
+                                                                       }
+
+                                                                       // Get icon:
                                                                        $icon = t3lib_iconWorks::getIconImage($table, $rec_off, $this->doc->backPath, ' align="top" title="'.t3lib_BEfunc::getRecordIconAltText($rec_off,$table).'"');
-                                                                       $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $rec_off['uid'], 2, '', '+edit,view,info,delete');
+                                                                       $tempUid = ($table != 'pages' || $vType==='branch' || $GLOBALS['BE_USER']->workspace == 0 ? $rec_off['uid'] : $rec_on['uid']);
+                                                                       $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $tempUid, 2, '', '+edit,' . ($table == 'pages' ? 'view,info,' : '') . 'delete');
 
                                                                        // Prepare diff-code:
                                                                        if ($this->diff)        {
@@ -404,17 +418,6 @@ class wslib_gui {
 
                                                                        } else $diffCode = '';
 
-                                                                       // Prepare swap-mode values:
-                                                                       if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1) {
-                                                                               if ($rec_off['t3ver_swapmode']>0)       {
-                                                                                       $vType = 'branch';      // Do not translate!
-                                                                               } else {
-                                                                                       $vType = 'page';        // Do not translate!
-                                                                               }
-                                                                       } else {
-                                                                               $vType = 'element';     // Do not translate!
-                                                                       }
-
                                                                        switch($vType) {
                                                                                case 'element':
                                                                                        $swapLabel = ' ['.$LANG->getLL('label_element').']';
@@ -447,12 +450,12 @@ class wslib_gui {
                                                                        $multipleWarning = (!$mainCell && $GLOBALS['BE_USER']->workspace!==0? '<br/>'.$this->doc->icons(3).'<b>'.$LANG->getLL('label_multipleversions').'</b>' : '');
                                                                        $verWarning = $warnAboutVersions || ($warnAboutVersions_nonPages && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages'])? '<br/>'.$this->doc->icons(3).'<b>'.$LANG->getLL('label_nestedversions').'</b>' : '';
                                                                        $verElement = $icon.
-                                                                       '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.($table==='pages'?$rec_on['uid']:$rec_on['pid']).'&details='.rawurlencode($table.':'.$rec_off['uid']).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
-                                                                       t3lib_BEfunc::getRecordTitle($table,$rec_off,TRUE).
-                                                                       '</a>'.
-                                                                       $versionsInOtherWSWarning.
-                                                                       $multipleWarning.
-                                                                       $verWarning;
+                                                                               '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.($table==='pages'?$rec_on['uid']:$rec_on['pid']).'&details='.rawurlencode($table.':'.$rec_off['uid']).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
+                                                                               t3lib_BEfunc::getRecordTitle($table,$rec_off,TRUE).
+                                                                               '</a>'.
+                                                                               $versionsInOtherWSWarning.
+                                                                               $multipleWarning.
+                                                                               $verWarning;
                                                                        if ($diffCode)  {
                                                                                $verElement = '
                                                                                <table border="0" cellpadding="0" cellspacing="0" class="ver-verElement">
index 19b65c3..8e86419 100755 (executable)
                                                // Initialize the page-select functions to check rootline:
                                        $temp_sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
                                        $temp_sys_page->init($this->showHiddenPage);
-
                                                // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
                                        if (!count($temp_sys_page->getRootLine($this->id,$this->MP)) && $temp_sys_page->error_getRootLine_failPid==-1)  {
 
 
                        // If not rootline we're off...
                if (!count($this->rootLine))    {
-                       $this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
-                       exit;
+                       $ws = $this->whichWorkspace();
+                       if ($this->sys_page->error_getRootLine_failPid==-1 && $ws) {
+                               $this->sys_page->versioningPreview = TRUE;
+                               $this->versioningWorkspaceId = $ws;
+                               $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
+                       }
+                       if (!count($this->rootLine))    {
+                               $this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
+                               exit;
+                       }
+                       $this->fePreview = 1;
                }
 
                        // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
index e29e2ae..4a71f81 100755 (executable)
@@ -800,8 +800,22 @@ class tx_version_cm1 extends t3lib_SCbase {
 
                                                        // Get the offline version record and icon:
                                                $rec_off = t3lib_BEfunc::getRecord($table,$rec['uid']);
+
+                                               // Prepare swap-mode values:
+                                               if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1) {
+                                                       if ($rec_off['t3ver_swapmode']>0)       {
+                                                               $vType = 'branch';
+                                                       } else {
+                                                               $vType = 'page';
+                                                       }
+                                               } else {
+                                                       $vType = 'element';
+                                               }
+                                               
+                                               // Get icon
                                                $icon = t3lib_iconWorks::getIconImage($table, $rec_off, $this->doc->backPath, ' align="top" title="'.t3lib_BEfunc::getRecordIconAltText($rec_off,$table).'"');
-                                               $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $rec_off['uid'], 1, '', '+edit,view,info,delete');
+                                               $tempUid = ($table != 'pages' || $vType==='branch' || $GLOBALS['BE_USER']->workspace===0 ? $rec_off['uid'] : $rec_on['uid']);
+                                               $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $tempUid, 1, '', '+edit,' . ($table == 'pages' ? 'view,info,' : '') . 'delete');
 
                                                        // Prepare diff-code:
                                                if ($this->MOD_SETTINGS['diff'] || $this->diffOnly)     {
@@ -818,17 +832,6 @@ class tx_version_cm1 extends t3lib_SCbase {
                                                        }
                                                } else $diffCode = '';
 
-                                                       // Prepare swap-mode values:
-                                               if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1) {
-                                                       if ($rec_off['t3ver_swapmode']>0)       {
-                                                               $vType = 'branch';
-                                                       } else {
-                                                               $vType = 'page';
-                                                       }
-                                               } else {
-                                                       $vType = 'element';
-                                               }
-
                                                switch($vType) {
                                                        case 'element':
                                                                $swapLabel = ' [Element]';