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
 +
 +
# DTD's
 +
# - using xmlwiki:document, xmlwiki:image etc is for validation purposes
 +
# - xwTransformArticle is generic and cares only for xmlwiki:*
  
 
# CSS STYLES
 
# CSS STYLES
Line 18: Line 22:
 
# INIT
 
# INIT
 
# - do admin and exit if running directly
 
# - do admin and exit if running directly
# - get wiki/request env
+
# - include geshi
# - get article
+
# - get wiki & request environment
# - permissions
+
# - get article (as an object if possible)
# - build env (if action=raw, env is empty but a header is added)
+
# - get user-info
 +
# - get object-specific info (perms, doc-root, doc-type)
 +
# - build env (if action=raw, env is empty)
 
# INPUT
 
# INPUT
# - validate xml and report error or,
+
# - deny access if !writable
# - process form-input (backslashes etc if necessary)
+
# - currently not doing anything else
 
# OUTPUT
 
# OUTPUT
 
# - trap MediaWiki output
 
# - trap MediaWiki output
# - extract content and links
+
# - extract links (not used yet)
# - if view/preview/raw, do transform:
+
# - apply security
#   - replace view/preview with transformed article
+
# - transform for raw, view, preview
# - render output
+
# - if saving, do publishing
# - if saving, foreach in publish-list,
+
# - render output & messages
#  - do transform but with specified env
 
#   - publish
 
 
# TRANSFORM
 
# TRANSFORM
# - process dom-article (pass PT,XSLT list and DOM-article, returns DOM-result)
+
# - if article is an object,
# - if docType is an xwArticle, see above
+
- process transforms if doctype is one of ours,
 +
- validate and apply XSLT if not
 +
# - apply geshi on article
 
# TRANSFORMS
 
# TRANSFORMS
 
# - document transforms
 
# - document transforms
Line 42: Line 48:
 
# - layout transforms
 
# - layout transforms
 
# - database table transforms
 
# - database table transforms
 +
# - transform object to php-nav-tree
 
# FUNCTIONS
 
# FUNCTIONS
 
# - get article
 
# - get article
Line 61: Line 68:
  
 
# 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();
 +
$xwEnv = array();
 +
 
$xwArticleTitle = $wgTitle->mTextform;
 
$xwArticleTitle = $wgTitle->mTextform;
 
$xwArticle = xwGetArticle($xwArticleTitle);
 
$xwArticle = xwGetArticle($xwArticleTitle);
 
$xwDocType = null;
 
$xwDocType = null;
$xwRoot = null;
+
$xwDocRoot = null;
  
 
$xwEdit = isset($_REQUEST['action'])&&($_REQUEST['action'] == 'edit');
 
$xwEdit = isset($_REQUEST['action'])&&($_REQUEST['action'] == 'edit');
$xwView = isset($_REQUEST['action'])&&($_REQUEST['action'] == 'view');
+
$xwView = (!isset($_REQUEST['action'])||(isset($_REQUEST['action'])&&($_REQUEST['action'] == 'view')));
 
$xwRaw = isset($_REQUEST['action'])&&($_REQUEST['action'] == 'raw');
 
$xwRaw = isset($_REQUEST['action'])&&($_REQUEST['action'] == 'raw');
 
$xwPreview = isset($_REQUEST['wpPreview']);  
 
$xwPreview = isset($_REQUEST['wpPreview']);  
Line 76: Line 87:
 
$xwReadable = true;
 
$xwReadable = true;
 
$xwWritable = true;
 
$xwWritable = true;
 
$xwMessages = array();
 
$xwArticleCache = array();
 
$xwEnv = array();
 
  
 
# If article is an object...
 
# If article is an object...
 
if (is_object($xwArticle)) {
 
if (is_object($xwArticle)) {
 
# Get doc info
 
# Get doc info
$xwDocType = $xwArticle->doctype->name;
+
$xwDocType = $xwArticle->doctype();
$xwRoot = $xwArticle->document_element();  
+
$xwDocType = $xwDocType->name;
 +
$xwDocRoot = $xwArticle->document_element();  
 
# Get perms
 
# Get perms
$xwUserGroups[] = $xwUserName; // This allows users to be specified in permissions-lists in addition to groups
+
$xwUserGroups[] = $xwUserName;
$xwReadable = null; # True if this article is readable by this user
+
$xwReadable = null;
$xwWritable = null; # True if this article is writeable by this user
+
$xwWritable = null;
 
}
 
}
 
+
 
# Build default transform environment (later from prefs, site etc)
 
# Build default transform environment (later from prefs, site etc)
 
if ($xwRaw) {
 
if ($xwRaw) {
Line 122: Line 130:
 
global $xwReadable;
 
global $xwReadable;
 
global $xwWritable;
 
global $xwWritable;
 +
global $xwMessages;
  
 
# If article is being updated,
 
# If article is being updated,
Line 147: Line 156:
 
global $xwPreview;
 
global $xwPreview;
 
global $xwSave;
 
global $xwSave;
 +
global $xwRaw;
  
 
global $xwUserName;
 
global $xwUserName;
Line 152: Line 162:
 
global $xwReadable;
 
global $xwReadable;
 
global $xwWritable;
 
global $xwWritable;
 +
global $xwMessages;
  
 
# First trap Wiki output and extract content and links (should use $ver like Admin Page)
 
# First trap Wiki output and extract content and links (should use $ver like Admin Page)
Line 157: Line 168:
 
$wgOut->output();
 
$wgOut->output();
 
$xwWikiOutput = ob_get_clean();
 
$xwWikiOutput = ob_get_clean();
 +
$xwOutput = '';
 
 
 
# Extract links (not used currently)
 
# Extract links (not used currently)
Line 172: Line 184:
 
}
 
}
  
# Transform article for raw request (ignores wiki-output completely)
+
# Transform article (the article will be reduced to a string for output)
if ($xwRaw) $xwOutput = xwTransformArticle();
+
xwTransformArticle();
 +
 +
# If raw, output consists only of transformed article
 +
if ($xwRaw) $xwOutput = $xwArticle;
  
# Transform article for normal view
+
# If normal view, article must appear within wiki content
 
if ($xwView) {
 
if ($xwView) {
if (preg_match('/^(.+<!-- start content -->).+(<!-- end content -->.+)$/m', $xwOutput, $xwMatch)) {
+
xwMessage("Viewing doctype: $xwDocType");
$xwOutput = xwTransformArticle();
+
if (preg_match('/^(.+<!-- start content -->).+(<!-- end content -->.+)$/s', $xwOutput, $m)) {
$xwOutput = $xwMatch[1].$xwOutput.$xwMatch[2];
+
$xwOutput = $m[1].$xwArticle.$m[2];
 
} else xwMessage('xmlWiki couldn\'t match view-output!', 'red');
 
} else xwMessage('xmlWiki couldn\'t match view-output!', 'red');
 
}
 
}
  
# Transform article for preview
+
# If preview, article must appear in wiki content preserving wiki editing content
 
if ($xwPreview) {
 
if ($xwPreview) {
if (preg_match('/^(.+<!-- start content -->.+Remember.+saved!.+?<\\/p>).+(<script.+?<\\/script>.?<form id="editform".+<!-- end content -->.+)$/m', $xwOutput, $xwMatch)) {
+
if (preg_match('/^(.+<!-- start content -->.+Remember.+saved!.+?<\\/p>).+(<script.+?<\\/script>.?<form id="editform".+<!-- end content -->.+)$/s', $xwOutput, $m)) {
$xwOutput = xwTransformArticle();
+
$xwOutput = $m[1].$xwArticle.$m[2];
$xwOutput = $xwMatch[1].$xwOutput.$xwMatch[2];
 
 
} else xwMessage('xmlWiki couldn\'t match preview-output!', 'red');
 
} else xwMessage('xmlWiki couldn\'t match preview-output!', 'red');
 
}
 
}
  
# Transform article for publishing
+
# If saving, check the publishing list
 
if ($xwSave && is_object($xwArticle)) {
 
if ($xwSave && is_object($xwArticle)) {
 
# Get publish list
 
# Get publish list
$xwPublishList = $xwRoot->get_elements_by_tagname('publish');
+
$xwPublishList = $xwDocRoot->get_elements_by_tagname('publish');
 
if (count($xwPublishList)) $xwPublishList = $xwPublishList[0]->dump_mem(true);
 
if (count($xwPublishList)) $xwPublishList = $xwPublishList[0]->dump_mem(true);
 
$xwPublishList = split(',', $xwPublishList);
 
$xwPublishList = split(',', $xwPublishList);
Line 210: Line 224:
 
# Render final output and messages
 
# Render final output and messages
 
# - not good if content isn't plain-text anymore!
 
# - not good if content isn't plain-text anymore!
 +
xwMessage('Rendering output','blue');
 
foreach ($xwMessages as $msg) $xwOutput .= $msg;
 
foreach ($xwMessages as $msg) $xwOutput .= $msg;
 
print $xwOutput;
 
print $xwOutput;
Line 222: Line 237:
 
global $xwArticleTitle;
 
global $xwArticleTitle;
 
global $xwDocType;
 
global $xwDocType;
 +
global $xwDocRoot;
 +
 +
xwMessage("Transforming doctype \"$xwDocType\"",'blue');
  
 
# If content is object,  
 
# If content is object,  
 
if (is_object($xwArticle)) {
 
if (is_object($xwArticle)) {
# we should check DTD's here for document, image, table, layout
+
# eg. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
# If it's one of ours,
#    <!DOCTYPE greeting SYSTEM "hello.dtd">
+
if (ereg('^xmlwiki:', $xwDocType)) {
if ($xwDocType == 'xmlwiki') {
+
xwMessage('It\'s one of ours, getting transform list...', 'blue');
 
# Get the documents transforms
 
# Get the documents transforms
 
# - the first transforms adjust the document while its still a DOM object
 
# - the first transforms adjust the document while its still a DOM object
 
# - but at some point it would normally transform to text,
 
# - but at some point it would normally transform to text,
 
# - it may then have some further text-based transforms
 
# - it may then have some further text-based transforms
$xwTransforms = $root->get_elements_by_tagname('transform');
+
$xwTransforms = $xwDocRoot->get_elements_by_tagname('transform');
  
 
#  - add php-transform-articles,CSS's & XSLT's to $xwEnv
 
#  - add php-transform-articles,CSS's & XSLT's to $xwEnv
Line 239: Line 257:
 
}
 
}
  
# If object wasn't one of ours, or didn't get transformed to a string...
+
# If object hasn't been transformed into a string yet (or it isn't one of our kind)...
 
if (!is_string($xwArticle)) {
 
if (!is_string($xwArticle)) {
 +
xwMessage('Dumping article-object to string', 'blue');
 
# validate, report errors
 
# validate, report errors
 
 
Line 336: Line 355:
 
# - or otherwise string content is returned (which can be parsed for highlighting)
 
# - or otherwise string content is returned (which can be parsed for highlighting)
 
function xwGetArticle($articleTitle) {
 
function xwGetArticle($articleTitle) {
 +
global $xwArticleCache;
 
# Return with results if already cached
 
# Return with results if already cached
global $xwArticleCache;
 
 
if (isset($xwArticleCache[$articleTitle])) return $xwArticleCache[$articleTitle];
 
if (isset($xwArticleCache[$articleTitle])) return $xwArticleCache[$articleTitle];
 
# Get wiki article content (XML)
 
# Get wiki article content (XML)
Line 343: Line 362:
 
$article = $article->getContent(false);
 
$article = $article->getContent(false);
 
# Convert to DOM object if possible
 
# Convert to DOM object if possible
if ($articleDOM = @domxml_open_mem($article)) $article = $articleDOM;
+
ob_start();
 +
if ($articleDOM = domxml_open_mem(trim($article))) $article = $articleDOM;
 +
else {
 +
# Trap error messages
 +
$err = preg_replace('/ in .+? on line.+?[0-9]+/', '', ob_get_contents());
 +
$err = preg_replace('/<b>Warning.+?\\(\\): /', '', $err);
 +
$err = preg_replace('/(\\n)|(<\\/b>)|(<br ?\\/>)/', "\n", $err);
 +
foreach (split("\n", $err) as $msg) if ($msg) xwMessage($msg);
 +
#xwMessage(ob_get_contents());
 +
}
 +
ob_end_clean();
 
# Return content
 
# Return content
 
return $xwArticleCache[$articleTitle] = $article;
 
return $xwArticleCache[$articleTitle] = $article;
Line 355: Line 384:
  
 
# Add message to queue
 
# Add message to queue
function xwMessage($msg, $col) {
+
function xwMessage($msg, $col='blue') {
 
global $xwMessages;
 
global $xwMessages;
$xwMessages[] = "<div class=\"xwMessage\"><font color=\"$col\">$msg</font></div>\n";
+
return $xwMessages[] = "<div class=\"xwMessage\"><font color=\"$col\">$msg</font></div>\n";
 
}
 
}
  
 
# Include Geshi syntax highlighting
 
# Include Geshi syntax highlighting
 
# - Geshi should be removed from LocalSettings.php
 
# - Geshi should be removed from LocalSettings.php
function xwGeshi() {
+
function xwGeshi() { return false;
 +
xwMessage("Hi, Geshi here, sorry I'm not currently functional.",'blue');
 
 
 
global $xwArticle;
 
global $xwArticle;
Line 391: Line 421:
 
$xwGeshi->set_tab_width(4);
 
$xwGeshi->set_tab_width(4);
 
$geshi->set_keywords_style(1, 'font-weight: 100;', true);
 
$geshi->set_keywords_style(1, 'font-weight: 100;', true);
$geshi->set_comments_style
+
#$geshi->set_comments_style
$geshi->set_escape_char_style
+
#$geshi->set_escape_char_style
$geshi->set_brackets_style
+
#$geshi->set_brackets_style
$geshi->set_strings_style
+
#$geshi->set_strings_style
$geshi->set_numbers_style
+
#$geshi->set_numbers_style
$geshi->set_methods_style
+
#$geshi->set_methods_style
$geshi->set_symbols_style
+
#$geshi->set_symbols_style
$geshi->set_regexps_style
+
#$geshi->set_regexps_style
$geshi->set_script_style
+
#$geshi->set_script_style
$xwArticle = $xwGeshi->parse_code();
+
#$xwArticle = $xwGeshi->parse_code();
 
}
 
}
 
}
 
}

Revision as of 09:46, 2 June 2005

<php> <?php

  1. xmlWiki - MediaWiki XML Hack
  2. Nad - 2005-05-18
  1. DTD's
  2. - using xmlwiki:document, xmlwiki:image etc is for validation purposes
  3. - xwTransformArticle is generic and cares only for xmlwiki:*
  1. CSS STYLES
  2. the are accessed via http, so their article url can be referred to locally in the html
  3. - maybe make the default request 'raw' and must specifically request 'view'
  4. - the default CSS's should deal with geshi colour/tab etc
  1. LATER:
  2. allow XIncludes to build large docs from others
  3. allow docBook and DSSSL content
  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. SCRIPT CONTENTS
  1. INIT
  2. - do admin and exit if running directly
  3. - include geshi
  4. - get wiki & request environment
  5. - get article (as an object if possible)
  6. - get user-info
  7. - get object-specific info (perms, doc-root, doc-type)
  8. - build env (if action=raw, env is empty)
  9. INPUT
  10. - deny access if !writable
  11. - currently not doing anything else
  12. OUTPUT
  13. - trap MediaWiki output
  14. - extract links (not used yet)
  15. - apply security
  16. - transform for raw, view, preview
  17. - if saving, do publishing
  18. - render output & messages
  19. TRANSFORM
  20. - if article is an object,
  21. - process transforms if doctype is one of ours,
  22. - validate and apply XSLT if not
  23. - apply geshi on article
  24. TRANSFORMS
  25. - document transforms
  26. - image transforms
  27. - layout transforms
  28. - database table transforms
  29. - transform object to php-nav-tree
  30. FUNCTIONS
  31. - get article
  32. - etxract hrefs from text
  33. - message/log
  34. - geshi syntax highlighting
  35. ADMIN
  36. - enable/disable patch
  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. INIT
  1. If xmlwiki.php requested directly, return admin page

if (eregi("xmlwiki\\.php", $_SERVER['SCRIPT_NAME'])) xwAdminPage(); else {

# Geshi syntax highlighting is 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 $xwMessages = array(); $xwArticleCache = array(); $xwEnv = array();

$xwArticleTitle = $wgTitle->mTextform; $xwArticle = xwGetArticle($xwArticleTitle); $xwDocType = null; $xwDocRoot = null;

$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; $xwUserArticle = xwGetArticle("User:$xwUserName"); $xwReadable = true; $xwWritable = true;

# If article is an object... if (is_object($xwArticle)) { # Get doc info $xwDocType = $xwArticle->doctype(); $xwDocType = $xwDocType->name; $xwDocRoot = $xwArticle->document_element(); # Get perms $xwUserGroups[] = $xwUserName; $xwReadable = null; $xwWritable = null; }

# Build default transform environment (later from prefs, site etc) if ($xwRaw) { # Raw article is requested, so env is empty } else { # Create default environment (the name of another article) # - this does default transforms depending on type (eg highlighting for *.php) $xwEnv[] = ; }

}

  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; global $xwArticleTitle; global $xwRoot; global $xwDocType;

global $xwSave;

global $xwReadable; global $xwWritable; global $xwMessages;

# 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

function xwProcessOutput() {

global $wgOut;

global $xwArticle; global $xwArticleTitle; global $xwRoot; global $xwDocType;

global $xwView; global $xwPreview; global $xwSave; global $xwRaw;

global $xwUserName; global $xwUserArticle; global $xwReadable; global $xwWritable; global $xwMessages;

# First trap Wiki output and extract content and links (should use $ver like Admin Page) ob_start(); $wgOut->output(); $xwWikiOutput = ob_get_clean(); $xwOutput = ;

# Extract links (not used currently) $xwUserLinks = preg_match('/id="p-personal"(.+?)<\/div>/s', $xwWikiOutput, $xwMatch) ? xwExtractHrefs($xwMatch[1]) : array(); $xwArticleLinks = preg_match('/id="p-cactions"(.+?)<\/div>/s', $xwWikiOutput, $xwMatch) ? xwExtractHrefs($xwMatch[1]) : array();

# Security if (!$xwReadable) { # change output to access denied message if !readable } if (!$xwWritable) { # remove edit link }

# Transform article (the article will be reduced to a string for output) xwTransformArticle();

# If raw, output consists only of transformed article if ($xwRaw) $xwOutput = $xwArticle;

# If normal view, article must appear within wiki content if ($xwView) { xwMessage("Viewing doctype: $xwDocType"); if (preg_match('/^(.+).+(.+)$/s', $xwOutput, $m)) { $xwOutput = $m[1].$xwArticle.$m[2]; } else xwMessage('xmlWiki couldn\'t match view-output!', 'red'); }

# If preview, article must appear in wiki content preserving wiki editing content if ($xwPreview) { if (preg_match('/^(.+.+Remember.+saved!.+?<\\/p>).+(<script.+?<\\/script>.?<form id="editform".+.+)$/s', $xwOutput, $m)) { $xwOutput = $m[1].$xwArticle.$m[2]; } else xwMessage('xmlWiki couldn\'t match preview-output!', 'red'); }

# If saving, check the publishing list if ($xwSave && is_object($xwArticle)) { # Get publish list $xwPublishList = $xwDocRoot->get_elements_by_tagname('publish'); if (count($xwPublishList)) $xwPublishList = $xwPublishList[0]->dump_mem(true); $xwPublishList = split(',', $xwPublishList); $xwOutput = xwTransformArticle(); # Publish each item foreach ($xwPublishList as $xwDestination) { if ($xwHandle = fopen($xwDestination, 'a')) { fwrite($xwHandle, $xwTransformedArticle); fclose($xwHandle); xwMessage("Article published to $cmDestination", 'green'); } else xwMessage("Failed to publish to $cmDestination", 'red'); } }

# Render final output and messages # - not good if content isn't plain-text anymore! xwMessage('Rendering output','blue'); foreach ($xwMessages as $msg) $xwOutput .= $msg; print $xwOutput; }

  1. ---------------------------------------------------------------------------------------------------------------------- #
  2. TRANSFORM

function xwTransformArticle() {

global $xwArticle; global $xwArticleTitle; global $xwDocType; global $xwDocRoot;

xwMessage("Transforming doctype \"$xwDocType\"",'blue');

# If content is object, if (is_object($xwArticle)) {

# If it's one of ours, if (ereg('^xmlwiki:', $xwDocType)) { xwMessage('It\'s one of ours, getting transform list...', 'blue'); # Get the documents transforms # - the first transforms adjust the document while its still a DOM object # - but at some point it would normally transform to text, # - it may then have some further text-based transforms $xwTransforms = $xwDocRoot->get_elements_by_tagname('transform');

# - add php-transform-articles,CSS's & XSLT's to $xwEnv # - $xwEnv transforms first! }

# If object hasn't been transformed into a string yet (or it isn't one of our kind)... if (!is_string($xwArticle)) { xwMessage('Dumping article-object to string', 'blue'); # validate, report errors

# apply stylesheet/XSLT if xml asks for one,

# Convert DOM back to XML $xwArticle = $xwArticle->dump_mem(true); } }

# Apply syntax highlighting if string (even if article was an object, it will be a string by now) # - This isn't a transform because it also applies to non-object articles if (is_string($xwArticle)) xwGeshi(); }

  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

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; global $xwArticleTitle; global $xwArticleImage; global $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. FUNCTIONS
  1. Retreive wiki-article
  2. - A DOM object is returned if possible,
  3. - or otherwise string content is returned (which can be parsed for highlighting)

function xwGetArticle($articleTitle) { global $xwArticleCache; # Return with results if already cached if (isset($xwArticleCache[$articleTitle])) return $xwArticleCache[$articleTitle]; # Get wiki article content (XML) $article = new Article(Title::newFromText($articleTitle)); $article = $article->getContent(false); # Convert to DOM object if possible ob_start(); if ($articleDOM = domxml_open_mem(trim($article))) $article = $articleDOM; else { # Trap error messages $err = preg_replace('/ in .+? on line.+?[0-9]+/', , ob_get_contents()); $err = preg_replace('/Warning.+?\\(\\): /', , $err); $err = preg_replace('/(\\n)|(<\\/b>)|(
)/', "\n", $err); foreach (split("\n", $err) as $msg) if ($msg) xwMessage($msg); #xwMessage(ob_get_contents()); } ob_end_clean(); # Return content return $xwArticleCache[$articleTitle] = $article; }

  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";

}

  1. Include Geshi syntax highlighting
  2. - Geshi should be removed from LocalSettings.php

function xwGeshi() { return false; xwMessage("Hi, Geshi here, sorry I'm not currently functional.",'blue');

global $xwArticle; global $xwArticleTitle;

# First check for entire article highlighting if (ereg('\\.as$', $xwArticleTitle)) $xwLang = 'actionscript'; elseif (ereg('\\.py$', $xwArticleTitle)) $xwLang = 'python'; elseif (ereg('\\.java$', $xwArticleTitle)) $xwLang = 'java'; elseif (ereg('\\.(cpp)|(h)$', $xwArticleTitle)) $xwLang = 'cpp'; elseif (ereg('\\.js$', $xwArticleTitle)) $xwLang = 'javascript'; elseif (ereg('\\.css$', $xwArticleTitle)) $xwLang = 'css'; elseif (ereg('^#![/a-zA-Z0-9]+\\/perl', $xwArticle)) $xwLang = 'perl'; elseif (ereg('^#![/a-zA-Z0-9]+sh', $xwArticle)) $xwLang = 'bash'; elseif (ereg('^<?xml', $xwArticle)) $xwLang = 'xml'; elseif (ereg('^<?html', $xwArticle)) $xwLang = 'html4strict'; else { # Otherwise, parse article for internal highlights # <?,<% lang (default % is asp, default ? is php) # <script language= (default is javascript)

$xwLang = false; }

# 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. ---------------------------------------------------------------------------------------------------------------------- #
  2. ADMIN

function xwAdminPage() {

?>xmlWiki Admin Page

xmlWiki
xmlWiki Admin Page





output\\(\\);/m"; # Apply patches if (preg_match($requireMatch[$ver], $file = join('', file('./index.php'))) && preg_match($inputMatch[$ver], $file) && preg_match($outputMatch[$ver], $file)) { $file = preg_replace($requireMatch[$ver], "wfProfileOut( 'main-misc-setup' );\nrequire_once( './xmlwiki.php' );", $file); $file = preg_replace($inputMatch[$ver], "xwProcessInput();\nwfProfileIn( 'main-action' );", $file); $file = preg_replace($outputMatch[$ver], "xwProcessOutput();", $file); if ($handle = fopen('./index.php', 'w')) { fwrite($handle, $file); fclose($handle); } else print xwMessage('Could not open index.php for writing!', '#d00000'); } else print xwMessage('Could not match content of index.php script!', '#d00000'); } elseif (array_key_exists('disable', $_GET)) { # Replace from backup if (!copy('./index.bak', './index.php')) print xwMessage('Could not copy index.bak over index.php', '#d00000'); } # Print current state if (filesize('./index.php') == filesize('./index.bak')) print xwMessage('xmlWiki is currently disabled. [ enable ]', '#003366'); else print xwMessage('xmlWiki is currently enabled. [ disable ]', '#003366'); ?>


XHTML1.0 PHP MediaWiki



<? }

?> </php>