<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AText_formats_2.0</id>
	<title>Development:Text formats 2.0 - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AText_formats_2.0"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Text_formats_2.0&amp;action=history"/>
	<updated>2026-05-06T20:57:08Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Text_formats_2.0&amp;diff=11938&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Text_formats_2.0&amp;diff=11938&amp;oldid=prev"/>
		<updated>2024-10-21T08:53:15Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:53, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Text_formats_2.0&amp;diff=11937&amp;oldid=prev</id>
		<title>1&gt;TimHunt в 12:56, 11 ноября 2010</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Text_formats_2.0&amp;diff=11937&amp;oldid=prev"/>
		<updated>2010-11-11T12:56:16Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;There have only been slight changes in how user-entered content is handled in 2.0, because there was not time to do a better job.&lt;br /&gt;
&lt;br /&gt;
We are talking about the kind of rich HTML content that was input using the HTML editor, or other means.&lt;br /&gt;
&lt;br /&gt;
==Database structure==&lt;br /&gt;
&lt;br /&gt;
Any column that stores rich content input by the user should have a corresponding format column. For example, the &amp;lt;tt&amp;gt;forum.intro&amp;lt;/tt&amp;gt; column has an associated &amp;lt;tt&amp;gt;forum.introformat&amp;lt;/tt&amp;gt; column that days which format the data in the &amp;lt;tt&amp;gt;intro&amp;lt;/tt&amp;gt; column is. The &amp;lt;tt&amp;gt;introformat&amp;lt;/tt&amp;gt; column is holds an integer that is one of the &amp;lt;tt&amp;gt;FORMAT_MOODLE&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;FORMAT_HTML&amp;lt;/tt&amp;gt; ... constants.&lt;br /&gt;
&lt;br /&gt;
As another example, in the &amp;lt;tt&amp;gt;question&amp;lt;/tt&amp;gt; table, there are two columns that hold rich-text, &amp;lt;tt&amp;gt;question.questiontext&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;question.generalfeedback&amp;lt;/tt&amp;gt; and they both need a separate format column, so there are columns &amp;lt;tt&amp;gt;question.questiontextformat&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;question.generalfeedbackformat&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
(Note that Moodle 1.x code should have done this, but it was not done consistently. In Moodle 2.0, all the missing ...format columns were added.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Outputting==&lt;br /&gt;
&lt;br /&gt;
Like before, when you want to output content like this, you have to use the &amp;lt;tt&amp;gt;format_text&amp;lt;/tt&amp;gt; function. You need to pass the appropriate content type to that function, and now, in Moodle 2.0, that format is always available because it is stored in the database with the content.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Editing==&lt;br /&gt;
&lt;br /&gt;
Rich content like this is edited using the &amp;lt;tt&amp;gt;editor&amp;lt;/tt&amp;gt; formslib element type. How to use this element type is explained in the [[Development:Using the File API in Moodle forms|File API documentation]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Upgrading tables from Moodle 1.9==&lt;br /&gt;
&lt;br /&gt;
When upgrading to Moodle 2.0, you need to inspect all your database table, and find any missing format columns, and add them.&lt;br /&gt;
&lt;br /&gt;
Then you need to go through all the existing data and fill in the correct format type, and possibly modify the content. In more detail, what you need to do is:&lt;br /&gt;
# Inspect the old code, and work out how it is treating this content. Presumably it is being output using &amp;lt;tt&amp;gt;format_text&amp;lt;/tt&amp;gt;. What format type is passed to those calls (hopefully it is the same everywhere). You need to set the format column to that value.&lt;br /&gt;
# If, in future, people will be editing this content using the &amp;lt;tt&amp;gt;editor&amp;lt;/tt&amp;gt; element, then convert any old &amp;lt;tt&amp;gt;FORMAT_MOODLE&amp;lt;/tt&amp;gt; content to &amp;lt;tt&amp;gt;FORMAT_HTML&amp;lt;/tt&amp;gt;, because that will work better in future. See [[#Example_1]] below.&lt;br /&gt;
# Change all the &amp;lt;tt&amp;gt;format_text&amp;lt;/tt&amp;gt; calls you found to use the format type that is now stored in the database, rather than the old hard-coded constants.&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
Here is some upgrade code from the forum module. The &amp;lt;tt&amp;gt;forum.introformat&amp;lt;/tt&amp;gt; column already existed in Moodle 1.9, so we just need to convert any old &amp;lt;tt&amp;gt;FORMAT_MOODLE&amp;lt;/tt&amp;gt; content to &amp;lt;tt&amp;gt;FORMAT_HTML&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We only do this if &amp;lt;tt&amp;gt;$CFG-&amp;gt;texteditors !== &amp;#039;textarea&amp;#039;&amp;lt;/tt&amp;gt;. &amp;lt;tt&amp;gt;$CFG-&amp;gt;texteditors&amp;lt;/tt&amp;gt; is an admin setting that controls which acutal editors are available for use by the &amp;lt;tt&amp;gt;editor&amp;lt;/tt&amp;gt; formslib element. If only the textarea editor is in use, then we do not covert. In all other situations we do convert.&lt;br /&gt;
&lt;br /&gt;
To do the conversion, we call &amp;lt;tt&amp;gt;text_to_html()&amp;lt;/tt&amp;gt; with the old content, and then the options &amp;lt;tt&amp;gt;false, false, true&amp;lt;/tt&amp;gt;. If you look at how &amp;lt;tt&amp;gt;text_to_html()&amp;lt;/tt&amp;gt; works, you will see why those are the appropriate options.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Taken from mod/forum/db/upgrade.php&lt;br /&gt;
        if ($CFG-&amp;gt;texteditors !== &amp;#039;textarea&amp;#039;) {&lt;br /&gt;
            $rs = $DB-&amp;gt;get_recordset(&amp;#039;forum&amp;#039;, array(&amp;#039;introformat&amp;#039;=&amp;gt;FORMAT_MOODLE), &amp;#039;&amp;#039;, &amp;#039;id,intro,introformat&amp;#039;);&lt;br /&gt;
            foreach ($rs as $f) {&lt;br /&gt;
                $f-&amp;gt;intro       = text_to_html($f-&amp;gt;intro, false, false, true);&lt;br /&gt;
                $f-&amp;gt;introformat = FORMAT_HTML;&lt;br /&gt;
                $DB-&amp;gt;update_record(&amp;#039;forum&amp;#039;, $f);&lt;br /&gt;
                upgrade_set_timeout();&lt;br /&gt;
            }&lt;br /&gt;
            $rs-&amp;gt;close();&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This is a tricky case. I hope the comment explains it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
        // Update question_answers.&lt;br /&gt;
        // In question_answers.feedback was previously always treated as&lt;br /&gt;
        // FORMAT_HTML in calculated, multianswer, multichoice, numerical,&lt;br /&gt;
        // shortanswer and truefalse; and&lt;br /&gt;
        // FORMAT_MOODLE in essay (despite being edited using the HTML editor)&lt;br /&gt;
        // So essay feedback needs to be converted to HTML unless $CFG-&amp;gt;texteditors == &amp;#039;textarea&amp;#039;.&lt;br /&gt;
        // For all question types except multichoice,&lt;br /&gt;
        // question_answers.answer is FORMAT_PLAIN and does not need to be changed.&lt;br /&gt;
        // For multichoice, question_answers.answer is FORMAT_MOODLE, and should&lt;br /&gt;
        // stay that way, at least for now.&lt;br /&gt;
        $rs = $DB-&amp;gt;get_recordset_sql(&amp;#039;&lt;br /&gt;
                SELECT qa.*, q.qtype&lt;br /&gt;
                FROM {question_answers} qa&lt;br /&gt;
                JOIN {question} q ON a.question = q.id&amp;#039;);&lt;br /&gt;
        foreach ($rs as $record) {&lt;br /&gt;
            // Convert question_answers.answer&lt;br /&gt;
            if ($record-&amp;gt;qtype !== &amp;#039;multichoice&amp;#039;) {&lt;br /&gt;
                $record-&amp;gt;answerformat = FORMAT_PLAIN;&lt;br /&gt;
            } else {&lt;br /&gt;
                $record-&amp;gt;answerformat = FORMAT_MOODLE;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            // Convert question_answers.feedback&lt;br /&gt;
            if ($CFG-&amp;gt;texteditors !== &amp;#039;textarea&amp;#039;) {&lt;br /&gt;
                if ($record-&amp;gt;qtype == &amp;#039;essay&amp;#039;) {&lt;br /&gt;
                    $record-&amp;gt;feedback = text_to_html($record-&amp;gt;feedback, false, false, true);&lt;br /&gt;
                }&lt;br /&gt;
                $record-&amp;gt;feedbackformat = FORMAT_HTML;&lt;br /&gt;
            } else {&lt;br /&gt;
                $record-&amp;gt;feedbackformat = FORMAT_MOODLE;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            $DB-&amp;gt;update_record(&amp;#039;question_answers&amp;#039;, $record);&lt;br /&gt;
        }&lt;br /&gt;
        $rs-&amp;gt;close();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Migrating_contrib_code_to_2.0|Other documentation on migrating code to Moodle 2.0]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{CategoryDeveloper}}&lt;/div&gt;</summary>
		<author><name>1&gt;TimHunt</name></author>
	</entry>
</feed>