~ubuntu-branches/ubuntu/hoary/moodle/hoary

« back to all changes in this revision

Viewing changes to mod/wiki/view.php

  • Committer: Bazaar Package Importer
  • Author(s): Isaac Clerencia
  • Date: 2004-12-29 00:49:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229004952-gliyqzpj2w3e7clx
Tags: 1.4.3-1
* Urgency high as upstream release fixes several security bugs
* New upstream release
* Write database creation errors and warn the user about it, 
closes: #285842, #285842

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?PHP  // $Id: view.php,v 1.15.2.9 2004/09/09 15:57:17 moodler Exp $
 
2
/// Extended by Michael Schneider
 
3
/// This page prints a particular instance of wiki
 
4
 
 
5
    global $CFG;
 
6
 
 
7
    require_once("../../config.php");
 
8
    require_once("lib.php");
 
9
#    require_once("$CFG->dirroot/course/lib.php"); // For side-blocks
 
10
 
 
11
    optional_variable($ewiki_action,"");     // Action on Wiki-Page
 
12
    optional_variable($id);     // Course Module ID, or
 
13
    optional_variable($wid);    // Wiki ID
 
14
    optional_variable($wikipage, false);     // Wiki Page Name
 
15
    optional_variable($q,"");    // Search Context
 
16
    optional_variable($userid);     // User wiki.
 
17
    optional_variable($groupid);    // Group wiki.
 
18
    optional_variable($canceledit,"");    // Editing has been cancelled
 
19
    if($canceledit) {
 
20
      @$wikipage=$ewiki_id;
 
21
    }
 
22
 
 
23
    if ($id) {
 
24
        if (! $cm = get_record("course_modules", "id", $id)) {
 
25
            error("Course Module ID was incorrect");
 
26
        }
 
27
 
 
28
        if (! $course = get_record("course", "id", $cm->course)) {
 
29
            error("Course is misconfigured");
 
30
        }
 
31
 
 
32
        if (! $wiki = get_record("wiki", "id", $cm->instance)) {
 
33
            error("Course module is incorrect");
 
34
        }
 
35
 
 
36
    } else {
 
37
        if (! $wiki = get_record("wiki", "id", $wid)) {
 
38
            error("Course module is incorrect");
 
39
        }
 
40
        if (! $course = get_record("course", "id", $wiki->course)) {
 
41
            error("Course is misconfigured");
 
42
        }
 
43
        if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id, $course->id)) {
 
44
            error("Course Module ID was incorrect");
 
45
        }
 
46
        $id = $cm->id;
 
47
        $_REQUEST["id"] = $id;
 
48
    }
 
49
 
 
50
    if ($course->category or !empty($CFG->forcelogin)) {
 
51
        require_login($course->id);
 
52
    }
 
53
 
 
54
    /// Add the course module 'groupmode' to the wiki object, for easy access.
 
55
    $wiki->groupmode = $cm->groupmode;
 
56
 
 
57
    /// Default format:
 
58
    $moodle_format=FORMAT_MOODLE;
 
59
 
 
60
    ### SAVE ID from Moodle
 
61
    $moodleID=@$_REQUEST["id"];
 
62
 
 
63
/// Globally disable CamelCase, if the option is selected for this wiki.
 
64
    $moodle_disable_camel_case = ($wiki->disablecamelcase == 1);
 
65
 
 
66
    if (($wiki_entry = wiki_get_default_entry($wiki, $course, $userid, $groupid))) {
 
67
 
 
68
///     ################# EWIKI Part ###########################
 
69
///     The wiki_entry->pagename is set to the specified value of the wiki,
 
70
///     or the default value in the 'lang' file if the specified value was empty.
 
71
        define("EWIKI_PAGE_INDEX",$wiki_entry->pagename);
 
72
 
 
73
        /// If the page has a ' in it, it may have slashes added to it. Remove them if it does.
 
74
        $wikipage = ($wikipage === false) ?  stripslashes(EWIKI_PAGE_INDEX) : stripslashes($wikipage);
 
75
 
 
76
///     ### Prevent ewiki getting id as PageID...
 
77
        unset($_REQUEST["id"]);
 
78
        unset($_GET["id"]);
 
79
        unset($_POST["id"]);
 
80
        unset($_POST["id"]);
 
81
        unset($_SERVER["QUERY_STRING"]);
 
82
        unset($HTTP_GET_VARS["id"]);
 
83
        unset($HTTP_POST_VARS["id"]);
 
84
        global $ewiki_title;
 
85
 
 
86
///     #-- predefine some of the configuration constants
 
87
        
 
88
        
 
89
        /// EWIKI_NAME is defined in ewikimoodlelibs, so that also admin.php can use this
 
90
        #define("EWIKI_NAME", $wiki_entry->pagename);
 
91
 
 
92
        /// Search Hilighting
 
93
        if($ewiki_title=="SearchPages") {
 
94
            $qArgument="&q=".urlencode($q);
 
95
        }
 
96
 
 
97
        /// Build the ewsiki script constant
 
98
        /// ewbase will also be needed by EWIKI_SCRIPT_BINARY
 
99
        $ewbase = $ME.'?id='.$moodleID;
 
100
        if (isset($userid)) $ewbase .= '&userid='.$userid;
 
101
        if (isset($groupid)) $ewbase .= '&groupid='.$groupid;
 
102
        $ewscript = $ewbase.'&wikipage=';
 
103
        define("EWIKI_SCRIPT", $ewscript);
 
104
        define("EWIKI_SCRIPT_URL", $ewscript);
 
105
 
 
106
        /// # Settings for this specific Wiki
 
107
        define("EWIKI_PRINT_TITLE", $wiki->ewikiprinttitle);
 
108
 
 
109
        define("EWIKI_INIT_PAGES", wiki_content_dir($wiki));
 
110
 
 
111
///     # fix broken PHP setup
 
112
        if (!function_exists("get_magic_quotes_gpc") || get_magic_quotes_gpc()) {
 
113
            include($CFG->dirroot."/mod/wiki/ewiki/fragments/strip_wonderful_slashes.php");
 
114
        }
 
115
        if (ini_get("register_globals")) {
 
116
            #    include($CFG->dirroot."/mod/wiki/ewiki/fragments/strike_register_globals.php");
 
117
        }
 
118
 
 
119
        # Database Handler
 
120
        include_once($CFG->dirroot."/mod/wiki/ewikimoodlelib.php");
 
121
        # Plugins
 
122
        //include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/email_protect.php");
 
123
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/patchsaving.php");
 
124
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/notify.php");
 
125
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/feature/imgresize_gd.php");
 
126
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_highlight.php");
 
127
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/f_fixhtml.php");
 
128
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/sitemap.php");
 
129
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_wikidump.php");
 
130
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/aview/backlinks.php");
 
131
        #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/css.php");
 
132
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/footnotes.php");
 
133
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/diff.php");
 
134
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/page/pageindex.php");
 
135
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/page/orphanedpages.php");
 
136
        include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/wantedpages.php");
 
137
 
 
138
        # Binary Handling
 
139
        if($wiki->ewikiacceptbinary) {
 
140
            define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
 
141
            define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
 
142
            define("EWIKI_ALLOW_BINARY",1);
 
143
            define("EWIKI_IMAGE_CACHING",1);
 
144
            #define("EWIKI_AUTOVIEW",1);
 
145
            include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/lib/mime_magic.php");
 
146
            include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/aview/downloads.php");
 
147
            include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/downloads.php");
 
148
            #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/db/binary_store.php");
 
149
            include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
 
150
        } else {
 
151
            define("EWIKI_SCRIPT_BINARY", 0);
 
152
            define("EWIKI_ALLOW_BINARY",0);
 
153
        }
 
154
 
 
155
        # The mighty Wiki itself
 
156
        include_once($CFG->dirroot."/mod/wiki/ewiki/ewiki.php");
 
157
 
 
158
        # Language-stuff: eWiki gets language from Browser. Lets correct it. Empty arrayelements do no harm
 
159
        $ewiki_t["languages"]=array(current_language(), $course->lang, $CFG->lang,"en","c");
 
160
 
 
161
        # Check Access Rights
 
162
        $canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
 
163
        if (!$canedit) {
 
164
            # Protected Mode
 
165
            unset($ewiki_plugins["action"]["edit"]);
 
166
            unset($ewiki_plugins["action"]["info"]);
 
167
        }
 
168
 
 
169
        # HTML Handling
 
170
        $ewiki_use_editor=0;
 
171
        if($wiki->htmlmode == 0) {
 
172
            # No HTML
 
173
            $ewiki_config["htmlentities"]=array(); // HTML is managed by moodle
 
174
            $moodle_format=FORMAT_TEXT;
 
175
        }
 
176
        if($wiki->htmlmode == 1) {
 
177
            # Safe HTML
 
178
            include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_rescue_html.php");
 
179
            $moodle_format=FORMAT_HTML;
 
180
        }
 
181
        if($wiki->htmlmode == 2) {
 
182
            # HTML Only 
 
183
            $moodle_format=FORMAT_HTML;
 
184
            $ewiki_use_editor=1;
 
185
            $ewiki_config["htmlentities"]=array(); // HTML is allowed
 
186
            $ewiki_config["wiki_link_regex"] = "\007 [!~]?(
 
187
                        \#?\[[^<>\[\]\n]+\] |
 
188
                        \^[-".EWIKI_CHARS_U.EWIKI_CHARS_L."]{3,} |
 
189
                        \b([\w]{3,}:)*([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}\#?[\w\d]* |
 
190
                        \w[-_.+\w]+@(\w[-_\w]+[.])+\w{2,}   ) \007x";
 
191
        }
 
192
 
 
193
        global $ewiki_author, $USER;
 
194
        $ewiki_author=fullname($USER);
 
195
        $content=ewiki_page($wikipage);
 
196
        $content2='';
 
197
 
 
198
        ### RESTORE ID from Moodle
 
199
        $_REQUEST["id"]=$moodleID;
 
200
        $id=$moodleID;
 
201
///     ################# EWIKI Part ###########################
 
202
    }
 
203
    else {
 
204
        $content = '';
 
205
        $content2 = '<div align="center">'.get_string('nowikicreated', 'wiki').'</div>';
 
206
    }
 
207
 
 
208
 
 
209
    # Group wiki, ...: No wikipage and no ewiki_title
 
210
    if(!isset($ewiki_title)) {
 
211
          $ewiki_title="";
 
212
    }
 
213
        
 
214
/// Moodle Log
 
215
    add_to_log($course->id, "wiki", $ewiki_action, "view.php?id=$cm->id&groupid=$groupid&userid=$userid&wikipage=$wikipage", $wiki->name." ".$ewiki_title);
 
216
 
 
217
 
 
218
/// Print the page header
 
219
 
 
220
    $strwikis = get_string("modulenameplural", "wiki");
 
221
    $strwiki  = get_string("modulename", "wiki");
 
222
 
 
223
    print_header_simple(($ewiki_title?$ewiki_title:$wiki->name), "",
 
224
                "<A HREF=\"index.php?id=$course->id\">$strwikis</A> -> <A HREF=\"view.php?id=$moodleID\">$wiki->name</a>".($ewiki_title?" -> $ewiki_title":""),
 
225
                "", "", true, update_module_button($cm->id, $course->id, $strwiki),
 
226
                navmenu($course, $cm));
 
227
 
 
228
 
 
229
    /// Print Page
 
230
 
 
231
    /// The top row contains links to other wikis, if applicable.
 
232
    if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) {
 
233
        $selected="";
 
234
        if (isset($wiki_list['selected'])) {
 
235
            $selected = $wiki_list['selected'];
 
236
            unset($wiki_list['selected']);
 
237
        }
 
238
        echo '<tr><td colspan="2">';
 
239
 
 
240
        echo '<form name="otherwikis" action="'.$CFG->wwwroot.'/mod/wiki/view.php">';
 
241
        echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
 
242
        echo '<td class="sideblockheading" bgcolor="'.$THEME->cellheading.'">&nbsp;'
 
243
            .$WIKI_TYPES[$wiki->wtype].' '
 
244
            .get_string('modulename', 'wiki')." ".get_string('for',"wiki")." "
 
245
            .wiki_get_owner($wiki_entry).':</td>';
 
246
 
 
247
        echo '<td class="sideblockheading" bgcolor="'.$THEME->cellheading.'" align="right">'
 
248
            .get_string('otherwikis', 'wiki').':&nbsp;&nbsp;';
 
249
        $script = 'self.location=document.otherwikis.wikiselect.options[document.otherwikis.wikiselect.selectedIndex].value';
 
250
        choose_from_menu($wiki_list, "wikiselect", $selected, "choose", $script);
 
251
        echo '</td>';        
 
252
        echo '</tr></table>';
 
253
        echo '</form>';
 
254
 
 
255
        echo '</td>';
 
256
        echo '</tr>';
 
257
    }
 
258
 
 
259
    if ($wiki_entry) {
 
260
        $specialpages=array("WikiExport", "SiteMap", "SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
 
261
    /// Page Actions
 
262
        echo '<table border="0" width="100%">';
 
263
        echo '<tr>';
 
264
        
 
265
        /// Searchform
 
266
        echo '<td align="center">';    
 
267
        wiki_print_search_form($cm->id, $q, $userid, $groupid, false);
 
268
        echo '</td>';
 
269
    
 
270
        /// Internal Wikilinks
 
271
        echo '<td align="center">';
 
272
        wiki_print_wikilinks_block($cm->id,  $wiki->ewikiacceptbinary);
 
273
        echo '</td>';
 
274
    
 
275
        /// Administrative Links
 
276
        if($canedit) {
 
277
          echo '<td align="center">';          
 
278
          wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $ewiki_title, $wiki->htmlmode!=2, $course);
 
279
          echo '</td>';
 
280
        }
 
281
        
 
282
        /// Formatting Rules
 
283
        echo '<td align="right">';          
 
284
        helpbutton('howtowiki', get_string('howtowiki', 'wiki'), 'wiki');
 
285
        echo '</td>';
 
286
        
 
287
        echo '</tr></table>';
 
288
    }
 
289
 
 
290
    if($ewiki_title==$wiki_entry->pagename && !empty($wiki->summary)) {
 
291
      if (trim(strip_tags($wiki->summary))) {
 
292
          print "<br>";
 
293
          print_simple_box(format_text($wiki->summary, FORMAT_MOODLE), "center");
 
294
          print "<br>";
 
295
      }
 
296
    }
 
297
    
 
298
    // The wiki Contents
 
299
 
 
300
    if (!empty($canedit)) {   /// Print tabs with commands for this page
 
301
        $tabstyle = ' style="padding-left: 5px;padding-right: 5px" ';
 
302
 
 
303
        echo '<table border="0">';
 
304
        echo "<tr>";
 
305
        $tabs = array('view', 'edit','links','info');
 
306
        if ($wiki->ewikiacceptbinary) {
 
307
            $tabs[] = 'attachments';
 
308
        }
 
309
        foreach ($tabs as $tab) {
 
310
            $tabname = get_string("tab$tab", 'wiki');
 
311
            if ($ewiki_action != "$tab" && !in_array($wikipage, $specialpages)) {          
 
312
                echo '<td class="generaltab" '.$tabstyle.' bgcolor="'.$THEME->cellheading.'">';
 
313
                echo '<a href="'.$ewbase.'&wikipage='.$tab.'/'.$ewiki_id.'">'.$tabname.'</a>';
 
314
                echo '</td>';
 
315
            } else {
 
316
                echo '<td class="generaltabselected" '.$tabstyle.' bgcolor="'.$THEME->cellcontent.'">'.$tabname.'</td>';
 
317
            }
 
318
        }
 
319
        echo "</tr>";
 
320
        echo "</table>";
 
321
    }
 
322
    print_simple_box_start( "right", "100%", "$THEME->cellcontent", "20");
 
323
    /// Don't filter any pages containing wiki actions (except view). A wiki page containing
 
324
    /// actions will have the form [action]/[pagename]. If the '/' isn't there, or the action
 
325
    /// is 'view', filter it. Also, if the page doesn't exist, it will default to 'edit'.
 
326
    $actions = explode('/', $wikipage);
 
327
//    if ($ewiki_action == "edit" || ($actions !== false && count($actions) > 1 && $actions[0] != 'view') ||
 
328
//        (count($actions) == 1 && !record_exists('wiki_pages', 'pagename', $wikipage, 'wiki', $wiki_entry->id))) {
 
329
//        print $content;
 
330
//    }
 
331
//    else {
 
332
//        print(format_text($content, $moodle_format));    /// DISABLED UNTIL IT CAN BE FIXED
 
333
//    }
 
334
    print $content;
 
335
    print $content2;
 
336
    print_simple_box_end();
 
337
    echo "<br clear=all />";
 
338
 
 
339
/// Finish the page
 
340
    print_footer($course);
 
341
?>