~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to mod/wiki/pagelib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
     * @var object wiki renderer
87
87
     */
88
88
    protected $wikioutput;
 
89
    /**
 
90
     * @var stdClass course module.
 
91
     */
 
92
    protected $cm;
89
93
 
90
94
    /**
91
95
     * page_wiki constructor
97
101
    function __construct($wiki, $subwiki, $cm) {
98
102
        global $PAGE, $CFG;
99
103
        $this->subwiki = $subwiki;
100
 
        $this->modcontext = context_module::instance($PAGE->cm->id);
 
104
        $this->cm = $cm;
 
105
        $this->modcontext = context_module::instance($this->cm->id);
101
106
 
102
107
        // initialise wiki renderer
103
108
        $this->wikioutput = $PAGE->get_renderer('mod_wiki');
105
110
        $PAGE->set_cm($cm);
106
111
        $PAGE->set_activity_record($wiki);
107
112
        // the search box
108
 
        $PAGE->set_button(wiki_search_form($cm));
 
113
        if (!empty($subwiki->id)) {
 
114
            $search = optional_param('searchstring', null, PARAM_ALPHANUMEXT);
 
115
            $PAGE->set_button(wiki_search_form($cm, $search, $subwiki));
 
116
        }
109
117
    }
110
118
 
111
119
    /**
114
122
    function print_header() {
115
123
        global $OUTPUT, $PAGE, $CFG, $USER, $SESSION;
116
124
 
117
 
        $PAGE->set_heading(format_string($PAGE->course->fullname));
 
125
        $PAGE->set_heading($PAGE->course->fullname);
118
126
 
119
127
        $this->set_url();
120
128
 
127
135
        $this->setup_tabs();
128
136
 
129
137
        echo $OUTPUT->header();
 
138
        $wiki = $PAGE->activityrecord;
 
139
        echo $OUTPUT->heading($wiki->name);
130
140
 
131
141
        echo $this->wikioutput->wiki_info();
132
142
 
143
153
        global $OUTPUT;
144
154
        $html = '';
145
155
 
146
 
        $html .= $OUTPUT->container_start();
147
 
        $html .= $OUTPUT->heading(format_string($this->title), 2, 'wiki_headingtitle');
 
156
        $html .= $OUTPUT->container_start('wiki_headingtitle');
 
157
        $html .= $OUTPUT->heading(format_string($this->title), 3);
148
158
        $html .= $OUTPUT->container_end();
149
159
        echo $html;
150
160
    }
155
165
     */
156
166
    protected function setup_tabs($options = array()) {
157
167
        global $CFG, $PAGE;
158
 
        $groupmode = groups_get_activity_groupmode($PAGE->cm);
 
168
        $groupmode = groups_get_activity_groupmode($this->cm);
159
169
 
160
170
        if (empty($CFG->usecomments) || !has_capability('mod/wiki:viewcomment', $PAGE->context)){
161
171
            unset($this->tabs['comments']);
166
176
        }
167
177
 
168
178
        if ($groupmode and $groupmode == VISIBLEGROUPS) {
169
 
            $currentgroup = groups_get_activity_group($PAGE->cm);
170
 
            $manage = has_capability('mod/wiki:managewiki', $PAGE->cm->context);
 
179
            $currentgroup = groups_get_activity_group($this->cm);
 
180
            $manage = has_capability('mod/wiki:managewiki', $this->modcontext);
171
181
            $edit = has_capability('mod/wiki:editpage', $PAGE->context);
172
182
            if (!$manage and !($edit and groups_is_member($currentgroup))) {
173
183
                unset($this->tabs['edit']);
283
293
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
284
294
 */
285
295
class page_wiki_view extends page_wiki {
286
 
    /**
287
 
     * @var int the coursemodule id
288
 
     */
289
 
    private $coursemodule;
290
296
 
291
297
    function print_header() {
292
298
        global $PAGE;
329
335
        global $PAGE, $CFG;
330
336
        $params = array();
331
337
 
332
 
        if (isset($this->coursemodule)) {
333
 
            $params['id'] = $this->coursemodule;
 
338
        if (isset($this->cm->id)) {
 
339
            $params['id'] = $this->cm->id;
334
340
        } else if (!empty($this->page) and $this->page != null) {
335
341
            $params['pageid'] = $this->page->id;
336
342
        } else if (!empty($this->gid)) {
337
 
            $params['wid'] = $PAGE->cm->instance;
 
343
            $params['wid'] = $this->cm->instance;
338
344
            $params['group'] = $this->gid;
339
345
        } else if (!empty($this->title)) {
340
346
            $params['swid'] = $this->subwiki->id;
342
348
        } else {
343
349
            print_error(get_string('invalidparameters', 'wiki'));
344
350
        }
345
 
 
346
351
        $PAGE->set_url(new moodle_url($CFG->wwwroot . '/mod/wiki/view.php', $params));
347
352
    }
348
353
 
349
 
    function set_coursemodule($id) {
350
 
        $this->coursemodule = $id;
351
 
    }
352
 
 
353
354
    protected function create_navbar() {
354
355
        global $PAGE;
355
356
 
391
392
        if (isset($this->section)) {
392
393
            $title .= ' : ' . $this->section;
393
394
        }
394
 
        echo $OUTPUT->container_start('wiki_clear');
395
 
        echo $OUTPUT->heading(format_string($title), 2, 'wiki_headingtitle');
 
395
        echo $OUTPUT->container_start('wiki_clear wiki_headingtitle');
 
396
        echo $OUTPUT->heading(format_string($title), 3);
396
397
        echo $OUTPUT->container_end();
397
398
    }
398
399
 
564
565
            $params['filearea']   = 'attachments';
565
566
        }
566
567
 
567
 
        if (!empty($CFG->usetags)) {
568
 
            $params['tags'] = tag_get_tags_csv('wiki_pages', $this->page->id, TAG_RETURN_TEXT);
569
 
        }
570
 
 
571
568
        $form = new mod_wiki_edit_form($url, $params);
572
569
 
573
570
        if ($formdata = $form->get_data()) {
576
573
            }
577
574
        } else {
578
575
            if (!empty($CFG->usetags)) {
579
 
                $data->tags = tag_get_tags_array('wiki', $this->page->id);
 
576
                $data->tags = tag_get_tags_array('wiki_pages', $this->page->id);
580
577
            }
581
578
        }
582
579
 
623
620
        $format = $version->contentformat;
624
621
 
625
622
        if (empty($comments)) {
626
 
            echo $OUTPUT->heading(get_string('nocomments', 'wiki'));
 
623
            echo html_writer::tag('p', get_string('nocomments', 'wiki'), array('class' => 'bold'));
627
624
        }
628
625
 
629
626
        foreach ($comments as $comment) {
834
831
        global $PAGE, $CFG;
835
832
        $PAGE->set_url($CFG->wwwroot . '/mod/wiki/search.php');
836
833
    }
 
834
 
 
835
    function print_header() {
 
836
        global $PAGE;
 
837
 
 
838
        parent::print_header();
 
839
 
 
840
        $wiki = $PAGE->activityrecord;
 
841
        $page = (object)array('title' => $wiki->firstpagetitle);
 
842
        $this->wikioutput->wiki_print_subwiki_selector($wiki, $this->subwiki, $page, 'search');
 
843
    }
 
844
 
837
845
    function print_content() {
838
846
        global $PAGE;
839
847
 
1051
1059
            }
1052
1060
            $parseroutput = wiki_parse_content($data->contentformat, $text, $options);
1053
1061
            $this->set_newcontent($text);
1054
 
            echo $OUTPUT->notification(get_string('previewwarning', 'wiki'), 'notifyproblem wiki_info');
 
1062
            echo $OUTPUT->notification(get_string('previewwarning', 'wiki'), 'notifyproblem');
1055
1063
            $content = format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true, 'filter'=>false));
1056
1064
            echo $OUTPUT->box($content, 'generalbox wiki_previewbox');
1057
1065
            $content = $this->newcontent;
1082
1090
        $vstring = new stdClass();
1083
1091
        $vstring->old = $this->compare;
1084
1092
        $vstring->new = $this->comparewith;
1085
 
        echo $OUTPUT->heading(get_string('comparewith', 'wiki', $vstring));
 
1093
        echo html_writer::tag('div', get_string('comparewith', 'wiki', $vstring), array('class' => 'wiki_headingtitle'));
1086
1094
    }
1087
1095
 
1088
1096
    /**
1189
1197
        global $OUTPUT;
1190
1198
        $html = '';
1191
1199
 
1192
 
        $html .= $OUTPUT->container_start();
1193
 
        $html .= $OUTPUT->heading_with_help(format_string($this->title), 'history', 'wiki');
 
1200
        $html .= $OUTPUT->container_start('wiki_headingtitle');
 
1201
        $html .= $OUTPUT->heading_with_help(format_string($this->title), 'history', 'wiki', '', '', 3);
1194
1202
        $html .= $OUTPUT->container_end();
1195
1203
        echo $html;
1196
1204
    }
1255
1263
        $a = new StdClass;
1256
1264
        $a->date = userdate($this->page->timecreated, get_string('strftimedaydatetime', 'langconfig'));
1257
1265
        $a->username = fullname($creator);
1258
 
        echo $OUTPUT->heading(get_string('createddate', 'wiki', $a), 4, 'wiki_headingtime');
 
1266
        echo html_writer::tag ('div', get_string('createddate', 'wiki', $a), array('class' => 'wiki_headingtime'));
1259
1267
        if ($vcount > 0) {
1260
1268
 
1261
1269
            /// If there is only one version, we don't need radios nor forms
1269
1277
                $time = userdate($row->timecreated, get_string('strftimetime', 'langconfig'));
1270
1278
                $versionid = wiki_get_version($row->id);
1271
1279
                $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id));
1272
 
                $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $PAGE->cm->course));
 
1280
                $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $this->cm->course));
1273
1281
                $contents[] = array('', html_writer::link($versionlink->out(false), $row->version), $picture . html_writer::link($userlink->out(false), fullname($username)), $time, $OUTPUT->container($date, 'wiki_histdate'));
1274
1282
 
1275
1283
                $table = new html_table();
1297
1305
                    } else {
1298
1306
                        $viewlink = $version->version;
1299
1307
                    }
1300
 
                    $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $PAGE->cm->course));
 
1308
                    $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $this->cm->course));
1301
1309
                    $contents[] = array($this->choose_from_radio(array($version->version  => null), 'compare', 'M.mod_wiki.history()', $checked - 1, true) . $this->choose_from_radio(array($version->version  => null), 'comparewith', 'M.mod_wiki.history()', $checked, true), $viewlink, $picture . html_writer::link($userlink->out(false), fullname($user)), $time, $OUTPUT->container($date, 'wiki_histdate'));
1302
1310
                }
1303
1311
 
1431
1439
            echo $this->wikioutput->menu_map($this->page->id, $this->view);
1432
1440
            $this->print_index_content();
1433
1441
            break;
1434
 
        case 5:
1435
 
            echo $this->wikioutput->menu_map($this->page->id, $this->view);
1436
 
            $this->print_page_list_content();
1437
 
            break;
1438
1442
        case 6:
1439
1443
            echo $this->wikioutput->menu_map($this->page->id, $this->view);
1440
1444
            $this->print_updated_content();
1441
1445
            break;
 
1446
        case 5:
1442
1447
        default:
1443
1448
            echo $this->wikioutput->menu_map($this->page->id, $this->view);
1444
1449
            $this->print_page_list_content();
1628
1633
        foreach ($pages as $page) {
1629
1634
            // We need to format the title here to account for any filtering
1630
1635
            $letter = format_string($page->title, true, array('context' => $this->modcontext));
1631
 
            $letter = textlib::substr($letter, 0, 1);
 
1636
            $letter = core_text::substr($letter, 0, 1);
1632
1637
            if (preg_match('/^[a-zA-Z]$/', $letter)) {
1633
 
                $letter = textlib::strtoupper($letter);
 
1638
                $letter = core_text::strtoupper($letter);
1634
1639
                $stdaux->{$letter}[] = wiki_parser_link($page);
1635
1640
            } else {
1636
1641
                $stdaux->{$strspecial}[] = wiki_parser_link($page);
1840
1845
    }
1841
1846
 
1842
1847
    function print_content() {
1843
 
        global $CFG, $PAGE;
1844
 
 
1845
 
        require_capability('mod/wiki:managewiki', $this->modcontext, NULL, true, 'nomanagewikipermission', 'wiki');
1846
 
 
1847
 
        $this->print_restoreversion();
 
1848
        global $PAGE;
 
1849
 
 
1850
        $wiki = $PAGE->activityrecord;
 
1851
        if (wiki_user_can_edit($this->subwiki, $wiki)) {
 
1852
            $this->print_restoreversion();
 
1853
        } else {
 
1854
            echo get_string('cannoteditpage', 'wiki');
 
1855
        }
 
1856
 
1848
1857
    }
1849
1858
 
1850
1859
    function set_url() {
1886
1895
        $restoreurl = new moodle_url('/mod/wiki/restoreversion.php', $optionsyes);
1887
1896
        $return = new moodle_url('/mod/wiki/viewversion.php', array('pageid'=>$this->page->id, 'versionid'=>$version->id));
1888
1897
 
1889
 
        echo $OUTPUT->heading(get_string('restoreconfirm', 'wiki', $version->version), 2);
1890
 
        print_container_start(false, 'wiki_restoreform');
 
1898
        echo $OUTPUT->container_start('wiki-form-center');
 
1899
        echo html_writer::tag('div', get_string('restoreconfirm', 'wiki', $version->version));
 
1900
        echo $OUTPUT->container_start(false, 'wiki_restoreform');
1891
1901
        echo '<form class="wiki_restore_yes" action="' . $restoreurl . '" method="post" id="restoreversion">';
1892
1902
        echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>';
1893
1903
        echo '</form>';
1894
1904
        echo '<form class="wiki_restore_no" action="' . $return . '" method="post">';
1895
1905
        echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
1896
1906
        echo '</form>';
1897
 
        print_container_end();
 
1907
        echo $OUTPUT->container_end();
 
1908
        echo $OUTPUT->container_end();
1898
1909
    }
1899
1910
}
1900
1911
/**
1954
1965
        $deleteurl = new moodle_url('/mod/wiki/instancecomments.php', $optionsyes);
1955
1966
        $return = new moodle_url('/mod/wiki/comments.php', array('pageid'=>$this->page->id));
1956
1967
 
1957
 
        echo $OUTPUT->heading($strdeletecheckfull);
1958
 
        print_container_start(false, 'wiki_deletecommentform');
 
1968
        echo $OUTPUT->container_start('wiki-form-center');
 
1969
        echo html_writer::tag('p', $strdeletecheckfull);
 
1970
        echo $OUTPUT->container_start(false, 'wiki_deletecommentform');
1959
1971
        echo '<form class="wiki_deletecomment_yes" action="' . $deleteurl . '" method="post" id="deletecomment">';
1960
1972
        echo '<div><input type="submit" name="confirmdeletecomment" value="' . get_string('yes') . '" /></div>';
1961
1973
        echo '</form>';
1962
1974
        echo '<form class="wiki_deletecomment_no" action="' . $return . '" method="post">';
1963
1975
        echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
1964
1976
        echo '</form>';
1965
 
        print_container_end();
 
1977
        echo $OUTPUT->container_end();
 
1978
        echo $OUTPUT->container_end();
1966
1979
    }
1967
1980
}
1968
1981
 
1981
1994
    function print_content() {
1982
1995
        global $PAGE;
1983
1996
 
1984
 
        $context = context_module::instance($PAGE->cm->id);
 
1997
        $context = context_module::instance($this->cm->id);
1985
1998
        require_capability('mod/wiki:editpage', $context, NULL, true, 'noeditpermission', 'wiki');
1986
1999
 
1987
2000
        $this->print_save();
2119
2132
 
2120
2133
        if ($pageversion) {
2121
2134
            $restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
2122
 
            echo $OUTPUT->heading(get_string('viewversion', 'wiki', $pageversion->version) . '<br />' . html_writer::link($restorelink->out(false), '(' . get_string('restorethis', 'wiki') . ')', array('class' => 'wiki_restore')) . '&nbsp;', 4);
 
2135
            echo html_writer::tag('div', get_string('viewversion', 'wiki', $pageversion->version) . '<br />' .
 
2136
                html_writer::link($restorelink->out(false), '(' . get_string('restorethis', 'wiki') .
 
2137
                ')', array('class' => 'wiki_restore')) . '&nbsp;', array('class' => 'wiki_headingtitle'));
2123
2138
            $userinfo = wiki_get_user_info($pageversion->userid);
2124
2139
            $heading = '<p><strong>' . get_string('modified', 'wiki') . ':</strong>&nbsp;' . userdate($pageversion->timecreated, get_string('strftimedatetime', 'langconfig'));
2125
2140
            $viewlink = new moodle_url('/user/view.php', array('id' => $userinfo->id));
2126
2141
            $heading .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('user') . ':</strong>&nbsp;' . html_writer::link($viewlink->out(false), fullname($userinfo));
2127
2142
            $heading .= '&nbsp;&nbsp;&rarr;&nbsp;' . $OUTPUT->user_picture(wiki_get_user_info($pageversion->userid), array('popup' => true)) . '</p>';
2128
 
            print_container($heading, false, 'mdl-align wiki_modifieduser wiki_headingtime');
 
2143
            echo $OUTPUT->container($heading, 'wiki_headingtime', 'mdl-align wiki_modifieduser');
2129
2144
            $options = array('swid' => $this->subwiki->id, 'pretty_print' => true, 'pageid' => $this->page->id);
2130
2145
 
2131
2146
            $pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
2132
2147
 
2133
2148
            $parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options);
2134
 
            $content = print_container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true);
 
2149
            $content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true);
2135
2150
            echo $OUTPUT->box($content, 'generalbox wiki_contentbox');
2136
2151
 
2137
2152
        } else {
2149
2164
        $PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
2150
2165
    }
2151
2166
 
 
2167
    function print_header() {
 
2168
        $this->set_url();
 
2169
    }
 
2170
 
2152
2171
    function print_content() {
2153
2172
        global $CFG, $PAGE;
2154
2173
 
2155
 
        require_capability('mod/wiki:managewiki', $this->modcontext, NULL, true, 'nomanagewikipermission', 'wiki');
2156
 
 
2157
2174
        $version = wiki_get_version($this->version->id);
2158
 
        if (wiki_restore_page($this->page, $version->content, $version->userid)) {
 
2175
        $wiki = $PAGE->activityrecord;
 
2176
        if (wiki_user_can_edit($this->subwiki, $wiki) &&
 
2177
                wiki_restore_page($this->page, $version->content, $version->userid)) {
2159
2178
            redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id, get_string('restoring', 'wiki', $version->version), 3);
2160
2179
        } else {
2161
2180
            print_error('restoreerror', 'wiki', $version->version);
2180
2199
        $this->set_url();
2181
2200
 
2182
2201
        echo $OUTPUT->header();
2183
 
        echo '<h1 id="wiki_printable_title">' . format_string($this->title) . '</h1>';
 
2202
        // Print dialog link.
 
2203
        $printtext = get_string('print', 'wiki');
 
2204
        $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'printicon');
 
2205
        $printiconlink = html_writer::link('#', $printtext, $printlinkatt);
 
2206
        echo html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon'));
 
2207
        echo html_writer::tag('h1', format_string($this->title), array('id' => 'wiki_printable_title'));
2184
2208
    }
2185
2209
 
2186
2210
    function print_content() {
2582
2606
        $a = new stdClass();
2583
2607
        $a->date = userdate($this->page->timecreated, get_string('strftimedaydatetime', 'langconfig'));
2584
2608
        $a->username = fullname($creator);
2585
 
        echo $OUTPUT->heading(get_string('createddate', 'wiki', $a), 4, 'wiki_headingtime');
 
2609
        echo $OUTPUT->heading(get_string('createddate', 'wiki', $a), 4);
2586
2610
        if ($versioncount > 0) {
2587
2611
            /// If there is only one version, we don't need radios nor forms
2588
2612
            if (count($versions) == 1) {
2593
2617
                $time = userdate($row->timecreated, get_string('strftimetime', 'langconfig'));
2594
2618
                $versionid = wiki_get_version($row->id);
2595
2619
                $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id));
2596
 
                $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $PAGE->cm->course));
 
2620
                $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $this->cm->course));
2597
2621
                $picturelink = $picture . html_writer::link($userlink->out(false), fullname($username));
2598
2622
                $historydate = $OUTPUT->container($date, 'wiki_histdate');
2599
2623
                $contents[] = array('', html_writer::link($versionlink->out(false), $row->version), $picturelink, $time, $historydate);
2630
2654
                        $viewlink = $version->version;
2631
2655
                    }
2632
2656
 
2633
 
                    $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $PAGE->cm->course));
 
2657
                    $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $this->cm->course));
2634
2658
                    $picturelink = $picture . html_writer::link($userlink->out(false), fullname($user));
2635
2659
                    $historydate = $OUTPUT->container($date, 'wiki_histdate');
2636
2660
                    $radiofromelement = $this->choose_from_radio(array($version->version  => null), 'fromversion', 'M.mod_wiki.deleteversion()', $versioncount, true);