Personal tools


Xwadmin.php

From OrganicDesign

Jump to: navigation, search
Image:legacy.png
Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.


<html>
        <head><title>xmlWiki Admin Page</title></head>
        <body bgcolor=#cccccc>
                <table border=0 width=100% cellpadding=0 cellspacing=0>
                <tr><td align=center><table border=0 width=30%>
                <tr><td align=center>
                <a href="../index.php/xmlWiki"><img src="./xmlwiki.jpg" border=0 alt="xmlWiki"></a>
                <tr><td align=center bgcolor=#003366>
                <b><font size=5 color=white face=helvetica>xmlWiki Admin Page</font></b>
                </table></table><br><br><br><br>
<?php
 
# Ensure all necessay files are in place
copyFile('../index.php','../index.php.bak');
copyFile('../includes/Parser.php','../includes/Parser.php.bak');
copyFile('./xwskin.php','../skins/xwskin.php');
copyFile('./images/xmlwikibullet.jpg','../skins/common/images/xmlwikibullet.jpg');
copyFile('./images/xmlwiki.jpg','../skins/common/images/xmlwiki.jpg');
copyFile('./images/icon-oo.png','../skins/common/images/icon-oo.png');
copyFile('./images/icon-pdf.png','../skins/common/images/icon-pdf.png');
copyFile('./images/icon-html.png','../skins/common/images/icon-html.png');
copyFile('./images/icon-rtf.png','../skins/common/images/icon-rtf.png');
 
if (array_key_exists('enable', $_GET)) {
 
        # Apply index.php patches
        # Old require-patch: "$1\nrequire_once( './xmlwiki/xmlwiki.php' );",
        $success = patchFile('../index.php', array(
                "/^(wfProfileOut\\( *'main-misc-setup' *\\);)$/m",
                "\$xw = new Article( Title::newFromText('LocalSettings.php') );\neval( \$xw->getContentWithoutUsingSoManyDamnGlobals() );\n$1\n\$xw = new Article( Title::newFromText('xmlwiki.php') );\neval( \$xw->getContentWithoutUsingSoManyDamnGlobals() );\n",
 
                "/^(wfProfileIn\\( *'main-action' *\\);)$/m",
                "wfRunHooks('Input', array());\n$1",
 
                "/(\\\$wgOut->output\\(\\);)/",
                "wfRunHooks('Output', array());"
                ));
 
        # Apply Parser.php patches
        if ($success) patchFile('../includes/Parser.php', array(
 
                "/(function\\s+parse\\s*\\(.+?\\)\\s*\\{.+?OT_HTML;.)(.+?)(\\s*\\\$this->mOutput->setText)/s",
                "$1\nif ( wfRunHooks('PreParser', array(&\$text))) {\n$2\n}$3",
 
                "/(default:\\s+)(return NULL;)/s",
                "$1\$ret = NULL; if (wfRunHooks('ParserGetVariableValueSwitch',array(&\$this,&\$varCache,&\$index,&\$ret))) return \$ret; else $2",
 
                "/\\s+# This should never be reached\\.(\\s+\\\$article = .+?)(?=\\s+if \\( \\\$articleContent !== false \\) \\{)/s",
                "\n\$articleContent = '';\nwfRunHooks('ParserFunctions', array(&\$part1,&\$articleContent,\$args,\$argc));\nif (\$part1) {\$1\n}"
 
                 ));
 
        }
 
elseif (array_key_exists('disable', $_GET)) {
        # Replace from backup
        replaceFiles(array('../index.php', '../includes/Parser.php'));
        replaceFiles(array('../index.php'));
        }
 
# Print current state (based on index.php)
if (filesize('../index.php') == filesize('../index.php.bak'))
                print xwMessage('xmlWiki is currently disabled. [ <a href="./index.php?enable">enable</a> ]', '#003366');
else    print xwMessage('xmlWiki is currently enabled. [ <a href="./index.php?disable">disable</a> ]', '#003366');
 
# Add message to queue
function xwMessage($msg, $col = 'blue') {
        global $xwMessages;
        return $xwMessages[] = "<center><div class=\"xwMessage\"><font color=\"$col\">$msg</font></div></center>\n";
        }
 
# Replace a list of files from their backups
function replaceFiles($list) {
        foreach ($list as $filename)
                if (!copy("$filename.bak", $filename))
                        print xwMessage("Could not replace \"$filename\" from backup!", '#d00000');
        }
 
function patchFile($filename, $rules) {
        # Back up file if doesn't already exist
        if (!file_exists("$filename.bak")) {
                if (!copy($filename, "$filename.bak")) {
                        print xwMessage("Could not back up MediaWiki \"$filename\"!", '#d00000');
                        exit;
                        }
                }
        # Replace from backup before enabling
        if (!copy("$filename.bak", $filename))
                print xwMessage("Could not find \"$filename.bak\"!", '#d00000');
 
        # Apply patches in passed list
        $file = join('', file($filename));
        $success = true;
        for ($i = 0; $i < count($rules); $i += 2) {
                $match = $rules[$i];
                $replace = $rules[$i+1];
                if (preg_match($match, $file)) $file = preg_replace($match, $replace, $file);
                else {
                        print xwMessage("Could not match rule".($i/2+1)." for \"$filename\"!", '#d00000');
                        $success = false;
                        }
                }
        if ($success) {
                if ($success && $handle = fopen($filename, 'w')) {
                        fwrite($handle, $file);
                        fclose($handle);
                        } else  print xwMessage("Could not open \"$filename\" for writing!", '#d00000');
                }
 
        return $success;
        }
 
# Copy a file if the destination doesn't exist
function copyFile($src, $dst) {
        if (file_exists($dst)) return;
        if (!copy($src, $dst)) print xwMessage("Could not copy \"$src\" to \"$dst\"!", '#d00000');
        }
 
 
?>
                <br><br><br><table border=0 width=100% cellpadding=0 cellspacing=0>
                <tr><td align=center colspan=3><table border=0 width=50%>
                <td align=right valign=top><a href="http://w3c.org/"><img src="./xhtml.jpg" alt="XHTML1.0" border=0 /></a>
                <td align=right valign=top><a href="http://www.php.net/"><img src="./php.jpg" alt="PHP" border=0 /></a>
                <td align=right valign=top><a href="http://www.mediawiki.org/"><img src="./mediawiki.jpg" alt="MediaWiki" border=0 /></a>
                </table></table><br><br>
        </body>
</html>

The GNU Project Debian Linux Ubuntu Linux Wikipedia online encycopedia MediaWiki