### Eclipse Workspace Patch 1.0
#P moodle
Index: lang/en_utf8/admin.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/admin.php,v
retrieving revision 1.79
diff -u -r1.79 admin.php
--- lang/en_utf8/admin.php	7 Dec 2006 01:01:19 -0000	1.79
+++ lang/en_utf8/admin.php	12 Dec 2006 10:00:39 -0000
@@ -336,6 +336,10 @@
 $string['messaging'] = 'Enable messaging system';
 $string['misc'] = 'Miscellaneous';
 $string['modulesecurity'] = 'Module security';
+$string['multilangforceold'] = 'Force old multilang syntax: &lt;span&gt; without the class=\"multilang\" and &lt;lang&gt;';
+$string['multilangupgrade'] = 'Multilang upgrade';
+$string['multilangupgradeinfo'] = 'The multilang filter syntax was changed in 1.8, &lt;lang&gt; tag is not supported any more. <br /><br />Example: &lt;span lang=\"en\" class=\"multilang\">Hello!&lt;/span&gt;&lt;span lang=\"es\" class=\"multilang\">Hola!&lt;/span&gt;<br /><br /><strong>Do you want to upgrade the syntax in all existing texts now?</strong>';
+$string['multilangupgradenotice'] = 'Your site is probably using old multilang syntax, <a href=\"multilangupgrade.php\">multilang upgrade</a> is recommended.';
 $string['mustenablestats'] = 'Stats have not yet been enabled on this site.';
 $string['mymoodle'] = 'My Moodle';
 $string['mymoodleredirect'] = 'Force users to use My Moodle';
Index: admin/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/index.php,v
retrieving revision 1.251
diff -u -r1.251 index.php
--- admin/index.php	11 Dec 2006 15:47:25 -0000	1.251
+++ admin/index.php	12 Dec 2006 10:00:38 -0000
@@ -183,7 +183,8 @@
                                                    'guestloginbutton' => 1,
                                                    'style' => 'default',
                                                    'template' => 'default',
-                                                   'theme' => 'standardwhite'));
+                                                   'theme' => 'standardwhite',
+                                                   'filter_multilang_converted' => 1));
 
             notify($strdatabasesuccess, "green");
         } else {
@@ -501,6 +502,11 @@
         print_simple_box(get_string('cronwarning', 'admin')."&nbsp;".$helpbutton, 'center', '60%');
     }
 
+/// Print multilang upgrade notice if needed
+    if (empty($CFG->filter_multilang_converted)) {
+        print_simple_box(get_string('multilangupgradenotice', 'admin'), 'center', '60%');
+    }
+
 /// Alert if we are currently in maintenance mode
     if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
         print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center', '60%');
Index: admin/settings/misc.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/misc.php,v
retrieving revision 1.9
diff -u -r1.9 misc.php
--- admin/settings/misc.php	30 Oct 2006 21:01:47 -0000	1.9
+++ admin/settings/misc.php	12 Dec 2006 10:00:38 -0000
@@ -16,5 +16,6 @@
 $ADMIN->add('misc', new admin_externalpage('oacleanup', 'Online Assignment Cleanup', $CFG->wwwroot.'/'.$CFG->admin.'/oacleanup.php', 'moodle/site:config', true));
 $ADMIN->add('misc', new admin_externalpage('upgradeforumread', 'Upgrade forum', $CFG->wwwroot.'/'.$CFG->admin.'/upgradeforumread.php', 'moodle/site:config', true));
 $ADMIN->add('misc', new admin_externalpage('upgradelogs', 'Upgrade logs', $CFG->wwwroot.'/'.$CFG->admin.'/upgradelogs.php', 'moodle/site:config', true));
+$ADMIN->add('misc', new admin_externalpage('multilangupgrade', get_string('multilangupgrade', 'admin'), $CFG->wwwroot.'/'.$CFG->admin.'/multilangupgrade.php', 'moodle/site:config', !empty($CFG->filter_multilang_converted)));
 
 ?>
Index: filter/multilang/README.txt
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/multilang/README.txt,v
retrieving revision 1.5
diff -u -r1.5 README.txt
--- filter/multilang/README.txt	14 Aug 2006 07:46:03 -0000	1.5
+++ filter/multilang/README.txt	12 Dec 2006 10:00:38 -0000
@@ -6,7 +6,7 @@
 To Use it:
     - Create your contents in multiple languages.
     - Enclose every language content between:
-        <span lang="XX">your_content_here</span>
+        <span lang="XX" class="multilang">your_content_here</span><span lang="YY" class="multilang">your_content_other_lang</span>
     - Test it (by changing your language).
 
 How it works:
@@ -23,9 +23,9 @@
 
 One example in action:
     - This text:
-        <span lang="en">Hello!</span><span lang="es">Hola!</span>
+        <span lang="en" class="multilang">Hello!</span><span lang="es" class="multilang">Hola!</span>
         This text is common for every language because it's out from any lang block.
-        <span lang="en">Bye!</span><span lang="it">Ciao!</span>
+        <span lang="en" class="multilang">Bye!</span><span lang="it" class="multilang">Ciao!</span>
 
     - Will print, if current language is English:
         Hello!
@@ -41,3 +41,7 @@
 Ciao, Eloy :-)
 stronk7@moodle.org
 2005-11-16
+
+Syntax was changed in 1.8, the conversion of existing text is done from admin/multilangupgrade.php
+Ciao, skodak :-)
+2006-12-11
\ No newline at end of file
Index: filter/multilang/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/multilang/filter.php,v
retrieving revision 1.16
diff -u -r1.16 filter.php
--- filter/multilang/filter.php	15 Sep 2006 08:23:40 -0000	1.16
+++ filter/multilang/filter.php	12 Dec 2006 10:00:38 -0000
@@ -23,29 +23,38 @@
 ///////////////////////////////////////////////////////////////////////////
 
 // Given XML multilinguage text, return relevant text according to
-// current language.  i.e.=
-//   - look for lang sections in the code.
+// current language:
+//   - look for multilang blocks in the text.
 //   - if there exists texts in the currently active language, print them.
 //   - else, if there exists texts in the current parent language, print them.
 //   - else, print the first language in the text.
 // Please note that English texts are not used as default anymore!
 //
-// This is an improved version of the original multilang filter by Gaetan Frenoy. 
-// It should be 100% compatible with the original one. Some new features are:
-//   - Supports a new "short" syntax to make things easier. Simply use:
-//         <span lang="XX">
-//   - Needs less resources and executes faster.
-//   - Allows any type of content to be used. No restrictions at all!
+// This version is based on original multilang filter by Gaetan Frenoy,
+// rewritten by Eloy and skodak.
+//
+// Following new syntax is not compatible with old one:
+//   <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
 
 function multilang_filter($courseid, $text) {
+    global $CFG;
 
     // [pj] I don't know about you but I find this new implementation funny :P
     // [skodak] I was laughing while rewriting it ;-)
-    $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>\s*)+/is';
+
+    if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
+        // new syntax
+        $search = '/(<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)(\s*<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)+/is';
+    } else {
+        // old syntax
+        $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
+    }
     return preg_replace_callback($search, 'multilang_filter_impl', $text);
 }
 
 function multilang_filter_impl($langblock) {
+    global $CFG;
+
     $mylang = str_replace('_utf8', '', current_language());
     static $parentcache;
     if (!isset($parentcache)) {
@@ -58,7 +67,14 @@
         $parentlang = $parentcache[$mylang];
     }
 
-    $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
+        // new syntax
+        $searchtosplit = '/<span lang="([a-zA-Z0-9_-]+)" class="multilang">(.+?)<\/span>/is';
+    } else {
+        // old syntax
+        $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    }
+
     preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
 
     $langlist = array();
Index: filter/multilang/filterconfig.html
===================================================================
RCS file: filter/multilang/filterconfig.html
diff -N filter/multilang/filterconfig.html
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ filter/multilang/filterconfig.html	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,14 @@
+<?php
+    // check the default settings
+    require_once "defaultsettings.php";
+
+?>
+
+<table cellpadding="9" cellspacing="0">
+    <tr valign="top">
+        <td align="right"><?php print_string('multilangforceold', 'admin'); ?></td>
+        <td><?php choose_from_menu(array(get_String('no'), get_String('yes')), 'filter_multilang_force_old',
+             $CFG->filter_multilang_force_old, ''); ?></td> 
+        <td />
+    </tr>
+</table>
Index: admin/multilangupgrade.php
===================================================================
RCS file: admin/multilangupgrade.php
diff -N admin/multilangupgrade.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ admin/multilangupgrade.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,112 @@
+<?php /// $Id: replace.php,v 1.6 2006/09/25 20:22:56 skodak Exp $
+      /// Search and replace strings throughout all texts in the whole database
+
+require_once('../config.php');
+require_once($CFG->dirroot.'/course/lib.php');
+require_once($CFG->libdir.'/adminlib.php');
+$adminroot = admin_get_root();
+admin_externalpage_setup('multilangupgrade', $adminroot);
+
+$go = optional_param('go', 0, PARAM_BOOL);
+
+require_login();
+
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
+
+###################################################################
+admin_externalpage_print_header($adminroot);
+
+print_heading(get_string('multilangupgrade', 'admin'));
+
+$strmultilangupgrade = get_String('multilangupgradeinfo', 'admin');
+
+if (!$go or !data_submitted() or !confirm_sesskey()) {   /// Print a form
+    $optionsyes = array('go'=>1, 'sesskey'=>sesskey());
+    notice_yesno($strmultilangupgrade, 'multilangupgrade.php', 'index.php', $optionsyes, null, 'post', 'get');
+    admin_externalpage_print_footer($adminroot);
+    die;
+}
+
+
+if (!$tables = $db->Metatables() ) {    // No tables yet at all.
+    error("no tables");
+}
+
+print_simple_box_start('center');
+
+/// Turn off time limits, sometimes upgrades can be slow.
+
+@set_time_limit(0);
+@ob_implicit_flush(true);
+while(@ob_end_flush());
+
+echo '<strong>Progress:</strong>';
+$i = 0;
+$skiptables = array($CFG->prefix.'config');//, $CFG->prefix.'sessions2');
+
+foreach ($tables as $table) {
+    if (strpos($table, $CFG->prefix) !== 0
+      or strpos($table, $CFG->prefix.'pma') === 0) { // Not our tables
+        continue;
+    }
+    if (in_array($table, $skiptables)) { // Don't process these
+        continue;
+    }
+    if ($columns = $db->MetaColumns($table, false)) {
+        if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) {
+            continue; // moodle tables have id
+        }
+        foreach ($columns as $column => $data) {
+            if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
+                // first find candidate records
+                $rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
+                if ($rs and $rs->RecordCount() > 0) {
+                    while (!$rs->EOF) {
+                        $text = $rs->fields[$column];
+                        $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
+                        $newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text);
+                        if ($newtext != $text) {
+                            $newtext = addslashes($newtext);
+                            execute_sql("UPDATE $table SET $column='$newtext' WHERE id=".$rs->fields['id'], false);
+                        }
+                        if ($i % 600 == 0) {
+                            echo '<br />';
+                        }
+                        if ($i % 10 == 0) {
+                            echo '.';
+                        }
+                        $i++;
+                        $rs->MoveNext();
+                    }
+                }
+            }
+        }
+    }
+}
+
+// set conversion flag - switches to new plugin automatically
+set_config('filter_multilang_converted', 1);
+
+print_simple_box_end();
+
+/// Rebuild course cache which might be incorrect now
+notify('Rebuilding course cache...', 'notifysuccess');
+rebuild_course_cache();
+notify('...finished', 'notifysuccess');
+
+print_continue('index.php');
+
+admin_externalpage_print_footer($adminroot);
+die;
+
+
+function multilangupgrade_impl($langblock) {
+    $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
+    $return = '';
+    foreach ($rawlanglist[1] as $index=>$lang) {
+        $return .= '<span lang="'.$lang.'" class="multilang">'.$rawlanglist[2][$index].'</span>';
+    }
+    return $return;
+}
+?>
Index: filter/multilang/defaultsettings.php
===================================================================
RCS file: filter/multilang/defaultsettings.php
diff -N filter/multilang/defaultsettings.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ filter/multilang/defaultsettings.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,14 @@
+<?php
+    // defaultsettings.php
+    // deafault settings are done here, saves doing all this twice in
+    // both the rendering routine and the config screen
+
+    if (!isset($forcereset)) {
+        $forcereset = false;
+    }
+
+    if (!isset($CFG->filter_multilang_force_old) or $forcereset) {
+        set_config('filter_multilang_force_old', 0);
+    }
+
+?>
