示例#1
0
 function contains($pagelist, $page)
 {
     if (!isset($this->_explodePageList)) {
         $this->_explodePageList = explodePageList($pagelist);
     }
     return in_array($page, $this->_explodePageList);
 }
示例#2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     $html = HTML();
     if (empty($args['pages'])) {
         return $html;
     }
     $include = new WikiPlugin_IncludePage();
     if (is_string($args['exclude']) and !empty($args['exclude'])) {
         $args['exclude'] = explodePageList($args['exclude']);
         $argstr = preg_replace("/exclude=\\S*\\s/", "", $argstr);
     } elseif (is_array($args['exclude'])) {
         $argstr = preg_replace("/exclude=<\\?plugin-list.*?\\>/", "", $argstr);
     }
     if (is_string($args['pages']) and !empty($args['pages'])) {
         $args['pages'] = explodePageList($args['pages']);
         $argstr = preg_replace("/pages=\\S*\\s/", "", $argstr);
     } elseif (is_array($args['pages'])) {
         $argstr = preg_replace("/pages=<\\?plugin-list.*?\\>/", "", $argstr);
     }
     foreach ($args['pages'] as $page) {
         if (empty($args['exclude']) or !in_array($page, $args['exclude'])) {
             $html = HTML($html, $include->run($dbi, "page='{$page}' " . $argstr, $request, $basepage));
         }
     }
     return $html;
 }
示例#3
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     if (empty($args['s'])) {
         return '';
     }
     extract($args);
     $query = new TextSearchQuery($s, $case_exact, $regex);
     $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
     $lines = array();
     $hilight_re = $hilight ? $query->getHighlightRegexp() : false;
     $count = 0;
     $found = 0;
     if ($quiet) {
         // see how easy it is with PageList...
         $list = new PageList(false, $exclude, $args);
         while ($page = $pages->next() and (!$limit or $count < $limit)) {
             $list->addPage($page);
         }
         return $list;
     }
     // Todo: we should better define a new PageListDL class for dl/dt/dd lists
     // But the new column types must have a callback then. (showhits)
     // See e.g. WikiAdminSearchReplace for custom pagelist columns
     $list = HTML::dl();
     if (!$limit or !is_int($limit)) {
         $limit = 0;
     }
     // expand all page wildcards to a list of pages which should be ignored
     if ($exclude) {
         $exclude = explodePageList($exclude);
     }
     while ($page = $pages->next() and (!$limit or $count < $limit)) {
         $name = $page->getName();
         if ($exclude and in_array($name, $exclude)) {
             continue;
         }
         $count++;
         $list->pushContent(HTML::dt(WikiLink($name)));
         if ($hilight_re) {
             $list->pushContent($this->showhits($page, $hilight_re));
         }
         unset($page);
     }
     if ($limit and $count >= $limit) {
         //todo: pager link to list of next matches
         $list->pushContent(HTML::dd(fmt("only %d pages displayed", $limit)));
     }
     if (!$list->getContent()) {
         $list->pushContent(HTML::dd(_("<no matches>")));
     }
     if (!empty($pages->stoplisted)) {
         $list = HTML(HTML::p(fmt(_("Ignored stoplist words '%s'"), join(', ', $pages->stoplisted))), $list);
     }
     if ($noheader) {
         return $list;
     }
     return HTML(HTML::p(fmt("Full text search results for '%s'", $s)), $list);
 }
示例#4
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     if ($args['basepage']) {
         $pagename = $args['basepage'];
     } else {
         $pagename = $request->getArg('pagename');
     }
     // FIXME: explodePageList from stdlib doesn't seem to work as
     // expected when there are no subpages. (see also
     // UnfoldSubPages plugin)
     $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
     if (!$subpages) {
         return $this->error(_("The current page has no subpages defined."));
     }
     extract($args);
     $content = HTML();
     $subpages = array_reverse($subpages);
     if ($maxpages) {
         $subpages = array_slice($subpages, 0, $maxpages);
     }
     $descrip = fmt("SubPages of %s:", WikiLink($pagename, 'auto'));
     if ($info) {
         $info = explode(",", $info);
         if (in_array('count', $info)) {
             $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
         }
     }
     $pagelist = new PageList($info, $exclude, $args);
     if (!$noheader) {
         $pagelist->setCaption($descrip);
     }
     foreach ($subpages as $page) {
         // A page cannot include itself. Avoid doublettes.
         static $included_pages = array();
         if (in_array($page, $included_pages)) {
             $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $page)));
             continue;
         }
         array_push($included_pages, $page);
         //if ($relative) {
         // TODO: add relative subpage name display to PageList class
         //}
         $pagelist->addPage($page);
         array_pop($included_pages);
     }
     $content->pushContent($pagelist);
     return $content;
 }
示例#5
0
function MakeWikiZipHtml(&$request)
{
    $request->_TemplatesProcessed = array();
    $zipname = "wikihtml.zip";
    $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname);
    $dbi =& $request->_dbi;
    $thispage = $request->getArg('pagename');
    // for "Return to ..."
    if ($exclude = $request->getArg('exclude')) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array();
    }
    if ($pages = $request->getArg('pages')) {
        // which pagenames
        if ($pages == '[]') {
            // current page
            $pages = $thispage;
        }
        $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages));
    } else {
        $page_iter = $dbi->getAllPages(false, false, false, $excludeList);
    }
    global $WikiTheme;
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $WikiTheme->DUMP_MODE = 'ZIPHTML';
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    /* ignore fatals in plugins */
    if (check_php_version(4, 1)) {
        global $ErrorManager;
        $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 20 : 240;
    while ($page = $page_iter->next()) {
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        $current = $page->getCurrentRevision();
        if ($current->getVersion() == 0) {
            continue;
        }
        $pagename = $page->getName();
        if (in_array($pagename, $excludeList)) {
            continue;
        }
        $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1);
        if ($page->get('locked')) {
            $attrib['write_protected'] = 1;
        }
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $revision = $page->getCurrentRevision();
        $transformedContent = $revision->getTransformedContent();
        $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $transformedContent));
        $data = GeneratePageasXML($template, $pagename);
        $zip->addRegularFile($filename, $data, $attrib);
        if (USECACHE) {
            $request->_dbi->_cache->invalidate_cache($pagename);
            unset($request->_dbi->_cache->_pagedata_cache);
            unset($request->_dbi->_cache->_versiondata_cache);
            unset($request->_dbi->_cache->_glv_cache);
        }
        unset($request->_dbi->_cache->_backend->_page_data);
        unset($revision->_transformedContent);
        unset($revision);
        unset($template->_request);
        unset($template);
        unset($data);
    }
    $page_iter->free();
    $attrib = false;
    // Deal with css and images here.
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        // dirs are created automatically
        //if ($WikiTheme->dumped_images) $zip->addRegularFile("images", "", $attrib);
        foreach ($WikiTheme->dumped_images as $img_file) {
            if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "images/" . basename($img_file);
                if (check_php_version(4, 3)) {
                    $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib);
                } else {
                    $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib);
                }
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        //if ($WikiTheme->dumped_buttons) $zip->addRegularFile("images/buttons", "", $attrib);
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "images/buttons/" . basename($img_file);
                if (check_php_version(4, 3)) {
                    $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib);
                } else {
                    $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib);
                }
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if ($from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                $target = basename($css_file);
                if (check_php_version(4, 3)) {
                    $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib);
                } else {
                    $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib);
                }
            }
        }
    }
    $zip->finish();
    if (check_php_version(4, 1)) {
        global $ErrorManager;
        $ErrorManager->popErrorHandler();
    }
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
}
示例#6
0
 /**
  * Preselect a list of pagenames by the supporting the follwing args:
  * 's': comma-seperated list of pagename wildcards
  * 'author', 'owner', 'creator': from WikiDB_Page
  * 'only: forgot what the diffrrence to 's' was.
  * Sets $this->_list, which is picked up by collectPages() and is a default for p[]
  */
 function preSelectS(&$args, &$request)
 {
     // override plugin argument by GET: probably not needed if s||="" is used
     // anyway, we force it for unique interface.
     if (!empty($request->getArg['s'])) {
         $args['s'] = $request->getArg['s'];
     }
     if (!empty($args['owner'])) {
         $sl = PageList::allPagesByOwner($args['owner'], false, $args['sortby'], $args['limit'], $args['exclude']);
     } elseif (!empty($args['author'])) {
         $sl = PageList::allPagesByAuthor($args['author'], false, $args['sortby'], $args['limit'], $args['exclude']);
     } elseif (!empty($args['creator'])) {
         $sl = PageList::allPagesByCreator($args['creator'], false, $args['sortby'], $args['limit'], $args['exclude']);
     } elseif (!empty($args['s']) or !empty($args['only'])) {
         // all pages by name
         $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
     }
     $this->_list = array();
     if (!empty($sl)) {
         $request->setArg('verify', 1);
         foreach ($sl as $name) {
             if (!empty($args['exclude'])) {
                 if (!in_array($name, $args['exclude'])) {
                     $this->_list[$name] = 1;
                 }
             } else {
                 $this->_list[$name] = 1;
             }
         }
     }
     return $this->_list;
 }
示例#7
0
function _DumpHtmlToDir($target, $page_iter, $exclude = false)
{
    global $WikiTheme, $request, $ErrorManager;
    $silent = true;
    $zip = false;
    $directory = false;
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $directory = $target;
        $silent = false;
    } elseif ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        $directory = $target;
    } elseif (is_object($target)) {
        // $WikiTheme->DUMP_MODE == 'ZIPHTML'
        $zip = $target;
    }
    $request->_TemplatesProcessed = array();
    if ($exclude) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array('DebugAuthInfo', 'DebugGroupInfo', 'AuthInfo');
    }
    $WikiTheme->VALID_LINKS = array();
    if ($request->getArg('format')) {
        // pagelist
        $page_iter_sav = $page_iter;
        foreach ($page_iter_sav->asArray() as $handle) {
            $WikiTheme->VALID_LINKS[] = is_string($handle) ? $handle : $handle->getName();
        }
        $page_iter_sav->reset();
    }
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
    // check if the dumped file will be accessible from outside
    $doc_root = $request->get("DOCUMENT_ROOT");
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $ldir = NormalizeLocalFileName($directory);
        $wikiroot = NormalizeLocalFileName('');
        if (string_starts_with($ldir, $doc_root)) {
            $link_prefix = substr($directory, strlen($doc_root)) . "/";
        } elseif (string_starts_with($ldir, $wikiroot)) {
            $link_prefix = NormalizeWebFileName(substr($directory, strlen($wikiroot))) . "/";
        } else {
            $prefix = '';
            if (isWindows()) {
                $prefix = '/';
                // . substr($doc_root,0,2); // add drive where apache is installed
            }
            $link_prefix = "file://" . $prefix . $directory . "/";
        }
    } else {
        $link_prefix = "";
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 60 : 240;
    if ($directory) {
        if (isWindows()) {
            $directory = str_replace("\\", "/", $directory);
        }
        // no Win95 support.
        @mkdir("{$directory}/images");
    }
    $already = array();
    $outfiles = array();
    $already_images = array();
    while ($page = $page_iter->next()) {
        if (is_string($page)) {
            $pagename = $page;
            $page = $request->_dbi->getPage($pagename);
        } else {
            $pagename = $page->getName();
        }
        if (empty($firstpage)) {
            $firstpage = $pagename;
        }
        if (array_key_exists($pagename, $already)) {
            continue;
        }
        $already[$pagename] = 1;
        $current = $page->getCurrentRevision();
        //if ($current->getVersion() == 0)
        //    continue;
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        if ($zip) {
            $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1);
            if ($page->get('locked')) {
                $attrib['write_protected'] = 1;
            }
        } elseif (!$silent) {
            if (!isa($request, 'MockRequest')) {
                PrintXML(HTML::br(), $pagename, ' ... ');
                flush();
            }
        }
        if (in_array($pagename, $excludeList)) {
            if (!$silent and !isa($request, 'MockRequest')) {
                PrintXML(_("Skipped."));
                flush();
            }
            continue;
        }
        $relative_base = '';
        if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
            $request->setArg('action', 'pdf');
        }
        // to omit cache headers
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $args = array('revision' => $current, 'CONTENT' => $current->getTransformedContent(), 'relative_base' => $relative_base);
        // For every %2F will need to mkdir -p dirname($pagename)
        if (preg_match("/(%2F|\\/)/", $filename)) {
            // mkdir -p and set relative base for subdir pages
            $filename = preg_replace("/%2F/", "/", $filename);
            $count = substr_count($filename, "/");
            $dirname = dirname($filename);
            if ($directory) {
                mkdir_p($directory . "/" . $dirname);
            }
            // Fails with "XX / YY", "XX" is created, "XX / YY" cannot be written
            // if (isWindows()) // interesting Windows bug: cannot mkdir "bla "
            // Since dumps needs to be copied, we have to disallow this for all platforms.
            $filename = preg_replace("/ \\//", "/", $filename);
            $relative_base = "../";
            while ($count > 1) {
                $relative_base .= "../";
                $count--;
            }
            $args['relative_base'] = $relative_base;
        }
        $msg = HTML();
        $DUMP_MODE = $WikiTheme->DUMP_MODE;
        $data = GeneratePageasXML(new Template('browse', $request, $args), $pagename, $current, $args);
        $WikiTheme->DUMP_MODE = $DUMP_MODE;
        if (preg_match_all("/<img .*?src=\"(\\/.+?)\"/", $data, $m)) {
            // fix to local relative path for uploaded images, so that pdf will work
            foreach ($m[1] as $img_file) {
                $base = basename($img_file);
                $data = str_replace('src="' . $img_file . '"', 'src="images/' . $base . '"', $data);
                if (array_key_exists($img_file, $already_images)) {
                    continue;
                }
                $already_images[$img_file] = 1;
                // resolve src from webdata to file
                $src = $doc_root . $img_file;
                if (file_exists($src) and $base) {
                    if ($directory) {
                        $target = "{$directory}/images/{$base}";
                        if (copy($src, $target)) {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... copied to %s", $target));
                            }
                        } else {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... not copied to %s", $target));
                            }
                        }
                    } else {
                        $target = "images/{$base}";
                        $zip->addSrcFile($target, $src);
                    }
                }
            }
        }
        if ($directory) {
            $outfile = $directory . "/" . $filename;
            if (!($fd = fopen($outfile, "wb"))) {
                $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", $outfile)));
                $request->finish($msg);
            }
            $len = strlen($data);
            $num = fwrite($fd, $data, $len);
            if ($pagename != $filename) {
                $link = LinkURL($link_prefix . $filename, $filename);
                $msg->pushContent(HTML::small(_("saved as "), $link, " ... "));
            }
            $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n"));
            if (!$silent) {
                if (!isa($request, 'MockRequest')) {
                    PrintXML($msg);
                }
                flush();
                $request->chunkOutput();
            }
            assert($num == $len);
            fclose($fd);
            $outfiles[] = $outfile;
        } else {
            $zip->addRegularFile($filename, $data, $attrib);
        }
        if (USECACHE) {
            $request->_dbi->_cache->invalidate_cache($pagename);
            unset($request->_dbi->_cache->_pagedata_cache);
            unset($request->_dbi->_cache->_versiondata_cache);
            unset($request->_dbi->_cache->_glv_cache);
        }
        unset($request->_dbi->_cache->_backend->_page_data);
        unset($msg);
        unset($current->_transformedContent);
        unset($current);
        if (!empty($template)) {
            unset($template->_request);
            unset($template);
        }
        unset($data);
    }
    $page_iter->free();
    $attrib = false;
    //array('is_ascii' => 0);
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        // @mkdir("$directory/images");
        foreach ($WikiTheme->dumped_images as $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        // Buttons also
        if ($directory) {
            @mkdir("{$directory}/images/buttons");
        }
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/buttons/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/buttons/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if (array_key_exists($css_file, $already_images)) {
                continue;
            }
            $already_images[$css_file] = 1;
            if ($css_file and $from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                // TODO: fix @import url(main.css);
                if ($directory) {
                    $target = "{$directory}/" . basename($css_file);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    //$attrib = array('is_ascii' => 0);
                    $target = basename($css_file);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if ($zip) {
        $zip->finish();
    }
    if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        if (USE_EXTERNAL_HTML2PDF and $outfiles) {
            $cmd = EXTERNAL_HTML2PDF_PAGELIST . ' "' . join('" "', $outfiles) . '"';
            $filename = FilenameForPage($firstpage);
            if (DEBUG) {
                $tmpfile = $directory . "/createpdf.bat";
                $fp = fopen($tmpfile, "wb");
                fwrite($fp, $cmd . " > {$filename}.pdf");
                fclose($fp);
            }
            if (!headers_sent()) {
                Header('Content-Type: application/pdf');
                passthru($cmd);
            } else {
                $tmpdir = getUploadFilePath();
                $s = passthru($cmd . " > {$tmpdir}/{$filename}.pdf");
                $errormsg = "<br />\nGenerated <a href=\"" . getUploadDataPath() . "{$filename}.pdf\">Upload:{$filename}.pdf</a>\n";
                $errormsg .= $s;
                echo $errormsg;
            }
            if (!DEBUG) {
                foreach ($outfiles as $f) {
                    unlink($f);
                }
            }
        }
        if (!empty($errormsg)) {
            $request->discardOutput();
            $GLOBALS['ErrorManager']->_postponed_errors = array();
        }
    }
    $ErrorManager->popErrorHandler();
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
}
示例#8
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     if (!empty($args['exclude_from'])) {
         $args['exclude_from'] = is_string($args['exclude_from']) ? explodePageList($args['exclude_from']) : $args['exclude_from'];
     }
     // <! plugin-list !>
     extract($args);
     if ($page == _("WantedPages")) {
         $page = "";
     }
     // There's probably a more memory-efficient way to do this (eg
     // a tailored SQL query via the backend, but this gets the job
     // done.
     // TODO: Move this to backend/dumb/WantedPagesIter.php
     if (!$page) {
         $GLOBALS['WikiTheme']->addPageListColumn(array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left')));
     }
     $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args);
     // search button?
     $pagelist->_wpagelist = array();
     if (!$page) {
         list($offset, $maxcount) = $pagelist->limit($limit);
         $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit);
         while ($row = $wanted_iter->next()) {
             $wanted = $row['pagename'];
             $wantedfrom = $row['wantedfrom'];
             // ignore duplicates:
             if (empty($pagelist->_wpagelist[$wanted])) {
                 $pagelist->addPage($wanted);
             }
             $pagelist->_wpagelist[$wanted][] = $wantedfrom;
         }
         $wanted_iter->free();
         // update limit, but it's still a hack.
         $pagelist->_options['limit'] = "{$offset}," . min($pagelist->getTotal(), $maxcount);
     } elseif ($dbi->isWikiPage($page)) {
         //only get WantedPages links for one page
         $page_handle = $dbi->getPage($page);
         $links = $page_handle->getPageLinks(true);
         // include_empty
         while ($link_handle = $links->next()) {
             if (!$dbi->isWikiPage($linkname = $link_handle->getName())) {
                 $pagelist->addPage($linkname);
                 //if (!array_key_exists($linkname, $this->_wpagelist))
                 $pagelist->_wpagelist[$linkname][] = 1;
             }
         }
     }
     /*
             if ($sortby) {
                 ksort($this->_wpagelist);
                 arsort($this->_wpagelist);
             }*/
     if (!$noheader) {
         if ($page) {
             $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
         } else {
             $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
         }
     }
     // reference obviously doesn't work, so force an update to add _wpagelist to parentobj
     if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted') {
         $pagelist->_columns[1]->parentobj =& $pagelist;
     }
     return $pagelist;
 }
示例#9
0
 function getArgs($argstr, $request = false, $defaults = false)
 {
     if ($defaults === false) {
         $defaults = $this->getDefaultArguments();
     }
     //Fixme: on POST argstr is empty
     list($argstr_args, $argstr_defaults) = $this->parseArgStr($argstr);
     $args = array();
     if (!empty($defaults)) {
         foreach ($defaults as $arg => $default_val) {
             if (isset($argstr_args[$arg])) {
                 $args[$arg] = $argstr_args[$arg];
             } elseif ($request and ($argval = $request->getArg($arg)) !== false) {
                 $args[$arg] = $argval;
             } elseif (isset($argstr_defaults[$arg])) {
                 $args[$arg] = (string) $argstr_defaults[$arg];
             } else {
                 $args[$arg] = $default_val;
             }
             // expand [arg]
             if ($request and is_string($args[$arg]) and strstr($args[$arg], "[")) {
                 $args[$arg] = $this->expandArg($args[$arg], $request);
             }
             unset($argstr_args[$arg]);
             unset($argstr_defaults[$arg]);
         }
     }
     foreach (array_merge($argstr_args, $argstr_defaults) as $arg => $val) {
         if ($request and $request->getArg('pagename') == _("PhpWikiAdministration") and $arg == 'overwrite') {
             // silence this warning
         } else {
             trigger_error(sprintf(_("Argument '%s' not declared by plugin."), $arg), E_USER_NOTICE);
         }
     }
     // add special handling of pages and exclude args to accept <! plugin-list !>
     // and split explodePageList($args['exclude']) => array()
     // TODO : handle p[] pagehash
     foreach (array('pages', 'exclude') as $key) {
         if (!empty($args[$key]) and array_key_exists($key, $defaults)) {
             $args[$key] = is_string($args[$key]) ? explodePageList($args[$key]) : $args[$key];
         }
         // <! plugin-list !>
     }
     // always override sortby,limit from the REQUEST. ignore defaults if defined as such.
     foreach (array('sortby', 'limit') as $key) {
         if (array_key_exists($key, $defaults)) {
             if ($val = $GLOBALS['request']->getArg($key)) {
                 $args[$key] = $val;
             } elseif (!empty($args[$key])) {
                 $GLOBALS['request']->setArg($key, $args[$key]);
             }
         }
     }
     return $args;
 }
示例#10
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (empty($page) and $page != '0') {
         return '';
     }
     // exclude is now already expanded in WikiPlugin::getArgs()
     if (empty($exclude)) {
         $exclude = array();
     }
     if (!$include_self) {
         $exclude[] = $page;
     }
     if ($info) {
         $info = explode(",", $info);
         if (in_array('count', $info)) {
             $args['types']['count'] = new _PageList_Column_BackLinks_count('count', _("#"), 'center');
         }
     }
     if (!empty($limit)) {
         $args['limit'] = $limit;
     }
     $args['dosort'] = !empty($args['sortby']);
     // override DB sort (??)
     $pagelist = new PageList($info, $exclude, $args);
     // support logical AND: page1,page2
     $pages = explodePageList($page);
     $count = count($pages);
     if (count($pages) > 1) {
         // AND: the intersection of all these pages
         $bl = array();
         foreach ($pages as $p) {
             $dp = $dbi->getPage($p);
             $bi = $dp->getBackLinks(false, $sortby, 0, $exclude);
             while ($b = $bi->next()) {
                 $name = $b->getName();
                 if (isset($bl[$name])) {
                     $bl[$name]++;
                 } else {
                     $bl[$name] = 1;
                 }
             }
         }
         foreach ($bl as $b => $v) {
             if ($v == $count) {
                 $pagelist->addPage($b);
             }
         }
     } else {
         $p = $dbi->getPage($page);
         $pagelist->addPages($p->getBackLinks(false, $sortby, 0, $exclude));
     }
     $total = $pagelist->getTotal();
     // Localization note: In English, the differences between the
     // various phrases spit out here may seem subtle or negligible
     // enough to tempt you to combine/normalize some of these
     // strings together, but the grammar employed most by other
     // languages does not always end up with so subtle a
     // distinction as it does with English in this case. :)
     if (!$noheader) {
         if ($page == $request->getArg('pagename') and !$dbi->isWikiPage($page)) {
             // BackLinks plugin is more than likely being called
             // upon for an empty page on said page, while either
             // 'browse'ing, 'create'ing or 'edit'ing.
             //
             // Don't bother displaying a WikiLink 'unknown', just
             // the Un~WikiLink~ified (plain) name of the uncreated
             // page currently being viewed.
             $pagelink = $page;
             if ($pagelist->isEmpty()) {
                 return HTML::p(fmt("No other page links to %s yet.", $pagelink));
             }
             if ($total == 1) {
                 $pagelist->setCaption(fmt("One page would link to %s:", $pagelink));
             } else {
                 $pagelist->setCaption(fmt("%s pages would link to %s:", $total, $pagelink));
             }
         } else {
             if ($count) {
                 $tmp_pages = $pages;
                 $p = array_shift($tmp_pages);
                 $pagelink = HTML(WikiLink($p, 'auto'));
                 foreach ($tmp_pages as $p) {
                     $pagelink->pushContent(" ", _("AND"), " ", WikiLink($p, 'auto'));
                 }
             } else {
                 // BackLinks plugin is being displayed on a normal page.
                 $pagelink = WikiLink($page, 'auto');
             }
             if ($pagelist->isEmpty()) {
                 return HTML::p(fmt("No page links to %s.", $pagelink));
             }
             //trigger_error("DEBUG: " . $pagelist->getTotal());
             if ($total == 1) {
                 $pagelist->setCaption(fmt("One page links to %s:", $pagelink));
             } else {
                 $pagelist->setCaption(fmt("%s pages link to %s:", $limit > 0 ? $total : _("Those"), $pagelink));
             }
         }
     }
     if (!empty($args['linkmore']) and $dbi->isWikiPage($args['linkmore']) and $limit > 0 and $total > $limit) {
         $pagelist->addCaption(WikiLink($args['linkmore'], "auto", _("More...")));
     }
     return $pagelist;
 }
示例#11
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     // If the ratings table does not exist, or on dba it will break otherwise.
     // Check if Theme isa 'wikilens'
     if ($info == 'pagename' and isa($GLOBALS['WikiTheme'], 'wikilens')) {
         $info .= ",top3recs";
     }
     if ($info) {
         $info = split(',', $info);
     } else {
         $info = array();
     }
     if (in_array('top3recs', $info)) {
         require_once 'lib/wikilens/Buddy.php';
         require_once 'lib/wikilens/PageListColumns.php';
         $active_user = $request->getUser();
         $active_userid = $active_user->_userid;
         // if userids is null or empty, fill it with just the active user
         if (!isset($userids) || !is_array($userids) || !count($userids)) {
             // TKL: moved getBuddies call inside if statement because it was
             // causing the userids[] parameter to be ignored
             if (is_string($active_userid) and strlen($active_userid) and $active_user->isSignedIn()) {
                 $userids = getBuddies($active_userid, $dbi);
             } else {
                 $userids = array();
                 // XXX: this wipes out the category caption...
                 $caption = _("You must be logged in to view ratings.");
             }
         }
         // find out which users we should show ratings for
         $allowed_users = array();
         foreach ($userids as $userid) {
             $user = new RatingsUser($userid);
             if ($user->allow_view_ratings($active_user)) {
                 array_push($allowed_users, $user);
             }
             // PHP's silly references... (the behavior with this line commented
             // out is... odd)
             unset($user);
         }
         $options = array('dimension' => $dimension, 'users' => $allowed_users);
         $args = array_merge($options, $args);
     }
     if (empty($pages) and $pages != '0') {
         return '';
     }
     if (in_array('numbacklinks', $info)) {
         $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
     }
     if (in_array('numpagelinks', $info)) {
         $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
     }
     $pagelist = new PageList($info, $exclude, $args);
     $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
     $pagelist->addPageList($pages_array);
     return $pagelist;
 }
示例#12
0
 function getArgs($argstr, $request = false, $defaults = false)
 {
     if ($defaults === false) {
         $defaults = $this->getDefaultArguments();
     }
     //Fixme: on POST argstr is empty
     list($argstr_args, $argstr_defaults) = $this->parseArgStr($argstr);
     $args = array();
     if (!empty($defaults)) {
         foreach ($defaults as $arg => $default_val) {
             if (isset($argstr_args[$arg])) {
                 $args[$arg] = $argstr_args[$arg];
             } elseif ($request and ($argval = $request->getArg($arg)) !== false) {
                 $args[$arg] = $argval;
             } elseif (isset($argstr_defaults[$arg])) {
                 $args[$arg] = (string) $argstr_defaults[$arg];
             } else {
                 $args[$arg] = $default_val;
             }
             // expand [arg]
             if ($request and is_string($args[$arg]) and strstr($args[$arg], "[")) {
                 $args[$arg] = $this->expandArg($args[$arg], $request);
             }
             unset($argstr_args[$arg]);
             unset($argstr_defaults[$arg]);
         }
     }
     foreach (array_merge($argstr_args, $argstr_defaults) as $arg => $val) {
         // TODO: where the heck comes this from? Put the new method over there and peace.
         /*if ($request and $request->getArg('pagename') == _("PhpWikiAdministration")
           and $arg == 'overwrite') // silence this warning
           ;*/
         if ($this->allow_undeclared_arg($arg, $val)) {
             $args[$arg] = $val;
         }
     }
     // Add special handling of pages and exclude args to accept <! plugin-list !>
     // and split explodePageList($args['exclude']) => array()
     // TODO : handle p[] pagehash
     foreach (array('pages', 'exclude') as $key) {
         if (!empty($args[$key]) and array_key_exists($key, $defaults)) {
             $args[$key] = is_string($args[$key]) ? explodePageList($args[$key]) : $args[$key];
         }
         // <! plugin-list !>
     }
     return $args;
 }
示例#13
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (empty($page)) {
         $page = $request->getArg('pagename');
     }
     $relhtml = HTML();
     if ($args['relations'] != '') {
         $relfilter = explode(",", $args['relations']);
     } else {
         $relfilter = array();
     }
     if ($args['attributes'] != '') {
         $attfilter = explode(",", $args['attributes']);
     } else {
         $attfilter = array();
     }
     foreach (explodePageList($page) as $pagename) {
         $p = $dbi->getPage($pagename);
         if ($args['relations'] != '0') {
             $links = $p->getRelations();
             // iter of pagelinks
             // TODO: merge same relations together located_in::here, located_in::there
             while ($object = $links->next()) {
                 if ($related = $object->get('linkrelation')) {
                     // a page name
                     if ($relfilter and !in_array($related, $relfilter)) {
                         continue;
                     }
                     $rellink = WikiLink($related, false, $related);
                     $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
                     $relhtml->pushContent($pagename . " ", $rellink, HTML::span(array('class' => 'relation-symbol'), "::"), WikiLink($object->_pagename), " ", $WikiTheme->makeActionButton(array('relation' => $related, 's' => $object->_pagename), '+', _("SemanticSearch")), count($relfilter) > 3 ? HTML::br() : " ");
                 }
             }
             if (!empty($relhtml->_content) and !$noheader) {
                 $relhtml = HTML(HTML::hr(), HTML::h3(fmt("Semantic relations for %s", $pagename)), $relhtml);
             }
         }
         $atthtml = HTML();
         if ($args['attributes'] != '0') {
             if ($attributes = $p->get('attributes')) {
                 // a hash of unique pairs
                 foreach ($attributes as $att => $val) {
                     if ($attfilter and !in_array($att, $attfilter)) {
                         continue;
                     }
                     $rellink = WikiLink($att, false, $att);
                     $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
                     $searchlink = $WikiTheme->makeActionButton(array('attribute' => $att, 's' => $val), $val, _("SemanticSearch"));
                     $searchlink->setAttr('class', $searchlink->getAttr('class') . ' attribute');
                     if (!$noheader) {
                         $atthtml->pushContent("{$pagename}  ");
                     }
                     $atthtml->pushContent(HTML::span(array('class' => 'attribute ' . $att), $rellink, HTML::span(array('class' => 'relation-symbol'), ":="), $searchlink), count($attfilter) > 3 ? HTML::br() : " ");
                 }
                 if (!$noheader) {
                     $relhtml = HTML($relhtml, HTML::hr(), HTML::h3(fmt("Attributes of %s", $pagename)), $atthtml);
                 } else {
                     $relhtml = HTML($relhtml, $atthtml);
                 }
             }
         }
     }
     if ($nohelp) {
         return $relhtml;
     }
     return HTML($relhtml, HTML::hr(), WikiLink(_("Help/SemanticRelations"), false, HTML::em(_("Help/SemanticRelations"))), " - ", HTML::em(_("Find out how to add relations and attributes to pages.")));
 }