| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           4 | 
           //
  | 
        
        
            | 
            | 
           5 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           6 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           7 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           8 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           9 | 
           //
  | 
        
        
            | 
            | 
           10 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           11 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           12 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           13 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           14 | 
           //
  | 
        
        
            | 
            | 
           15 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           16 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
           /**
  | 
        
        
            | 
            | 
           19 | 
            * Moodle Wiki 2.0 Renderer
  | 
        
        
            | 
            | 
           20 | 
            *
  | 
        
        
            | 
            | 
           21 | 
            * @package   mod_wiki
  | 
        
        
            | 
            | 
           22 | 
            * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  | 
        
        
            | 
            | 
           23 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           24 | 
            */
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           defined('MOODLE_INTERNAL') || die();
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           class mod_wiki_renderer extends plugin_renderer_base {
  | 
        
        
            | 
            | 
           29 | 
               public function page_index() {
  | 
        
        
            | 
            | 
           30 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           31 | 
                   $output = '';
  | 
        
        
            | 
            | 
           32 | 
                   // Checking wiki instance
  | 
        
        
            | 
            | 
           33 | 
                   if (!$wiki = wiki_get_wiki($this->page->cm->instance)) {
  | 
        
        
            | 
            | 
           34 | 
                       return false;
  | 
        
        
            | 
            | 
           35 | 
                   }
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
                   // @TODO: Fix call to wiki_get_subwiki_by_group
  | 
        
        
            | 
            | 
           38 | 
                   $gid = groups_get_activity_group($this->page->cm);
  | 
        
        
            | 
            | 
           39 | 
                   $gid = !empty($gid) ? $gid : 0;
  | 
        
        
            | 
            | 
           40 | 
                   if (!$subwiki = wiki_get_subwiki_by_group($this->page->cm->instance, $gid)) {
  | 
        
        
            | 
            | 
           41 | 
                       return false;
  | 
        
        
            | 
            | 
           42 | 
                   }
  | 
        
        
            | 
            | 
           43 | 
                   $swid = $subwiki->id;
  | 
        
        
            | 
            | 
           44 | 
                   $pages = wiki_get_page_list($swid);
  | 
        
        
            | 
            | 
           45 | 
                   $selectoptions = array();
  | 
        
        
            | 
            | 
           46 | 
                   foreach ($pages as $page) {
  | 
        
        
            | 
            | 
           47 | 
                       $selectoptions[$page->id] = format_string($page->title, true, array('context' => $this->page->context));
  | 
        
        
            | 
            | 
           48 | 
                   }
  | 
        
        
            | 
            | 
           49 | 
                   $label = get_string('pageindex', 'wiki') . ': ';
  | 
        
        
            | 
            | 
           50 | 
                   $select = new single_select(new moodle_url('/mod/wiki/view.php'), 'pageid', $selectoptions);
  | 
        
        
            | 
            | 
           51 | 
                   $select->label = $label;
  | 
        
        
            | 
            | 
           52 | 
                   return $this->output->container($this->output->render($select), 'wiki_index');
  | 
        
        
            | 
            | 
           53 | 
               }
  | 
        
        
            | 
            | 
           54 | 
              | 
        
        
            | 
            | 
           55 | 
               public function search_result($records, $subwiki) {
  | 
        
        
            | 
            | 
           56 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           57 | 
                   $table = new html_table();
  | 
        
        
            | 
            | 
           58 | 
                   $context = context_module::instance($this->page->cm->id);
  | 
        
        
            | 
            | 
           59 | 
                   $strsearchresults = get_string('searchresult', 'wiki');
  | 
        
        
            | 
            | 
           60 | 
                   $totalcount = count($records);
  | 
        
        
            | 
            | 
           61 | 
                   $html = $this->output->heading("$strsearchresults $totalcount", 3);
  | 
        
        
            | 
            | 
           62 | 
                   foreach ($records as $page) {
  | 
        
        
            | 
            | 
           63 | 
                       $table->head = array('title' => format_string($page->title) . ' (' . html_writer::link($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $page->id, get_string('view', 'wiki')) . ')');
  | 
        
        
            | 
            | 
           64 | 
                       $table->align = array('title' => 'left');
  | 
        
        
            | 
            | 
           65 | 
                       $table->width = '100%';
  | 
        
        
            | 
            | 
           66 | 
                       $table->data = array(array(file_rewrite_pluginfile_urls(format_text($page->cachedcontent, FORMAT_HTML), 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwiki->id)));
  | 
        
        
            | 
            | 
           67 | 
                       $table->colclasses = array('wikisearchresults');
  | 
        
        
            | 
            | 
           68 | 
                       $html .= html_writer::table($table);
  | 
        
        
            | 
            | 
           69 | 
                   }
  | 
        
        
            | 
            | 
           70 | 
                   $html = html_writer::tag('div', $html, array('class'=>'no-overflow'));
  | 
        
        
            | 
            | 
           71 | 
                   return $this->output->container($html);
  | 
        
        
            | 
            | 
           72 | 
               }
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
               public function diff($pageid, $old, $new, $options = array()) {
  | 
        
        
            | 
            | 
           75 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           76 | 
                   if (!empty($options['total'])) {
  | 
        
        
            | 
            | 
           77 | 
                       $total = $options['total'];
  | 
        
        
            | 
            | 
           78 | 
                   } else {
  | 
        
        
            | 
            | 
           79 | 
                       $total = 0;
  | 
        
        
            | 
            | 
           80 | 
                   }
  | 
        
        
            | 
            | 
           81 | 
                   $diff1 = format_text($old->diff, FORMAT_HTML, array('overflowdiv'=>true));
  | 
        
        
            | 
            | 
           82 | 
                   $diff2 = format_text($new->diff, FORMAT_HTML, array('overflowdiv'=>true));
  | 
        
        
            | 
            | 
           83 | 
                   $strdatetime = get_string('strftimedatetime', 'langconfig');
  | 
        
        
            | 
            | 
           84 | 
              | 
        
        
            | 
            | 
           85 | 
                   $olduser = $old->user;
  | 
        
        
            | 
            | 
           86 | 
                   $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $old->id));
  | 
        
        
            | 
            | 
           87 | 
                   $restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $pageid, 'versionid' => $old->id));
  | 
        
        
            | 
            | 
           88 | 
                   $userlink = new moodle_url('/user/view.php', array('id' => $olduser->id));
  | 
        
        
            | 
            | 
           89 | 
                   // view version link
  | 
        
        
            | 
            | 
           90 | 
                   $oldversionview = ' ';
  | 
        
        
            | 
            | 
           91 | 
                   $oldversionview .= html_writer::link($versionlink->out(false), get_string('view', 'wiki'), array('class' => 'wiki_diffview'));
  | 
        
        
            | 
            | 
           92 | 
                   $oldversionview .= ' ';
  | 
        
        
            | 
            | 
           93 | 
                   // restore version link
  | 
        
        
            | 
            | 
           94 | 
                   $oldversionview .= html_writer::link($restorelink->out(false), get_string('restore', 'wiki'), array('class' => 'wiki_diffview'));
  | 
        
        
            | 
            | 
           95 | 
              | 
        
        
            | 
            | 
           96 | 
                   // userinfo container
  | 
        
        
            | 
            | 
           97 | 
                   $oldheading = $this->output->container_start('wiki_diffuserleft');
  | 
        
        
            | 
            | 
           98 | 
                   // username
  | 
        
        
            | 
            | 
           99 | 
                   $oldheading .= html_writer::link($CFG->wwwroot . '/user/view.php?id=' . $olduser->id, fullname($olduser)) . ' ';
  | 
        
        
            | 
            | 
           100 | 
                   // user picture
  | 
        
        
            | 
            | 
           101 | 
                   $oldheading .= html_writer::link($userlink->out(false), $this->output->user_picture($olduser, array('popup' => true)), array('class' => 'notunderlined'));
  | 
        
        
            | 
            | 
           102 | 
                   $oldheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           103 | 
              | 
        
        
            | 
            | 
           104 | 
                   // version number container
  | 
        
        
            | 
            | 
           105 | 
                   $oldheading .= $this->output->container_start('wiki_diffversion');
  | 
        
        
            | 
            | 
           106 | 
                   $oldheading .= get_string('version') . ' ' . $old->version . $oldversionview;
  | 
        
        
            | 
            | 
           107 | 
                   $oldheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           108 | 
                   // userdate container
  | 
        
        
            | 
            | 
           109 | 
                   $oldheading .= $this->output->container_start('wiki_difftime');
  | 
        
        
            | 
            | 
           110 | 
                   $oldheading .= userdate($old->timecreated, $strdatetime);
  | 
        
        
            | 
            | 
           111 | 
                   $oldheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           112 | 
              | 
        
        
            | 
            | 
           113 | 
                   $newuser = $new->user;
  | 
        
        
            | 
            | 
           114 | 
                   $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $new->id));
  | 
        
        
            | 
            | 
           115 | 
                   $restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $pageid, 'versionid' => $new->id));
  | 
        
        
            | 
            | 
           116 | 
                   $userlink = new moodle_url('/user/view.php', array('id' => $newuser->id));
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
                   $newversionview = ' ';
  | 
        
        
            | 
            | 
           119 | 
                   $newversionview .= html_writer::link($versionlink->out(false), get_string('view', 'wiki'), array('class' => 'wiki_diffview'));
  | 
        
        
            | 
            | 
           120 | 
                   // new user info
  | 
        
        
            | 
            | 
           121 | 
                   $newheading = $this->output->container_start('wiki_diffuserright');
  | 
        
        
            | 
            | 
           122 | 
                   $newheading .= $this->output->user_picture($newuser, array('popup' => true));
  | 
        
        
            | 
            | 
           123 | 
              | 
        
        
            | 
            | 
           124 | 
                   $newheading .= html_writer::link($userlink->out(false), fullname($newuser), array('class' => 'notunderlined'));
  | 
        
        
            | 
            | 
           125 | 
                   $newheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           126 | 
              | 
        
        
            | 
            | 
           127 | 
                   // version
  | 
        
        
            | 
            | 
           128 | 
                   $newheading .= $this->output->container_start('wiki_diffversion');
  | 
        
        
            | 
            | 
           129 | 
                   $newheading .= get_string('version') . ' ' . $new->version . $newversionview;
  | 
        
        
            | 
            | 
           130 | 
                   $newheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           131 | 
                   // userdate
  | 
        
        
            | 
            | 
           132 | 
                   $newheading .= $this->output->container_start('wiki_difftime');
  | 
        
        
            | 
            | 
           133 | 
                   $newheading .= userdate($new->timecreated, $strdatetime);
  | 
        
        
            | 
            | 
           134 | 
                   $newheading .= $this->output->container_end();
  | 
        
        
            | 
            | 
           135 | 
              | 
        
        
            | 
            | 
           136 | 
                   $oldheading = html_writer::tag('div', $oldheading, array('class'=>'wiki-diff-heading header clearfix'));
  | 
        
        
            | 
            | 
           137 | 
                   $newheading = html_writer::tag('div', $newheading, array('class'=>'wiki-diff-heading header clearfix'));
  | 
        
        
            | 
            | 
           138 | 
              | 
        
        
            | 
            | 
           139 | 
                   $output  = '';
  | 
        
        
            | 
            | 
           140 | 
                   $output .= html_writer::start_tag('div', array('class'=>'wiki-diff-container clearfix'));
  | 
        
        
            | 
            | 
           141 | 
                   $output .= html_writer::tag('div', $oldheading.$diff1, array('class'=>'wiki-diff-leftside'));
  | 
        
        
            | 
            | 
           142 | 
                   $output .= html_writer::tag('div', $newheading.$diff2, array('class'=>'wiki-diff-rightside'));
  | 
        
        
            | 
            | 
           143 | 
                   $output .= html_writer::end_tag('div');
  | 
        
        
            | 
            | 
           144 | 
              | 
        
        
            | 
            | 
           145 | 
                   if (!empty($total)) {
  | 
        
        
            | 
            | 
           146 | 
                       $output .= '<div class="wiki_diff_paging">';
  | 
        
        
            | 
            | 
           147 | 
                       $output .= $this->output->container($this->diff_paging_bar(1, $new->version - 1, $old->version, $CFG->wwwroot . '/mod/wiki/diff.php?pageid=' . $pageid . '&comparewith=' . $new->version . '&', 'compare', false, true), 'wiki_diff_oldpaging');
  | 
        
        
            | 
            | 
           148 | 
                       $output .= $this->output->container($this->diff_paging_bar($old->version + 1, $total, $new->version, $CFG->wwwroot . '/mod/wiki/diff.php?pageid=' . $pageid . '&compare=' . $old->version . '&', 'comparewith', false, true), 'wiki_diff_newpaging');
  | 
        
        
            | 
            | 
           149 | 
                       $output .= '</div>';
  | 
        
        
            | 
            | 
           150 | 
                   }
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   return $output;
  | 
        
        
            | 
            | 
           153 | 
               }
  | 
        
        
            | 
            | 
           154 | 
              | 
        
        
            | 
            | 
           155 | 
               /**
  | 
        
        
            | 
            | 
           156 | 
                * Prints a single paging bar to provide access to other versions
  | 
        
        
            | 
            | 
           157 | 
                *
  | 
        
        
            | 
            | 
           158 | 
                * @param int $minpage First page to be displayed in the bar
  | 
        
        
            | 
            | 
           159 | 
                * @param int $maxpage Last page to be displayed in the bar
  | 
        
        
            | 
            | 
           160 | 
                * @param int $page The page you are currently viewing
  | 
        
        
            | 
            | 
           161 | 
                * @param mixed $baseurl If this  is a string then it is the url which will be appended with $pagevar, an equals sign and the page number.
  | 
        
        
            | 
            | 
           162 | 
                *                          If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
  | 
        
        
            | 
            | 
           163 | 
                * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
  | 
        
        
            | 
            | 
           164 | 
                * @param bool $nocurr do not display the current page as a link
  | 
        
        
            | 
            | 
           165 | 
                * @param bool $return whether to return an output string or echo now
  | 
        
        
            | 
            | 
           166 | 
                * @return bool or string
  | 
        
        
            | 
            | 
           167 | 
                */
  | 
        
        
            | 
            | 
           168 | 
               public function diff_paging_bar($minpage, $maxpage, $page, $baseurl, $pagevar = 'page', $nocurr = false) {
  | 
        
        
            | 
            | 
           169 | 
                   $totalcount = $maxpage - $minpage;
  | 
        
        
            | 
            | 
           170 | 
                   $maxdisplay = 2;
  | 
        
        
            | 
            | 
           171 | 
                   $output = '';
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
                   if ($totalcount > 0) {
  | 
        
        
            | 
            | 
           174 | 
                       $output .= '<div class="paging">';
  | 
        
        
            | 
            | 
           175 | 
                       $output .= get_string('version', 'wiki') . ':';
  | 
        
        
            | 
            | 
           176 | 
                       if ($page - $minpage > 0) {
  | 
        
        
            | 
            | 
           177 | 
                           $pagenum = $page - 1;
  | 
        
        
            | 
            | 
           178 | 
                           if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           179 | 
                               $output .= ' (<a class="previous" href="' . $baseurl . $pagevar . '=' . $pagenum . '">' . get_string('previous') . '</a>) ';
  | 
        
        
            | 
            | 
           180 | 
                           } else {
  | 
        
        
            | 
            | 
           181 | 
                               $output .= ' (<a class="previous" href="' . $baseurl->out(false, array($pagevar => $pagenum)) . '">' . get_string('previous') . '</a>) ';
  | 
        
        
            | 
            | 
           182 | 
                           }
  | 
        
        
            | 
            | 
           183 | 
                       }
  | 
        
        
            | 
            | 
           184 | 
              | 
        
        
            | 
            | 
           185 | 
                       if ($page - $minpage > 4) {
  | 
        
        
            | 
            | 
           186 | 
                           $startpage = $page - 3;
  | 
        
        
            | 
            | 
           187 | 
                           if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           188 | 
                               $output .= ' <a href="' . $baseurl . $pagevar . '=' . $minpage . '">' . $minpage . '</a> ...';
  | 
        
        
            | 
            | 
           189 | 
                           } else {
  | 
        
        
            | 
            | 
           190 | 
                               $output .= ' <a href="' . $baseurl->out(false, array($pagevar => $minpage)) . '">' . $minpage . '</a> ...';
  | 
        
        
            | 
            | 
           191 | 
                           }
  | 
        
        
            | 
            | 
           192 | 
                       } else {
  | 
        
        
            | 
            | 
           193 | 
                           $startpage = $minpage;
  | 
        
        
            | 
            | 
           194 | 
                       }
  | 
        
        
            | 
            | 
           195 | 
                       $currpage = $startpage;
  | 
        
        
            | 
            | 
           196 | 
                       $displaycount = 0;
  | 
        
        
            | 
            | 
           197 | 
                       while ($displaycount < $maxdisplay and $currpage <= $maxpage) {
  | 
        
        
            | 
            | 
           198 | 
                           if ($page == $currpage && empty($nocurr)) {
  | 
        
        
            | 
            | 
           199 | 
                               $output .= '  ' . $currpage;
  | 
        
        
            | 
            | 
           200 | 
                           } else {
  | 
        
        
            | 
            | 
           201 | 
                               if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           202 | 
                                   $output .= '  <a href="' . $baseurl . $pagevar . '=' . $currpage . '">' . $currpage . '</a>';
  | 
        
        
            | 
            | 
           203 | 
                               } else {
  | 
        
        
            | 
            | 
           204 | 
                                   $output .= '  <a href="' . $baseurl->out(false, array($pagevar => $currpage)) . '">' . $currpage . '</a>';
  | 
        
        
            | 
            | 
           205 | 
                               }
  | 
        
        
            | 
            | 
           206 | 
              | 
        
        
            | 
            | 
           207 | 
                           }
  | 
        
        
            | 
            | 
           208 | 
                           $displaycount++;
  | 
        
        
            | 
            | 
           209 | 
                           $currpage++;
  | 
        
        
            | 
            | 
           210 | 
                       }
  | 
        
        
            | 
            | 
           211 | 
                       if ($currpage < $maxpage) {
  | 
        
        
            | 
            | 
           212 | 
                           if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           213 | 
                               $output .= ' ...<a href="' . $baseurl . $pagevar . '=' . $maxpage . '">' . $maxpage . '</a> ';
  | 
        
        
            | 
            | 
           214 | 
                           } else {
  | 
        
        
            | 
            | 
           215 | 
                               $output .= ' ...<a href="' . $baseurl->out(false, array($pagevar => $maxpage)) . '">' . $maxpage . '</a> ';
  | 
        
        
            | 
            | 
           216 | 
                           }
  | 
        
        
            | 
            | 
           217 | 
                       } else if ($currpage == $maxpage) {
  | 
        
        
            | 
            | 
           218 | 
                           if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           219 | 
                               $output .= '  <a href="' . $baseurl . $pagevar . '=' . $currpage . '">' . $currpage . '</a>';
  | 
        
        
            | 
            | 
           220 | 
                           } else {
  | 
        
        
            | 
            | 
           221 | 
                               $output .= '  <a href="' . $baseurl->out(false, array($pagevar => $currpage)) . '">' . $currpage . '</a>';
  | 
        
        
            | 
            | 
           222 | 
                           }
  | 
        
        
            | 
            | 
           223 | 
                       }
  | 
        
        
            | 
            | 
           224 | 
                       $pagenum = $page + 1;
  | 
        
        
            | 
            | 
           225 | 
                       if ($page != $maxpage) {
  | 
        
        
            | 
            | 
           226 | 
                           if (!is_a($baseurl, 'moodle_url')) {
  | 
        
        
            | 
            | 
           227 | 
                               $output .= '  (<a class="next" href="' . $baseurl . $pagevar . '=' . $pagenum . '">' . get_string('next') . '</a>)';
  | 
        
        
            | 
            | 
           228 | 
                           } else {
  | 
        
        
            | 
            | 
           229 | 
                               $output .= '  (<a class="next" href="' . $baseurl->out(false, array($pagevar => $pagenum)) . '">' . get_string('next') . '</a>)';
  | 
        
        
            | 
            | 
           230 | 
                           }
  | 
        
        
            | 
            | 
           231 | 
                       }
  | 
        
        
            | 
            | 
           232 | 
                       $output .= '</div>';
  | 
        
        
            | 
            | 
           233 | 
                   }
  | 
        
        
            | 
            | 
           234 | 
              | 
        
        
            | 
            | 
           235 | 
                   return $output;
  | 
        
        
            | 
            | 
           236 | 
               }
  | 
        
        
            | 
            | 
           237 | 
              | 
        
        
            | 
            | 
           238 | 
               /**
  | 
        
        
           | 1441 | 
           ariadna | 
           239 | 
                * @deprecated since Moodle 4.0 MDL-72413. Now handled in PAGE's activity header
  | 
        
        
           | 1 | 
           efrain | 
           240 | 
                */
  | 
        
        
           | 1441 | 
           ariadna | 
           241 | 
               #[\core\attribute\deprecated(null, since: '4.3', mdl: 'MDL-72413', final: true)]
  | 
        
        
           | 1 | 
           efrain | 
           242 | 
               public function wiki_info() {
  | 
        
        
           | 1441 | 
           ariadna | 
           243 | 
                   \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
  | 
        
        
           | 1 | 
           efrain | 
           244 | 
               }
  | 
        
        
            | 
            | 
           245 | 
              | 
        
        
            | 
            | 
           246 | 
               public function tabs($page, $tabitems, $options) {
  | 
        
        
            | 
            | 
           247 | 
                   $tabs = array();
  | 
        
        
            | 
            | 
           248 | 
                   $context = context_module::instance($this->page->cm->id);
  | 
        
        
            | 
            | 
           249 | 
              | 
        
        
            | 
            | 
           250 | 
                   $pageid = null;
  | 
        
        
            | 
            | 
           251 | 
                   if (!empty($page)) {
  | 
        
        
            | 
            | 
           252 | 
                       $pageid = $page->id;
  | 
        
        
            | 
            | 
           253 | 
                   }
  | 
        
        
            | 
            | 
           254 | 
              | 
        
        
            | 
            | 
           255 | 
                   $selected = $options['activetab'];
  | 
        
        
            | 
            | 
           256 | 
              | 
        
        
            | 
            | 
           257 | 
                   // make specific tab linked even it is active
  | 
        
        
            | 
            | 
           258 | 
                   if (!empty($options['linkedwhenactive'])) {
  | 
        
        
            | 
            | 
           259 | 
                       $linked = $options['linkedwhenactive'];
  | 
        
        
            | 
            | 
           260 | 
                   } else {
  | 
        
        
            | 
            | 
           261 | 
                       $linked = '';
  | 
        
        
            | 
            | 
           262 | 
                   }
  | 
        
        
            | 
            | 
           263 | 
              | 
        
        
            | 
            | 
           264 | 
                   if (!empty($options['inactivetabs'])) {
  | 
        
        
            | 
            | 
           265 | 
                       $inactive = $options['inactivetabs'];
  | 
        
        
            | 
            | 
           266 | 
                   } else {
  | 
        
        
            | 
            | 
           267 | 
                       $inactive = array();
  | 
        
        
            | 
            | 
           268 | 
                   }
  | 
        
        
            | 
            | 
           269 | 
              | 
        
        
            | 
            | 
           270 | 
                   foreach ($tabitems as $tab) {
  | 
        
        
            | 
            | 
           271 | 
                       if ($tab == 'edit' && !has_capability('mod/wiki:editpage', $context)) {
  | 
        
        
            | 
            | 
           272 | 
                           continue;
  | 
        
        
            | 
            | 
           273 | 
                       }
  | 
        
        
            | 
            | 
           274 | 
                       if ($tab == 'comments' && !has_capability('mod/wiki:viewcomment', $context)) {
  | 
        
        
            | 
            | 
           275 | 
                           continue;
  | 
        
        
            | 
            | 
           276 | 
                       }
  | 
        
        
            | 
            | 
           277 | 
                       if ($tab == 'files' && !has_capability('mod/wiki:viewpage', $context)) {
  | 
        
        
            | 
            | 
           278 | 
                           continue;
  | 
        
        
            | 
            | 
           279 | 
                       }
  | 
        
        
            | 
            | 
           280 | 
                       if (($tab == 'view' || $tab == 'map' || $tab == 'history') && !has_capability('mod/wiki:viewpage', $context)) {
  | 
        
        
            | 
            | 
           281 | 
                           continue;
  | 
        
        
            | 
            | 
           282 | 
                       }
  | 
        
        
            | 
            | 
           283 | 
                       if ($tab == 'admin' && !has_capability('mod/wiki:managewiki', $context)) {
  | 
        
        
            | 
            | 
           284 | 
                           continue;
  | 
        
        
            | 
            | 
           285 | 
                       }
  | 
        
        
            | 
            | 
           286 | 
                       $link = new moodle_url('/mod/wiki/'. $tab. '.php', array('pageid' => $pageid));
  | 
        
        
            | 
            | 
           287 | 
                       if ($linked == $tab) {
  | 
        
        
            | 
            | 
           288 | 
                           $tabs[] = new tabobject($tab, $link, get_string($tab, 'wiki'), '', true);
  | 
        
        
            | 
            | 
           289 | 
                       } else {
  | 
        
        
            | 
            | 
           290 | 
                           $tabs[] = new tabobject($tab, $link, get_string($tab, 'wiki'));
  | 
        
        
            | 
            | 
           291 | 
                       }
  | 
        
        
            | 
            | 
           292 | 
                   }
  | 
        
        
            | 
            | 
           293 | 
              | 
        
        
            | 
            | 
           294 | 
                   return $this->tabtree($tabs, $selected, $inactive);
  | 
        
        
            | 
            | 
           295 | 
               }
  | 
        
        
            | 
            | 
           296 | 
              | 
        
        
            | 
            | 
           297 | 
               public function prettyview_link($page) {
  | 
        
        
            | 
            | 
           298 | 
                   $html = '';
  | 
        
        
            | 
            | 
           299 | 
                   $link = new moodle_url('/mod/wiki/prettyview.php', array('pageid' => $page->id));
  | 
        
        
            | 
            | 
           300 | 
                   $html .= $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           301 | 
                   $html .= $this->output->action_link($link, get_string('prettyprint', 'wiki'), new popup_action('click', $link), array('class' => 'printicon'));
  | 
        
        
            | 
            | 
           302 | 
                   $html .= $this->output->container_end();
  | 
        
        
            | 
            | 
           303 | 
                   return $html;
  | 
        
        
            | 
            | 
           304 | 
               }
  | 
        
        
            | 
            | 
           305 | 
              | 
        
        
            | 
            | 
           306 | 
               public function wiki_print_subwiki_selector($wiki, $subwiki, $page, $pagetype = 'view') {
  | 
        
        
            | 
            | 
           307 | 
                   global $CFG, $USER;
  | 
        
        
            | 
            | 
           308 | 
                   require_once($CFG->dirroot . '/user/lib.php');
  | 
        
        
            | 
            | 
           309 | 
                   $cm = get_coursemodule_from_instance('wiki', $wiki->id);
  | 
        
        
            | 
            | 
           310 | 
              | 
        
        
            | 
            | 
           311 | 
                   switch ($pagetype) {
  | 
        
        
            | 
            | 
           312 | 
                   case 'files':
  | 
        
        
            | 
            | 
           313 | 
                       $baseurl = new moodle_url('/mod/wiki/files.php',
  | 
        
        
            | 
            | 
           314 | 
                               array('wid' => $wiki->id, 'title' => $page->title, 'pageid' => $page->id));
  | 
        
        
            | 
            | 
           315 | 
                       break;
  | 
        
        
            | 
            | 
           316 | 
                   case 'search':
  | 
        
        
            | 
            | 
           317 | 
                       $search = optional_param('searchstring', null, PARAM_TEXT);
  | 
        
        
            | 
            | 
           318 | 
                       $searchcontent = optional_param('searchwikicontent', 0, PARAM_INT);
  | 
        
        
            | 
            | 
           319 | 
                       $baseurl = new moodle_url('/mod/wiki/search.php',
  | 
        
        
            | 
            | 
           320 | 
                               array('cmid' => $cm->id, 'courseid' => $cm->course,
  | 
        
        
            | 
            | 
           321 | 
                                   'searchstring' => $search, 'searchwikicontent' => $searchcontent));
  | 
        
        
            | 
            | 
           322 | 
                       break;
  | 
        
        
            | 
            | 
           323 | 
                   case 'view':
  | 
        
        
            | 
            | 
           324 | 
                   default:
  | 
        
        
            | 
            | 
           325 | 
                       $baseurl = new moodle_url('/mod/wiki/view.php',
  | 
        
        
            | 
            | 
           326 | 
                               array('wid' => $wiki->id, 'title' => $page->title));
  | 
        
        
            | 
            | 
           327 | 
                       break;
  | 
        
        
            | 
            | 
           328 | 
                   }
  | 
        
        
            | 
            | 
           329 | 
              | 
        
        
            | 
            | 
           330 | 
                   $context = context_module::instance($cm->id);
  | 
        
        
            | 
            | 
           331 | 
                   // @TODO: A plenty of duplicated code below this lines.
  | 
        
        
            | 
            | 
           332 | 
                   // Create private functions.
  | 
        
        
            | 
            | 
           333 | 
                   switch (groups_get_activity_groupmode($cm)) {
  | 
        
        
            | 
            | 
           334 | 
                   case NOGROUPS:
  | 
        
        
            | 
            | 
           335 | 
                       if ($wiki->wikimode == 'collaborative') {
  | 
        
        
            | 
            | 
           336 | 
                           // No need to print anything
  | 
        
        
            | 
            | 
           337 | 
                           return;
  | 
        
        
            | 
            | 
           338 | 
                       } else if ($wiki->wikimode == 'individual') {
  | 
        
        
            | 
            | 
           339 | 
                           // We have private wikis here
  | 
        
        
            | 
            | 
           340 | 
              | 
        
        
            | 
            | 
           341 | 
                           $view = has_capability('mod/wiki:viewpage', $context);
  | 
        
        
            | 
            | 
           342 | 
                           $manage = has_capability('mod/wiki:managewiki', $context);
  | 
        
        
            | 
            | 
           343 | 
              | 
        
        
            | 
            | 
           344 | 
                           // Only people with these capabilities can view all wikis
  | 
        
        
            | 
            | 
           345 | 
                           if ($view && $manage) {
  | 
        
        
            | 
            | 
           346 | 
                               // @TODO: Print here a combo that contains all users.
  | 
        
        
            | 
            | 
           347 | 
                               $users = get_enrolled_users($context);
  | 
        
        
            | 
            | 
           348 | 
                               $options = array();
  | 
        
        
            | 
            | 
           349 | 
                               foreach ($users as $user) {
  | 
        
        
            | 
            | 
           350 | 
                                   $options[$user->id] = fullname($user);
  | 
        
        
            | 
            | 
           351 | 
                               }
  | 
        
        
            | 
            | 
           352 | 
              | 
        
        
            | 
            | 
           353 | 
                               echo $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           354 | 
                               $name = 'uid';
  | 
        
        
            | 
            | 
           355 | 
                               $selected = $subwiki->userid;
  | 
        
        
            | 
            | 
           356 | 
                               echo $this->output->single_select($baseurl, $name, $options, $selected, null, null,
  | 
        
        
            | 
            | 
           357 | 
                                   array('label' => get_string('user') . ':'));
  | 
        
        
            | 
            | 
           358 | 
                               echo $this->output->container_end();
  | 
        
        
            | 
            | 
           359 | 
                           }
  | 
        
        
            | 
            | 
           360 | 
                           return;
  | 
        
        
            | 
            | 
           361 | 
                       } else {
  | 
        
        
            | 
            | 
           362 | 
                           // error
  | 
        
        
            | 
            | 
           363 | 
                           return;
  | 
        
        
            | 
            | 
           364 | 
                       }
  | 
        
        
            | 
            | 
           365 | 
                   case SEPARATEGROUPS:
  | 
        
        
            | 
            | 
           366 | 
                       if ($wiki->wikimode == 'collaborative') {
  | 
        
        
            | 
            | 
           367 | 
                           // We need to print a select to choose a course group
  | 
        
        
            | 
            | 
           368 | 
              | 
        
        
            | 
            | 
           369 | 
                           echo $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           370 | 
                           groups_print_activity_menu($cm, $baseurl);
  | 
        
        
            | 
            | 
           371 | 
                           echo $this->output->container_end();
  | 
        
        
            | 
            | 
           372 | 
                           return;
  | 
        
        
            | 
            | 
           373 | 
                       } else if ($wiki->wikimode == 'individual') {
  | 
        
        
            | 
            | 
           374 | 
                           //  @TODO: Print here a combo that contains all users of that subwiki.
  | 
        
        
            | 
            | 
           375 | 
                           $view = has_capability('mod/wiki:viewpage', $context);
  | 
        
        
            | 
            | 
           376 | 
                           $manage = has_capability('mod/wiki:managewiki', $context);
  | 
        
        
            | 
            | 
           377 | 
              | 
        
        
            | 
            | 
           378 | 
                           // Only people with these capabilities can view all wikis
  | 
        
        
            | 
            | 
           379 | 
                           if ($view && $manage) {
  | 
        
        
            | 
            | 
           380 | 
                               $users = get_enrolled_users($context);
  | 
        
        
            | 
            | 
           381 | 
                               $options = array();
  | 
        
        
            | 
            | 
           382 | 
                               foreach ($users as $user) {
  | 
        
        
            | 
            | 
           383 | 
                                   $groups = groups_get_all_groups($cm->course, $user->id);
  | 
        
        
            | 
            | 
           384 | 
                                   if (!empty($groups)) {
  | 
        
        
            | 
            | 
           385 | 
                                       foreach ($groups as $group) {
  | 
        
        
            | 
            | 
           386 | 
                                           $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
  | 
        
        
            | 
            | 
           387 | 
                                       }
  | 
        
        
            | 
            | 
           388 | 
                                   } else {
  | 
        
        
            | 
            | 
           389 | 
                                       $name = get_string('notingroup', 'wiki');
  | 
        
        
            | 
            | 
           390 | 
                                       $options[0][$name]['0' . '-' . $user->id] = fullname($user);
  | 
        
        
            | 
            | 
           391 | 
                                   }
  | 
        
        
            | 
            | 
           392 | 
                               }
  | 
        
        
            | 
            | 
           393 | 
                           } else {
  | 
        
        
            | 
            | 
           394 | 
                               $group = groups_get_group($subwiki->groupid);
  | 
        
        
            | 
            | 
           395 | 
                               if (!$group) {
  | 
        
        
            | 
            | 
           396 | 
                                   return;
  | 
        
        
            | 
            | 
           397 | 
                               }
  | 
        
        
            | 
            | 
           398 | 
                               $users = groups_get_members($subwiki->groupid);
  | 
        
        
            | 
            | 
           399 | 
                               foreach ($users as $user) {
  | 
        
        
            | 
            | 
           400 | 
                                   $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
  | 
        
        
            | 
            | 
           401 | 
                               }
  | 
        
        
            | 
            | 
           402 | 
                           }
  | 
        
        
            | 
            | 
           403 | 
                           echo $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           404 | 
                           $name = 'groupanduser';
  | 
        
        
            | 
            | 
           405 | 
                           $selected = $subwiki->groupid . '-' . $subwiki->userid;
  | 
        
        
            | 
            | 
           406 | 
                           echo $this->output->single_select($baseurl, $name, $options, $selected, null, null,
  | 
        
        
            | 
            | 
           407 | 
                               array('label' => get_string('user') . ':'));
  | 
        
        
            | 
            | 
           408 | 
                           echo $this->output->container_end();
  | 
        
        
            | 
            | 
           409 | 
              | 
        
        
            | 
            | 
           410 | 
                           return;
  | 
        
        
            | 
            | 
           411 | 
              | 
        
        
            | 
            | 
           412 | 
                       } else {
  | 
        
        
            | 
            | 
           413 | 
                           // error
  | 
        
        
            | 
            | 
           414 | 
                           return;
  | 
        
        
            | 
            | 
           415 | 
                       }
  | 
        
        
            | 
            | 
           416 | 
                   CASE VISIBLEGROUPS:
  | 
        
        
            | 
            | 
           417 | 
                       if ($wiki->wikimode == 'collaborative') {
  | 
        
        
            | 
            | 
           418 | 
                           // We need to print a select to choose a course group
  | 
        
        
            | 
            | 
           419 | 
                           // moodle_url will take care of encoding for us
  | 
        
        
            | 
            | 
           420 | 
              | 
        
        
            | 
            | 
           421 | 
                           echo $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           422 | 
                           groups_print_activity_menu($cm, $baseurl);
  | 
        
        
            | 
            | 
           423 | 
                           echo $this->output->container_end();
  | 
        
        
            | 
            | 
           424 | 
                           return;
  | 
        
        
            | 
            | 
           425 | 
              | 
        
        
            | 
            | 
           426 | 
                       } else if ($wiki->wikimode == 'individual') {
  | 
        
        
            | 
            | 
           427 | 
                           $users = get_enrolled_users($context);
  | 
        
        
            | 
            | 
           428 | 
                           $options = array();
  | 
        
        
            | 
            | 
           429 | 
                           foreach ($users as $user) {
  | 
        
        
            | 
            | 
           430 | 
                               $groups = groups_get_all_groups($cm->course, $user->id);
  | 
        
        
            | 
            | 
           431 | 
                               if (!empty($groups)) {
  | 
        
        
            | 
            | 
           432 | 
                                   foreach ($groups as $group) {
  | 
        
        
            | 
            | 
           433 | 
                                       $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
  | 
        
        
            | 
            | 
           434 | 
                                   }
  | 
        
        
            | 
            | 
           435 | 
                               } else {
  | 
        
        
            | 
            | 
           436 | 
                                   $name = get_string('notingroup', 'wiki');
  | 
        
        
            | 
            | 
           437 | 
                                   $options[0][$name]['0' . '-' . $user->id] = fullname($user);
  | 
        
        
            | 
            | 
           438 | 
                               }
  | 
        
        
            | 
            | 
           439 | 
                           }
  | 
        
        
            | 
            | 
           440 | 
              | 
        
        
            | 
            | 
           441 | 
                           echo $this->output->container_start('wiki_right');
  | 
        
        
            | 
            | 
           442 | 
                           $name = 'groupanduser';
  | 
        
        
            | 
            | 
           443 | 
                           $selected = $subwiki->groupid . '-' . $subwiki->userid;
  | 
        
        
            | 
            | 
           444 | 
                           echo $this->output->single_select($baseurl, $name, $options, $selected, null, null,
  | 
        
        
            | 
            | 
           445 | 
                               array('label' => get_string('user') . ':'));
  | 
        
        
            | 
            | 
           446 | 
                           echo $this->output->container_end();
  | 
        
        
            | 
            | 
           447 | 
              | 
        
        
            | 
            | 
           448 | 
                           return;
  | 
        
        
            | 
            | 
           449 | 
              | 
        
        
            | 
            | 
           450 | 
                       } else {
  | 
        
        
            | 
            | 
           451 | 
                           // error
  | 
        
        
            | 
            | 
           452 | 
                           return;
  | 
        
        
            | 
            | 
           453 | 
                       }
  | 
        
        
            | 
            | 
           454 | 
                   default:
  | 
        
        
            | 
            | 
           455 | 
                       // error
  | 
        
        
            | 
            | 
           456 | 
                       return;
  | 
        
        
            | 
            | 
           457 | 
              | 
        
        
            | 
            | 
           458 | 
                   }
  | 
        
        
            | 
            | 
           459 | 
              | 
        
        
            | 
            | 
           460 | 
               }
  | 
        
        
            | 
            | 
           461 | 
              | 
        
        
            | 
            | 
           462 | 
               function menu_map($pageid, $currentselect) {
  | 
        
        
            | 
            | 
           463 | 
                   if (empty($currentselect)) {
  | 
        
        
            | 
            | 
           464 | 
                       // The wiki uses digit number to match the options and 5 is the default one.
  | 
        
        
            | 
            | 
           465 | 
                       $currentselect = 5;
  | 
        
        
            | 
            | 
           466 | 
                   }
  | 
        
        
            | 
            | 
           467 | 
                   $options = array('contributions', 'links', 'orphaned', 'pageindex', 'pagelist', 'updatedpages');
  | 
        
        
            | 
            | 
           468 | 
                   $items = array();
  | 
        
        
            | 
            | 
           469 | 
                   foreach ($options as $opt) {
  | 
        
        
            | 
            | 
           470 | 
                       $items[] = get_string($opt, 'wiki');
  | 
        
        
            | 
            | 
           471 | 
                   }
  | 
        
        
            | 
            | 
           472 | 
                   $selectoptions = array();
  | 
        
        
            | 
            | 
           473 | 
                   foreach ($items as $key => $item) {
  | 
        
        
            | 
            | 
           474 | 
                       $selectoptions[$key + 1] = $item;
  | 
        
        
            | 
            | 
           475 | 
                   }
  | 
        
        
            | 
            | 
           476 | 
                   $select = new single_select(new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid)), 'option', $selectoptions, $currentselect, null);
  | 
        
        
            | 
            | 
           477 | 
                   $select->label = get_string('mapmenu', 'wiki') . ': ';
  | 
        
        
            | 
            | 
           478 | 
                   return $this->output->container($this->output->render($select), 'midpad');
  | 
        
        
            | 
            | 
           479 | 
               }
  | 
        
        
            | 
            | 
           480 | 
               public function wiki_files_tree($context, $subwiki) {
  | 
        
        
            | 
            | 
           481 | 
                   return $this->render(new wiki_files_tree($context, $subwiki));
  | 
        
        
            | 
            | 
           482 | 
               }
  | 
        
        
            | 
            | 
           483 | 
               public function render_wiki_files_tree(wiki_files_tree $tree) {
  | 
        
        
            | 
            | 
           484 | 
                   if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) {
  | 
        
        
            | 
            | 
           485 | 
                       $html = $this->output->box(get_string('nofilesavailable', 'repository'));
  | 
        
        
            | 
            | 
           486 | 
                   } else {
  | 
        
        
            | 
            | 
           487 | 
                       $htmlid = 'wiki_files_tree_'.uniqid();
  | 
        
        
            | 
            | 
           488 | 
                       $module = array('name'=>'mod_wiki', 'fullpath'=>'/mod/wiki/module.js');
  | 
        
        
            | 
            | 
           489 | 
                       $this->page->requires->js_init_call('M.mod_wiki.init_tree', array(false, $htmlid), false, $module);
  | 
        
        
            | 
            | 
           490 | 
                       $html = '<div id="'.$htmlid.'">';
  | 
        
        
            | 
            | 
           491 | 
                       $html .= $this->htmllize_tree($tree, $tree->dir);
  | 
        
        
            | 
            | 
           492 | 
                       $html .= '</div>';
  | 
        
        
            | 
            | 
           493 | 
                   }
  | 
        
        
            | 
            | 
           494 | 
                   return $html;
  | 
        
        
            | 
            | 
           495 | 
               }
  | 
        
        
            | 
            | 
           496 | 
              | 
        
        
            | 
            | 
           497 | 
               function menu_admin($pageid, $currentselect) {
  | 
        
        
            | 
            | 
           498 | 
                   $options = array('removepages', 'deleteversions');
  | 
        
        
            | 
            | 
           499 | 
                   $items = array();
  | 
        
        
            | 
            | 
           500 | 
                   foreach ($options as $opt) {
  | 
        
        
            | 
            | 
           501 | 
                       $items[] = get_string($opt, 'wiki');
  | 
        
        
            | 
            | 
           502 | 
                   }
  | 
        
        
            | 
            | 
           503 | 
                   $selectoptions = array();
  | 
        
        
            | 
            | 
           504 | 
                   foreach ($items as $key => $item) {
  | 
        
        
            | 
            | 
           505 | 
                       $selectoptions[$key + 1] = $item;
  | 
        
        
            | 
            | 
           506 | 
                   }
  | 
        
        
            | 
            | 
           507 | 
                   $select = new single_select(new moodle_url('/mod/wiki/admin.php', array('pageid' => $pageid)), 'option', $selectoptions, $currentselect, null);
  | 
        
        
            | 
            | 
           508 | 
                   $select->label = get_string('adminmenu', 'wiki') . ': ';
  | 
        
        
            | 
            | 
           509 | 
                   return $this->output->container($this->output->render($select), 'midpad');
  | 
        
        
            | 
            | 
           510 | 
               }
  | 
        
        
            | 
            | 
           511 | 
              | 
        
        
            | 
            | 
           512 | 
               /**
  | 
        
        
            | 
            | 
           513 | 
                * Internal function - creates htmls structure suitable for YUI tree.
  | 
        
        
            | 
            | 
           514 | 
                */
  | 
        
        
            | 
            | 
           515 | 
               protected function htmllize_tree($tree, $dir) {
  | 
        
        
            | 
            | 
           516 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           517 | 
                   $yuiconfig = array();
  | 
        
        
            | 
            | 
           518 | 
                   $yuiconfig['type'] = 'html';
  | 
        
        
            | 
            | 
           519 | 
              | 
        
        
            | 
            | 
           520 | 
                   if (empty($dir['subdirs']) and empty($dir['files'])) {
  | 
        
        
            | 
            | 
           521 | 
                       return '';
  | 
        
        
            | 
            | 
           522 | 
                   }
  | 
        
        
            | 
            | 
           523 | 
                   $result = '<ul>';
  | 
        
        
            | 
            | 
           524 | 
                   foreach ($dir['subdirs'] as $subdir) {
  | 
        
        
            | 
            | 
           525 | 
                       $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
  | 
        
        
            | 
            | 
           526 | 
                       $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
  | 
        
        
            | 
            | 
           527 | 
                   }
  | 
        
        
            | 
            | 
           528 | 
                   foreach ($dir['files'] as $file) {
  | 
        
        
            | 
            | 
           529 | 
                       $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
  | 
        
        
            | 
            | 
           530 | 
                       $filename = $file->get_filename();
  | 
        
        
            | 
            | 
           531 | 
                       $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
  | 
        
        
            | 
            | 
           532 | 
                       $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
  | 
        
        
            | 
            | 
           533 | 
                   }
  | 
        
        
            | 
            | 
           534 | 
                   $result .= '</ul>';
  | 
        
        
            | 
            | 
           535 | 
              | 
        
        
            | 
            | 
           536 | 
                   return $result;
  | 
        
        
            | 
            | 
           537 | 
               }
  | 
        
        
            | 
            | 
           538 | 
              | 
        
        
            | 
            | 
           539 | 
               /**
  | 
        
        
            | 
            | 
           540 | 
                * Renders the action bar.
  | 
        
        
            | 
            | 
           541 | 
                *
  | 
        
        
            | 
            | 
           542 | 
                * @param \mod_wiki\output\action_bar $actionbar
  | 
        
        
            | 
            | 
           543 | 
                * @return string The HTML output
  | 
        
        
            | 
            | 
           544 | 
                */
  | 
        
        
            | 
            | 
           545 | 
               public function render_action_bar(\mod_wiki\output\action_bar $actionbar): string {
  | 
        
        
            | 
            | 
           546 | 
                   $data = $actionbar->export_for_template($this);
  | 
        
        
            | 
            | 
           547 | 
                   return $this->render_from_template('mod_wiki/action_bar', $data);
  | 
        
        
            | 
            | 
           548 | 
               }
  | 
        
        
            | 
            | 
           549 | 
           }
  | 
        
        
            | 
            | 
           550 | 
              | 
        
        
            | 
            | 
           551 | 
           class wiki_files_tree implements renderable {
  | 
        
        
            | 
            | 
           552 | 
               public $context;
  | 
        
        
            | 
            | 
           553 | 
               public $dir;
  | 
        
        
            | 
            | 
           554 | 
               public $subwiki;
  | 
        
        
            | 
            | 
           555 | 
               public function __construct($context, $subwiki) {
  | 
        
        
            | 
            | 
           556 | 
                   $fs = get_file_storage();
  | 
        
        
            | 
            | 
           557 | 
                   $this->context = $context;
  | 
        
        
            | 
            | 
           558 | 
                   $this->subwiki = $subwiki;
  | 
        
        
            | 
            | 
           559 | 
                   $this->dir = $fs->get_area_tree($context->id, 'mod_wiki', 'attachments', $subwiki->id);
  | 
        
        
            | 
            | 
           560 | 
               }
  | 
        
        
            | 
            | 
           561 | 
           }
  |