Difference between revisions of "Xmlwiki.php"

From Organic Design wiki
Line 3: Line 3:
 
# xmlWiki - MediaWiki XML Hack
 
# xmlWiki - MediaWiki XML Hack
 
# Nad - 2005-05-18
 
# Nad - 2005-05-18
 
+
# TODO:
# Maybe only use XML transforms
+
# Security:
# - use PHP via processing instructions
+
# - xml:article - holds article perms, it doesn't have perms of its own (owner, read-groups, write-groups)
 
+
# - xml:user    - r/w by user, not currently used, but for xmlWiki prefs etc
# DTD's
+
# - sys:user    - r/w by admin only, holds users groups and other system info like stats
# - using xmlwiki:document, xmlwiki:image etc is for validation purposes
+
# Publish:
# - xwTransformArticle is generic and cares only for xmlwiki:*
+
# - xml:article - holds article publish-list
 
+
# Transforms:
# CSS STYLES
+
# - xml:article - now transforms are in here (main article is now like <body>)
# the are accessed via http, so their article url can be referred to locally in the html
+
# - so we don't do the "its one of ours" thing anymore
# - maybe make the default request 'raw' and must specifically request 'view'
+
# Raw as Default:
# - the default CSS's should deal with geshi colour/tab etc
+
# - Need to mod the article-link so it has action=view
  
 
# LATER:
 
# LATER:
 
# allow XIncludes to build large docs from others
 
# allow XIncludes to build large docs from others
 
# allow docBook and DSSSL content
 
# allow docBook and DSSSL content
 
+
# Maybe only use XML transforms and use PHP via PI's
# ---------------------------------------------------------------------------------------------------------------------- #
 
# SCRIPT CONTENTS
 
 
 
# INIT
 
# - do admin and exit if running directly
 
# - include geshi
 
# - get wiki & request environment
 
# - get article (as an object if possible)
 
# - get user-info
 
# - get object-specific info (perms, doc-root, doc-type)
 
# - build env (if action=raw, env is empty)
 
# INPUT
 
# - deny access if !writable
 
# - currently not doing anything else
 
# OUTPUT
 
# - trap MediaWiki output
 
# - extract links (not used yet)
 
# - apply security
 
# - transform for raw, view, preview
 
# - if saving, do publishing
 
# - render output & messages
 
# ARTICLE FUNCTIONS
 
# - get article content
 
# - get article type
 
# - domificate article
 
# - transform article
 
# TRANSFORMS (Temp - will be separare articles)
 
# - document transforms
 
# - image transforms
 
# - layout transforms
 
# - database table transforms
 
# - transform object to php-nav-tree
 
# - geshi syntax highlighting
 
# FUNCTIONS
 
# - etxract hrefs from text
 
# - message/log
 
  
 
# ---------------------------------------------------------------------------------------------------------------------- #
 
# ---------------------------------------------------------------------------------------------------------------------- #
Line 61: Line 25:
  
 
# Exit if not included from index.php
 
# Exit if not included from index.php
if (!eregi("index\\.php", $_SERVER['SCRIPT_NAME'])) die('xmlwiki.php must be included from index.php!');
+
defined('MEDIAWIKI') or die('xmlwiki.php must be included from index.php!');
 
 
# Geshi syntax highlighting is now called from xmlWiki and should be removed from LocalSettings.php
 
require_once("extensions/GeshiSyntaxHighlight.php");
 
  
 
# Otherwise set up xmlWiki global environment ready for input and output processing
 
# Otherwise set up xmlWiki global environment ready for input and output processing
$xwMessages = array();
 
$xwArticleCache = array();
 
 
 
$xwEdit = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'edit');
 
$xwEdit = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'edit');
 
$xwView = (!isset($_REQUEST['action']) || (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'view')));
 
$xwView = (!isset($_REQUEST['action']) || (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'view')));
Line 75: Line 33:
 
$xwPreview = isset($_REQUEST['wpPreview']);  
 
$xwPreview = isset($_REQUEST['wpPreview']);  
 
$xwSave = isset($_REQUEST['wpSave']);
 
$xwSave = isset($_REQUEST['wpSave']);
 +
$xwUserName = $wgUser->mName;
 +
$xwArticleTitle = $wgTitle->getPrefixedURL();
 +
$xwArticleCache = array();
 +
$xwArticleLinks = array();
 
$xwUserLinks = array();
 
$xwUserLinks = array();
$xwArticleLinks = array();
+
$xwMessages = array();
  
$xwArticleTitle = $wgTitle->getPrefixedURL();
+
# Get articles and attempt to Domificate
$xwArticle = $wgArticle->getContent(false);
+
if ($xwArticle = $wgArticle->getContent(false)) xwDomificateArticle($xwArticle, $xwArticleTitle);
$xwArticleMeta = xwArticleContent("xmlwiki:$wgTitle");
+
if ($xwArticleXML = xwArticleContent("xml:$xwArticleTitle")) xwDomificateArticle($xwArticleXML, "xml:$xwArticleTitle");
$xwArticlePublish = null;
+
if ($xwUserXML = xwArticleContent("xml:$xwUserName")) xwDomificateArticle($xwUserXML, "xml:$xwUserName");
 
+
if ($xwUserSYS = xwArticleContent("sys:$xwUserName")) xwDomificateArticle($xwUserXML, "sys:$xwUserName");
$xwUserName = $wgUser->mName;
 
$xwUserMeta = xwArticleContent("xmlwiki:$xwUserName");
 
 
 
$xwSecurity = xwArticleContent("xmlwiki:Security"); # holds group membership info
 
$xwReadable = true;
 
$xwWritable = true;
 
 
 
# Try to convert articles to DOM objects
 
xwDomificateArticle($xwArticle, $xwArticleTitle);
 
xwDomificateArticle($xwArticleMeta, "xmlwiki:$xwArticleTitle");
 
xwDomificateArticle($xwUserMeta, "xmlwiki:$xwUserName");
 
  
 
# Security
 
# Security
if (is_object($xwArticleMeta)) {
+
if (is_object($xwArticleXML)) {
 
#$xwUserGroups[] = $xwUserName;
 
#$xwUserGroups[] = $xwUserName;
 
# can't write to xmlwiki:security unless admin
 
# can't write to xmlwiki:security unless admin
#$xwReadable = null;
 
#$xwWritable = null;
 
 
 
# Get publish list
 
# Get publish list
 
#$root = $xwArticle->document_element();
 
#$root = $xwArticle->document_element();
Line 107: Line 55:
 
#if (count($publist)) $publist = $publist[0]->dump_mem(true);
 
#if (count($publist)) $publist = $publist[0]->dump_mem(true);
 
#$publist = split(',', $publist);
 
#$publist = split(',', $publist);
+
} else $xwReadable = $xwWritable = true;
}
 
  
 
# ---------------------------------------------------------------------------------------------------------------------- #
 
# ---------------------------------------------------------------------------------------------------------------------- #
Line 122: Line 69:
 
global $xwReadable, $xwWritable, $xwMessages;
 
global $xwReadable, $xwWritable, $xwMessages;
 
global $xwSave;
 
global $xwSave;
 +
 +
# TODO: Only admin can write to a sys: article
  
 
# If article is being updated,
 
# If article is being updated,
Line 135: Line 84:
  
 
# Generate new output to send back to browser
 
# Generate new output to send back to browser
 +
# - if article is not XML, then wikiOut is used
 
function xwProcessOutput() {
 
function xwProcessOutput() {
  
Line 149: Line 99:
 
$xwArticleLinks = preg_match('/id="p-cactions"(.+?)<\/div>/s', $wikiOut, $m) ? xwExtractHrefs($m[1]) : array();
 
$xwArticleLinks = preg_match('/id="p-cactions"(.+?)<\/div>/s', $wikiOut, $m) ? xwExtractHrefs($m[1]) : array();
 
ob_end_clean();
 
ob_end_clean();
 
 
# Security
 
# Security
 
if (!$xwReadable) {
 
if (!$xwReadable) {
Line 173: Line 122:
 
xwMessage('Previewing Page...');
 
xwMessage('Previewing Page...');
 
if (preg_match('/^.+(<!-- start content -->.+Remember.+saved!.+?<\\/p>)(.+?)(<br style="clear:both;" \\/>.+<textarea.+?>\\s*(.+)<\\/textarea>.+<!-- end content -->).+$/s', $wikiOut, $m)) {
 
if (preg_match('/^.+(<!-- start content -->.+Remember.+saved!.+?<\\/p>)(.+?)(<br style="clear:both;" \\/>.+<textarea.+?>\\s*(.+)<\\/textarea>.+<!-- end content -->).+$/s', $wikiOut, $m)) {
#xwRemoveWikiMarkup($xwArticle = $m[2]);
 
 
xwDomificateArticle($xwArticle = html_entity_decode($m[4]));
 
xwDomificateArticle($xwArticle = html_entity_decode($m[4]));
 
if (is_object($xwArticle)) {
 
if (is_object($xwArticle)) {
Line 207: Line 155:
 
# Apply xmlwiki-environment-transforms to output unless 'raw' requested
 
# Apply xmlwiki-environment-transforms to output unless 'raw' requested
 
if (!$xwRaw) {
 
if (!$xwRaw) {
 +
xwTransformWikiMarkup();
 
xwTransformGeshi();
 
xwTransformGeshi();
 
xwTransformAddMessages();
 
xwTransformAddMessages();
Line 230: Line 179:
 
if ($articleTitle) $xwArticleCache[$articleTitle] = $article;
 
if ($articleTitle) $xwArticleCache[$articleTitle] = $article;
 
return $article;
 
return $article;
}
 
 
# To transform extracted content, we must remove wiki-markup
 
function xwRemoveWikiMarkup(&$article) {
 
$article = preg_replace("/<a href=.+?title=(.+?)&.+?<\\/a>/s", '[[$1]]', $article);
 
$article = preg_replace("/<\\/?p>/", '', $article);
 
$article = html_entity_decode($article);
 
 
}
 
}
  
Line 275: Line 217:
  
 
# Reduce article to a string if it's a DOM object
 
# Reduce article to a string if it's a DOM object
# - ie if all xslt's had xml-output-method, or it was a non-xmlwiki:* dtd
+
# - ie if all xslt's had xml-output-method
 
function xwUndomificateArticle(&$article, $id = '') {
 
function xwUndomificateArticle(&$article, $id = '') {
 
if (!is_object($article)) return false;
 
if (!is_object($article)) return false;
Line 281: Line 223:
 
# Validate, report errors
 
# Validate, report errors
 
# xwApplyXSLT($article, $xslt) if xml referrs one
 
# xwApplyXSLT($article, $xslt) if xml referrs one
# Convert DOM back to XML
+
# Convert DOM back to XML if still an object
$article = $article->dump_mem(true);
+
if (is_object($article)) $article = $article->dump_mem(true);
 
return true;
 
return true;
 
}
 
}
Line 289: Line 231:
 
# - if output-method is html, article will get stringified
 
# - if output-method is html, article will get stringified
 
function xwApplyXSLT(&$article, &$xslt) {
 
function xwApplyXSLT(&$article, &$xslt) {
 +
xwMessage('Processing XSLT');
 
ob_start();
 
ob_start();
 
$tObject = domxml_xslt_stylesheet($xslt);
 
$tObject = domxml_xslt_stylesheet($xslt);
 
$tResult = $tObject->process($article);
 
$tResult = $tObject->process($article);
 
# If output-method is html, use XSLT's dump_mem to create an html-string
 
# If output-method is html, use XSLT's dump_mem to create an html-string
if (preg_match('/<xsl:output +?method *= *"html"/i', $xslt)) {
+
if (preg_match('/<xsl:output +?method *= *"html"/i', $xslt))
xwMessage('xwApplyXSLT() is htmlifying');
 
xwMessage("&nbsp;&nbsp;&nbsp;NOTE! Messages are not content - they can only be transformed by CSS!", 'purple');
 
 
$tResult = $tObject->result_dump_mem($tResult);
 
$tResult = $tObject->result_dump_mem($tResult);
}
 
 
$err = preg_replace("/<.+?>/", "", ob_get_contents());
 
$err = preg_replace("/<.+?>/", "", ob_get_contents());
 
$err = preg_replace('/ in .+? on line.+?[0-9]+/', '', $err);
 
$err = preg_replace('/ in .+? on line.+?[0-9]+/', '', $err);
Line 318: Line 258:
 
$aType = $aType->name;
 
$aType = $aType->name;
 
$aRoot = $article->document_element();  
 
$aRoot = $article->document_element();  
if (!ereg('^xmlwiki:', $aType)) return false;
+
if (!ereg('^xmlwiki:', $aType)) return false; # this must change to meta article
 
xwMessage("Transforming doctype \"$aType\"");
 
xwMessage("Transforming doctype \"$aType\"");
  
Line 366: Line 306:
 
# - we should use DTD's for each kind: document, image, layout, table
 
# - we should use DTD's for each kind: document, image, layout, table
  
 +
# Do wiki markup on content
 +
function xwTransformWikiMarkup() {
 +
}
 +
 
# Include Geshi syntax highlighting
 
# Include Geshi syntax highlighting
# - Remember, Geshi should be removed from LocalSettings.php
+
# NOTE: Geshi can be installed the normal way too now!
 +
#      because transforms don't use wikiOut
 
function xwTransformGeshi() {
 
function xwTransformGeshi() {
xwMessage("Hi, Geshi here, sorry I'm not currently functional.");
 
 
return;
 
return;
 
 

Revision as of 04:17, 9 June 2005

<php> <?php

  1. xmlWiki - MediaWiki XML Hack
  2. Nad - 2005-05-18
  3. TODO:
  4. Security:
  5. - xml:article - holds article perms, it doesn't have perms of its own (owner, read-groups, write-groups)
  6. - xml:user - r/w by user, not currently used, but for xmlWiki prefs etc
  7. - sys:user - r/w by admin only, holds users groups and other system info like stats
  8. Publish:
  9. - xml:article - holds article publish-list
  10. Transforms:
  11. - xml:article - now transforms are in here (main article is now like <body>)
  12. - so we don't do the "its one of ours" thing anymore
  13. Raw as Default:
  14. - Need to mod the article-link so it has action=view
  1. LATER:
  2. allow XIncludes to build large docs from others
  3. allow docBook and DSSSL content
  4. Maybe only use XML transforms and use PHP via PI's
  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. INIT
  1. Exit if not included from index.php

defined('MEDIAWIKI') or die('xmlwiki.php must be included from index.php!');

  1. Otherwise set up xmlWiki global environment ready for input and output processing

$xwEdit = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'edit'); $xwView = (!isset($_REQUEST['action']) || (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'view'))); $xwRaw = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'raw'); $xwPreview = isset($_REQUEST['wpPreview']); $xwSave = isset($_REQUEST['wpSave']); $xwUserName = $wgUser->mName; $xwArticleTitle = $wgTitle->getPrefixedURL(); $xwArticleCache = array(); $xwArticleLinks = array(); $xwUserLinks = array(); $xwMessages = array();

  1. Get articles and attempt to Domificate

if ($xwArticle = $wgArticle->getContent(false)) xwDomificateArticle($xwArticle, $xwArticleTitle); if ($xwArticleXML = xwArticleContent("xml:$xwArticleTitle")) xwDomificateArticle($xwArticleXML, "xml:$xwArticleTitle"); if ($xwUserXML = xwArticleContent("xml:$xwUserName")) xwDomificateArticle($xwUserXML, "xml:$xwUserName"); if ($xwUserSYS = xwArticleContent("sys:$xwUserName")) xwDomificateArticle($xwUserXML, "sys:$xwUserName");

  1. Security

if (is_object($xwArticleXML)) { #$xwUserGroups[] = $xwUserName; # can't write to xmlwiki:security unless admin # Get publish list #$root = $xwArticle->document_element(); #$publist = $root->get_elements_by_tagname('publish'); #if (count($publist)) $publist = $publist[0]->dump_mem(true); #$publist = split(',', $publist); } else $xwReadable = $xwWritable = true;

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. INPUT
  1. No input processing for now
  2. - used later for custom edit forms (database table article will need it)
  1. Parse and process input from forms

function xwProcessInput() {

global $xwArticle, $xwArticleTitle; global $xwReadable, $xwWritable, $xwMessages; global $xwSave;

# TODO: Only admin can write to a sys: article

# If article is being updated, if ($xwSave) { #global $_POST; #if (!$xwReadable || !$xwWritable) die("I'm sorry Dave, I'm afraid I can't do that."); }

}

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. OUTPUT
  1. Generate new output to send back to browser
  2. - if article is not XML, then wikiOut is used

function xwProcessOutput() {

global $wgOut; global $xwArticle, $xwArticleTitle, $xwArticlePublish; global $xwView, $xwPreview, $xwSave, $xwRaw, $xwUserLinks, $xwArticleLinks; global $xwUserName, $xwUserMeta, $xwReadable, $xwWritable, $xwMessages;

# First trap Wiki output and extract content and links (should use $ver like Admin Page) ob_start(); $wgOut->output(); $wikiOut = ob_get_contents(); $xwUserLinks = preg_match('/id="p-personal"(.+?)<\/div>/s', $wikiOut, $m) ? xwExtractHrefs($m[1]) : array(); $xwArticleLinks = preg_match('/id="p-cactions"(.+?)<\/div>/s', $wikiOut, $m) ? xwExtractHrefs($m[1]) : array(); ob_end_clean(); # Security if (!$xwReadable) { # change output to access denied message if !readable } if (!$xwWritable) { # remove edit link }

# If Viewing, # - if DOM, transform else extract marked-up content from wikiOut

# save-match: (preg_match('/^(.+\\s*

)(.+)(<\\/p>\\s*.+)$/ms', $wikiOut, $m)) if ($xwView) { xwMessage('Viewing Page...'); if (is_object($xwArticle)) xwTransformArticle($xwArticle); else if (preg_match('/^(.+)(.+)(.+)$/ms', $wikiOut, $m)) $xwArticle = $m[2]; else xwMessage('xmlWiki couldn\'t match view-output!', 'red'); } # If Previewing, we can get our raw content from inside the <textarea> # old-match: (preg_match('/^(.+.+Remember.+saved!.+?<\\/p>)(.+?)(
.+)(.+)$/s', $wikiOut, $m)) elseif ($xwPreview) { xwMessage('Previewing Page...'); if (preg_match('/^.+(.+Remember.+saved!.+?<\\/p>)(.+?)(
.+<textarea.+?>\\s*(.+)<\\/textarea>.+).+$/s', $wikiOut, $m)) { xwDomificateArticle($xwArticle = html_entity_decode($m[4])); if (is_object($xwArticle)) { xwTransformArticle($xwArticle); $xwArticle = $m[1].$xwArticle.$m[3]; } else $xwArticle = $m[1].$m[2].$m[3]; } else xwMessage('xmlWiki couldn\'t match preview-output!', 'red'); } # If saving, check the publishing list # - pblish info should be in $articleMeta elseif (false && $xwSave && count($xwArticlePublish)) { xwMessage('Publishing...', 'purple'); xwTransformArticle($xwArticle, $xwArticleTitle); # Publish each item foreach ($xwArticlePublish as $url) { if ($FH = fopen($url, 'a')) { fwrite($FH, $xwArticle); fclose($FH); xwMessage("Article published to $url"); } else xwMessage("Failed to publish to $url", 'red'); } } else { # This is probably a special page # - we'll just extract the content and leave as-is if (preg_match('/^(.+)(.+)(.+)$/ms', $wikiOut, $m)) $xwArticle = $m[2]; else xwMessage('xmlWiki couldn\'t match special-output!', 'red'); } # Apply xmlwiki-environment-transforms to output unless 'raw' requested if (!$xwRaw) { xwTransformWikiMarkup(); xwTransformGeshi(); xwTransformAddMessages(); xwTransformPageLayout(); xwTransformPageStyle(); } # And finally, output the sunovabitch print $xwArticle; }

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. ARTICLE FUNCTIONS
  1. Retreive wiki-article as raw text

function xwArticleContent($articleTitle) { # Return with results if already cached global $xwArticleCache; if (isset($xwArticleCache[$articleTitle])) return $xwArticleCache[$articleTitle]; # Get wiki article content (or use global if no article passed) if ($article = new Article(Title::newFromText($articleTitle))) $article = $article->getContent(false); if ($article == '(There is currently no text in this page)') return false; if ($articleTitle) $xwArticleCache[$articleTitle] = $article; return $article; }

  1. Decide kind of article from content and title

function xwArticleType($title, $article) { # Name based matches if (ereg('\\.php$', $title)) return 'php'; if (ereg('\\.css$', $title)) return 'css'; if (ereg('\\.as$', $title)) return 'actionscript'; if (ereg('\\.py$', $title)) return 'python'; if (ereg('\\.java$', $title)) return 'java'; if (ereg('\\.(cpp)|(h)$', $title)) return 'cpp'; if (ereg('\\.js$', $title)) return 'javascript'; if (ereg('\\.css$', $title)) return 'css'; # Content based matches if (preg_match('/^<\\?xml.+?\\?>\\s*<xsl:stylesheet/', $article)) return 'xslt'; if (ereg('^<\\?xml', $article)) return 'xml'; if (ereg('^<\\?html', $article)) return 'html4strict'; if (ereg('^#![/a-zA-Z0-9]+\\/perl', $article)) return 'perl'; if (ereg('^#![/a-zA-Z0-9]+sh', $article)) return 'bash'; }

  1. Convert passed article to a DOM object
  2. - Article is unchanged if not valid XML

function xwDomificateArticle(&$article, $id = ) { xwMessage("Domificating $id"); ob_start(); if ($dom = domxml_open_mem($article)) $article = $dom; else { # Could not convert, extract error messages from output xwMessage("   Failed :-(", 'red'); $err = preg_replace("/<.+?>/", "", ob_get_contents()); $err = preg_replace('/ in .+? on line.+?[0-9]+/', , $err); $err = preg_replace('/Warning.+?\\(\\): /', , $err); foreach (split("\n", $err) as $msg) if ($msg) xwMessage("   $msg", 'red'); } ob_end_clean(); }

  1. Reduce article to a string if it's a DOM object
  2. - ie if all xslt's had xml-output-method

function xwUndomificateArticle(&$article, $id = ) { if (!is_object($article)) return false; xwMessage("Undomificating $id"); # Validate, report errors # xwApplyXSLT($article, $xslt) if xml referrs one # Convert DOM back to XML if still an object if (is_object($article)) $article = $article->dump_mem(true); return true; }

  1. Apply XSLT to article-dom
  2. - if output-method is html, article will get stringified

function xwApplyXSLT(&$article, &$xslt) { xwMessage('Processing XSLT'); ob_start(); $tObject = domxml_xslt_stylesheet($xslt); $tResult = $tObject->process($article); # If output-method is html, use XSLT's dump_mem to create an html-string if (preg_match('/<xsl:output +?method *= *"html"/i', $xslt)) $tResult = $tObject->result_dump_mem($tResult); $err = preg_replace("/<.+?>/", "", ob_get_contents()); $err = preg_replace('/ in .+? on line.+?[0-9]+/', , $err); $err = preg_replace('/Warning.+?\\(\\): /', , $err); foreach (split("\n", $err) as $msg) if ($msg) xwMessage("   $msg", 'red'); ob_end_clean(); if ($tResult) $article = $tResult; else return false; return true; }

  1. Transform an article object
  2. - Article must be an xmlwiki:* DOM object to be transformable
  3. - Article is undomificated if DOM but not xmlwiki:*
  4. - Article remains unchanged if not DOM

function xwTransformArticle(&$article) { # Get doc info or exit if not one of ours if (!is_object($article)) return false; $aType = $article->doctype(); $aType = $aType->name; $aRoot = $article->document_element(); if (!ereg('^xmlwiki:', $aType)) return false; # this must change to meta article xwMessage("Transforming doctype \"$aType\""); # Loop thru transforms applying each foreach ($aRoot->get_elements_by_tagname('transform') as $tElement) { $tName = $tElement->get_content(); if (ereg('^(.+)\\(\\)$', $tName, $m)) { # Transform is "name()" format, try to execute from a local function declaration # - probably this is not needed soon, only accept article-transforms $tName = $m[1]; if ($tResult = @call_user_func("xwTransform_$tName", $article)) $article = $tResult; else xwMessage("   Unknown transform \"$tName\"!", 'red'); } else { # Get transform-article and apply to $article if ($tText = xwArticleContent($tName)) { # Get transform type $tType = xwArticleType($tName, $tText); if ($tType == 'xslt') xwApplyXSLT($article, $tText); elseif ($tType == 'php') { # php, check perms and execute (trapping errors for reporting - unless fatal) if ($perms_check_out_ok) { ob_start(); eval($tText); $err = preg_replace("/<.+?>/", "", ob_get_contents()); foreach (split("\n", $err) as $msg) if ($msg) xwMessage($msg, 'red'); ob_end_clean(); } } elseif ($tType == 'css') { # include CSS ref in content } } else xwMessage("   No such transform-article \"$tName\"!", 'red'); } } # If article is still a DOM object, stringify it again xwUndomificateArticle($article); return true; }

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. TRANSFORMS
  3. - these transforms are only temporarily here - they should be articles
  4. - we should use DTD's for each kind: document, image, layout, table
  1. Do wiki markup on content

function xwTransformWikiMarkup() { }

  1. Include Geshi syntax highlighting
  2. NOTE: Geshi can be installed the normal way too now!
  3. because transforms don't use wikiOut

function xwTransformGeshi() { return; global $xwArticle, $xwArticleTitle; # First check for entire article highlighting # Highlight entire article if xwLang has been set if ($xwLang) { $xwGeshi = new GeSHi($xwArticle, $xwLang, "extensions/geshi/geshi"); $xwGeshi->set_tab_width(4); $geshi->set_keywords_style(1, 'font-weight: 100;', true); #$geshi->set_comments_style #$geshi->set_escape_char_style #$geshi->set_brackets_style #$geshi->set_strings_style #$geshi->set_numbers_style #$geshi->set_methods_style #$geshi->set_symbols_style #$geshi->set_regexps_style #$geshi->set_script_style #$xwArticle = $xwGeshi->parse_code(); } }

  1. Append messages to content

function xwTransformAddMessages() { global $xwArticle, $xwMessages; $xwArticle .= join("\n", $xwMessages); }

  1. This is the default postTransform which surrounds the page
  2. - most transforms do not reference the global-current-article like this one
  3. - this is a special transform, because it affects all pages, even special pages

function xwTransformPageLayout() { global $xwArticle, $xwArticleTitle, $xwUserLinks, $xwArticleLinks; xwMessage("Hi defaultTransform here :-)"); $xwArticle = "

xmlWiki - $xwArticleTitle
".join('
',$xwArticleLinks)."
\"xmlWiki\"
$xwArticleTitle
$xwArticle

"; }

  1. Apply styling to page

function xwTransformPageStyle() { global $xwArticle; $xwArticle = preg_replace("/(

)(.+?)(<\\/p>)/", '

   $2   

', $xwArticle);

}

function xwTransform_document_xxx() { # documents are built from parts, # the parts are a tree in its body # includes 'edit' link for each (like section, and also like table) }

  1. A document object is finalised by transforming it to its body's text

function xwTransform_document_render() { global $xwArticle; $root = $xwArticle->document_element(); $body = $root->get_elements_by_tagname('body'); if (count($body)) $xwArticle = $body[0]->dump_mem(true); }

function xwTransform_layout_xxx() { # for layout container style article }

function xwTransform_image_xxx() { # object contains properties for loading and transforming an image # image needs no body # Get the global image on which imageTransforms work global $xwArticleImage; }

  1. Converts the in-memory-working image into article content

function xwTransform_image_render() { global $xwArticle, $xwArticleTitle, $xwArticleImage, $xwRaw; if ($xwRaw) { # render article directly if 'raw' request imagePng($xwArticleImage); # Clear article or it will render as xml $xwArticle = ; # set header to image header("Content-type: image/png"); }

else { # the raw image is not being requested, render image in-page with info instead $xwArticle = "<img src=\"$xwArticleTitle?action=raw\" alt=\"$xwArticleTitle\"/>"; } }

  1. A table object is an interface to a database table
  2. - this can't be implimented fully until the 'edit' hook is done
  3. - the query result is a list in document body, so any normal document transforms can follow it

function xwTransform_table_xxx() { # - view lists the table/result with links to edit each (like a normal composition-doc) # - also form for create/edit/edlete # - result rows are in document body (just like a content-tree in a document would be)

# NODE-LIKE-DB

# - if all tables have GUID for pri-key, # - and all have time/duration (or cycle?), # - and we have master list of cols-to-table # - then we could create a meta-query (resulting in pri-key-list of all matches)

}

  1. Transform the body content to a xtml/javascript tree

function xwTransform_tree() { # import php-tree-component }

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. UTILITY FUNCTIONS
  1. Return a list of the hrefs found in the passed content

function xwExtractHrefs($content) { preg_match_all('/(<a.+?<\/a>)/', $content, $match); return $match[1]; }

  1. Add message to queue

function xwMessage($msg, $col = 'blue') { global $xwMessages;

return $xwMessages[] = "

$msg

\n";

}

?> </php>