Skip to content

Commit

Permalink
Revert "MDL-26392, nwiki and creole format wiki pages should support …
Browse files Browse the repository at this point in the history
…file attachments"

This reverts commit 0c5e812  because UI is going to be reimplemented.
  • Loading branch information
skodak committed Mar 8, 2011
1 parent 97b4297 commit 23c7994
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 82 deletions.
28 changes: 14 additions & 14 deletions mod/wiki/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ protected function definition() {
$mform->addElement('hidden', 'contentformat');
$mform->setDefault('contentformat', $format);

if ($format != 'html') {
//uploads
$mform->addElement('header', 'attachments_tags', get_string('uploadtitle', 'wiki'));
$mform->addElement('filemanager', 'attachments', '', null, page_wiki_edit::$attachmentoptions);
$fileinfo = array(
'contextid'=>$contextid,
'component'=>'mod_wiki',
'filearea'=>$filearea,
'itemid'=>$fileitemid,
);

//$mform->addElement('wikifiletable', 'deleteuploads', get_string('wikifiletable', 'wiki'), null, $fileinfo, $format);
//$mform->addElement('submit', 'editoption', get_string('upload', 'wiki'), array('id' => 'tags'));
}
// if ($format != 'html') {
// //uploads
// $mform->addElement('header', 'attachments_tags', get_string('attachments', 'wiki'));
// $mform->addElement('filemanager', 'attachments', get_string('attachments', 'wiki'), null, page_wiki_edit::$attachmentoptions);
// $fileinfo = array(
// 'contextid'=>$contextid,
// 'component'=>'mod_wiki',
// 'filearea'=>$filearea,
// 'itemid'=>$fileitemid,
// );
//
// $mform->addElement('wikifiletable', 'deleteuploads', get_string('wikifiletable', 'wiki'), null, $fileinfo, $format);
// $mform->addElement('submit', 'editoption', get_string('upload', 'wiki'), array('id' => 'tags'));
// }

if (!empty($CFG->usetags)) {
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
Expand Down
8 changes: 2 additions & 6 deletions mod/wiki/lang/en/wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@
$string['formatcreole'] = 'Creole format';
$string['formatcreole_help'] = 'Creole is a common wiki markup language with an edit toolbar for inserting appropriate markup.
To create a new page, type the new page name enclosed in double square brackets, for example [[Page 2]].
To insert image, attach the image files in file manager, then reference the file name using creole markup language.';
To create a new page, type the new page name enclosed in double square brackets, for example [[Page 2]].';
$string['formatcreole_link'] = 'mod/wiki/creole';
$string['formatnwiki'] = 'NWiki format';
$string['formatnwiki_help'] = 'Nwiki is the Mediawiki-like markup language used in the contributed Nwiki module.
To create a new page, type the new page name enclosed in double square brackets, for example [[Page 2]].
To insert image, attach the image files in file manager, then reference the file name using nwiki markup language.';
To create a new page, type the new page name enclosed in double square brackets, for example [[Page 2]].';
$string['formatnwiki_link'] = 'mod/wiki/nwiki';
$string['history'] = 'History';
$string['history_help'] = 'The history lists links to previous versions of the page.';
Expand Down
116 changes: 83 additions & 33 deletions mod/wiki/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,23 +578,7 @@ function wiki_parse_content($markup, $pagecontent, $options = array()) {
$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);

$parser_options = array('link_callback' => '/mod/wiki/locallib.php:wiki_parser_link',
'link_callback_args' => array('swid' => $options['swid']),
'table_callback' => '/mod/wiki/locallib.php:wiki_parser_table',
'real_path_callback' => '/mod/wiki/locallib.php:wiki_parser_real_path',
'real_path_callback_args' => array(
'context' => $context,
'component' => 'mod_wiki',
'filearea' => 'attachments',
'subwikiid'=> $subwiki->id,
'pageid' => $options['pageid']
),
'preview' => !empty($options['preview']) ? true : false,
'itemid' => !empty($options['itemid']) ? $options['itemid'] : null,
'pageid' => $options['pageid'],
'pretty_print' => (isset($options['pretty_print']) && $options['pretty_print']),
'printable' => (isset($options['printable']) && $options['printable'])
);
$parser_options = array('link_callback' => '/mod/wiki/locallib.php:wiki_parser_link', 'link_callback_args' => array('swid' => $options['swid']), 'table_callback' => '/mod/wiki/locallib.php:wiki_parser_table', 'real_path_callback' => '/mod/wiki/locallib.php:wiki_parser_real_path', 'real_path_callback_args' => array('context' => $context, 'component' => 'mod_wiki', 'filearea' => 'attachments', 'pageid' => $options['pageid']), 'pageid' => $options['pageid'], 'pretty_print' => (isset($options['pretty_print']) && $options['pretty_print']), 'printable' => (isset($options['printable']) && $options['printable']));

return wiki_parser_proxy::parse($pagecontent, $markup, $parser_options);
}
Expand Down Expand Up @@ -677,34 +661,21 @@ function wiki_parser_table($table) {
/**
* Returns an absolute path link, unless there is no such link.
*
* @param string url Link's URL or filename
* @param string url Link's URL
* @param stdClass context filearea params
* @param string filearea
* @param int fileareaid
*
* @return File full path
*/

function wiki_parser_real_path($url, $context, $component, $filearea, $swid) {
function wiki_parser_real_path($url, $context, $filearea, $fileareaid) {
global $CFG;

if (preg_match("/^(?:http|ftp)s?\:\/\//", $url)) {
return $url;
} else {
if ($context->contextlevel == CONTEXT_USER) {
// when preview wiki page, files are in draft area
$file = 'draftfile.php';
} else if ($context->contextlevel == CONTEXT_MODULE) {
$file = 'pluginfile.php';
} else {
$file = 'brokenfile.php#';
}
if (!$CFG->slasharguments) {
$file = $file . '?file=';
}
$baseurl = "$CFG->wwwroot/$file/{$context->id}/$component/$filearea/$swid/";
// it is a file in current file area
return $baseurl . $url;
return "{$CFG->wwwroot}/pluginfile.php/{$context->id}/$filearea/$fileareaid/$url";
}
}

Expand Down Expand Up @@ -1024,6 +995,85 @@ function wiki_delete_old_locks() {
$DB->delete_records_select('wiki_locks', "lockedat < ?", array(time() - 3600));
}

/**
* File processing
*/

/**
* Uploads files to permanent disk space.
*
* @param int draftitemid Draft space ID
* @param int contextid
*
* @return array of files that have not been inserted.
*/

function wiki_process_attachments($draftitemid, $deleteuploads, $contextid, $filearea, $itemid, $options = null) {
global $CFG, $USER;

if (empty($options)) {
$options = page_wiki_edit::$attachmentoptions;
}

$errors = array();

$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();

$oldfiles = $fs->get_area_files($contextid, 'mod_wiki', 'attachments', $itemid, 'id');

foreach ($oldfiles as $file) {
if (in_array($file->get_pathnamehash(), $deleteuploads)) {
$file->delete();
}
}

$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id');
$oldfiles = $fs->get_area_files($contextid, 'mod_wiki', 'attachments', $itemid, 'id');

$file_record = array('contextid' => $contextid, 'component' => 'mod_wiki', 'filearea' => 'attachments', 'itemid' => $itemid);
//more or less a merge...
$newhashes = array();
foreach ($draftfiles as $file) {
$newhash = sha1("/$contextid/mod_wiki/attachments/$itemid" . $file->get_filepath() . $file->get_filename());
$newhashes[$newhash] = $file;
}

$filecount = 0;
foreach ($oldfiles as $file) {
$oldhash = $file->get_pathnamehash();
if (!$file->is_directory() && isset($newhashes[$oldhash])) {
//repeated file: ERROR!!!
unset($newhashes[$oldhash]);
$errors[] = $file;
}

if (!$file->is_directory()) {
$filecount++;
}
}

foreach ($newhashes as $file) {
if ($file->get_filepath() !== '/' or $file->is_directory()) {
continue;
}

if ($options['maxfiles'] and $options['maxfiles'] <= $filecount) {
break;
}

if (!$file->is_directory()) {
$filecount++;
$fs->create_file_from_storedfile($file_record, $file);
}
}

//delete all draft files
$fs->delete_area_files($usercontext->id, 'user', 'draft', $draftitemid);

return $errors;
}

function wiki_get_comment($commentid){
global $DB;
return $DB->get_record('comments', array('id' => $commentid));
Expand Down
14 changes: 7 additions & 7 deletions mod/wiki/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class page_wiki_edit extends page_wiki {
function __construct($wiki, $subwiki, $cm) {
global $CFG, $PAGE;
parent::__construct($wiki, $subwiki, $cm);
self::$attachmentoptions = array('subdirs' => false, 'maxfiles' => - 1, 'maxbytes' => $CFG->maxbytes, 'accepted_types' => 'image');
self::$attachmentoptions = array('subdirs' => false, 'maxfiles' => - 1, 'maxbytes' => $CFG->maxbytes, 'accepted_types' => '*');
$PAGE->requires->js_init_call('M.mod_wiki.renew_lock', null, true);
$PAGE->requires->yui2_lib('connection');
}
Expand Down Expand Up @@ -540,9 +540,9 @@ protected function print_edit($content = null) {
$data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'mod_wiki', 'attachments', $this->subwiki->id);
break;
default:
$draftitemid = file_get_submitted_draft_itemid('attachments');
file_prepare_draft_area($draftitemid, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
$data->attachments = $draftitemid;
//$draftitemid = file_get_submitted_draft_itemid('attachments');
//file_prepare_draft_area($draftitemid, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
//$data->attachments = $draftitemid;
}

if ($version->contentformat != 'html') {
Expand Down Expand Up @@ -588,6 +588,7 @@ protected function process_uploads($context) {
if ($this->upload) {
file_save_draft_area_files($this->attachments, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
return null;
//return wiki_process_attachments($this->attachments, $this->deleteuploads, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
}
}
}
Expand Down Expand Up @@ -1033,21 +1034,20 @@ protected function print_preview() {
$form = new mod_wiki_edit_form($url, $params);


$options = array('swid' => $this->page->subwikiid, 'pageid' => $this->page->id, 'pretty_print' => true, 'preview'=>true);
$options = array('swid' => $this->page->subwikiid, 'pageid' => $this->page->id, 'pretty_print' => true);

if ($data = $form->get_data()) {
if (isset($data->newcontent)) {
// wiki fromat
$text = $data->newcontent;
$options['itemid'] = $data->attachments;
} else {
// html format
$text = $data->newcontent_editor['text'];
}
$parseroutput = wiki_parse_content($data->contentformat, $text, $options);
$this->set_newcontent($text);
echo $OUTPUT->notification(get_string('previewwarning', 'wiki'), 'notifyproblem wiki_info');
$content = format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true, 'filter'=>false));
$content = format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true));
echo $OUTPUT->box($content, 'generalbox wiki_previewbox');
$content = $this->newcontent;
}
Expand Down
21 changes: 1 addition & 20 deletions mod/wiki/parser/markups/wikimarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ abstract class wiki_markup_parser extends generic_parser {

//header & ToC
protected $toc = array();
/** @var boolean parse content for preview*/
protected $preview = false;
/** @var int if preview, itemid will be required to generate file url */
protected $itemid = null;

/**
* function wiki_parser_link_callback($link = "")
Expand Down Expand Up @@ -147,10 +143,6 @@ protected function set_options($options) {
$this->printable = true;
}
break;
case 'preview':
$this->preview = $options['preview'];
$this->itemid = $options['itemid'];
break;
}
}
}
Expand Down Expand Up @@ -332,18 +324,7 @@ protected function format_image($src, $alt, $caption = "", $align = 'left') {
}

protected function real_path($url) {
global $USER;
if ($this->preview) {
// when preview wiki page, images are in draft area
$callbackargs = array();
$callbackargs[] = $url;
$callbackargs[] = get_context_instance(CONTEXT_USER, $USER->id);
$callbackargs[] = 'user';
$callbackargs[] = 'draft';
$callbackargs[] = $this->itemid;
} else {
$callbackargs = array_merge(array($url), $this->realpathcallbackargs);
}
$callbackargs = array_merge(array($url), $this->realpathcallbackargs);
return call_user_func_array($this->realpathcallback, $callbackargs);
}

Expand Down
4 changes: 2 additions & 2 deletions mod/wiki/parser/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public function parse(&$string, $options = array()) {
/**
* Initialize options
*/
protected function set_options($options) {
}

protected function set_options($options) {}

/**
* Block processing function & callbacks
Expand Down

0 comments on commit 23c7994

Please sign in to comment.