From: <var...@us...> - 2011-11-28 16:58:07
|
Revision: 8187 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=8187&view=rev Author: vargenau Date: 2011-11-28 16:58:01 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Fix indentation Modified Paths: -------------- trunk/lib/CachedMarkup.php Modified: trunk/lib/CachedMarkup.php =================================================================== --- trunk/lib/CachedMarkup.php 2011-11-28 15:13:31 UTC (rev 8186) +++ trunk/lib/CachedMarkup.php 2011-11-28 16:58:01 UTC (rev 8187) @@ -27,16 +27,15 @@ function CacheableMarkup($content, $basepage) { $this->_basepage = $basepage; - $this->_buf = ''; - $this->_content = array(); - $this->_append($content); - if ($this->_buf != '') - $this->_content[] = $this->_buf; - unset($this->_buf); + $this->_buf = ''; + $this->_content = array(); + $this->_append($content); + if ($this->_buf != '') + $this->_content[] = $this->_buf; + unset($this->_buf); } function pack() { - // FusionForge hack // This causes a strange bug when a comment containing // a single quote is entered in the Summary box: @@ -94,9 +93,9 @@ * @return array of hashes { linkto=>pagename, relation=>pagename } */ function getWikiPageLinks() { - $links = array(); - foreach ($this->_content as $item) { - if (!isa($item, 'Cached_DynamicContent')) + $links = array(); + foreach ($this->_content as $item) { + if (!isa($item, 'Cached_DynamicContent')) continue; if (!($item_links = $item->getWikiPageLinks($this->_basepage))) continue; @@ -104,8 +103,8 @@ } // array_unique has a bug with hashes! // set_links checks for duplicates, array_merge does not - //return array_unique($links); - return $links; + //return array_unique($links); + return $links; } /** Get link info. @@ -116,63 +115,63 @@ * Returns an array of hashes. */ function getLinkInfo() { - $link = array(); - foreach ($this->_content as $link) { - if (! isa($link, 'Cached_Link')) - continue; - $info = $link->getLinkInfo($this->_basepage); - $links[$info->href] = $info; + $link = array(); + foreach ($this->_content as $link) { + if (! isa($link, 'Cached_Link')) + continue; + $info = $link->getLinkInfo($this->_basepage); + $links[$info->href] = $info; + } + return array_values($links); } - return array_values($links); - } function _append($item) { - if (is_array($item)) { - foreach ($item as $subitem) - $this->_append($subitem); - } - elseif (!is_object($item)) { - $this->_buf .= $this->_quote((string) $item); - } - elseif (isa($item, 'Cached_DynamicContent')) { - if ($this->_buf) { - $this->_content[] = $this->_buf; - $this->_buf = ''; + if (is_array($item)) { + foreach ($item as $subitem) + $this->_append($subitem); } - $this->_content[] = $item; - } - elseif (isa($item, 'XmlElement')) { - if ($item->isEmpty()) { - $this->_buf .= $item->emptyTag(); + elseif (!is_object($item)) { + $this->_buf .= $this->_quote((string) $item); } - else { - $this->_buf .= $item->startTag(); - foreach ($item->getContent() as $subitem) - $this->_append($subitem); - $this->_buf .= "</$item->_tag>"; + elseif (isa($item, 'Cached_DynamicContent')) { + if ($this->_buf) { + $this->_content[] = $this->_buf; + $this->_buf = ''; + } + $this->_content[] = $item; + } + elseif (isa($item, 'XmlElement')) { + if ($item->isEmpty()) { + $this->_buf .= $item->emptyTag(); + } + else { + $this->_buf .= $item->startTag(); + foreach ($item->getContent() as $subitem) + $this->_append($subitem); + $this->_buf .= "</$item->_tag>"; if (!$this->getDescription() and $item->getTag() == 'p') { // performance: when is this really needed? $this->_glean_description($item->asString()); } + } + if (!$item->isInlineElement()) + $this->_buf .= "\n"; } - if (!$item->isInlineElement()) - $this->_buf .= "\n"; + elseif (isa($item, 'XmlContent')) { + foreach ($item->getContent() as $item) + $this->_append($item); + } + elseif (method_exists($item, 'asXML')) { + $this->_buf .= $item->asXML(); + } + elseif (method_exists($item, 'asString')) { + $this->_buf .= $this->_quote($item->asString()); + } + else { + $this->_buf .= sprintf("==Object(%s)==", get_class($item)); + } } - elseif (isa($item, 'XmlContent')) { - foreach ($item->getContent() as $item) - $this->_append($item); - } - elseif (method_exists($item, 'asXML')) { - $this->_buf .= $item->asXML(); - } - elseif (method_exists($item, 'asString')) { - $this->_buf .= $this->_quote($item->asString()); - } - else { - $this->_buf .= sprintf("==Object(%s)==", get_class($item)); - } - } function _glean_description($text) { static $two_sentences; @@ -206,10 +205,10 @@ } function asXML () { - $xml = ''; + $xml = ''; $basepage = $this->_basepage; - foreach ($this->_content as $item) { + foreach ($this->_content as $item) { if (is_string($item)) { $xml .= $item; } @@ -224,15 +223,15 @@ else { $xml .= $item->asXML(); } + } + return $xml; } - return $xml; - } function printXML () { $basepage = $this->_basepage; // _content might be changed from a plugin (CreateToc) - for ($i=0; $i < count($this->_content); $i++) { - $item = $this->_content[$i]; + for ($i=0; $i < count($this->_content); $i++) { + $item = $this->_content[$i]; if (is_string($item)) { print $item; } @@ -249,8 +248,8 @@ else { $item->printXML(); } + } } - } } /** @@ -262,7 +261,7 @@ class Cached_DynamicContent { function cache(&$cache) { - $cache[] = $this; + $cache[] = $this; } function expand($basepage, &$obj) { @@ -276,18 +275,18 @@ class XmlRpc_LinkInfo { function XmlRpc_LinkInfo($page, $type, $href, $relation = '') { - $this->page = $page; - $this->type = $type; - $this->href = $href; - $this->relation = $relation; - //$this->pageref = str_replace("/RPC2.php", "/index.php", $href); + $this->page = $page; + $this->type = $type; + $this->href = $href; + $this->relation = $relation; + //$this->pageref = str_replace("/RPC2.php", "/index.php", $href); } } class Cached_Link extends Cached_DynamicContent { function isInlineElement() { - return true; + return true; } /** Get link info (for XML-RPC support) @@ -296,17 +295,17 @@ * (See http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface) */ function getLinkInfo($basepage) { - return new XmlRpc_LinkInfo($this->_getName($basepage), + return new XmlRpc_LinkInfo($this->_getName($basepage), $this->_getType(), $this->_getURL($basepage), $this->_getRelation($basepage)); } function _getURL($basepage) { - return $this->_url; + return $this->_url; } function __getRelation($basepage) { - return $this->_relation; + return $this->_relation; } } /* @@ -315,34 +314,34 @@ */ class Cached_InlinedImage extends Cached_DynamicContent { function isInlineElement() { - return true; + return true; } function _getURL($basepage) { - return $this->_url; + return $this->_url; } // TODO: fix interwiki inline links in case of static dumps function expand($basepage, &$markup) { - global $WikiTheme; + global $WikiTheme; $this->_basepage = $basepage; - $label = isset($this->_label) ? $this->_label : false; - if ($WikiTheme->DUMP_MODE) { + $label = isset($this->_label) ? $this->_label : false; + if ($WikiTheme->DUMP_MODE) { // In case of static dumps we need to check if we should // inline the image or not: external: keep link, internal: copy locally - return LinkImage($label); - } else { - return LinkImage($label); + return LinkImage($label); + } else { + return LinkImage($label); + } } - } } class Cached_WikiLink extends Cached_Link { function Cached_WikiLink ($page, $label = false, $anchor = false) { - $this->_page = $page; - /* ":DontStoreLink" */ - if (substr($this->_page,0,1) == ':') { - $this->_page = substr($this->_page,1); - $this->_nolink = true; + $this->_page = $page; + /* ":DontStoreLink" */ + if (substr($this->_page,0,1) == ':') { + $this->_page = substr($this->_page,1); + $this->_nolink = true; } if ($anchor) $this->_anchor = $anchor; @@ -357,13 +356,13 @@ function getPagename($basepage) { $page = new WikiPageName($this->_page, $basepage); - if ($page->isValid()) return $page->name; - else return false; + if ($page->isValid()) return $page->name; + else return false; } function getWikiPageLinks($basepage) { if ($basepage == '') return false; - if (isset($this->_nolink)) return false; + if (isset($this->_nolink)) return false; if ($link = $this->getPagename($basepage)) return array(array('linkto' => $link)); else @@ -371,41 +370,41 @@ } function _getName($basepage) { - return $this->getPagename($basepage); + return $this->getPagename($basepage); } function _getURL($basepage) { - return WikiURL($this->getPagename($basepage)); - //return WikiURL($this->getPagename($basepage), false, 'abs_url'); + return WikiURL($this->getPagename($basepage)); + //return WikiURL($this->getPagename($basepage), false, 'abs_url'); } function expand($basepage, &$markup) { - global $WikiTheme; + global $WikiTheme; $this->_basepage = $basepage; - $label = isset($this->_label) ? $this->_label : false; - $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; + $label = isset($this->_label) ? $this->_label : false; + $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; $page = new WikiPageName($this->_page, $basepage, $anchor); - if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) { - if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) - return HTML($label ? $label : $page->getName()); - } + if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) { + if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) + return HTML($label ? $label : $page->getName()); + } if ($page->isValid()) return WikiLink($page, 'auto', $label); - else return HTML($label); + else return HTML($label); } function asXML() { - global $WikiTheme; - $label = isset($this->_label) ? $this->_label : false; - $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; - //TODO: need basepage for subpages like /Remove (within CreateTOC) + global $WikiTheme; + $label = isset($this->_label) ? $this->_label : false; + $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; + //TODO: need basepage for subpages like /Remove (within CreateTOC) $page = new WikiPageName($this->_page, $this->_basepage, $anchor); - if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { - if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) - return $label ? $label : $page->getName(); + if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { + if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) + return $label ? $label : $page->getName(); + } + $link = WikiLink($page, 'auto', $label); + return $link->asXML(); } - $link = WikiLink($page, 'auto', $label); - return $link->asXML(); - } function asString() { if (isset($this->_label)) @@ -417,15 +416,15 @@ class Cached_WikiLinkIfKnown extends Cached_WikiLink { function Cached_WikiLinkIfKnown ($moniker) { - $this->_page = $moniker; + $this->_page = $moniker; } function expand($basepage, &$markup) { - global $WikiTheme; - if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { - if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) - return HTML($label ? $label : $page->getName()); - } + global $WikiTheme; + if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { + if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) + return HTML($label ? $label : $page->getName()); + } return WikiLink($this->_page, 'if_known'); } } @@ -433,8 +432,8 @@ class Cached_SpellCheck extends Cached_WikiLink { function Cached_SpellCheck ($word, $suggs) { - $this->_page = $word; - $this->suggestions = $suggs; + $this->_page = $word; + $this->suggestions = $suggs; } function expand($basepage, &$markup) { @@ -455,16 +454,16 @@ } function isInlineElement() { - return true; + return true; } function expand($basepage, &$markup) { global $WikiTheme; $label = isset($this->_label) ? $this->_label : false; - if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { - if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) - return HTML($label ? $label : $page->getName()); - } + if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { + if (!in_array($this->_page, $WikiTheme->VALID_LINKS)) + return HTML($label ? $label : $page->getName()); + } return LinkPhpwikiURL($this->_url, $label, $basepage); } @@ -501,14 +500,14 @@ } function isInlineElement() { - return true; + return true; } function getPagename($basepage) { - if (!isset($this->_page)) return false; - $page = new WikiPageName($this->_page, $basepage); - if ($page->isValid()) return $page->name; - else return false; + if (!isset($this->_page)) return false; + $page = new WikiPageName($this->_page, $basepage); + if ($page->isValid()) return $page->name; + else return false; } /* Add relation to the link table. @@ -516,14 +515,14 @@ */ function getWikiPageLinks($basepage) { if ($basepage == '') return false; - if (!isset($this->_page) and isset($this->_attribute)) { + if (!isset($this->_page) and isset($this->_attribute)) { // An attribute: we store it in the basepage now, to fill the cache for page->save // TODO: side-effect free query $page = $GLOBALS['request']->getPage($basepage); $page->setAttribute($this->_relation, $this->_attribute); $this->_page = $basepage; return array(array('linkto' => '', 'relation' => $this->_relation)); - } + } if ($link = $this->getPagename($basepage)) return array(array('linkto' => $link, 'relation' => $this->_relation)); else @@ -535,50 +534,48 @@ if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) { return HTML::span(array('class' => 'error'), _("BAD semantic relation link")); } - $this->_relation = urldecode($m[1]); + $this->_relation = urldecode($m[1]); $is_attribute = ($m[2] == ':='); if ($is_attribute) { $this->_attribute = urldecode($m[3]); - // since this stored in the markup cache, we are extra sensible - // not to store false empty stuff. - $units = new Units(); - if (!DISABLE_UNITS and !$units->errcode) - { - $this->_attribute_base = $units->Definition($this->_attribute); - $this->_unit = $units->baseunit($this->_attribute); - } + // since this stored in the markup cache, we are extra sensible + // not to store false empty stuff. + $units = new Units(); + if (!DISABLE_UNITS and !$units->errcode) { + $this->_attribute_base = $units->Definition($this->_attribute); + $this->_unit = $units->baseunit($this->_attribute); + } } else { - $this->_page = urldecode($m[3]); + $this->_page = urldecode($m[3]); } - return $m; + return $m; } function _expand($url, $label = false) { - global $WikiTheme; - $m = $this->_expandurl($url); + global $WikiTheme; + $m = $this->_expandurl($url); $class = 'wiki'; // do not link to the attribute value, but to the attribute $is_attribute = ($m[2] == ':='); - if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { - if (isset($this->_page) and !in_array($this->_page, $WikiTheme->VALID_LINKS)) - return HTML($label ? $label : ($is_attribute ? $this->_relation : $this->_page)); - } - if ($is_attribute) - $title = isset($this->_attribute_base) - ? sprintf(_("Attribute %s, base value: %s"), $this->_relation, $this->_attribute_base) - : sprintf(_("Attribute %s, value: %s"), $this->_relation, $this->_attribute); - if ($label) { - return HTML::span - ( - HTML::a(array('href' => WikiURL($is_attribute ? $this->_relation : $this->_page), + if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) { + if (isset($this->_page) and !in_array($this->_page, $WikiTheme->VALID_LINKS)) + return HTML($label ? $label : ($is_attribute ? $this->_relation : $this->_page)); + } + if ($is_attribute) + $title = isset($this->_attribute_base) + ? sprintf(_("Attribute %s, base value: %s"), $this->_relation, $this->_attribute_base) + : sprintf(_("Attribute %s, value: %s"), $this->_relation, $this->_attribute); + if ($label) { + return HTML::span( + HTML::a(array('href' => WikiURL($is_attribute ? $this->_relation : $this->_page), 'class' => "wiki ".($is_attribute ? "attribute" : "relation"), 'title' => $is_attribute ? $title : sprintf(_("Relation %s to page %s"), $this->_relation, $this->_page)), $label) ); - } elseif ($is_attribute) { - return HTML::span + } elseif ($is_attribute) { + return HTML::span ( HTML::a(array('href' => WikiURL($this->_relation), 'class' => "wiki attribute", @@ -623,8 +620,8 @@ class Cached_SearchHighlight extends Cached_DynamicContent { function Cached_SearchHighlight ($word, $engine) { - $this->_word = $word; - $this->engine = $engine; + $this->_word = $word; + $this->engine = $engine; } function expand($basepage, &$markup) { @@ -637,7 +634,7 @@ class Cached_ExternalLink extends Cached_Link { function Cached_ExternalLink($url, $label=false) { - $this->_url = $url; + $this->_url = $url; if ($label && $label != $url) $this->_label = $label; } @@ -647,15 +644,15 @@ } function _getName($basepage) { - $label = isset($this->_label) ? $this->_label : false; - return ($label and is_string($label)) ? $label : $this->_url; + $label = isset($this->_label) ? $this->_label : false; + return ($label and is_string($label)) ? $label : $this->_url; } function expand($basepage, &$markup) { global $request; - $label = isset($this->_label) ? $this->_label : false; - $link = LinkURL($this->_url, $label); + $label = isset($this->_label) ? $this->_label : false; + $link = LinkURL($this->_url, $label); if (GOOGLE_LINKS_NOFOLLOW) { // Ignores nofollow when the user who saved the page was authenticated. @@ -677,24 +674,24 @@ class Cached_InterwikiLink extends Cached_ExternalLink { function Cached_InterwikiLink($link, $label=false) { - $this->_link = $link; + $this->_link = $link; if ($label) $this->_label = $label; } function getPagename($basepage) { list ($moniker, $page) = explode (":", $this->_link, 2); - $page = new WikiPageName($page, $basepage); - if ($page->isValid()) return $page->name; - else return false; + $page = new WikiPageName($page, $basepage); + if ($page->isValid()) return $page->name; + else return false; } function getWikiPageLinks($basepage) { if ($basepage == '') return false; - /* ":DontStoreLink" */ - if (substr($this->_link,0,1) == ':') return false; - /* store only links to valid pagenames */ - $dbi = $GLOBALS['request']->getDbh(); + /* ":DontStoreLink" */ + if (substr($this->_link,0,1) == ':') return false; + /* store only links to valid pagenames */ + $dbi = $GLOBALS['request']->getDbh(); if ($link = $this->getPagename($basepage) and $dbi->isWikiPage($link)) { return array(array('linkto' => $link)); } else { @@ -703,8 +700,8 @@ } function _getName($basepage) { - $label = isset($this->_label) ? $this->_label : false; - return ($label and is_string($label)) ? $label : $this->_link; + $label = isset($this->_label) ? $this->_label : false; + return ($label and is_string($label)) ? $label : $this->_link; } /* there may be internal interwiki links also */ @@ -713,21 +710,21 @@ } function _getURL($basepage) { - $link = $this->expand($basepage, $this); - return $link->getAttr('href'); + $link = $this->expand($basepage, $this); + return $link->getAttr('href'); } function expand($basepage, &$markup) { - global $WikiTheme; - $intermap = getInterwikiMap(); - $label = isset($this->_label) ? $this->_label : false; - //FIXME: check Upload: inlined images - if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) { - if (!in_array($this->_link, $WikiTheme->VALID_LINKS)) - return HTML($label ? $label : $this->_link); + global $WikiTheme; + $intermap = getInterwikiMap(); + $label = isset($this->_label) ? $this->_label : false; + //FIXME: check Upload: inlined images + if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) { + if (!in_array($this->_link, $WikiTheme->VALID_LINKS)) + return HTML($label ? $label : $this->_link); + } + return $intermap->link($this->_link, $label); } - return $intermap->link($this->_link, $label); - } function asString() { if (isset($this->_label)) @@ -742,9 +739,9 @@ class Cached_UserLink extends Cached_WikiLink { function expand($basepage, &$markup) { $label = isset($this->_label) ? $this->_label : false; - $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; + $anchor = isset($this->_anchor) ? (string)$this->_anchor : ''; $page = new WikiPageName($this->_page, $basepage, $anchor); - $link = WikiLink($page, 'auto', $label); + $link = WikiLink($page, 'auto', $label); // $link = HTML::a(array('href' => $PageName)); $link->setContent(PossiblyGlueIconToText('wikiuser', $this->_page)); $link->setAttr('class', 'wikiuser'); @@ -760,8 +757,8 @@ class Cached_PluginInvocation extends Cached_DynamicContent { function Cached_PluginInvocation ($pi) { - $this->_pi = $pi; - $loader = $this->_getLoader(); + $this->_pi = $pi; + $loader = $this->_getLoader(); if (is_array($plugin_cmdline = $loader->parsePI($pi)) and $plugin_cmdline[1]) { $this->pi_name = $plugin_cmdline[0]; // plugin, plugin-form, plugin-list $this->name = $plugin_cmdline[1]->getName(); @@ -773,7 +770,7 @@ } function isInlineElement() { - return false; + return false; } function expand($basepage, &$markup) { @@ -795,9 +792,9 @@ function & _getLoader() { static $loader = false; - if (!$loader) { + if (!$loader) { include_once('lib/WikiPlugin.php'); - $loader = new WikiPluginLoader; + $loader = new WikiPluginLoader; } return $loader; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |