Пример #1
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.")));
     }
 }
Пример #2
0
 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks = false, $createredirect = false)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_rename');
     $options = array('regex' => isset($post_args['regex']) ? $post_args['regex'] : null, 'icase' => isset($post_args['icase']) ? $post_args['icase'] : null);
     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('edit', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to rename page '%s'.", WikiLink($name))));
             } elseif ($dbi->renamePage($name, $newname, $updatelinks)) {
                 /* not yet implemented for all backends */
                 $page = $dbi->getPage($newname);
                 $current = $page->getCurrentRevision();
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("Renamed page from '%s' to '%s'"), $name, $newname);
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 if ($createredirect) {
                     $page = $dbi->getPage($name);
                     $text = "<<RedirectTo page=\"" . $newname . "\">>";
                     $meta['summary'] = sprintf(_("Renaming created redirect page from '%s' to '%s'"), $name, $newname);
                     $meta['is_minor_edit'] = 0;
                     $meta['author'] = $request->_user->UserName();
                     $page->save($text, 1, $meta);
                 }
                 $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();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently renamed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently renamed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p(fmt("No pages renamed.")));
         $result->pushContent($ul);
         return $result;
     }
 }
Пример #3
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.")));
     }
 }
Пример #4
0
 function removePages(&$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('remove', $name)) {
             $dbi->deletePage($name);
             $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Didn't remove 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 removed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently removed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages removed."));
         return $result;
     }
 }
Пример #5
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;
 }
Пример #6
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.")));
     }
 }
Пример #7
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;
     }
 }
Пример #8
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;
     }
 }
Пример #9
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)));
 }
Пример #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;
     }
 }
Пример #11
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.")));
     }
 }
Пример #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.")));
     }
 }
Пример #13
0
 /**
  * Test generating proper listing
  *
  * @group laravel
  */
 public function testGeneratingListing()
 {
     $list = array('foo', 'foobar' => array('hello', 'hello world'));
     $html1 = HTML::ul($list);
     $html2 = HTML::ul($list, array('class' => 'nav'));
     $html3 = HTML::ol($list);
     $html4 = HTML::ol($list, array('class' => 'nav'));
     $this->assertEquals('<ul><li>foo</li><li>foobar<ul><li>hello</li><li>hello world</li></ul></li></ul>', $html1);
     $this->assertEquals('<ul class="nav"><li>foo</li><li>foobar<ul><li>hello</li><li>hello world</li></ul></li></ul>', $html2);
     $this->assertEquals('<ol><li>foo</li><li>foobar<ol><li>hello</li><li>hello world</li></ol></li></ol>', $html3);
     $this->assertEquals('<ol class="nav"><li>foo</li><li>foobar<ol><li>hello</li><li>hello world</li></ol></li></ol>', $html4);
 }
Пример #14
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;
 }
Пример #15
0
    <div class="row">
        <div class="col-lg-12">
            
            <h2>My Thoughts</h2>
            <p>
                Over all pretty simple and straight forward challenge, no tricks or anything like that.  
                The only real issue I ran into was dumbing down the built in Yii2 ActiveController actions.  
                By default the ActiveController offers all the basic CRUD options and the challenge states only the provided User Stories be exposed.
                I could have created my own class to handle the API curling but I just decided to use Guzzle instead.
            </p>
            <p>
                It seemed logical, so I combined stories 1 and 4.    
            </p>
            <p>  
                I like these types of "real world" challenges rather than "trick puzzles".    
            </p>
            <p>
                <span class="text-primary"><strong>TODO:</strong></span>
                <? echo HTML::ul([
                    "Need to add authentication to the User API request",
                    "Story 1,2, and 4 currently retrieve all shifts (past & future) for the employee.
                        By default it should search future shifts only but if a start and/or end date is supplied use that range instead.",
                    "Combine 2 with 1 & 4?",
                 ]); ?>
                
            </p>
        </div>
    </div>

</div>
Пример #16
0
 function format($changes)
 {
     include_once 'lib/InlineParser.php';
     $html = HTML(HTML::h2(false, $this->title()));
     if ($desc = $this->description()) {
         $html->pushContent($desc);
     }
     if ($this->_args['daylist']) {
         $html->pushContent(new DayButtonBar($this->_args));
     }
     $last_date = '';
     $lines = false;
     $first = true;
     while ($rev = $changes->next()) {
         if (($date = $this->date($rev)) != $last_date) {
             if ($lines) {
                 $html->pushContent($lines);
             }
             $html->pushContent(HTML::h3($date));
             $lines = HTML::ul();
             $last_date = $date;
         }
         // enforce view permission
         if (mayAccessPage('view', $rev->_pagename)) {
             $lines->pushContent($this->format_revision($rev));
             if ($first) {
                 $this->setValidators($rev);
             }
             $first = false;
         }
     }
     if ($lines) {
         $html->pushContent($lines);
     }
     if ($first) {
         $html->pushContent(HTML::p(array('class' => 'rc-empty'), $this->empty_message()));
     }
     return $html;
 }
Пример #17
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     extract($this->getArgs($argstr, $request));
     if ($pagename) {
         // Expand relative page names.
         $page = new WikiPageName($pagename, $basepage);
         $pagename = $page->name;
     }
     if (!$pagename) {
         return $this->error(_("no page specified"));
     }
     if ($jshide and isBrowserIE() and browserDetect("Mac")) {
         //trigger_error(_("jshide set to 0 on Mac IE"), E_USER_NOTICE);
         $jshide = 0;
     }
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     //FIXME: I suspect this only to crash with Apache2
     if (!$current->get('markup') or $current->get('markup') < 2) {
         if (in_array(php_sapi_name(), array('apache2handler', 'apache2filter'))) {
             trigger_error(_("CreateToc disabled for old markup"), E_USER_WARNING);
             return '';
         }
     }
     $content = $current->getContent();
     $html = HTML::div(array('class' => 'toc', 'id' => 'toc'));
     /*if ($liststyle == 'dl')
           $list = HTML::dl(array('id'=>'toclist','class' => 'toc'));
       elseif ($liststyle == 'ul')
           $list = HTML::ul(array('id'=>'toclist','class' => 'toc'));
       elseif ($liststyle == 'ol')
           $list = HTML::ol(array('id'=>'toclist','class' => 'toc'));
           */
     $list = HTML::ul(array('id' => 'toclist', 'class' => 'toc'));
     if (!strstr($headers, ",")) {
         $headers = array($headers);
     } else {
         $headers = explode(",", $headers);
     }
     $levels = array();
     foreach ($headers as $h) {
         //replace !!! with level 1, ...
         if (strstr($h, "!")) {
             $hcount = substr_count($h, '!');
             $level = min(max(1, $hcount), 3);
             $levels[] = $level;
         } else {
             $level = min(max(1, (int) $h), 3);
             $levels[] = $level;
         }
     }
     if (TOC_FULL_SYNTAX) {
         require_once "lib/InlineParser.php";
     }
     if ($headers = $this->extractHeaders($content, $dbi->_markup, $with_toclink, $with_counter, $levels, $basepage)) {
         $container = $list;
         $levelRefs = array();
         $previousLevel = 3;
         foreach ($headers as $k => $h) {
             if ($h['level'] < $previousLevel) {
                 // h2 -> h3 (level 3 -> level 2)
                 // Keep track of previous points
                 $levelRefs[$previousLevel] = $container;
                 // Create new container
                 $ul = HTML::ul();
                 $container->pushContent($ul);
                 $container = $ul;
             } elseif ($h['level'] > $previousLevel) {
                 // h4 -> h3 (level 1 -> level 2)
                 if (isset($levelRefs[$h['level']])) {
                     $container = $levelRefs[$h['level']];
                 }
             }
             $h = $headers[$k];
             $link = new WikiPageName($pagename, $page, $h['anchor']);
             $li = WikiLink($link, 'known', $h['text']);
             $container->pushContent(HTML::li($li));
             $previousLevel = $h['level'];
         }
     }
     $list->setAttr('style', 'display:' . ($jshide ? 'none;' : 'block;'));
     $open = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowOpen.png");
     $close = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowClosed.png");
     $html->pushContent(Javascript("\nfunction toggletoc(a) {\n  var toc=document.getElementById('toclist')\n  //toctoggle=document.getElementById('toctoggle')\n  var open='" . $open . "'\n  var close='" . $close . "'\n  if (toc.style.display=='none') {\n    toc.style.display='block'\n    a.title='" . _("Click to hide the TOC") . "'\n    a.src = open\n  } else {\n    toc.style.display='none';\n    a.title='" . _("Click to display") . "'\n    a.src = close\n  }\n}"));
     if ($extracollapse) {
         $toclink = HTML(_("Table Of Contents"), " ", HTML::a(array('name' => 'TOC')), HTML::img(array('id' => 'toctoggle', 'class' => 'wikiaction', 'title' => _("Click to display to TOC"), 'onClick' => "toggletoc(this)", 'height' => 15, 'width' => 15, 'border' => 0, 'src' => $jshide ? $close : $open)));
     } else {
         $toclink = HTML::a(array('name' => 'TOC', 'class' => 'wikiaction', 'title' => _("Click to display"), 'onclick' => "toggletoc(this)"), _("Table Of Contents"), HTML::span(array('style' => 'display:none', 'id' => 'toctoggle'), " "));
     }
     $html->pushContent(HTML::h4($toclink));
     $html->pushContent($list);
     return $html;
 }
Пример #18
0
 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.")));
     }
 }
Пример #19
0
 function _generateList($caption = '')
 {
     if (empty($this->_pages)) {
         return;
     }
     // stop recursion
     $out = HTML();
     if ($caption) {
         $out->pushContent(HTML::p($caption));
     }
     // need a recursive switch here for the azhead and cols grouping.
     if (!empty($this->_options['cols']) and $this->_options['cols'] > 1) {
         $count = count($this->_pages);
         $length = $count / $this->_options['cols'];
         $width = sprintf("%d", 100 / $this->_options['cols']) . '%';
         $cols = HTML::tr(array('valign' => 'top'));
         for ($i = 0; $i < $count; $i += $length) {
             $this->_saveOptions(array('cols' => 0));
             $this->_pages = array_slice($this->_pages, $i, $length);
             $cols->pushContent(HTML::td($this->_generateList()));
             $this->_restoreOptions();
         }
         // speed up table rendering by defining colgroups
         $out->pushContent(HTML::table(HTML::colgroup(array('span' => $this->_options['cols'], 'width' => $width)), $cols));
         return $out;
     }
     // Ignore azhead if not sorted by pagename
     if (!empty($this->_options['azhead']) and strstr($this->sortby($this->_options['sortby'], 'init'), "pagename")) {
         $cur_h = substr($this->_pages[0]->getName(), 0, 1);
         $out->pushContent(HTML::h3($cur_h));
         // group those pages together with same $h
         $j = 0;
         for ($i = 0; $i < count($this->_pages); $i++) {
             $page =& $this->_pages[$i];
             $h = substr($page->getName(), 0, 1);
             if ($h != $cur_h and $i > $j) {
                 $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
                 $this->_pages = array_slice($this->_pages, $j, $i - $j);
                 $out->pushContent($this->_generateList());
                 $this->_restoreOptions();
                 $j = $i;
                 $out->pushContent(HTML::h3($h));
                 $cur_h = $h;
             }
         }
         if ($i > $j) {
             // flush the rest
             $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
             $this->_pages = array_slice($this->_pages, $j, $i - $j);
             $out->pushContent($this->_generateList());
             $this->_restoreOptions();
         }
         return $out;
     }
     if (!empty($this->_options['comma'])) {
         if ($this->_options['comma'] == 1) {
             $out->pushContent($this->_generateCommaListAsString());
         } else {
             $out->pushContent($this->_generateCommaList($this->_options['comma']));
         }
         return $out;
     }
     $do_paging = (isset($this->_options['paging']) and !empty($this->_options['limit']) and $this->getTotal() and $this->_options['paging'] != 'none');
     if ($do_paging) {
         $tokens = $this->pagingTokens($this->getTotal(), count($this->_columns), $this->_options['limit']);
         if ($tokens) {
             $paging = Template("pagelink", $tokens);
             $out->pushContent(HTML::table($paging));
         }
     }
     if (!empty($this->_options['ordered'])) {
         $list = HTML::ol(array('class' => 'pagelist'));
     } else {
         $list = HTML::ul(array('class' => 'pagelist'));
     }
     $i = 0;
     //TODO: currently we ignore limit here and hope tha the backend didn't ignore it. (BackLinks)
     if (!empty($this->_options['limit'])) {
         list($offset, $pagesize) = $this->limit($this->_options['limit']);
     } else {
         $pagesize = 0;
     }
     foreach ($this->_pages as $pagenum => $page) {
         $pagehtml = $this->_renderPageRow($page);
         $group = $i++ / $this->_group_rows;
         //TODO: here we switch every row, in tables every third.
         //      unification or parametrized?
         $class = $group % 2 ? 'oddrow' : 'evenrow';
         $list->pushContent(HTML::li(array('class' => $class), $pagehtml));
         if ($pagesize and $i > $pagesize) {
             break;
         }
     }
     $out->pushContent($list);
     if ($do_paging and $tokens) {
         $out->pushContent(HTML::table($paging));
     }
     return $out;
 }
Пример #20
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $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\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();
     //$url_prefix = SERVER_NAME . DATA_PATH;
     $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)));
     /// MV add pv
     /// @todo: have a generic method to transmit pv
     if (!empty($_REQUEST['pv'])) {
         $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'pv', 'value' => $_REQUEST['pv'])));
     }
     $contents->pushContent(HTML::input(array('name' => 'userfile', 'type' => 'file', 'size' => '50')));
     $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()) {
             $message->pushContent(HTML::h2(_("ACCESS DENIED: You must log in to upload files.")), HTML::br(), HTML::br());
             $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));
         $userfile_tmpname = $userfile->getTmpName();
         $err_header = HTML::h2(fmt("ERROR uploading '%s': ", $userfile_name));
         /// MV add
         /// Wiki attachments
         $wa = new WikiAttachment(GROUP_ID);
         $rev = $wa->createRevision($userfile_name, $userfile->getSize(), $userfile->getType(), $userfile->getTmpName());
         if ($rev >= 0) {
             $prev = $rev + 1;
             $interwiki = new PageType_interwikimap();
             $link = $interwiki->link("Upload:{$prev}/{$userfile_name}");
             $message->pushContent(HTML::h2(_("File successfully uploaded.")));
             $message->pushContent(HTML::ul(HTML::li($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:{$userfile_name}]";
                     $meta = $current->_data;
                     $meta['summary'] = sprintf(_("uploaded %s"), $userfile_name);
                     $pagehandle->save($newtext, $version + 1, $meta);
                 }
             }
         } else {
             $message->pushContent($err_header);
             $message->pushContent(HTML::br(), _("Uploading failed."), HTML::br());
         }
     } else {
         $message->pushContent(HTML::br(), HTML::br());
     }
     /// {{{ Codendi Specific
     // URL arguments
     if (array_key_exists('offset', $_REQUEST)) {
         $offset = $_REQUEST['offset'];
     } else {
         $offset = 0;
     }
     if (array_key_exists('limit', $_REQUEST)) {
         $limit = $_REQUEST['limit'];
     } else {
         $limit = 10;
     }
     $attchTab = HTML::table(array('border' => '1', 'width' => '100%'));
     $attchTab->pushContent(HTML::tr(HTML::th(_("Attachment")), HTML::th(_("Number of revision"))));
     $wai =& WikiAttachment::getListWithCounter(GROUP_ID, user_getid(), array('offset' => $offset, 'nb' => $limit));
     $wai->rewind();
     while ($wai->valid()) {
         $wa =& $wai->current();
         $filename = basename($wa->getFilename());
         $url = getUploadDataPath() . urlencode($filename);
         $line = HTML::tr();
         $line->pushContent(HTML::td(HTML::a(array('href' => $url), "Attach:" . $filename)));
         $line->pushContent(HTML::td($wa->count()));
         $attchTab->pushContent($line);
         $wai->next();
     }
     $attchList = HTML();
     $attchList->pushContent(HTML::hr(), HTML::h2(_("Attached files")));
     $attchList->pushContent($attchTab);
     $url = WikiURL("UpLoad");
     if (!empty($_REQUEST['pv'])) {
         $url .= '&pv=' . $_REQUEST['pv'];
     }
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset - $limit)), "<- Previous"));
     $attchList->pushContent(" - ");
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset + $limit)), "Next ->"));
     /// }}}
     //$result = HTML::div( array( 'class' => 'wikiaction' ) );
     $result = HTML();
     $result->pushContent($form);
     $result->pushContent($message);
     $result->pushContent($attchList);
     return $result;
 }
Пример #21
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 '';
     }
 }
Пример #22
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;
     }
 }
Пример #23
0
 function _generateList($caption)
 {
     $list = HTML();
     $c = count($this->pagelist);
     if ($caption) {
         $list->pushContent(HTML::p($caption));
     }
     if ($c > 0) {
         $list->pushContent(HTML::ul($this->_rows));
     } else {
         $list->pushContent(HTML::p($this->_messageIfEmpty));
     }
     return $list;
 }
Пример #24
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;
 }
Пример #25
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}");
        }
    }
}
Пример #26
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;
 }
Пример #27
0
 function format($changes)
 {
     include_once 'lib/InlineParser.php';
     $html = HTML(HTML::h2(false, $this->headline()));
     if ($desc = $this->description()) {
         $html->pushContent($desc);
     }
     if ($this->_args['daylist']) {
         $html->pushContent(new OptionsButtonBars($this->_args));
     }
     $last_date = '';
     $lines = false;
     $first = true;
     while ($rev = $changes->next()) {
         if (($date = $this->date($rev)) != $last_date) {
             if ($lines) {
                 $html->pushContent($lines);
             }
             // for user contributions no extra date line
             $html->pushContent(HTML::h3($date));
             $lines = HTML::ul();
             $last_date = $date;
         }
         // enforce view permission
         if (mayAccessPage('view', $rev->_pagename)) {
             $lines->pushContent($this->format_revision($rev));
             if ($first) {
                 $this->setValidators($rev);
             }
             $first = false;
         }
     }
     if ($lines) {
         $html->pushContent($lines);
     }
     if ($first) {
         if ($this->_args['daylist']) {
             $html->pushContent(JavaScript("document.getElementById('rc-action-body').style.display='block';"));
         }
         $html->pushContent(HTML::p(array('class' => 'rc-empty'), $this->empty_message()));
     }
     return $html;
 }
Пример #28
0
<?php

echo '<div id="login">';
echo Form::open('login', 'POST', array('class' => 'form-stacked'));
echo '<fieldset>';
echo '<legend>Login</legend>';
echo '<div class="clearfix">';
echo Form::label('email', 'Email Address', array('class' => 'description'));
echo '<div class="input">';
echo Form::text('email', '', array('class' => 'element text huge', 'maxlength' => '140'));
echo '<span class="help-inline">';
echo 'Email';
echo '</span>';
echo '</div>';
echo '</div>';
echo '<div class="clearfix">';
echo Form::label('password', 'Password', array('class' => 'description'));
echo '<div class="input">';
echo Form::password('password', array('class' => 'element text huge', 'maxlength' => '140'));
echo '<span class="help-inline">';
echo 'Password';
echo '</span>';
echo '</div>';
echo '</div>';
echo Form::submit('LOGIN', array('class' => 'btn primary', 'name' => 'submit'));
echo '</fieldset>';
echo Form::close();
if (isset($errors)) {
    echo HTML::ul($errors);
}
echo '</div>';
Пример #29
0
<?php

require "classes/html.php";
?>

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<?php 
echo HTML::link("about/index.php", "About Us");
?>
	<?php 
echo HTML::ul(array("item1", "item2", "item3", "item4"));
?>
	<?php 
echo HTML::image("https://d85wutc1n854v.cloudfront.net/live/products/icons/WB0DX86RM.jpg?v=1.0", "node.js");
?>
</body>
</html>
Пример #30
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;
 }