Esempio n. 1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $maincat = $dbi->getPage(_("CategoryCategory"));
     $bi = $maincat->getBackLinks(false);
     $bl = array();
     while ($b = $bi->next()) {
         $name = $b->getName();
         if (preg_match("/^" . _("Template") . "/", $name)) {
             continue;
         }
         $pages = $b->getBackLinks(false);
         $bl[] = array('name' => $name, 'count' => $pages->count());
     }
     usort($bl, 'cmp_by_count');
     $html = HTML::ul();
     $i = 0;
     foreach ($bl as $b) {
         $i++;
         $name = $b['name'];
         $count = $b['count'];
         if ($count < $mincount) {
             break;
         }
         if ($i > $limit) {
             break;
         }
         $wo = preg_replace("/^(" . _("Category") . "|" . _("Topic") . ")/", "", $name);
         $wo = HTML(HTML::span($wo), HTML::raw("&nbsp;"), HTML::small("(" . $count . ")"));
         $link = WikiLink($name, 'auto', $wo);
         $html->pushContent(HTML::li($link));
     }
     return $html;
 }
Esempio n. 2
0
function ActionButton($action, $label = false, $page_or_rev = false, $options = false)
{
    global $WikiTheme;
    global $request;
    if (is_array($action)) {
        $attr = $action;
        $act = isset($attr['action']) ? $attr['action'] : 'browse';
    } else {
        $act = $action;
    }
    $class = is_safe_action($act) ? 'named-wiki' : 'wikiadmin';
    /* if selected action is current then prepend selected */
    $curract = $request->getArg("action");
    if ($curract == $act and $curract != 'browse') {
        $class = "selected {$class}";
    }
    if (!empty($options['class'])) {
        if ($curract == 'browse') {
            $class = "{$class} " . $options['class'];
        } else {
            $class = $options['class'];
        }
    }
    return HTML::li(array('class' => $class), $WikiTheme->makeActionButton($action, $label, $page_or_rev, $options));
}
Esempio n. 3
0
 function purgePages(&$request, $pages)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $dbi = $request->getDbh();
     $count = 0;
     foreach ($pages as $name) {
         $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
         if (mayAccessPage('purge', $name)) {
             $dbi->purgePage($name);
             $ul->pushContent(HTML::li(fmt("Purged page '%s' successfully.", $name)));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Didn't purge page '%s'. Access denied.", $name)));
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently purged:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently purged:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages purged."));
         return $result;
     }
 }
Esempio n. 4
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     include_once "lib/imdb.php";
     $imdb = new imdb();
     if (method_exists($imdb, $query)) {
         $SqlResult = $imdb->{$query}($title ? $title : $name);
     } else {
         $SqlResult = array();
     }
     // if ($limit) ; // TODO: fill paging vars (see PageList)
     if ($ordered) {
         $html = HTML::ol(array('class' => 'sqlresult'));
         foreach ($SqlResult as $row) {
             $html->pushContent(HTML::li(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'), $row[0]));
         }
     } else {
         $html = HTML::table(array('class' => 'sqlresult'));
         $i = 0;
         foreach ($SqlResult as $row) {
             $tr = HTML::tr(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'));
             foreach ($row as $col) {
                 $tr->pushContent(HTML::td($col));
             }
             $html->pushContent($tr);
         }
     }
     // if ($limit) ; // do paging via pagelink template
     return $html;
 }
Esempio n. 5
0
 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks = false)
 {
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_rename');
     $options = array('regex' => @$post_args['regex'], 'icase' => @$post_args['icase']);
     foreach ($pages as $name) {
         if ($newname = $this->renameHelper($name, $from, $to, $options) and $newname != $name) {
             if ($dbi->isWikiPage($newname)) {
                 $ul->pushContent(HTML::li(fmt("Page %s already exists. Ignored.", WikiLink($newname))));
             } elseif (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } elseif ($dbi->renamePage($name, $newname, $updatelinks)) {
                 /* not yet implemented for all backends */
                 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.", $name, WikiLink($newname))));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
             }
         } else {
             $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently renamed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages renamed.")));
     }
 }
Esempio n. 6
0
 function chownPages(&$dbi, &$request, $pages, $newowner)
 {
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         if ($owner = $page->getOwner() and $newowner != $owner) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $page->set('owner', $newowner);
                 if ($page->get('owner') === $newowner) {
                     $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.", WikiLink($name), WikiLink($newowner))));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.", WikiLink($name), $newowner)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Esempio n. 7
0
function Wordpress_RC_revision_formatter(&$fmt, &$rev)
{
    $class = 'rc-' . $fmt->importance($rev);
    $time = $fmt->time($rev);
    if ($rev->get('is_minor_edit')) {
        $minor_flag = HTML::small("(" . _("minor edit") . ")");
    } else {
        $time = HTML::strong($time);
        $minor_flag = '';
    }
    return HTML::li(array('class' => $class), $fmt->diffLink($rev), ' ', $fmt->pageLink($rev), ' ', $time, ' ', $minor_flag, ' ', " . . . ", $fmt->summaryAsHTML($rev), ' ', " . . . ", $fmt->authorLink($rev));
}
Esempio n. 8
0
 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $markup = $current->get('markup');
         if (!$markup or $newmarkup != $markup) {
             if (!mayAccessPage('change', $name)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $meta['markup'] = $newmarkup;
                 // convert text?
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 $current = $page->getCurrentRevision();
                 if ($current->get('markup') === $newmarkup) {
                     $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
Esempio n. 9
0
 function chownPages(&$dbi, &$request, $pages, $newowner)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         if ($owner = $page->getOwner() and $newowner != $owner) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = "Change page owner from '" . $owner . "' to '" . $newowner . "'";
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->set('owner', $newowner);
                 $page->save($text, $version + 1, $meta);
                 if ($page->get('owner') === $newowner) {
                     $ul->pushContent(HTML::li(fmt("Change owner of page '%s' to '%s'.", WikiLink($name), WikiLink($newowner))));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Could not change owner of page '%s' to '%s'.", WikiLink($name), $newowner)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
Esempio n. 10
0
 function setExternalPages(&$dbi, &$request, $pages)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $external = $current->get('external');
         if (!$external) {
             $external = 0;
         }
         $external = (bool) $external;
         if (!$external) {
             if (!mayAccessPage('change', $name)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $page->set('external', (bool) 1);
                 $ul->pushContent(HTML::li(fmt("change page '%s' to external.", WikiLink($name))));
                 $count++;
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
Esempio n. 11
0
 function format_revision($rev)
 {
     static $doublettes = array();
     if (isset($doublettes[$rev->getPageName()])) {
         return;
     }
     $doublettes[$rev->getPageName()] = 1;
     $args =& $this->_args;
     $class = 'rc-' . $this->importance($rev);
     $time = $this->time($rev);
     if (!$rev->get('is_minor_edit')) {
         $time = HTML::strong(array('class' => 'pageinfo-majoredit'), $time);
     }
     $line = HTML::li(array('class' => $class));
     if ($args['difflinks']) {
         $line->pushContent($this->diffLink($rev), ' ');
     }
     if ($args['historylinks']) {
         $line->pushContent($this->historyLink($rev), ' ');
     }
     $line->pushContent($this->pageLink($rev), ' ', $time, ' ', ' . . . . ', _("latest comment by "), $this->authorLink($rev));
     return $line;
 }
Esempio n. 12
0
 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
 {
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $markup = $current->get('markup');
         if (!$markup or $newmarkup != $markup) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $meta['markup'] = $newmarkup;
                 // convert text?
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("WikiAdminMarkup from %s to %s"), $markup, $newmarkup);
                 $page->save($text, $version + 1, $meta);
                 $current = $page->getCurrentRevision();
                 if ($current->get('markup') === $newmarkup) {
                     $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Esempio n. 13
0
 function chmodPages(&$dbi, &$request, $pages, $permstring)
 {
     $ul = HTML::ul();
     $count = 0;
     $acl = chmodHelper($permstring);
     if ($perm = new PagePermission($acl)) {
         foreach ($pages as $name) {
             if ($perm->store($dbi->getPage($name))) {
                 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.", $name, $permstring)));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
             }
         }
     } else {
         $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Esempio n. 14
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if ($exclude) {
         if (!is_array($exclude)) {
             $exclude = explode(',', $exclude);
         }
     }
     if ($page == _("WantedPages")) {
         $page = "";
     }
     // The PageList class can't handle the 'count' column needed
     // for this table
     $this->pagelist = array();
     // 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.
     if (!$page) {
         $include_empty = false;
         $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
         while ($page_handle = $allpages_iter->next()) {
             $name = $page_handle->getName();
             if ($name == _("InterWikiMap")) {
                 continue;
             }
             if (!in_array($name, $exclude)) {
                 $this->_iterateLinks($page_handle, $dbi);
             }
         }
     } else {
         if ($page && ($pageisWikiPage = $dbi->isWikiPage($page))) {
             //only get WantedPages links for one page
             $page_handle = $dbi->getPage($page);
             $this->_iterateLinks($page_handle, $dbi);
             if (!$request->getArg('count')) {
                 $args['count'] = count($this->pagelist);
             } else {
                 $args['count'] = $request->getArg('count');
             }
         }
     }
     ksort($this->pagelist);
     arsort($this->pagelist);
     $this->_rows = HTML();
     $caption = false;
     $this->_messageIfEmpty = _("<none>");
     if ($page) {
         // link count always seems to be 1 for a single page so
         // omit count column
         foreach ($this->pagelist as $key => $val) {
             $row = HTML::li(WikiLink((string) $key, 'unknown'));
             $this->_rows->pushContent($row);
         }
         if (!$noheader) {
             if ($pageisWikiPage) {
                 $pagelink = WikiLink($page);
             } else {
                 $pagelink = WikiLink($page, 'unknown');
             }
             $c = count($this->pagelist);
             $caption = fmt("Wanted Pages for %s (%d total):", $pagelink, $c);
         }
         return $this->_generateList($caption);
     } else {
         $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
         // Clicking on the number in the links column does a
         // FullTextSearch for the citations of the WantedPage
         // link.
         foreach ($this->pagelist as $key => $val) {
             $key = (string) $key;
             // TODO: Not sure why, but this
             // string cast type-coersion
             // does seem necessary here.
             // Enclose any FullTextSearch keys containing a space
             // with quotes in oder to request a defnitive search.
             $searchkey = strstr($key, ' ') === false ? $key : "\"{$key}\"";
             $row = HTML::tr(HTML::td(array('align' => 'right'), Button(array('s' => $searchkey), $val, _("FullTextSearch")), HTML::td(HTML($spacer, WikiLink($key, 'unknown')))));
             $this->_rows->pushContent($row);
         }
         $c = count($this->pagelist);
         if (!$noheader) {
             $caption = sprintf(_("Wanted Pages in this wiki (%d total):"), $c);
         }
         $this->_columns = array(_("Count"), _("Page Name"));
         if ($c > 0) {
             return $this->_generateTable($caption);
         } else {
             return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
         }
     }
 }
Esempio n. 15
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     //        if (empty($args['s']))
     //    return '';
     $html = HTML();
     extract($args);
     // prevent from dump
     if ($q and $request->isPost()) {
         require_once "lib/Google.php";
         $google = new Google();
         if (!$google) {
             return '';
         }
         switch ($mode) {
             case 'search':
                 $result = $google->doGoogleSearch($q);
                 break;
             case 'cache':
                 $result = $google->doGetCachedPage($q);
                 break;
             case 'spell':
                 $result = $google->doSpellingSuggestion($q);
                 break;
             default:
                 trigger_error("Invalid mode");
         }
         if (isa($result, 'HTML')) {
             $html->pushContent($result);
         }
         if (isa($result, 'GoogleSearchResults')) {
             //TODO: result template
             if (!empty($result->resultElements)) {
                 $list = HTML::ol();
                 foreach ($result->resultElements as $res) {
                     $li = HTML::li(LinkURL($res['URL'], $res['directoryTitle']), HTML::br(), $res['directoryTitle'] ? HTML(HTML::raw('&nbsp;&nbsp;'), HTML::em($res['summary']), ' -- ', LinkURL($res['URL'])) : '');
                     $list->pushContent($li);
                 }
                 $html->pushContent($list);
             } else {
                 return _("Nothing found");
             }
         }
         if (is_string($result)) {
             // cache content also?
             $html->pushContent(HTML::blockquote(HTML::raw($result)));
         }
     }
     if ($formsize < 1) {
         $formsize = 30;
     }
     // todo: template
     $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('pagename' => $basepage, 'mode' => $mode)));
     $form->pushContent(HTML::input(array('type' => 'text', 'value' => $q, 'name' => 'q', 'size' => $formsize)));
     $form->pushContent(HTML::input(array('type' => 'submit', 'class' => 'button', 'value' => gettext($mode))));
     return HTML($html, $form);
 }
Esempio n. 16
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     //if ($request->getArg('action') != 'browse')
     //    return $this->disabled("(action != 'browse')");
     $args = $this->getArgs($argstr, $request);
     $this->_args = $args;
     extract($args);
     $this->preSelectS($args, $request);
     $info = $args['info'];
     $this->debug = $args['debug'];
     // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
     $pagename = $request->getArg('pagename');
     // GetUrlToSelf() with all given params
     //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
     //$uri = $request->getURLtoSelf();//false, array('verify'));
     $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
     if ($request->getArg('WikiAdminSelect') == _("Go")) {
         $p = false;
     } else {
         $p = $request->getArg('p');
     }
     //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
     $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "), HTML::input(array('type' => 'text', 'name' => 's', 'value' => $args['s'])), HTML::input(array('type' => 'submit', 'name' => 'WikiAdminSelect', 'value' => _("Go")))));
     if ($request->isPost() && !$request->getArg('wikiadmin') && !empty($p)) {
         $this->_list = array();
         // List all selected pages again.
         foreach ($p as $page => $name) {
             $this->_list[$name] = 1;
         }
     } elseif ($request->isPost() and $request->_user->isAdmin() and !empty($p) and $request->getArg('action') == 'WikiAdminSelect' and $request->getArg('wikiadmin')) {
         // handle external plugin
         $loader = new WikiPluginLoader();
         $a = array_keys($request->getArg('wikiadmin'));
         $plugin_action = $a[0];
         $single_arg_plugins = array("Remove");
         if (in_array($plugin_action, $single_arg_plugins)) {
             $plugin = $loader->getPlugin($plugin_action);
             $ul = HTML::ul();
             foreach ($p as $page => $name) {
                 $plugin_args = "run_page={$name}";
                 $request->setArg($plugin_action, 1);
                 $request->setArg('p', array($page => $name));
                 // if the plugin requires more args than the pagename,
                 // then this plugin will not return. (Rename, SearchReplace, ...)
                 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
                 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.", $name, $select)));
                 $ul->pushContent(HTML::ul(HTML::li($action_result)));
             }
         } else {
             // redirect to the plugin page.
             // in which page is this plugin?
             $plugin_action = preg_replace("/^WikiAdmin/", "", $plugin_action);
             $args = array();
             foreach ($p as $page => $x) {
                 $args["p[{$page}]"] = 1;
             }
             header("Location: " . WikiURL(_("PhpWikiAdministration") . "/" . _($plugin_action), $args, 1));
             exit;
         }
     } elseif (empty($args['s'])) {
         // List all pages to select from.
         $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
     }
     $pagelist = new PageList_Selectable($info, $args['exclude'], $args);
     $pagelist->addPageList($this->_list);
     $form->pushContent($pagelist->getContent());
     foreach ($args as $k => $v) {
         if (!in_array($k, array('s', 'WikiAdminSelect', 'action', 'verify'))) {
             $form->pushContent(HiddenInputs(array($k => $v)));
         }
         // plugin params
     }
     /*
     foreach ($_GET as $k => $v) {
         if (!in_array($k,array('s','WikiAdminSelect','action')))
             $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
     }
     */
     if (!$request->getArg('verify')) {
         $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify')));
         $form->pushContent(Button('submit:verify', _("Select pages"), 'wikiadmin'), Button('submit:cancel', _("Cancel"), 'button'));
     } else {
         global $WikiTheme;
         $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'WikiAdminSelect')));
         // Add the Buttons for all registered WikiAdmin plugins
         $plugin_dir = 'lib/plugin';
         if (defined('PHPWIKI_DIR')) {
             $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}";
         }
         $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
         $actions = $fs->getFiles();
         foreach ($actions as $f) {
             $f = preg_replace('/.php$/', '', $f);
             $s = preg_replace('/^WikiAdmin/', '', $f);
             if (!in_array($s, array("Select", "Utils"))) {
                 // disable Select and Utils
                 $form->pushContent(Button("submit:wikiadmin[{$f}]", _($s), "wikiadmin"));
                 $form->pushContent($WikiTheme->getButtonSeparator());
             }
         }
         $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
     }
     if (!$request->getArg('select')) {
         return $form;
     } else {
         //return $action_result;
     }
 }
Esempio n. 17
0
function SpaceWiki_PH_revision_formatter(&$fmt, &$rev)
{
    $class = 'rc-' . $fmt->importance($rev);
    return HTML::li(array('class' => $class), $fmt->diffLink($rev), ' ', $fmt->pageLink($rev), ' ', $rev->get('is_minor_edit') ? $fmt->time($rev) : HTML::strong($fmt->time($rev)), ' ', ' . . . ', $fmt->summaryAsHTML($rev), ' . . . ', $fmt->authorLink($rev), $fmt->importance($rev) == 'minor' ? HTML::small(" (" . _("minor edit") . ")") : '');
}
 function searchReplacePages(&$dbi, &$request, $pages, $from, $to)
 {
     if (empty($from)) {
         return HTML::p(HTML::strong(fmt("Error: Empty search string.")));
     }
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_replace');
     $case_exact = !empty($post_args['case_exact']);
     $regex = !empty($post_args['regex']);
     foreach ($pages as $pagename) {
         if (!mayAccessPage('edit', $pagename)) {
             $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
         } elseif ($result = $this->replaceHelper($dbi, $pagename, $from, $to, $case_exact, $regex)) {
             $ul->pushContent(HTML::li(fmt("Replaced '%s' with '%s' in page '%s'.", $from, $to, WikiLink($pagename))));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Search string '%s' not found in content of page '%s'.", $from, WikiLink($pagename))));
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Esempio n. 19
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->allowed_extensions = explode("\n", "7z\navi\nbmp\nbz2\nc\ncfg\ndiff\ndoc\ndocx\nflv\ngif\nh\nics\nini\njpeg\njpg\nkmz\nmp3\nodg\nodp\nods\nodt\nogg\npatch\npdf\npng\nppt\npptx\nrar\nsvg\ntar\ntar.gz\ntxt\nxls\nxlsx\nxml\nxsd\nzip");
     $this->disallowed_extensions = explode("\n", "ad[ep]\nasd\nba[st]\nchm\ncmd\ncom\ncgi\ncpl\ncrt\ndll\neml\nexe\nhlp\nhta\nin[fs]\nisp\njse?\nlnk\nmd[betw]\nms[cipt]\nnws\nocx\nops\npcd\np[ir]f\nphp\\d?\nphtml\npl\npy\nreg\nsc[frt]\nsh[bsm]?\nswf\nurl\nvb[esx]?\nvxd\nws[cfh]");
     //removed "\{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}"
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $file_dir = getUploadFilePath();
     $file_dir .= "/";
     $form = HTML::form(array('action' => $request->getPostURL(), 'enctype' => 'multipart/form-data', 'method' => 'post'));
     $contents = HTML::div(array('class' => 'wikiaction'));
     $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => MAX_UPLOAD_SIZE)));
     $contents->pushContent(HTML::input(array('name' => 'userfile', 'type' => 'file', 'size' => $size)));
     if ($mode == 'edit') {
         $contents->pushContent(HTML::input(array('name' => 'action', 'type' => 'hidden', 'value' => 'edit')));
         $contents->pushContent(HTML::raw(" "));
         $contents->pushContent(HTML::input(array('value' => _("Upload"), 'name' => 'edit[upload]', 'type' => 'submit')));
     } else {
         $contents->pushContent(HTML::raw(" "));
         $contents->pushContent(HTML::input(array('value' => _("Upload"), 'type' => 'submit')));
     }
     $form->pushContent($contents);
     $message = HTML();
     if ($request->isPost() and $this->only_authenticated) {
         // Make sure that the user is logged in.
         $user = $request->getUser();
         if (!$user->isAuthenticated()) {
             if (defined('FUSIONFORGE') and FUSIONFORGE) {
                 $message->pushContent(HTML::div(array('class' => 'error'), HTML::p(_("You cannot upload files.")), HTML::ul(HTML::li(_("Check you are logged in.")), HTML::li(_("Check you are in the right project.")), HTML::li(_("Check you are a member of the current project.")))));
             } else {
                 $message->pushContent(HTML::div(array('class' => 'error'), HTML::p(_("ACCESS DENIED: You must log in to upload files."))));
             }
             $result = HTML();
             $result->pushContent($form);
             $result->pushContent($message);
             return $result;
         }
     }
     $userfile = $request->getUploadedFile('userfile');
     if ($userfile) {
         $userfile_name = $userfile->getName();
         $userfile_name = trim(basename($userfile_name));
         if (UPLOAD_USERDIR) {
             $file_dir .= $request->_user->_userid;
             if (!file_exists($file_dir)) {
                 mkdir($file_dir, 0775);
             }
             $file_dir .= "/";
             $u_userfile = $request->_user->_userid . "/" . $userfile_name;
         } else {
             $u_userfile = $userfile_name;
         }
         $u_userfile = preg_replace("/ /", "%20", $u_userfile);
         $userfile_tmpname = $userfile->getTmpName();
         $err_header = HTML::div(array('class' => 'error'), HTML::p(fmt("ERROR uploading '%s'", $userfile_name)));
         if (preg_match("/(\\." . join("|\\.", $this->disallowed_extensions) . ")(\\.|\$)/i", $userfile_name)) {
             $message->pushContent($err_header);
             $message->pushContent(HTML::p(fmt("Files with extension %s are not allowed.", join(", ", $this->disallowed_extensions))));
         } elseif (!DISABLE_UPLOAD_ONLY_ALLOWED_EXTENSIONS and !preg_match("/(\\." . join("|\\.", $this->allowed_extensions) . ")\$/i", $userfile_name)) {
             $message->pushContent($err_header);
             $message->pushContent(HTML::p(fmt("Only files with the extension %s are allowed.", join(", ", $this->allowed_extensions))));
         } elseif (preg_match("/[^._a-zA-Z0-9- ]/", strip_accents($userfile_name))) {
             $message->pushContent($err_header);
             $message->pushContent(HTML::p(_("Invalid filename. File names may only contain alphanumeric characters and dot, underscore, space or dash.")));
         } elseif (file_exists($file_dir . $userfile_name)) {
             $message->pushContent($err_header);
             $message->pushContent(HTML::p(fmt("There is already a file with name %s uploaded.", $u_userfile)));
         } elseif ($userfile->getSize() > MAX_UPLOAD_SIZE) {
             $message->pushContent($err_header);
             $message->pushContent(HTML::p(_("Sorry but this file is too big.")));
         } elseif (move_uploaded_file($userfile_tmpname, $file_dir . $userfile_name) or IsWindows() and rename($userfile_tmpname, $file_dir . $userfile_name)) {
             $interwiki = new PageType_interwikimap();
             $link = $interwiki->link("Upload:{$u_userfile}");
             $message->pushContent(HTML::div(array('class' => 'feedback'), HTML::p(_("File successfully uploaded.")), HTML::p($link)));
             // the upload was a success and we need to mark this event in the "upload log"
             if ($logfile) {
                 $upload_log = $file_dir . basename($logfile);
                 $this->log($userfile, $upload_log, $message);
             }
             if ($autolink) {
                 require_once "lib/loadsave.php";
                 $pagehandle = $dbi->getPage($page);
                 if ($pagehandle->exists()) {
                     // don't replace default contents
                     $current = $pagehandle->getCurrentRevision();
                     $version = $current->getVersion();
                     $text = $current->getPackedContent();
                     $newtext = $text . "\n* Upload:{$u_userfile}";
                     // don't inline images
                     $meta = $current->_data;
                     $meta['summary'] = sprintf(_("uploaded %s"), $u_userfile);
                     $pagehandle->save($newtext, $version + 1, $meta);
                 }
             }
         } else {
             $message->pushContent($err_header);
             $message->pushContent(HTML::br(), _("Uploading failed."), HTML::br());
         }
     } else {
         $message->pushContent(HTML::br(), _("No file selected. Please select one."), HTML::br());
     }
     //$result = HTML::div( array( 'class' => 'wikiaction' ) );
     $result = HTML();
     $result->pushContent($form);
     $result->pushContent($message);
     return $result;
 }
Esempio n. 20
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $DBParams;
     //$request->setArg('nocache','1');
     extract($this->getArgs($argstr, $request));
     if (!$alias) {
         return $this->error(_("No DSN alias for SqlResult.ini specified"));
     }
     $sql = $this->_sql;
     // apply custom filters
     if ($where and strstr($sql, "%%where%%")) {
         $sql = str_replace("%%where%%", $where, $sql);
     }
     // TODO: use a SQL construction library?
     if ($limit) {
         $pagelist = new PageList();
         $limit = $pagelist->limit($limit);
         if (strstr($sql, "%%limit%%")) {
             $sql = str_replace("%%limit%%", $limit, $sql);
         } else {
             if (strstr($sql, "LIMIT")) {
                 $sql = preg_replace("/LIMIT\\s+[\\d,]+\\s+/m", "LIMIT " . $limit . " ", $sql);
             }
         }
     }
     if (strstr($sql, "%%sortby%%")) {
         if (!$sortby) {
             $sql = preg_replace("/ORDER BY .*%%sortby%%\\s/m", "", $sql);
         } else {
             $sql = str_replace("%%sortby%%", $sortby, $sql);
         }
     } elseif (PageList::sortby($sortby, 'db')) {
         // add sorting: support paging sortby links
         if (preg_match("/\\sORDER\\s/", $sql)) {
             $sql = preg_replace("/ORDER BY\\s\\S+\\s/m", "ORDER BY " . PageList::sortby($sortby, 'db'), $sql);
         } else {
             $sql .= " ORDER BY " . PageList::sortby($sortby, 'db');
         }
     }
     $inidsn = $this->getDsn($alias);
     if (!$inidsn) {
         return $this->error(sprintf(_("No DSN for alias %s in SqlResult.ini found"), $alias));
     }
     // adodb or pear? adodb as default, since we distribute per default it.
     // for pear there may be overrides.
     // TODO: native PDO support (for now we use ADODB)
     if ($DBParams['dbtype'] == 'SQL') {
         $dbh = DB::connect($inidsn);
         $all = $dbh->getAll($sql);
         if (DB::isError($all)) {
             return $this->error($all->getMessage() . ' ' . $all->userinfo);
         }
     } else {
         // unless PearDB use the included ADODB, regardless if dba, file or PDO, ...
         if ($DBParams['dbtype'] != 'ADODB') {
             // require_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php');
             require_once 'lib/WikiDB/adodb/adodb.inc.php';
         }
         $parsed = parseDSN($inidsn);
         $dbh =& ADONewConnection($parsed['phptype']);
         $conn = $dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']);
         if (!$conn) {
             return $this->error($dbh->errorMsg());
         }
         $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
         $dbh->SetFetchMode(ADODB_FETCH_ASSOC);
         $all = $dbh->getAll($sql);
         $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM;
         $dbh->SetFetchMode(ADODB_FETCH_NUM);
         if (!$all) {
             return $this->error($dbh->errorMsg());
         }
     }
     $args = array();
     if ($limit) {
         // fill paging vars (see PageList)
         $args = $pagelist->pagingTokens(count($all), count($all[0]), $limit);
         if (!$args) {
             $args = array();
         }
     }
     if ($template) {
         $args = array_merge(array('SqlResult' => $all, 'ordered' => $ordered, 'where' => $where, 'sortby' => $sortby, 'limit' => $limit), $args);
         // paging params override given params
         return Template($template, $args);
     } else {
         if ($ordered) {
             $html = HTML::ol(array('class' => 'sqlresult'));
             if ($all) {
                 foreach ($all as $row) {
                     $html->pushContent(HTML::li(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'), $row[0]));
                 }
             }
         } else {
             $html = HTML::table(array('class' => 'sqlresult'));
             $i = 0;
             if ($all) {
                 foreach ($all as $row) {
                     $tr = HTML::tr(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'));
                     if ($row) {
                         foreach ($row as $col) {
                             $tr->pushContent(HTML::td($col));
                         }
                     }
                     $html->pushContent($tr);
                 }
             }
         }
     }
     // do paging via pagelink template
     if (!empty($args['NUMPAGES'])) {
         $paging = Template("pagelink", $args);
         $html = $table->pushContent(HTML::thead($paging), HTML::tbody($html), HTML::tfoot($paging));
     }
     if (0 and DEBUG) {
         // test deferred error/warning/notice collapsing
         trigger_error("test notice", E_USER_NOTICE);
         trigger_error("test warning", E_USER_WARNING);
     }
     return $html;
 }
Esempio n. 21
0
 function _getDetail($count = 0)
 {
     // Codendi : don't display notices
     //if ($this->isNotice()) return;
     if (!$count) {
         $count = $this->_count;
     }
     $dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR : substr(dirname(__FILE__), 0, -4);
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         $dir = str_replace('/', '\\', $dir);
         $this->errfile = str_replace('/', '\\', $this->errfile);
         $dir .= "\\";
     } else {
         $dir .= '/';
     }
     $errfile = preg_replace('|^' . preg_quote($dir) . '|', '', $this->errfile);
     if (is_string($this->errstr)) {
         $lines = explode("\n", $this->errstr);
     } elseif (is_object($this->errstr)) {
         $lines = array($this->errstr->asXML());
     }
     $errtype = DEBUG & _DEBUG_VERBOSE ? sprintf("%s[%d]", $this->getDescription(), $this->errno) : sprintf("%s", $this->getDescription());
     $msg = sprintf("%s:%d: %s: %s %s", $errfile, $this->errline, $errtype, array_shift($lines), $count > 1 ? sprintf(" (...repeated %d times)", $count) : "");
     $html = HTML::div(array('class' => $this->getHtmlClass()), HTML::p($msg));
     if ($lines) {
         $list = HTML::ul();
         foreach ($lines as $line) {
             $list->pushContent(HTML::li($line));
         }
         $html->pushContent($list);
     }
     return $html;
 }
Esempio n. 22
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     if (is_array($argstr)) {
         // can do with array also.
         $args =& $argstr;
         if (!isset($args['order'])) {
             $args['order'] = 'reverse';
         }
     } else {
         $args = $this->getArgs($argstr, $request);
     }
     if (empty($args['user'])) {
         $user = $request->getUser();
         if ($user->isAuthenticated()) {
             $args['user'] = $user->UserName();
         } else {
             $args['user'] = '';
         }
     }
     if (!$args['user'] or $args['user'] == ADMIN_USER) {
         if (BLOG_EMPTY_DEFAULT_PREFIX) {
             $args['user'] = '';
         } else {
             $args['user'] = ADMIN_USER;
         }
         // "Admin/Blogs/day" pages
     }
     $parent = empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR;
     //$info = explode(',', $args['info']);
     //$pagelist = new PageList($args['info'], $args['exclude'], $args);
     //if (!is_array('pagename'), explode(',', $info))
     //    unset($pagelist->_columns['pagename']);
     $sp = HTML::Raw('&middot; ');
     if (!empty($args['month'])) {
         $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
         $pages = $dbi->titleSearch(new TextSearchQuery("^" . $prefix, true, 'posix'));
         $html = HTML::ul();
         while ($page = $pages->next()) {
             $rev = $page->getCurrentRevision(false);
             if ($rev->get('pagetype') != 'wikiblog') {
                 continue;
             }
             $blog = $this->_blog($rev);
             $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
         }
         if (!$args['noheader']) {
             return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))), $html);
         } else {
             return $html;
         }
     }
     $blogs = $this->findBlogs($dbi, $args['user'], 'wikiblog');
     if ($blogs) {
         if (!$basepage) {
             $basepage = _("BlogArchives");
         }
         $html = HTML::ul();
         usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
         if ($args['order'] == 'reverse') {
             $blogs = array_reverse($blogs);
         }
         // collapse pagenames by month
         $months = array();
         foreach ($blogs as $rev) {
             $blog = $this->_blog($rev);
             $mon = $blog['month'];
             if (empty($months[$mon])) {
                 $months[$mon] = array('title' => $this->_monthTitle($mon), 'num' => 1, 'month' => $mon, 'link' => WikiURL($basepage, $this->_nonDefaultArgs(array('month' => $mon))));
             } else {
                 $months[$mon]['num']++;
             }
         }
         foreach ($months as $m) {
             $html->pushContent(HTML::li(HTML::a(array('href' => $m['link'], 'class' => 'named-wiki'), $m['title'] . " (" . $m['num'] . ")")));
         }
         if (!$args['noheader']) {
             return HTML(HTML::h3(_("Blog Archives:")), $html);
         } else {
             return $html;
         }
     } else {
         return '';
     }
 }
Esempio n. 23
0
 /** 
  * Handle AntiSpam here. How? http://wikiblacklist.blogspot.com/
  * Need to check dynamically some blacklist wikipage settings 
  * (plugin WikiAccessRestrictions) and some static blacklist.
  * DONE: 
  *   Always: More then 20 new external links
  *   ENABLE_SPAMASSASSIN:  content patterns by babycart (only php >= 4.3 for now)
  *   ENABLE_SPAMBLOCKLIST: content domain blacklist
  */
 function isSpam()
 {
     $current =& $this->current;
     $request =& $this->request;
     $oldtext = $current->getPackedContent();
     $newtext =& $this->_content;
     // FIXME: in longer texts the NUM_SPAM_LINKS number should be increased.
     //        better use a certain text : link ratio.
     // 1. Not more then 20 new external links
     if (defined("NUM_SPAM_LINKS")) {
         if ($this->numLinks($newtext) - $this->numLinks($oldtext) >= NUM_SPAM_LINKS) {
             // Allow strictly authenticated users?
             // TODO: mail the admin?
             $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML($this->getSpamMessage(), HTML::p(HTML::strong(_("Too many external links."))));
             return true;
         }
     }
     // 2. external babycart (SpamAssassin) check
     // This will probably prevent from discussing sex or viagra related topics. So beware.
     if (ENABLE_SPAMASSASSIN) {
         include_once "lib/spam_babycart.php";
         if ($babycart = check_babycart($newtext, $request->get("REMOTE_ADDR"), $this->user->getId())) {
             // TODO: mail the admin
             if (is_array($babycart)) {
                 $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML($this->getSpamMessage(), HTML::p(HTML::em(_("SpamAssassin reports: "), join("\n", $babycart))));
             }
             return true;
         }
     }
     // 3. extract (new) links and check surbl for blocked domains
     if (ENABLE_SPAMBLOCKLIST and $this->numLinks($newtext)) {
         include_once "lib/SpamBlocklist.php";
         include_once "lib/InlineParser.php";
         $parsed = TransformLinks($newtext);
         foreach ($parsed->_content as $link) {
             if (isa($link, 'Cached_ExternalLink')) {
                 $uri = $link->_getURL($this->page->getName());
                 if ($res = IsBlackListed($uri)) {
                     // TODO: mail the admin
                     $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML($this->getSpamMessage(), HTML::p(HTML::strong(_("External links contain blocked domains:")), HTML::ul(HTML::li(sprintf(_("%s is listed at %s"), $res[2], $res[0])))));
                     return true;
                 }
             }
         }
     }
     return false;
 }
Esempio n. 24
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     $source = $current->getPackedContent();
     if (empty($source)) {
         return $this->error(fmt("empty source"));
     }
     if ($basepage == _("SpellCheck")) {
         return $this->error(fmt("Cannot SpellCheck myself"));
     }
     $lang = $page->get('lang');
     if (empty($lang)) {
         $lang = $GLOBALS['LANG'];
     }
     $html = HTML();
     if (!function_exists('pspell_new_config')) {
         // use the aspell commandline interface
         include_once "lib/WikiPluginCached.php";
         $args = "";
         $source = preg_replace("/^/m", "^", $source);
         if (ASPELL_DATA_DIR) {
             $args .= " --data-dir=" . ASPELL_DATA_DIR;
         }
         // MAYBE TODO: do we have the language dictionary?
         $args .= " --lang=" . $lang;
         // use -C or autosplit wikiwords in the text
         $commandLine = ASPELL_EXE . " -a -C {$args} ";
         $cache = new WikiPluginCached();
         $code = $cache->filterThroughCmd($source, $commandLine);
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $sugg = array();
         foreach (preg_split("/\n/", $code) as $line) {
             if (preg_match("/^& (\\w+) \\d+ \\d+: (.+)\$/", $line, $m)) {
                 $sugg[$m[1]] = preg_split("/, /", $m[2]);
             }
         }
         /*$pre = HTML::pre(HTML::raw($code));
           $html->pushContent($pre);*/
     } else {
         $sugg = pspell_check($source, $lang);
     }
     //$html->pushContent(HTML::hr(),HTML::h1(_("Spellcheck")));
     $page = $request->getPage();
     if ($version) {
         $revision = $page->getRevision($version);
         if (!$revision) {
             NoSuchRevision($request, $page, $version);
         }
     } else {
         $revision = $page->getCurrentRevision();
     }
     $GLOBALS['request']->setArg('suggestions', $sugg);
     include_once "lib/BlockParser.php";
     $ori_html = TransformText($revision, $revision->get('markup'), $page);
     $GLOBALS['request']->setArg('suggestions', false);
     $html->pushContent($ori_html, HTML::hr(), HTML::h1(_("SpellCheck result")));
     $list = HTML::ul();
     foreach ($sugg as $word => $suggs) {
         $w = HTML::span(array('class' => 'spell-wrong'), $word);
         // TODO: optional replace-link. jscript or request button with word replace.
         $r = HTML();
         foreach ($suggs as $s) {
             $r->pushContent(HTML::a(array('class' => 'spell-sugg', 'href' => "javascript:do_replace('{$word}','{$s}')"), $s), ", ");
         }
         $list->pushContent(HTML::li($w, ": ", $r));
     }
     $html->pushContent($list);
     return $html;
 }
Esempio n. 25
0
 function setaclPages(&$request, $pages, $acl)
 {
     $ul = HTML::ul();
     $count = 0;
     $dbi =& $request->_dbi;
     // check new_group and new_perm
     if (isset($acl['_add_group'])) {
         //add groups with perm
         foreach ($acl['_add_group'] as $access => $dummy) {
             $group = $acl['_new_group'][$access];
             $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
         }
         unset($acl['_add_group']);
     }
     unset($acl['_new_group']);
     unset($acl['_new_perm']);
     if (isset($acl['_del_group'])) {
         //del groups with perm
         foreach ($acl['_del_group'] as $access => $del) {
             while (list($group, $dummy) = each($del)) {
                 unset($acl[$access][$group]);
             }
         }
         unset($acl['_del_group']);
     }
     if ($perm = new PagePermission($acl)) {
         $perm->sanify();
         foreach ($pages as $pagename) {
             // check if unchanged? we need a deep array_equal
             $page = $dbi->getPage($pagename);
             $oldperm = getPagePermissions($page);
             if ($oldperm) {
                 $oldperm->sanify();
             }
             if ($oldperm and $perm->equal($oldperm->perm)) {
                 // (serialize($oldperm->perm) == serialize($perm->perm))
                 $ul->pushContent(HTML::li(fmt("ACL not changed for page '%s'.", $pagename)));
             } elseif (mayAccessPage('change', $pagename)) {
                 setPagePermissions($page, $perm);
                 $ul->pushContent(HTML::li(fmt("ACL changed for page '%s'.", $pagename)));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
             }
         }
     } else {
         $ul->pushContent(HTML::li(fmt("Invalid ACL")));
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Esempio n. 26
0
function LoadDir(&$request, $dirname, $files = false, $exclude = false)
{
    $fileset = new LimitedFileSet($dirname, $files, $exclude);
    if (!$files and $skiplist = $fileset->getSkippedFiles()) {
        PrintXML(HTML::dt(HTML::strong(_("Skipping"))));
        $list = HTML::ul();
        foreach ($skiplist as $file) {
            $list->pushContent(HTML::li(WikiLink($file)));
        }
        PrintXML(HTML::dd($list));
    }
    // Defer HomePage loading until the end. If anything goes wrong
    // the pages can still be loaded again.
    $files = $fileset->getFiles();
    if (in_array(HOME_PAGE, $files)) {
        $files = array_diff($files, array(HOME_PAGE));
        $files[] = HOME_PAGE;
    }
    $timeout = !$request->getArg('start_debug') ? 20 : 120;
    foreach ($files as $file) {
        longer_timeout($timeout);
        // longer timeout per page
        if (substr($file, -1, 1) != '~') {
            // refuse to load backup files
            LoadFile($request, "{$dirname}/{$file}");
        }
    }
}
Esempio n. 27
0
 function format_revision($rev)
 {
     $args =& $this->_args;
     $class = 'rc-' . $this->importance($rev);
     $time = $this->time($rev);
     if (!$rev->get('is_minor_edit')) {
         $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time);
     }
     $line = HTML::li(array('class' => $class));
     $line->pushContent($this->time($rev), ", ");
     $line->pushContent($this->date($rev), " ");
     $line->pushContent($this->diffLink($rev), ' ');
     $line->pushContent($this->historyLink($rev), ' ');
     $line->pushContent($this->pageLink($rev), ' ', $this->summaryAsHTML($rev));
     return $line;
 }
Esempio n. 28
0
 /** Constructor
  *
  * @param object $request
  * @param mixed $head  Header ("title") for alert box.
  * @param mixed $body  The text in the alert box.
  * @param hash $buttons  An array mapping button labels to URLs.
  *    The default is a single "Okay" button pointing to $request->getURLtoSelf().
  */
 function Alert($head, $body, $buttons = false)
 {
     if ($buttons === false) {
         $buttons = array();
     }
     if (is_array($body)) {
         $html = HTML::ol();
         foreach ($body as $li) {
             $html->pushContent(HTML::li($li));
         }
         $body = $html;
     }
     $this->_tokens = array('HEADER' => $head, 'CONTENT' => $body);
     $this->_buttons = $buttons;
 }
Esempio n. 29
0
 /** 
  * Purge all non-referenced empty pages. Mainly those created by bad link extraction.
  */
 function _do_purge_empty_pages(&$request, $args)
 {
     $dbi = $request->getDbh();
     $count = 0;
     $notpurgable = 0;
     $list = HTML::ol(array('align' => 'left'));
     $pages = $dbi->getAllPages('include_empty');
     while ($page = $pages->next()) {
         if (!$page->exists() and $links = $page->getBackLinks('include_empty') and !$links->next()) {
             $pagename = $page->getName();
             if ($pagename == 'global_data' or $pagename == '.') {
                 continue;
             }
             if ($dbi->purgePage($pagename)) {
                 $list->pushContent(HTML::li($pagename . ' ' . _("[purged]")));
             } else {
                 $list->pushContent(HTML::li($pagename . ' ' . _("[not purgable]")));
                 $notpurgable++;
             }
             $count++;
         }
     }
     $pages->free();
     if (!$count) {
         return _("No empty, unreferenced pages were found.");
     } else {
         return HTML(fmt("Deleted %s unreferenced pages:", $count), HTML::div(array('align' => 'left'), $list), $notpurgable ? fmt("The %d not-purgable pages/links are links in some page(s). You might want to edit them.", $notpurgable) : '');
     }
 }
Esempio n. 30
0
 function revertPages(&$request, $pages)
 {
     $ul = HTML::ul();
     $dbi = $request->getDbh();
     $count = 0;
     foreach ($pages as $name) {
         $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
         if (mayAccessPage('remove', $name)) {
             $version = $dbi->revertPage($name);
             $ul->pushContent(HTML::li(fmt("Reverted page '%s' to version '%s'.", $name, $version)));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Didn't revert page '%s'. Access denied.", $name)));
         }
     }
     if ($count) {
         $dbi->touch();
     }
     return HTML($ul, HTML::p(fmt("%d pages have been reverted.", $count)));
 }