MDL-50851 mod_wiki: use new tag API

This commit is contained in:
Marina Glancy
2016-01-10 15:25:46 +08:00
parent c026a28d59
commit b0b2c93da9
10 changed files with 72 additions and 60 deletions
@@ -104,8 +104,10 @@ class backup_wiki_activity_structure_step extends backup_activity_structure_step
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.itemid = ?', array(
backup_helper::is_sqlparam('wiki_pages'),
backup_helper::is_sqlparam('mod_wiki'),
backup::VAR_PARENTID));
}
@@ -159,7 +159,7 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st
$data = (object)$data;
$oldid = $data->id;
if (empty($CFG->usetags)) { // tags disabled in server, nothing to process
if (!core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { // Tags disabled in server, nothing to process.
return;
}
@@ -167,8 +167,8 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st
$itemid = $this->get_new_parentid('wiki_page');
$wikiid = $this->get_new_parentid('wiki');
$cm = get_coursemodule_from_instance('wiki', $wikiid);
tag_set_add('wiki_pages', $itemid, $tag, 'mod_wiki', context_module::instance($cm->id)->id);
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $itemid, $context, $tag);
}
protected function after_execute() {
+33
View File
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tag areas in component mod_wiki
*
* @package mod_wiki
* @copyright 2015 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tagareas = array(
array(
'itemtype' => 'wiki_pages',
'component' => 'mod_wiki',
),
);
+3 -3
View File
@@ -100,11 +100,11 @@ class mod_wiki_edit_form extends moodleform {
$mform->addElement('hidden', 'contentformat', $format);
$mform->setType('contentformat', PARAM_ALPHANUMEXT);
if (!empty($CFG->usetags)) {
if (core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) {
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
$mform->addElement('tags', 'tags', get_string('tags'));
$mform->setType('tags', PARAM_TEXT);
}
$mform->addElement('tags', 'tags', get_string('tags'),
array('itemtype' => 'wiki_pages', 'component' => 'mod_wiki'));
$buttongroup = array();
$buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save'));
+1
View File
@@ -219,6 +219,7 @@ $string['searchterms'] = 'Search terms';
$string['searchwikis'] = 'Search wikis';
$string['special'] = 'Special';
$string['tableofcontents'] = 'Table of contents';
$string['tagarea_wiki_pages'] = 'Wiki pages';
$string['tagsdeleted'] = 'Wiki tags have been deleted';
$string['tagtitle'] = 'See the "{$a}" tag';
$string['teacherrating'] = 'Teacher rating';
+23 -16
View File
@@ -141,10 +141,15 @@ function wiki_delete_instance($id) {
return $result;
}
/**
* Implements callback to reset course
*
* @param stdClass $data
* @return boolean|array
*/
function wiki_reset_userdata($data) {
global $CFG,$DB;
require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
require_once($CFG->dirroot . '/tag/lib.php');
require_once($CFG->dirroot . "/mod/wiki/locallib.php");
$componentstr = get_string('modulenameplural', 'wiki');
@@ -154,10 +159,12 @@ function wiki_reset_userdata($data) {
if (!$wikis = $DB->get_records('wiki', array('course' => $data->courseid))) {
return false;
}
$errors = false;
foreach ($wikis as $wiki) {
if (empty($data->reset_wiki_comments) && empty($data->reset_wiki_tags) && empty($data->reset_wiki_pages)) {
return $status;
}
if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) {
foreach ($wikis as $wiki) {
if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id, $data->courseid)) {
continue;
}
$context = context_module::instance($cm->id);
@@ -175,14 +182,7 @@ function wiki_reset_userdata($data) {
if (empty($data->reset_wiki_pages)) {
// Go through each page and delete the tags.
foreach ($pages as $page) {
$tags = tag_get_tags_array('wiki_pages', $page->id);
foreach ($tags as $tagid => $tagname) {
// Delete the related tag_instances related to the wiki page.
$errors = tag_delete_instance('wiki_pages', $page->id, $tagid);
$status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'),
'error' => $errors);
}
core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $page->id);
}
} else {
// Otherwise we are removing pages and tags.
@@ -196,17 +196,24 @@ function wiki_reset_userdata($data) {
// Delete any attached files.
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_wiki', 'attachments');
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'),
'error' => $errors);
}
}
if (!empty($data->reset_wiki_pages)) {
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'),
'error' => false);
}
if (!empty($data->reset_wiki_tags)) {
$status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => false);
}
}
// Remove all comments.
if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) {
$DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id));
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
if (!empty($data->reset_wiki_comments)) {
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
}
}
}
return $status;
+3 -18
View File
@@ -1163,8 +1163,6 @@ function wiki_delete_pages($context, $pageids = null, $subwikiid = null) {
return;
}
require_once($CFG->dirroot . '/tag/lib.php');
/// Delete page and all it's relevent data
foreach ($pageids as $pageid) {
if (is_object($pageid)) {
@@ -1178,10 +1176,7 @@ function wiki_delete_pages($context, $pageids = null, $subwikiid = null) {
}
//Delete page tags
$tags = tag_get_tags_array('wiki_pages', $pageid);
foreach ($tags as $tagid => $tagvalue) {
tag_delete_instance('wiki_pages', $pageid, $tagid);
}
core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $pageid);
//Delete Synonym
wiki_delete_synonym($subwikiid, $pageid);
@@ -1386,18 +1381,8 @@ function wiki_print_page_content($page, $context, $subwikiid) {
$html = format_text($html, FORMAT_MOODLE, array('overflowdiv'=>true, 'allowid'=>true));
echo $OUTPUT->box($html);
if (!empty($CFG->usetags)) {
$tags = tag_get_tags_array('wiki_pages', $page->id);
echo $OUTPUT->container_start('wiki-tags');
echo '<span class="wiki-tags-title">'.get_string('tags').': </span>';
$links = array();
foreach ($tags as $tagid=>$tag) {
$url = new moodle_url('/tag/index.php', array('tag'=>$tag));
$links[] = html_writer::link($url, $tag, array('title'=>get_string('tagtitle', 'wiki', $tag)));
}
echo join($links, ", ");
echo $OUTPUT->container_end();
}
echo $OUTPUT->tag_list(core_tag_tag::get_item_tags('mod_wiki', 'wiki_pages', $page->id),
null, 'wiki-tags');
wiki_increment_pageviews($page);
}
+3 -15
View File
@@ -34,7 +34,6 @@
*/
require_once($CFG->dirroot . '/mod/wiki/edit_form.php');
require_once($CFG->dirroot . '/tag/lib.php');
/**
* Class page_wiki contains the common code between all pages
@@ -570,18 +569,9 @@ class page_wiki_edit extends page_wiki {
$params['filearea'] = 'attachments';
}
$data->tags = core_tag_tag::get_item_tags_array('mod_wiki', 'wiki_pages', $this->page->id);
$form = new mod_wiki_edit_form($url, $params);
if ($formdata = $form->get_data()) {
if (!empty($CFG->usetags)) {
$data->tags = $formdata->tags;
}
} else {
if (!empty($CFG->usetags)) {
$data->tags = tag_get_tags_array('wiki_pages', $this->page->id);
}
}
$form->set_data($data);
$form->display();
}
@@ -2060,9 +2050,7 @@ class page_wiki_save extends page_wiki_edit {
}
if ($save && $data) {
if (!empty($CFG->usetags)) {
tag_set('wiki_pages', $this->page->id, $data->tags, 'mod_wiki', $this->modcontext->id);
}
core_tag_tag::set_item_tags('mod_wiki', 'wiki_pages', $this->page->id, $this->modcontext, $data->tags);
$message = '<p>' . get_string('saving', 'wiki') . '</p>';
-4
View File
@@ -128,10 +128,6 @@
text-align: right;
}
.wiki-tags span {
font-weight: bold;
}
.wiki_modifieduser p {
line-height: 35px;
}
+1 -1
View File
@@ -33,7 +33,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015111602; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2016011100; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2015111000; // Requires this Moodle version
$plugin->component = 'mod_wiki'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;