Exemple #1
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     if (!$et) {
         return '';
     }
     $p = explode(',', $et);
     $page = array_shift($p);
     $nolink = false;
     $p = explode(' ', end($p));
     foreach ($p as $a) {
         $a = trim($a);
         if ($a == 'nolink') {
             $nolink = true;
         }
     }
     // Is it numeric?
     $scope = '';
     if (is_numeric($page)) {
         // Yes
         $row = \Components\Wiki\Models\Page::oneOrNew(intval($page));
     } else {
         $page = rtrim($page, '/');
         $row = \Components\Wiki\Models\Page::oneByPagename($page, $this->domain, $this->domain_id);
     }
     if (!$row->exists()) {
         return '(Page(' . $et . ') failed)';
     }
     if ($nolink) {
         return stripslashes($row->get('title', $row->get('pagename')));
     }
     // Build and return the link
     return '<a href="' . Route::url($row->link()) . '">' . stripslashes($row->get('title', $row->get('pagename'))) . '</a>';
 }
Exemple #2
0
 /**
  * Display a list of blog entries
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('page_id' => Request::getState($this->_option . '.' . $this->_controller . '.page_id', 'page_id', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $page = Page::oneOrFail($filters['page_id']);
     $comments = Comment::all();
     if ($filters['search']) {
         $comments->whereLike('ctext', strtolower((string) $filters['search']));
     }
     if ($filters['page_id']) {
         $comments->whereEquals('page_id', $filters['page_id']);
     }
     $rows = $comments->ordered('filter_order', 'filter_order_Dir')->rows();
     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
     $list = array();
     $children = array();
     if ($rows) {
         // First pass - collect children
         foreach ($rows as $k) {
             $pt = $k->get('parent');
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $k);
             $children[$pt] = $list;
         }
         // Second pass - get an indent list of the items
         $list = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('page', $page)->set('total', count($list))->set('rows', array_slice($list, $filters['start'], $filters['limit']))->display();
 }
Exemple #3
0
 /**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     $et = $this->args;
     $sort = '';
     if ($et) {
         $et = strip_tags($et);
         if (strstr($et, ',')) {
             $attribs = explode(',', $et);
             $et = trim($attribs[0]);
             $sort = strtolower(trim($attribs[1]));
         }
         if (strtolower($et) == 'sort=modified' || strtolower($et) == 'sort=created' || strtolower($et) == 'sort=title') {
             $sort = $et;
             $et = '';
         }
     }
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', 1);
     if ($et) {
         $pages->whereLike('pagename', strtolower($et) . '%');
     }
     if ($this->domain && substr(strtolower($et), 0, 4) != 'help') {
         $pages->whereEquals('scope', $this->domain);
         $pages->whereEquals('scope_id', $this->domain_id);
     }
     switch ($sort) {
         case 'sort=created':
             $pages->order('created', 'asc');
             break;
         case 'sort=modified':
             $pages->order('modified', 'asc');
             break;
         case 'sort=title':
         default:
             $pages->order('title', 'asc');
             break;
     }
     $rows = $pages->rows();
     // Did we get a result from the database?
     if ($rows) {
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             if ($row->get('pagename') == $this->pagename) {
                 continue;
             }
             if ($row->get('namespace') == 'Help') {
                 $row->set('path', $row->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($row->get('path'), '/') : $this->scope);
                 $row->set('scope', $this->domain);
                 $row->set('scope_id', $this->domain_id);
             }
             $html .= '<li><a href="' . Route::url($row->link()) . '">';
             $html .= stripslashes($row->get('title', $row->get('pagename')));
             $html .= '</a></li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     }
     // Return error message
     return '(No ' . $et . ' pages to display)';
 }
Exemple #4
0
 /**
  * Pull a list of records that were created within the time frame ($period)
  *
  * @param      object  $period     Time period to pull results for
  * @param      mixed   $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      array   $areas      Active area(s)
  * @param      array   $tagids     Array of tag IDs
  * @return     array
  */
 public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array())
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas)) {
             return array();
         }
     }
     // Do we have a time period?
     if (!is_object($period)) {
         return array();
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     if (!$limit) {
         return \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->where('created', '>=', $period->cStartDate)->where('created', '<', $period->cEndDate)->order('created', 'desc')->count();
     } else {
         $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('created', 'desc')->where('created', '>=', $period->cStartDate)->where('created', '<', $period->cEndDate)->limit($limit)->start($limitstart)->rows();
         $rows = array();
         foreach ($pages as $page) {
             $row = new stdClass();
             $row->title = $page->title;
             $row->href = Route::url($page->link());
             $row->text = strip_tags($page->version->get('pagehtml'));
             $row->category = $page->get('scope');
             $row->section = $this->_name;
             $rows[] = $row;
         }
         return $rows;
     }
 }
Exemple #5
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $limit = 1;
     $cls = '';
     $limitstart = 0;
     if ($this->args) {
         $args = explode(',', $this->args);
         if (isset($args[0])) {
             $args[0] = intval($args[0]);
             if ($args[0]) {
                 $limit = $args[0];
             }
         }
         if (isset($args[1])) {
             $cls = $args[1];
         }
         if (isset($args[2])) {
             $args[2] = intval($args[2]);
             if ($args[2]) {
                 $limitstart = $args[2];
             }
         }
     }
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('modified', 'desc')->limit($limit)->start($limitstart);
     if ($this->domain) {
         $pages->whereEquals('scope', $this->domain);
         $pages->whereEquals('scope_id', $this->domain_id);
     }
     $rows = $pages->rows();
     $html = '';
     // Did we get a result from the database?
     if ($rows) {
         foreach ($rows as $row) {
             $txt = strip_tags($row->version->get('pagehtml'));
             $txt = str_replace(array("\n", "\r", "\t", '   '), ' ', $txt);
             $txt = trim($txt);
             $html .= '<div';
             if ($cls) {
                 $html .= ' class="' . $cls . '"';
             }
             $html .= '>' . "\n";
             $html .= "\t" . '<h3><a href="' . Route::url($row->link()) . '">' . stripslashes($row->title) . '</a></h3>' . "\n";
             $html .= "\t" . '<p class="modified-date">';
             if ($row->get('version') > 1) {
                 $html .= Lang::txt('PLG_WIKI_PARSERDEFAULT_MODIFIED_ON', Date::of($row->get('created'))->toLocal(Lang::txt('DATE_FORMAT_HZ1')));
             } else {
                 $html .= Lang::txt('PLG_WIKI_PARSERDEFAULT_CREATED_ON', Date::of($row->get('created'))->toLocal(Lang::txt('DATE_FORMAT_HZ1')));
             }
             $html .= '</p>' . "\n";
             $html .= '<p>' . \Hubzero\Utility\String::truncate($txt, 300) . '</p>' . "\n";
             $html .= "\t" . '<p><a href="' . Route::url($row->link()) . '">' . Lang::txt('PLG_WIKI_PARSERDEFAULT_READ_MORE') . '</a></p>' . "\n";
             $html .= '</div>' . "\n";
         }
     } else {
         $html .= '<p class="warning">' . Lang::txt('PLG_WIKI_PARSERDEFAULT_NO_RESULTS') . '</p>' . "\n";
     }
     return $html;
 }
Exemple #6
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     switch (trim($et)) {
         case 'title':
             $page = \Components\Wiki\Models\Page::oneByPath($this->pagename, $this->domain, $this->domain_id);
             return stripslashes($row->title);
             break;
         case 'alias':
         default:
             return $this->pagename;
             break;
     }
 }
Exemple #7
0
 /**
  * Build search query and add it to the $results
  *
  * @param      object $request  \Components\Search\Models\Basic\Request
  * @param      object &$results \Components\Search\Models\Basic\Result\Set
  * @param      object $authz    \Components\Search\Models\Basic\Authorization
  * @return     void
  */
 public static function onSearch($request, &$results, $authz)
 {
     $terms = $request->get_term_ar();
     $weight = '(match(wp.title) against (\'' . join(' ', $terms['stemmed']) . '\') + match(wv.pagetext) against (\'' . join(' ', $terms['stemmed']) . '\'))';
     $addtl_where = array();
     foreach ($terms['mandatory'] as $mand) {
         $addtl_where[] = "(wp.title LIKE '%{$mand}%' OR wv.pagetext LIKE '%{$mand}%')";
     }
     foreach ($terms['forbidden'] as $forb) {
         $addtl_where[] = "(wp.title NOT LIKE '%{$forb}%' AND wv.pagetext NOT LIKE '%{$forb}%')";
     }
     $viewlevels = implode(',', User::getAuthorisedViewLevels());
     if ($gids = $authz->get_group_ids()) {
         $authorization = '(wp.access IN (0,' . $viewlevels . ') OR (wp.access = 1 AND xg.gidNumber IN (' . join(',', $gids) . ')))';
     } else {
         $authorization = '(wp.access IN (0,' . $viewlevels . '))';
     }
     // fml
     $groupAuth = array();
     if ($authz->is_super_admin()) {
         $groupAuth[] = '1';
     } else {
         $groupAuth[] = 'xg.plugins LIKE \'%wiki=anyone%\'';
         if (!$authz->is_guest()) {
             $groupAuth[] = 'xg.plugins LIKE \'%wiki=registered%\'';
             if ($gids = $authz->get_group_ids()) {
                 $groupAuth[] = '(xg.plugins LIKE \'%wiki=members%\' AND xg.gidNumber IN (' . join(',', $gids) . '))';
             }
         }
     }
     $rows = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t\t\twp.title,\n\t\t\t\twp.scope,\n\t\t\t\twp.scope_id,\n\t\t\t\twv.pagehtml AS description,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN wp.path != '' THEN concat(wp.path, '/', wp.pagename)\n\t\t\t\t\tELSE wp.pagename\n\t\t\t\tEND AS link,\n\t\t\t\t{$weight} AS weight,\n\t\t\t\twv.created AS date,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN wp.scope='project' THEN 'Project Notes'\n\t\t\t\t\tELSE 'Wiki'\n\t\t\t\tEND AS section\n\t\t\tFROM `#__wiki_versions` wv\n\t\t\tINNER JOIN `#__wiki_pages` wp\n\t\t\t\tON wp.id = wv.page_id\n\t\t\tLEFT JOIN `#__xgroups` xg ON xg.gidNumber = wp.scope_id AND wp.scope='group'\n\t\t\tWHERE\n\t\t\t\t{$authorization} AND\n\t\t\t\t{$weight} > 0 AND\n\t\t\t\twp.state < 2 AND\n\t\t\t\twv.id = (SELECT MAX(wv2.id) FROM `#__wiki_versions` wv2 WHERE wv2.page_id = wv.page_id) " . ($addtl_where ? ' AND ' . join(' AND ', $addtl_where) : '') . " AND (xg.gidNumber IS NULL OR (" . implode(' OR ', $groupAuth) . "))\n\t\t\t ORDER BY {$weight} DESC");
     include_once Component::path('com_wiki') . DS . 'models' . DS . 'page.php';
     foreach ($rows->to_associative() as $row) {
         if (!$row) {
             continue;
         }
         $page = \Components\Wiki\Models\Page::blank();
         $page->set('pagename', $row->link);
         $page->set('scope', $row->scope);
         $page->set('scope_id', $row->scope_id);
         $row->set_link(Route::url($page->link()));
         // rough de-wikifying. probably a bit faster than rendering to html and then stripping the tags, but not perfect
         //$row->set_description(preg_replace('/(\[+.*?\]+|\{+.*?\}+|[=*])/', '', $row->get_description()));
         $row->set_description(strip_tags($row->get_description()));
         $results->add($row);
     }
 }
Exemple #8
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     $live_site = rtrim(Request::base(), '/');
     // Get resource by ID
     $attach = \Components\Wiki\Models\Attachment::all()->whereEquals('page_id', $this->pageid);
     if ($et) {
         $et = strip_tags($et);
         $attach->whereLike('filename', strtolower($et) . '%');
     }
     $rows = $attach->rows();
     // Did we get a result from the database?
     if ($rows) {
         $config = Component::params('com_wiki');
         if ($this->filepath != '') {
             $config->set('filepath', $this->filepath);
         }
         $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid);
         if ($page->get('namespace') == 'help') {
             $page->set('path', $page->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($page->get('path'), '/') : $this->scope);
         }
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             $page->set('pagename', $page->get('pagename') . '/' . 'File:' . $row->get('filename'));
             $link = $page->link();
             $fpath = $row->filespace() . DS . $this->pageid . DS . $row->get('filename');
             $html .= '<li><a href="' . Route::url($link) . '">' . $row->get('filename') . '</a> (' . (file_exists($fpath) ? \Hubzero\Utility\Number::formatBytes(filesize($fpath)) : '-- file not found --') . ') ';
             $huser = $row->creator();
             if ($huser->get('id')) {
                 $html .= '- added by <a href="' . Route::url('index.php?option=com_members&id=' . $huser->get('id')) . '">' . stripslashes($huser->get('name')) . '</a> ';
             }
             if ($row->get('created') && $row->get('created') != '0000-00-00 00:00:00') {
                 $html .= Date::of($row->get('created'))->relative() . '. ';
             }
             $html .= $row->get('description') ? '<span>"' . stripslashes($row->get('description')) . '"</span>' : '';
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     }
     // Return error message
     return '(No ' . $et . ' files to display)';
 }
Exemple #9
0
 /**
  * Retrieves a row from the database
  *
  * @param   string  $refid     ID of the database table row
  * @param   string  $category  Element type (determines table to look in)
  * @param   string  $parent    If the element has a parent element
  * @return  array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     $query = "SELECT rc.id, rc.page_id AS entry_id, rc.chtml as `text`, rc.created_by as author, rc.created, NULL as subject, rc.anonymous as anon, 'wiki' AS parent_category\n\t\t\t\t\tFROM `#__wiki_comments` AS rc\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         foreach ($rows as $key => $row) {
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             $entry = \Components\Wiki\Models\Page::oneOrFail($rows[$key]->entry_id);
             $rows[$key]->text = $rows[$key]->text;
             $rows[$key]->href = Route::url($entry->link() . '#c' . $rows[$key]->id);
         }
     }
     return $rows;
 }
 /**
  * Save a revision
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $revision = Request::getVar('revision', array(), 'post', 'none', 2);
     $revision = array_map('trim', $revision);
     // Initiate extended database class
     $row = new Revision($revision['id']);
     $before = $row->get('approved');
     if (!$row->bind($revision)) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     if (!$row->exists()) {
         $row->set('created', Date::toSql());
     }
     $page = new Page(intval($row->get('pageid')));
     // Parse text
     $wikiconfig = array('option' => $this->_option, 'scope' => $page->get('scope'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '', 'domain' => $this->_group);
     $p = Parser::getInstance();
     $row->set('pagehtml', $p->parse($row->get('pagetext'), $wikiconfig));
     // Store new content
     if (!$row->store()) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     // Get the most recent revision and compare to the set "current" version
     if ($before != 1 && $row->get('approved') == 1) {
         $page->revisions('list', array(), true)->last();
         if ($page->revisions()->current()->get('id') == $row->get('id')) {
             // The newly approved revision is now the most current
             // So, we need to update the page's version_id
             $page->set('version_id', $page->revisions()->current()->get('id'));
             $page->store(false, 'revision_approved');
         } else {
             $page->log('revision_approved');
         }
     }
     // Set the redirect
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $row->get('pageid'), false), Lang::txt('COM_WIKI_REVISION_SAVED'));
 }
Exemple #11
0
 /**
  * Delete a page
  *
  * @apiMethod DELETE
  * @apiUri    /wiki/{id}
  * @apiParameter {
  * 		"name":          "id",
  * 		"description":   "Page identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       0
  * }
  * @return  void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $page = Page::oneOrFail(Request::getInt('id', 0));
     if (!$page->get('id')) {
         throw new Exception(Lang::txt('COM_WIKI_ERROR_PAGE_NOT_FOUND'), 404);
     }
     if (!$page->access('delete')) {
         throw new Exception(Lang::txt('COM_WIKI_ERROR_NOTAUTH'), 403);
     }
     $page->set('state', Page::STATE_DELETED);
     if (!$page->save()) {
         throw new Exception(Lang::txt('COM_WIKI_UNABLE_TO_DELETE'), 500);
     }
     $this->send(null, 202);
 }
Exemple #12
0
 /**
  * Set the state for a page
  *
  * @return  void
  */
 public function stateTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $id = Request::getInt('id', 0);
     // Make sure we have an ID to work with
     if (!$id) {
         Notify::warning(Lang::txt('COM_WIKI_ERROR_MISSING_ID'));
     } else {
         // Load and set state
         $page = Page::oneOrFail(intval($id));
         $page->set('state', Request::getInt('state', 0));
         if (!$page->save()) {
             Notify::error($page->getError());
         }
     }
     // Redirect to main listing
     $this->cancelTask();
 }
Exemple #13
0
 /**
  * Download a file
  *
  * @param      string $filename File name
  * @return     void
  */
 public function downloadTask($filename)
 {
     //get the course
     $course = Course::getInstance($this->gid);
     //authorize
     $authorized = $this->_authorize();
     //get the file name
     if (substr(strtolower($filename), 0, 5) == 'image') {
         $file = urldecode(substr($filename, 6));
     } elseif (substr(strtolower($filename), 0, 4) == 'file') {
         $file = urldecode(substr($filename, 5));
     }
     //if were on the wiki we need to output files a specific way
     if ($this->active == 'wiki') {
         //check to make sure user has access to wiki section
         if (!in_array(User::get('id'), $course->get('members')) || User::isGuest()) {
             return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file);
         }
         //load wiki page from db
         require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
         $page = \Components\Wiki\Models\Page::oneByPath(Request::getVar('pagename'), 'course', $course->get('id'));
         //check specific wiki page access
         if ($page->get('access') == 1 && !in_array(User::get('id'), $course->get('members')) && $authorized != 'admin') {
             return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file);
         }
         //get the config and build base path
         $wiki_config = Component::params('com_wiki');
         $base_path = $wiki_config->get('filepath') . DS . $page->get('id');
     } else {
         //check to make sure we can access it
         if (!in_array(User::get('id'), $course->get('members')) || User::isGuest()) {
             return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file);
         }
         // Build the path
         $base_path = $this->config->get('uploadpath');
         $base_path .= DS . $course->get('gidNumber');
     }
     // Final path of file
     $file_path = $base_path . DS . $file;
     // Ensure the file exist
     if (!file_exists(PATH_APP . DS . $file_path)) {
         return App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND') . ' ' . $file);
     }
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename(PATH_APP . DS . $file_path);
     $xserver->disposition('attachment');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     if (!$xserver->serve()) {
         return App::abort(404, Lang::txt('COM_COURSES_SERVER_ERROR'));
     }
     exit;
 }
Exemple #14
0
 /**
  * Return either a count or an array of the member's contributions
  *
  * @param   object   $member      Current member
  * @param   string   $option      Component name
  * @param   string   $authorized  Authorization level
  * @param   integer  $limit       Number of record to return
  * @param   integer  $limitstart  Record return start
  * @param   string   $sort        Field to sort records on
  * @param   array    $areas       Areas to return data for
  * @return  array
  */
 public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null)
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($this->onMembersContributionsAreas()))) {
             return array();
         }
     }
     // Do we have a member ID?
     if ($member instanceof \Hubzero\User\User) {
         if (!$member->get('id')) {
             return array();
         } else {
             $uidNumber = $member->get('id');
             $username = $member->get('username');
         }
     } else {
         if (!$member->uidNumber) {
             return array();
         } else {
             $uidNumber = $member->uidNumber;
             $username = $member->username;
         }
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     $versions = \Components\Wiki\Models\Version::all()->whereEquals('created_by', $uidNumber)->whereEquals('approved', 1)->group('page_id')->rows();
     $ids = array();
     foreach ($versions as $version) {
         $ids[] = $version->get('page_id');
     }
     $rows = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->whereEquals('scope', 'site')->whereIn('id', $ids)->limit($limit)->start($limitstart);
     if (!$limit) {
         return $rows->count();
     } else {
         return $rows->rows();
     }
 }
Exemple #15
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
$page = \Components\Wiki\Models\Page::getInstance(Request::getVar('page'), Request::getVar('scope'));
$revision = $page->revision(Request::getInt('version', 0));
$yFormat = 'Y';
$apaFormat = 'Y, M d';
$apaFormatRetrieved = 'H:i, M d, Y';
$mlaFormat = 'd M. Y';
$mlaFormatRetrieved = 'd M. Y';
$mhraFormat = 'd M Y H:i';
$mhraFormatRetrieved = 'd M Y';
$cbeFormat = 'Y M d';
$bluebookFormat = 'M. d, Y';
$amaFormat = 'M d, Y, H:i';
$amaFormatRetrieved = 'M d, Y';
$now = Date::toSql();
$permalink = rtrim(Request::base(), '/') . '/' . ltrim(Route::url($page->link() . '&version=' . $revision->get('version')), DS);
?>
Exemple #16
0
 /**
  * Create an item entry for a wiki page
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'book.php';
     $page = null;
     if (!$id) {
         $group = Request::getVar('cn', '');
         $book = new Book($group ? $group : '__site__');
         $page = $book->page();
         $id = $page->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$page) {
         $page = new Page($id);
     }
     if (!$page->exists()) {
         $this->setError(Lang::txt('Wiki page not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $page->get('id'))->set('created', $page->get('created'))->set('created_by', $page->get('created_by'))->set('title', $page->get('title'))->set('description', $page->revision()->content('clean', 300))->set('url', Route::url($page->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Exemple #17
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $row = \Components\Wiki\Models\Page::all()->whereEquals('scope', $this->domain)->whereEquals('scope_id', $this->domain_id)->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->order('rand()')->row();
     // Build and return the link
     return '<a href="' . Route::url($row->link()) . '">' . $row->title . '</a>';
 }
Exemple #18
0
 * @package   hubzero-cms
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
Pathway::append(Lang::txt('COM_WIKI_SEARCH'), $this->page->link('base') . '&pagename=Special:Search');
$database = App::get('db');
$limit = Request::getInt('limit', Config::get('list_limit'));
$start = Request::getInt('limitstart', 0);
$term = Request::getVar('q', '');
$filters = array('state' => array(0, 1));
if ($space = Request::getVar('namespace', '')) {
    $filters['namespace'] = urldecode($space);
}
$pages = \Components\Wiki\Models\Page::blank()->getTableName();
$versions = \Components\Wiki\Models\Version::blank()->getTableName();
$weight = '(match(' . $pages . '.title) against (' . $database->Quote($term) . ') + match(' . $versions . '.pagetext) against (' . $database->Quote($term) . '))';
$rows = $this->book->pages($filters)->select($pages . '.*')->select($versions . '.created_by')->select($versions . '.summary')->select($weight, 'weight')->join($versions, $versions . '.id', $pages . '.version_id')->whereRaw($weight . ' > 0')->order('weight', 'desc')->paginated()->rows();
?>
<form action="<?php 
echo Route::url($this->page->link('base') . '&pagename=Special:Search');
?>
" method="get">
	<div class="container data-entry">
		<input class="entry-search-submit" type="submit" value="<?php 
echo Lang::txt('COM_WIKI_SEARCH');
?>
" />
		<fieldset class="entry-search">
			<legend><?php 
Exemple #19
0
 /**
  * Download a wiki file
  *
  * @return  void
  */
 public function downloadTask()
 {
     $pagename = urldecode(Request::getVar('pagename', '', 'default', 'none', 2));
     $pagename = explode('/', $pagename);
     $filename = array_pop($pagename);
     $pagename = implode('/', $pagename);
     // Get the parent page the file is attached to
     $this->page = Page::oneByPath($pagename, $this->page->get('scope'), $this->page->get('scope_id'));
     // Load the page
     if ($this->page->exists()) {
         // Check if the page is group restricted and the user is not authorized
         if ($this->page->get('scope') != 'site' && $this->page->get('access') != 0 && !$this->page->access('view')) {
             App::abort(403, Lang::txt('COM_WIKI_WARNING_NOT_AUTH'));
         }
     } else {
         if ($this->page->getNamespace() == 'tmp') {
             $this->page->set('id', $this->page->stripNamespace());
         } else {
             App::abort(404, Lang::txt('COM_WIKI_PAGE_NOT_FOUND'));
         }
     }
     $filename = $this->page->stripNamespace($filename);
     // Instantiate an attachment object
     $attachment = $this->page->attachments()->whereEquals('filename', $filename)->row();
     // Ensure we have a path
     if (!$attachment->get('filename')) {
         App::abort(404, Lang::txt('COM_WIKI_FILE_NOT_FOUND'));
     }
     // Add root
     $filename = $attachment->filespace() . DS . $this->page->get('id') . DS . ltrim($attachment->get('filename'), DS);
     // Ensure the file exist
     if (!file_exists($filename)) {
         App::abort(404, Lang::txt('COM_WIKI_FILE_NOT_FOUND') . ' ' . $attachment->get('filename'));
     }
     // Initiate a new content server and serve up the file
     $xserver = new Server();
     $xserver->filename($filename);
     $xserver->disposition('inline');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     if (!$xserver->serve()) {
         // Should only get here on error
         App::abort(500, Lang::txt('COM_WIKI_SERVER_ERROR'));
     }
     exit;
 }
Exemple #20
0
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
Pathway::append(Lang::txt('COM_WIKI_SPECIAL_ALL_PAGES'), $this->page->link());
$dir = strtoupper(Request::getVar('dir', 'ASC'));
if (!in_array($dir, array('ASC', 'DESC'))) {
    $dir = 'ASC';
}
$filters = array('state' => \Components\Wiki\Models\Page::STATE_PUBLISHED);
$namespace = urldecode(Request::getVar('namespace', ''));
if ($namespace) {
    $filters['namespace'] = $namespace;
}
$rows = $this->book->pages($filters)->order('title', $dir)->ordered()->rows();
$namespaces = \Components\Wiki\Models\Page::all()->select('namespace')->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->whereEquals('scope', $this->book->get('scope'))->whereEquals('scope_id', $this->book->get('scope_id'))->group('namespace')->order('namespace', 'asc')->rows();
?>
<form method="get" action="<?php 
echo Route::url($this->page->link());
?>
">
	<fieldset class="filters">
		<legend><?php 
echo Lang::txt('COM_WIKI_FILTER_LIST');
?>
</legend>

		<label for="field-namespace">
			<?php 
echo Lang::txt('COM_WIKI_FIELD_NAMESPACE');
?>
Exemple #21
0
 /**
  * Generate a link to a file
  * If $file starts with (http|https|mailto|ftp|gopher|feed|news|file), then it's an external URL and returned
  *
  * @param   string  $file  Filename
  * @return  string
  */
 private function _link($file)
 {
     $urlPtrn = "[^=\"\\'](https?:|mailto:|ftp:|gopher:|feed:|news:|file:)" . "([^ |\\/\"\\']*\\/)*([^ |\\t\\n\\/\"\\']*[A-Za-z0-9\\/?=&~_])";
     if (preg_match("/^(https?:|mailto:|ftp:|gopher:|news:|file:)/", $file) || preg_match("/{$urlPtrn}/", $file) || substr($file, 0, 1) == DS) {
         return $file;
     }
     $file = trim($file, DS);
     if (Request::getVar('format') == 'pdf') {
         return $this->_path($file);
     }
     if ($this->pageid) {
         $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid);
         $link = $page->link();
     } else {
         $link = '/' . substr($this->option, 4, strlen($this->option)) . '/';
         if ($this->scope) {
             $scope = trim($this->scope, '/');
             $link .= $scope . '/';
         }
         $link .= $this->pagename;
     }
     $link = rtrim($link, '/');
     $link .= '/Image:' . $file;
     return Route::url($link);
 }
Exemple #22
0
 /**
  * List children of a page
  *
  * @param   integer  $currentDepth  How far down the tree we are
  * @param   integer  $targetDepth   How far down the tree to go
  * @param   integer  $pageid
  * @return  string   HMTL
  */
 private function listChildren($currentDepth, $targetDepth, $pageid)
 {
     $html = '';
     if ($currentDepth > $targetDepth) {
         return $html;
     }
     $rows = \Components\Wiki\Models\Page::all()->whereEquals('parent', $pageid)->whereEquals('state', 1)->rows();
     if ($rows->count()) {
         $html = '<ul>';
         foreach ($rows as $row) {
             $row = new \Components\Wiki\Models\Page($row);
             $html .= '<li><a href="' . Route::url($row->link()) . '">';
             $html .= stripslashes($row->get('title', $row->get('pagename')));
             $html .= '</a>';
             $html .= $this->listChildren($currentDepth + 1, $targetDepth, $row->get('id'));
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
     } elseif ($currentDepth == 1) {
         // Return error message
         return '<p>(No sub-pages to display)</p>';
     }
     return $html;
 }
Exemple #23
0
 /**
  * Get a list of page IDs associated with this group
  *
  * @param   integer  $gid
  * @return  array
  */
 public function getPages($gid = NULL)
 {
     // Import needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     // Start the log text
     $log = Lang::txt('PLG_GROUPS_WIKI_LOG') . ': ';
     $pages = \Components\Wiki\Models\Page::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $gid)->rows();
     return $pages;
 }
Exemple #24
0
 /**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     $et = $this->args;
     if (!$et) {
         return '';
     }
     $pages = explode(',', $et);
     $html = '<div class="rellink relarticle mainarticle">Main articles: ';
     foreach ($pages as $page) {
         $page = trim($page);
         // Is it numeric?
         $scope = '';
         if (is_numeric($page)) {
             // Yes
             $page = intval($page);
         } else {
             $page = trim($page, '/');
             if (strstr($page, '/') && !strstr($page, ' ')) {
                 $bits = explode('/', $page);
                 $page = array_pop($bits);
                 $scope = implode('/', $bits);
             }
         }
         if ($this->domain != '' && $scope == '') {
             $scope = $this->scope;
         }
         // No, get resource by alias
         if (strstr($page, ' ')) {
             $g = \Components\Wiki\Models\Page::oneByTitle($page, $this->domain, $this->domain_id);
         } else {
             $g = \Components\Wiki\Models\Page::oneByPath(($scope ? $scope . '/' : '') . $page, $this->domain, $this->domain_id);
         }
         if (!$g->get('id')) {
             $g->set('pagename', $page);
             $g->set('scope', $this->domain);
             $g->set('scope_id', $this->domain_id);
         }
         // Build and return the link
         if (!$g->get('id')) {
             $l[] = '<a href="' . Route::url($g->link()) . '">' . stripslashes($g->title) . '</a>';
         } else {
             $l[] = '<a class="int-link" href="' . Route::url($g->link()) . '">' . stripslashes($g->title) . '</a>';
         }
     }
     if (count($l) > 1) {
         $last = array_pop($l);
         $html .= implode(', ', $l);
         $html .= ' and ' . $last;
     } else {
         $html .= $l[0];
     }
     return $html . '</div>';
 }
 /**
  * Delete a page
  *
  * @apiParameter {
  * 		"name":          "id",
  * 		"description":   "Page identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       0
  * }
  * @return  void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $id = Request::getInt('id', 0);
     $record = new Page($id);
     if (!$record->exists()) {
         throw new Exception(Lang::txt('Specified page does not exist.'), 404);
     }
     if (!$record->delete()) {
         throw new Exception(Lang::txt('Failed to delete page.'), 500);
     }
     $this->send(null, 202);
 }
Exemple #26
0
// No direct access.
defined('_HZEXEC_') or die;
if (!$this->sub) {
    $this->css();
}
$this->js('wiki.js', 'com_wiki')->js('jquery.fileuploader.js', 'system');
$tags = $this->page->tags('string');
if ($this->page->exists()) {
    $lid = $this->page->get('id');
} else {
    $lid = Request::getInt('lid', time() . rand(0, 10000), 'post');
    $lid = '-' . substr($lid, -8);
}
$macros = \Components\Wiki\Models\Page::oneByPath('Help:WikiMacros', 'site', 0);
$macros->set('scope', $this->book->get('scope'))->set('scope_id', $this->book->get('scope_id'));
$formatting = \Components\Wiki\Models\Page::oneByPath('Help:WikiFormatting', 'site', 0);
$formatting->set('scope', $this->book->get('scope'))->set('scope_id', $this->book->get('scope_id'));
$authors = array();
foreach ($this->page->authors()->rows() as $auth) {
    $authors[] = $auth->user()->get('username');
}
$authors = implode(', ', $authors);
?>
<header id="<?php 
echo $this->sub ? 'sub-content-header' : 'content-header';
?>
">
	<h2><?php 
echo $this->escape($this->page->title);
?>
</h2>
Exemple #27
0
 /**
  * Save a revision
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $revision = Request::getVar('revision', array(), 'post', 'none', 2);
     $revision = array_map('trim', $revision);
     // Initiate extended database class
     $version = Version::oneOrNew($revision['id']);
     // Get the "approved" state before binding incoming data
     $before = $version->get('approved');
     // Bind data
     $version->set($revision);
     // Get the parent page
     $page = Page::oneOrFail(intval($version->get('page_id')));
     // Parse text
     $parser = Parser::getInstance();
     $version->set('pagehtml', $parser->parse($version->get('pagetext'), array('option' => $this->_option, 'scope' => $page->get('scope'), 'scope_id' => $page->get('scope_id'), 'path' => $page->get('path'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '')));
     // Store new content
     if (!$version->save()) {
         Notify::error($version->getError());
         return $this->editTask($version);
     }
     // Get the most recent revision and compare to the set "current" version
     if ($before != 1 && $version->get('approved') == 1) {
         $current = $page->versions()->whereEquals('approved', 1)->ordered()->row();
         if ($current->get('id') == $version->get('id')) {
             // The newly approved revision is now the most current
             // So, we need to update the page's version_id
             $page->set('version_id', $version->get('id'));
             $page->save();
         }
         $page->log('revision_approved');
     }
     // Set the success message
     Notify::success(Lang::txt('COM_WIKI_REVISION_SAVED'));
     // Fall through to the edit form
     if ($this->getTask() == 'apply') {
         return $this->editTask($version);
     }
     // Redirect to listing
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $version->get('page_id'), false));
 }
Exemple #28
0
 /**
  * Retrieve a wiki page by alias
  *
  * @param   string  $alias
  * @param   string  $scope
  * @return  mixed
  */
 private function _getPageByAlias($alias, $scope)
 {
     $page = \Components\Wiki\Models\Page::oneByPath($scope ? $scope . '/' . $alias : '', $this->doman, $this->domain_id);
     // Check for a result
     if ($page->get('id')) {
         return $page;
     }
     return null;
 }
Exemple #29
0
 /**
  * Erases all project information (to be used for test projects only)
  *
  * @return  void
  */
 public function eraseTask()
 {
     $id = Request::getVar('id', 0);
     $permanent = 1;
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Get project group
     $group_prefix = $this->config->get('group_prefix', 'pr-');
     $prGroup = $group_prefix . $obj->alias;
     // Store project info
     $alias = $obj->alias;
     $identifier = $alias;
     // Delete project
     $obj->delete();
     // Erase all owners
     $objO = new Tables\Owner($this->database);
     $objO->removeOwners($id, '', 0, $permanent, '', $all = 1);
     // Erase owner group
     $group = new \Hubzero\User\Group();
     $group->read($prGroup);
     if ($group) {
         $group->delete();
     }
     // Erase all comments
     $objC = new Tables\Comment($this->database);
     $objC->deleteProjectComments($id, $permanent);
     // Erase all activities
     $objA = new Tables\Activity($this->database);
     $objA->deleteActivities($id, $permanent);
     // Erase all todos
     $objTD = new Tables\Todo($this->database);
     $objTD->deleteTodos($id, '', $permanent);
     // Erase all blog entries
     $objB = new Tables\Blog($this->database);
     $objB->deletePosts($id, $permanent);
     // Erase all notes
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
         // Get all notes
         $this->database->setQuery("SELECT DISTINCT p.id FROM `#__wiki_pages` AS p\n\t\t\t\tWHERE p.scope_id=" . $this->database->quote($id) . " AND p.scope=" . $this->database->quote('project'));
         $notes = $this->database->loadObjectList();
         if ($notes) {
             foreach ($notes as $note) {
                 $page = \Components\Wiki\Models\Page::oneOrFail($note->id);
                 // Finally, delete the page itself
                 $page->destroy();
             }
         }
     }
     // Erase all files, remove files repository
     if ($alias) {
         // Delete base dir for .git repos
         $dir = $alias;
         $prefix = $this->config->get('offroot', 0) ? '' : PATH_CORE;
         $repodir = DS . trim($this->config->get('webpath'), DS);
         $path = $prefix . $repodir . DS . $dir;
         if (is_dir($path)) {
             Filesystem::deleteDirectory($path);
         }
         // Delete images/preview directories
         $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
         $webpath = PATH_APP . $webdir . DS . $dir;
         if (is_dir($webpath)) {
             Filesystem::deleteDirectory($webpath);
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_PROJECT') . ' #' . $id . ' (' . $alias . ') ' . Lang::txt('COM_PROJECTS_PROJECT_ERASED'));
 }
Exemple #30
0
 /**
  * Display a page
  *
  * @return  void
  */
 public function displayTask()
 {
     $this->view->book = $this->book;
     $this->view->page = $this->page;
     $this->view->config = $this->config;
     $this->view->base_path = $this->_base_path;
     $this->view->sub = $this->_sub;
     // Prep the pagename for display
     $this->view->title = $this->page->get('title');
     //getTitle();
     // Set the page's <title> tag
     if ($this->_sub) {
         Document::setTitle(Document::getTitle() . ': ' . $this->view->title);
     } else {
         Document::setTitle(($this->_sub ? Lang::txt('COM_GROUPS') . ': ' : '') . Lang::txt('COM_WIKI') . ': ' . $this->view->title);
     }
     // Set the pathway
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller);
     }
     // Is this a special page?
     if ($this->page->get('namespace') == 'special') {
         // Set the layout
         $this->view->setLayout('special');
         $this->view->layout = $this->page->denamespaced();
         $this->view->page->set('scope', Request::getVar('scope', ''));
         $this->view->page->set('group_cn', $this->_group);
         $this->view->message = $this->_message;
         // Ensure the special page exists
         if (!in_array(strtolower($this->view->layout), $this->book->special())) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&scope=' . $this->view->page->get('scope')));
             return;
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     // Does a page exist for the given pagename?
     if (!$this->page->exists() || $this->page->isDeleted()) {
         if (!$this->page->access('create')) {
             App::abort(404, Lang::txt('COM_WIKI_WARNING_PAGE_DOES_NOT_EXIST'));
         }
         // No! Ask if they want to create a new page
         $this->view->setLayout('doesnotexist');
         if ($this->_group) {
             $this->page->set('group_cn', $this->_group);
             $this->page->set('scope', $this->_group . '/wiki');
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     if ($this->page->get('group_cn') && !$this->_group) {
         App::redirect(Route::url('index.php?option=com_groups&scope=' . $this->page->get('scope') . '&pagename=' . $this->page->get('pagename')));
         return;
     }
     // Check if the page is group restricted and the user is authorized
     if (!$this->page->access('view', 'page')) {
         throw new Exception(Lang::txt('COM_WIKI_WARNING_NOT_AUTH'), 403);
     }
     if ($scope = $this->page->get('scope')) {
         $s = array();
         if ($cn = $this->page->get('group_cn')) {
             $scope = substr($scope, strlen($cn . '/wiki'));
             $s[] = $cn;
             $s[] = 'wiki';
         }
         $scope = trim($scope, '/');
         if ($scope) {
             $bits = explode('/', $scope);
             foreach ($bits as $bit) {
                 $bit = trim($bit);
                 if ($bit != '/' && $bit != '') {
                     $p = Article::getInstance($bit, implode('/', $s));
                     if ($p->exists()) {
                         Pathway::append($p->get('title'), $p->link());
                     }
                     $s[] = $bit;
                 }
             }
         }
     }
     Pathway::append($this->view->title, $this->page->link());
     // Retrieve a specific version if given
     $this->view->version = Request::getInt('version', 0);
     $this->view->revision = $this->page->revision($this->view->version);
     if (!$this->view->revision->exists()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('nosuchrevision')->display();
         return;
     }
     if (Request::getVar('format', '') == 'raw') {
         Request::setVar('no_html', 1);
         echo nl2br($this->view->revision->get('pagetext'));
         return;
     } elseif (Request::getVar('format', '') == 'printable') {
         echo $this->view->revision->get('pagehtml');
         return;
     }
     // Load the wiki parser
     $wikiconfig = array('option' => $this->_option, 'scope' => $this->page->get('scope'), 'pagename' => $this->page->get('pagename'), 'pageid' => $this->page->get('id'), 'filepath' => '', 'domain' => $this->page->get('group_cn'));
     $p = Parser::getInstance();
     // Parse the text
     if (intval($this->book->config('cache', 1))) {
         // Caching
         if (!($rendered = Cache::get('wiki.r' . $this->view->revision->get('id')))) {
             $rendered = $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true);
             Cache::put('wiki.r' . $this->view->revision->get('id'), $rendered, intval($this->book->config('cache_time', 15)));
         }
         $this->view->revision->set('pagehtml', $rendered);
     } else {
         $this->view->revision->set('pagehtml', $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true));
     }
     App::get('config')->get('debug') || App::get('config')->get('profile') ? App::get('profiler')->mark('afterWikiParse') : null;
     // Handle display events
     $this->page->event = new \stdClass();
     $results = Event::trigger('wiki.onAfterDisplayTitle', array($this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayTitle = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onBeforeDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->beforeDisplayContent = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onAfterDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayContent = trim(implode("\n", $results));
     $this->view->message = $this->_message;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }