Ejemplo n.º 1
0
function OpenDataBase($dbinfo)
{
    global $msql_db;
    if (!($dbc = msql_connect())) {
        $msg = gettext("Cannot establish connection to database, giving up.");
        $msg .= "<BR>";
        $msg .= sprintf(gettext("Error message: %s"), msql_error());
        ExitWiki($msg);
    }
    if (!msql_select_db($msql_db, $dbc)) {
        $msg = gettext("Cannot open database %s, giving up.");
        $msg .= "<BR>";
        $msg .= sprintf(gettext("Error message: %s"), msql_error());
        ExitWiki($msg);
    }
    $dbi['dbc'] = $dbc;
    $dbi['table'] = $dbinfo['table'];
    // page metadata
    $dbi['page_table'] = $dbinfo['page_table'];
    // page content
    return $dbi;
}
Ejemplo n.º 2
0
 function _savePageData($pagename, $data)
 {
     $type = 'page_data';
     $version = 1;
     $filename = $this->_pagename2filename($type, $pagename, $version);
     // Construct a dummy page_revision object
     $page = new WikiDB_Page($this->_wikidb, $pagename);
     // data may be pagedate or versiondata updates
     if (USECACHE and empty($data['pagedata'])) {
         $cache =& $this->_wikidb->_cache;
         if (!empty($cache->_pagedata_cache[$pagename]) and is_array($cache->_pagedata_cache[$pagename])) {
             $cachedata =& $cache->_pagedata_cache[$pagename];
             foreach ($data as $key => $val) {
                 $cachedata[$key] = $val;
             }
         } else {
             $cache->_pagedata_cache[$pagename] = $data;
         }
     }
     //unset ($data['pagedata']);
     //if (empty($data['versiondata']))
     //    $data['versiondata'] = $data;
     // TODO:
     //   with versiondata merge it with previous pagedata, not to overwrite with empty pagedata
     //   with pagedata merge it with previous versiondata, not to overwrite with empty versiondata (content)
     $olddata = $this->_loadPageData($pagename);
     if (isset($data['version'])) {
         $version = $data['version'];
         $latestversion = $this->_getLatestVersion($pagename);
         if ($latestversion < $version) {
             $oldversiondata = $this->_loadVersionData($pagename, $latestversion);
             if ($oldversiondata) {
                 $olddata['versiondata'] = array_merge($oldversiondata, $olddata['versiondata']);
             }
         }
     }
     $data['pagedata'] = array_merge($olddata['pagedata'], $data['pagedata']);
     $data['versiondata'] = array_merge($olddata['versiondata'], $data['versiondata']);
     if (empty($data['versiondata']['%content'])) {
         $data['versiondata']['%content'] = $olddata['content'];
     }
     $current = new WikiDB_PageRevision($this->_wikidb, $pagename, $version, $data['versiondata']);
     unset($data['versiondata']);
     foreach ($data as $k => $v) {
         if ($k == 'pagedata') {
             $current->_data = array_merge($current->_data, $v);
         } elseif ($k == 'versiondata') {
             $current->_data = array_merge($current->_data, $v);
         } else {
             $current->_data[$k] = $v;
         }
     }
     $this->_page_data = $current->_data;
     $pagedata = "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n";
     $pagedata .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", PHPWIKI_VERSION);
     $pagedata .= MimeifyPageRevision($page, $current);
     if ($fd = fopen($filename, 'a+b')) {
         $locked = flock($fd, 2);
         // Exclusive blocking lock
         if (!$locked) {
             ExitWiki("Timeout while obtaining lock. Please try again");
         }
         rewind($fd);
         ftruncate($fd, 0);
         $len = strlen($pagedata);
         $num = fwrite($fd, $pagedata, $len);
         assert($num == $len);
         fclose($fd);
     } else {
         ExitWiki("Error while writing page '{$pagename}'");
     }
 }
Ejemplo n.º 3
0
 /**
  * Check a WikiDiff for validity.
  *
  * This is here only for debugging purposes.
  */
 function _check($from_lines, $to_lines)
 {
     $test = $this->apply($from_lines);
     if (serialize($test) != serialize($to_lines)) {
         ExitWiki(tra('WikiDiff::_check: failed'));
     }
     reset($this->edits);
     $prev = current($this->edits);
     $prevtype = is_array($prev) ? 'a' : ($prev > 0 ? 'c' : 'd');
     while ($edit = next($this->edits)) {
         $type = is_array($edit) ? 'a' : ($edit > 0 ? 'c' : 'd');
         if ($prevtype == $type) {
             ExitWiki(tra('WikiDiff::_check: edit sequence is non-optimal'));
         }
         $prevtype = $type;
     }
     $lcs = $this->lcs();
     printf('<strong>' . tra('WikiDiff Okay: LCS = %s') . "</strong>\n", $lcs);
 }
Ejemplo n.º 4
0
 function readFile()
 {
     $head = $this->_read(30);
     // FIXME: This is bad for gzip compressed buffers
     extract(unpack("a4magic/vreq_version/vflags/vcomp_type" . "/vmod_time/vmod_date" . "/Vcrc32/Vcomp_size/Vuncomp_size" . "/vfilename_len/vextrafld_len", $head));
     if ($magic != ZIP_LOCHEAD_MAGIC) {
         // maybe gzip?
         //$x = substr($magic,0,3);
         if (substr($magic, 0, 3) == "‹•") {
             if ($this->fp) {
                 fclose($this->fp);
                 $this->fp = fopen($this->zipfile, "rb");
                 $content = $this->_read(filesize($this->fp));
             } else {
                 $content = $this->buf;
             }
             // TODO...
             $data = zip_deflate($content);
             return array($filename, $data, $attrib);
         }
         if ($magic != ZIP_CENTHEAD_MAGIC) {
             // FIXME: better message?
             ExitWiki(sprintf("Unsupported ZIP header type: %s", $magic));
         }
         return $this->done();
     }
     if (($flags & 0x21) != 0) {
         ExitWiki("Encryption and/or zip patches not supported.");
     }
     if (($flags & 0x8) != 0) {
         // FIXME: better message?
         ExitWiki("Postponed CRC not yet supported.");
     }
     $filename = $this->_read($filename_len);
     //FIXME: we should probably check $req_version.
     $attrib['mtime'] = dostime2unixtime($mod_date, $mod_time);
     if ($extrafld_len != 0) {
         $attrib['extra_field'] = $this->_read($extrafld_len);
     }
     $data = $this->_read($comp_size);
     if ($comp_type == ZIP_DEFLATE) {
         $data = zip_inflate($data, $crc32, $uncomp_size);
     } else {
         if ($comp_type == ZIP_STORE) {
             $crc = zip_crc32($data);
             if ($crc32 != $crc) {
                 ExitWiki(sprintf("CRC mismatch %x != %x", $crc, $crc32));
             }
         } else {
             ExitWiki(sprintf("Compression method %s unsupported", $comp_method));
         }
     }
     if (strlen($data) != $uncomp_size) {
         ExitWiki(sprintf("Uncompressed size mismatch %d != %d", strlen($data), $uncomp_size));
     }
     return array($filename, $data, $attrib);
 }
Ejemplo n.º 5
0
<!-- $Id: lockpage.php,v 1.1 2004/09/28 21:48:44 gcasse Exp $ -->
<?php 
if (isset($lock)) {
    $page = $lock;
} elseif (isset($unlock)) {
    $page = $unlock;
}
$argv[0] = $page;
// necessary for displaying the page afterwards
$pagename = rawurldecode($page);
$pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
if (!is_array($pagehash)) {
    ExitWiki("Unknown page '" . htmlspecialchars($pagename) . "'\n");
}
if (isset($lock)) {
    $pagehash['flags'] |= FLAG_PAGE_LOCKED;
    InsertPage($dbi, $pagename, $pagehash);
    // echo htmlspecialchars($page) . " locked\n";
} elseif (isset($unlock)) {
    $pagehash['flags'] &= ~FLAG_PAGE_LOCKED;
    InsertPage($dbi, $pagename, $pagehash);
    // echo htmlspecialchars($page) . " unlocked\n";
}
Ejemplo n.º 6
0
function SetHTMLOutputMode($tag, $tagtype, $level)
   {
      global $stack;
      $retvar = '';

      if ($level > 10) {
      $level = 10;
      }
      
      if ($tagtype == "0") {
         // empty the stack until $level == 0;
         if ($tag == $stack->top()) {
            return; // same tag? -> nothing to do
         }
         while ($stack->cnt() > 0) {
            $closetag = $stack->pop();
            $retvar .= "</$closetag>\n";
         }
   
         if ($tag) {
            $retvar .= "<$tag>\n";
            $stack->push($tag);
         }

      } elseif ($tagtype == "1") {
         if ($level < $stack->cnt()) {
            while ($stack->cnt() > $level) {
               $closetag = $stack->pop();
               if ($closetag == false) {
                  
                  break;
               }
               $retvar .= "</$closetag>\n";
            }
        
        if ($tag != $stack->top()) {
           $closetag = $stack->pop();
           $retvar .= "</$closetag><$tag>\n";
           $stack->push($tag);
        }
   
         } elseif ($level > $stack->cnt()) {
        if ($stack->cnt() == 1 and
            preg_match('/^(p|pre|h\d)$/i', $stack->top()))
        {
           $closetag = $stack->pop();
           $retvar .= "</$closetag>";
        }

        
        if ($stack->cnt() < $level) {
           while ($stack->cnt() < $level - 1) {
          
          $retvar .= "<dl><dd>";
          $stack->push('dl');
           }

           $retvar .= "<$tag>\n";
           $stack->push($tag);
            }
   
         } else { // $level == $stack->cnt()
            if ($tag == $stack->top()) {
               return; // same tag? -> nothing to do
            } else {
           // different tag - close old one, add new one
               $closetag = $stack->pop();
               $retvar .= "</$closetag>\n";
               $retvar .= "<$tag>\n";
               $stack->push($tag);
            }
         }
   
      } else { // unknown $tagtype
         ExitWiki ("Passed bad tag type value in SetHTMLOutputMode");
      }

      return $retvar;
}
Ejemplo n.º 7
0
function SaveCopyToArchive($dbi, $pagename, $pagehash)
{
    global $ArchivePageStore;
    $pagedata = PadSerializedData(serialize($pagehash));
    if (dbminsert($dbi[$ArchivePageStore], $pagename, $pagedata)) {
        if (dbmreplace($dbi['archive'], $pagename, $pagedata)) {
            ExitWiki("Error storing '{$pagename}' into archive");
        }
    }
}
Ejemplo n.º 8
0
function RemovePage($dbi, $pagename)
{
    global $WikiPageStore, $ArchivePageStore;
    global $WikiLinksStore, $HitCountStore, $WikiScoreStore;
    $pagename = addslashes($pagename);
    $msg = gettext("Cannot delete '%s' from table '%s'");
    $msg .= "<br>\n";
    $msg .= gettext("MSSQL error: %s");
    if (!mssql_query("delete from {$WikiPageStore} where pagename='{$pagename}'", $dbi['dbc'])) {
        ExitWiki(sprintf($msg, $pagename, $WikiPageStore, mssql_get_last_message()));
    }
    if (!mssql_query("delete from {$ArchivePageStore} where pagename='{$pagename}'", $dbi['dbc'])) {
        ExitWiki(sprintf($msg, $pagename, $ArchivePageStore, mssql_get_last_message()));
    }
    if (!mssql_query("delete from {$WikiLinksStore} where frompage='{$pagename}'", $dbi['dbc'])) {
        ExitWiki(sprintf($msg, $pagename, $WikiLinksStore, mssql_get_last_message()));
    }
    if (!mssql_query("delete from {$HitCountStore} where pagename='{$pagename}'", $dbi['dbc'])) {
        ExitWiki(sprintf($msg, $pagename, $HitCountStore, mssql_get_last_message()));
    }
    if (!mssql_query("delete from {$WikiScoreStore} where pagename='{$pagename}'", $dbi['dbc'])) {
        ExitWiki(sprintf($msg, $pagename, $WikiScoreStore, mssql_get_last_message()));
    }
}
Ejemplo n.º 9
0
	function readFile()
	{
		$head = $this->_read(30);

		extract(
						unpack(
										'a4magic/vreq_version/vflags/vcomp_type' 
										. '/vmod_time/vmod_date' 
										. '/Vcrc32/Vcomp_size/Vuncomp_size' 
										. '/vfilename_len/vextrafld_len', 
										$head
						)
		);

		//FIXME: we should probably check $req_version.
		$attrib['mtime'] = dostime2unixtime($mod_date, $mod_time);

		if ($magic != ZIP_LOCHEAD_MAGIC) {
			if ($magic != ZIP_CENTHEAD_MAGIC)
				// FIXME: better message?
				ExitWiki(sprintf('Bad header type: %s', $magic));

			return $this->done();
		}

		if (($flags & 0x21) != 0)
			ExitWiki('Encryption and/or zip patches not supported.');

		if (($flags & 0x08) != 0)
			// FIXME: better message?
			ExitWiki('Postponed CRC not yet supported.');

		$filename = $this->_read($filename_len);

		if ($extrafld_len != 0)
			$attrib['extra_field'] = $this->_read($extrafld_len);

		$data = $this->_read($comp_size);

		if ($comp_type == ZIP_DEFLATE) {
			$data = zip_inflate($data, $crc32, $uncomp_size);
		} else if ($comp_type == ZIP_STORE) {
			$crc = zip_crc32($data);

			if ($crc32 != $crc)
				ExitWiki(sprintf('CRC mismatch %x != %x', $crc, $crc32));
		} else
			ExitWiki(sprintf('Compression method %s unsupported', $comp_method));

		if (strlen($data) != $uncomp_size)
			ExitWiki(sprintf('Uncompressed size mismatch %d != %d', strlen($data), $uncomp_size));

		return array(
				$filename,
				$data,
				$attrib
				);
	}
Ejemplo n.º 10
0
$pages = GetAllWikiPagenames($dbi);
// see if we can access the directory the user wants us to use
if (!file_exists($directory)) {
    if (!mkdir($directory, 0755)) {
        ExitWiki("Cannot create directory '{$directory}'<br>\n");
    } else {
        $html = "Created directory '{$directory}' for the page dump...<br>\n";
    }
} else {
    $html = "Using directory '{$directory}'<br>\n";
}
$numpages = count($pages);
for ($x = 0; $x < $numpages; $x++) {
    $pagename = htmlspecialchars($pages[$x]);
    $filename = preg_replace('/^\\./', '%2e', rawurlencode($pages[$x]));
    $html .= "<br>{$pagename} ... ";
    if ($pagename != $filename) {
        $html .= "<small>saved as {$filename}</small> ... ";
    }
    $data = serialize(RetrievePage($dbi, $pages[$x], $WikiPageStore));
    if ($fd = fopen("{$directory}/{$filename}", "w")) {
        $num = fwrite($fd, $data, strlen($data));
        $html .= "<small>{$num} bytes written</small>\n";
    } else {
        ExitWiki("<b>couldn't open file '{$directory}/{$filename}' for writing</b>\n");
    }
}
$html .= "<p><b>Dump complete.</b>";
GeneratePage('MESSAGE', $html, 'Dump serialized pages', 0);
ExitWiki('');
Ejemplo n.º 11
0
 function _savePage($type, $pagename, $version, $data)
 {
     $filename = $this->_pagename2filename($type, $pagename, $version);
     if ($fd = fopen($filename, 'a+b')) {
         $locked = flock($fd, 2);
         // Exclusive blocking lock
         if (!$locked) {
             ExitWiki("Timeout while obtaining lock. Please try again");
         }
         rewind($fd);
         ftruncate($fd, 0);
         $pagedata = serialize($data);
         $len = strlen($pagedata);
         $num = fwrite($fd, $pagedata, $len);
         assert($num == $len);
         fclose($fd);
     } else {
         ExitWiki("Error while writing page '{$pagename}'");
     }
 }
Ejemplo n.º 12
0
        $pagename = stripslashes($pagename);
    }
    $banner = htmlspecialchars(sprintf(gettext("Copy of %s"), $pagename));
    $pagehash = RetrievePage($dbi, $pagename, $ArchivePageStore);
} else {
    ExitWiki(gettext("No page name passed into editpage!"));
}
if (is_array($pagehash)) {
    if ($pagehash['flags'] & FLAG_PAGE_LOCKED && !defined('WIKI_ADMIN')) {
        $html = "<p>";
        $html .= gettext("This page has been locked by the administrator and cannot be edited.");
        $html .= "\n<p>";
        $html .= gettext("Sorry for the inconvenience.");
        $html .= "\n";
        GeneratePage('MESSAGE', $html, sprintf(gettext("Problem while editing %s"), $pagename), 0);
        ExitWiki("");
    }
    $textarea = htmlspecialchars(implode("\n", $pagehash["content"]));
    if (isset($copy)) {
        // $cdbi = OpenDataBase($WikiPageStore);
        $currentpage = RetrievePage($dbi, $pagename, $WikiPageStore);
        $pagehash["version"] = $currentpage["version"];
    } elseif ($pagehash["version"] > 1) {
        if (IsInArchive($dbi, $pagename)) {
            $pagehash["copy"] = 1;
        }
    }
} else {
    if (preg_match("/^{$WikiNameRegexp}\$/", $pagename)) {
        $newpage = $pagename;
    } else {
Ejemplo n.º 13
0
function Filesystem_WritePage($dbi, $pagename, $pagehash)
{
    global $WikiPageStore;
    $pagedata = serialize($pagehash);
    if (!file_exists($dbi)) {
        $d = split("/", $dbi);
        $dt = "";
        while (list($key, $val) = each($d)) {
            $dt = $dt . $val . "/";
            @mkdir($dt, 0755);
        }
    }
    $filename = $dbi . "/" . EncodePagename($pagename);
    if ($fd = fopen($filename, 'a+b')) {
        $locked = flock($fd, 2);
        #Exclusive blocking lock
        if (!$locked) {
            ExitWiki("Timeout while obtaining lock. Please try again");
        }
        #Second (actually used) filehandle
        #$fdsafe = fopen($filename, 'wb');
        #fwrite($fdsafe, $pagedata);
        #fclose($fdsafe);
        rewind($fd);
        ftruncate($fd, 0);
        fwrite($fd, $pagedata);
        fclose($fd);
    } else {
        ExitWiki("Error while writing page '{$pagename}'");
    }
}
Ejemplo n.º 14
0
function SetHTMLOutputMode($tag, $tagtype, $level)
{
    global $stack;
    $retvar = '';
    if ($level > 10) {
        // arbitrarily limit tag nesting
        //ExitWiki(gettext ("Nesting depth exceeded in SetHTMLOutputMode"));
        // Now, instead of crapping out when we encounter a deeply
        // nested list item, we just clamp the the maximum depth.
        $level = 10;
    }
    if ($tagtype == ZERO_LEVEL) {
        // empty the stack until $level == 0;
        if ($tag == $stack->top()) {
            return;
            // same tag? -> nothing to do
        }
        while ($stack->cnt() > 0) {
            $closetag = $stack->pop();
            $retvar .= "</{$closetag}>\n";
        }
        if ($tag) {
            $retvar .= "<{$tag}>\n";
            $stack->push($tag);
        }
    } elseif ($tagtype == NESTED_LEVEL) {
        if ($level < $stack->cnt()) {
            // $tag has fewer nestings (old: tabs) than stack,
            // reduce stack to that tab count
            while ($stack->cnt() > $level) {
                $closetag = $stack->pop();
                if ($closetag == false) {
                    //echo "bounds error in tag stack";
                    break;
                }
                $retvar .= "</{$closetag}>\n";
            }
            // if list type isn't the same,
            // back up one more and push new tag
            if ($tag != $stack->top()) {
                $closetag = $stack->pop();
                $retvar .= "</{$closetag}><{$tag}>\n";
                $stack->push($tag);
            }
        } elseif ($level > $stack->cnt()) {
            // Test for and close top level elements which are not allowed to contain
            // other block-level elements.
            if ($stack->cnt() == 1 and preg_match('/^(p|pre|h\\d)$/i', $stack->top())) {
                $closetag = $stack->pop();
                $retvar .= "</{$closetag}>";
            }
            // we add the diff to the stack
            // stack might be zero
            if ($stack->cnt() < $level) {
                while ($stack->cnt() < $level - 1) {
                    // This is a bit of a hack:
                    //
                    // We're not nested deep enough, and have to make up
                    // some kind of block element to nest within.
                    //
                    // Currently, this can only happen for nested list
                    // element (either <ul> <ol> or <dl>).  What we used
                    // to do here is to open extra lists of whatever
                    // type was requested.  This would result in invalid
                    // HTML, since and list is not allowed to contain
                    // another list without first containing a list
                    // item.  ("<ul><ul><li>Item</ul></ul>" is invalid.)
                    //
                    // So now, when we need extra list elements, we use
                    // a <dl>, and open it with an empty <dd>.
                    $retvar .= "<dl><dd>";
                    $stack->push('dl');
                }
                $retvar .= "<{$tag}>\n";
                $stack->push($tag);
            }
        } else {
            // $level == $stack->cnt()
            if ($tag == $stack->top()) {
                return;
                // same tag? -> nothing to do
            } else {
                // different tag - close old one, add new one
                $closetag = $stack->pop();
                $retvar .= "</{$closetag}>\n";
                $retvar .= "<{$tag}>\n";
                $stack->push($tag);
            }
        }
    } else {
        // unknown $tagtype
        ExitWiki("Passed bad tag type value in SetHTMLOutputMode");
    }
    return $retvar;
}