mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 17:18:51 +02:00
N°567 Enhance WikiText URLs synthax (usage of IDs and labels supported)
[[<objClass>:<objName|objId>|<label>]] <label> is optional Examples: - [[Server:db1.tnut.com]] - [[Server:123]] - [[Server:db1.tnut.com|Production server]] - [[Server:123|Production server]]
This commit is contained in:
@@ -3696,11 +3696,19 @@ class AttributeEncryptedString extends AttributeString
|
||||
}
|
||||
|
||||
|
||||
// Wiki formatting - experimental
|
||||
//
|
||||
// [[<objClass>:<objName>]]
|
||||
// Example: [[Server:db1.tnut.com]]
|
||||
define('WIKI_OBJECT_REGEXP', '/\[\[(.+):(.+)\]\]/U');
|
||||
/**
|
||||
* Wiki formatting - experimental
|
||||
*
|
||||
* [[<objClass>:<objName|objId>|<label>]]
|
||||
* <label> is optional
|
||||
*
|
||||
* Examples:
|
||||
* - [[Server:db1.tnut.com]]
|
||||
* - [[Server:123]]
|
||||
* - [[Server:db1.tnut.com|Production server]]
|
||||
* - [[Server:123|Production server]]
|
||||
*/
|
||||
define('WIKI_OBJECT_REGEXP', '/\[\[(.+):(.+)(\|(.+))?\]\]/U');
|
||||
|
||||
|
||||
/**
|
||||
@@ -3791,21 +3799,34 @@ class AttributeText extends AttributeString
|
||||
{
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (MetaModel::IsValidClass($sClass))
|
||||
{
|
||||
$oObj = MetaModel::GetObjectByName($sClass, $sName, false /* MustBeFound */);
|
||||
if (is_object($oObj))
|
||||
{
|
||||
$bFound = false;
|
||||
|
||||
// Try to find by name, then by id
|
||||
if (is_object($oObj = MetaModel::GetObjectByName($sClass, $sName, false /* MustBeFound */)))
|
||||
{
|
||||
$bFound = true;
|
||||
}
|
||||
elseif(is_object($oObj = MetaModel::GetObject($sClass, (int) $sName, false /* MustBeFound */, true)))
|
||||
{
|
||||
$bFound = true;
|
||||
}
|
||||
|
||||
if($bFound === true)
|
||||
{
|
||||
// Propose a std link to the object
|
||||
$sText = str_replace($aMatches[0], $oObj->GetHyperlink(), $sText);
|
||||
$sHyperlinkLabel = (empty($sLabel)) ? $oObj->GetName() : $sLabel;
|
||||
$sText = str_replace($aMatches[0], $oObj->GetHyperlink(null, true, $sHyperlinkLabel), $sText);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Propose a std link to the object
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sText = str_replace($aMatches[0],
|
||||
"<span class=\"wiki_broken_link\">$sClassLabel:$sName</span>", $sText);
|
||||
$sReplacement = "<span class=\"wiki_broken_link\">$sClassLabel:$sName" . (!empty($sLabel) ? " ($sLabel)" : "") . "</span>";
|
||||
$sText = str_replace($aMatches[0], $sReplacement, $sText);
|
||||
// Later: propose a link to create a new object
|
||||
// Anyhow... there is no easy way to suggest default values based on the given FRIENDLY name
|
||||
//$sText = preg_replace('/\[\[(.+):(.+)\]\]/', '<a href="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&default[att1]=xxx&default[att2]=yyy">'.$sName.'</a>', $sText);
|
||||
@@ -3859,13 +3880,15 @@ class AttributeText extends AttributeString
|
||||
{
|
||||
foreach($aAllMatches as $iPos => $aMatches)
|
||||
{
|
||||
$sClass = $aMatches[1];
|
||||
$sName = $aMatches[2];
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (MetaModel::IsValidClass($sClass))
|
||||
{
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sValue = str_replace($aMatches[0], "[[$sClassLabel:$sName]]", $sValue);
|
||||
$sReplacement = "[[$sClassLabel:$sName" . (!empty($sLabel) ? " | $sLabel" : "") . "]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3916,15 +3939,17 @@ class AttributeText extends AttributeString
|
||||
{
|
||||
foreach($aAllMatches as $iPos => $aMatches)
|
||||
{
|
||||
$sClassLabel = $aMatches[1];
|
||||
$sName = $aMatches[2];
|
||||
$sClassLabel = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (!MetaModel::IsValidClass($sClassLabel))
|
||||
{
|
||||
$sClass = MetaModel::GetClassFromLabel($sClassLabel);
|
||||
if ($sClass)
|
||||
{
|
||||
$sValue = str_replace($aMatches[0], "[[$sClass:$sName]]", $sValue);
|
||||
$sReplacement = "[[$sClassLabel:$sName" . (!empty($sLabel) ? " | $sLabel" : "") . "]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -855,17 +855,20 @@ abstract class DBObject implements iDisplay
|
||||
return $oAtt->GetAsCSV($this->GetOriginal($sAttCode), $sSeparator, $sTextQualifier, $this, $bLocalize, $bConvertToPlainText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sObjClass
|
||||
* @param $sObjKey
|
||||
* @param string $sHtmlLabel Label with HTML entities escaped (< escaped as <)
|
||||
* @param null $sUrlMakerClass
|
||||
* @param bool|true $bWithNavigationContext
|
||||
* @param bool|false $bArchived
|
||||
* @param bool|false $bObsolete
|
||||
* @return string
|
||||
* @throws DictExceptionMissingString
|
||||
*/
|
||||
/**
|
||||
* @param string $sObjClass
|
||||
* @param string $sObjKey
|
||||
* @param string $sHtmlLabel Label with HTML entities escaped (< escaped as <)
|
||||
* @param null $sUrlMakerClass
|
||||
* @param bool|true $bWithNavigationContext
|
||||
* @param bool|false $bArchived
|
||||
* @param bool|false $bObsolete
|
||||
*
|
||||
* @return string
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public static function MakeHyperLink($sObjClass, $sObjKey, $sHtmlLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true, $bArchived = false, $bObsolete = false)
|
||||
{
|
||||
if ($sObjKey <= 0) return '<em>'.Dict::S('UI:UndefinedObject').'</em>'; // Objects built in memory have negative IDs
|
||||
@@ -936,11 +939,23 @@ abstract class DBObject implements iDisplay
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true)
|
||||
/**
|
||||
* @param string $sUrlMakerClass
|
||||
* @param bool $bWithNavigationContext
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return string
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null)
|
||||
{
|
||||
if($sLabel === null)
|
||||
{
|
||||
$sLabel = $this->GetName();
|
||||
}
|
||||
$bArchived = $this->IsArchived();
|
||||
$bObsolete = $this->IsObsolete();
|
||||
return self::MakeHyperLink(get_class($this), $this->GetKey(), $this->GetName(), $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete);
|
||||
return self::MakeHyperLink(get_class($this), $this->GetKey(), $sLabel, $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete);
|
||||
}
|
||||
|
||||
public static function ComputeStandardUIPage($sClass)
|
||||
|
||||
Reference in New Issue
Block a user