[dev] [commit] r919 - templates/admin wwwbase/admin wwwbase/ajax

automailer at dexonline.ro automailer at dexonline.ro
Wed Jul 31 13:48:35 EEST 2013


Author: cata
Date: Wed Jul 31 13:48:35 2013
New Revision: 919

Log:
Hacky script to fix some errors reported in DEX.

Added:
   templates/admin/fixDexErrors.ihtml
   wwwbase/admin/fixDexErrors.php
   wwwbase/ajax/fixDexError.php

Added: templates/admin/fixDexErrors.ihtml
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ templates/admin/fixDexErrors.ihtml	Wed Jul 31 13:48:35 2013	(r919)
@@ -0,0 +1,29 @@
+<style type="text/css">
+{literal}
+  del { color: red; }
+  ins { color: green; }
+{/literal}
+</style>
+
+{foreach from=$data item=row}
+  <div class="typoWrapper" style="margin-top: 10px">
+    {$row.diff}<br/>
+    <span class="defDetails">
+      <a id="def_{$row.def->id}" class="acceptLink" href="#">acceptă</a> | 
+      <a href="../definitie/{$row.def->id}">vezi definiția</a>
+    </span>
+  </div>
+{/foreach}
+
+<script>
+{literal}
+  $(function() {
+    $('.acceptLink').click(function() {
+      var defId = $(this).attr('id').substring(4);
+      $.get(wwwRoot + 'ajax/fixDexError.php?id=' + defId);
+      $(this).closest('.typoWrapper').slideToggle();
+      return false;
+    });
+  });
+{/literal}
+</script>

Added: wwwbase/admin/fixDexErrors.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ wwwbase/admin/fixDexErrors.php	Wed Jul 31 13:48:35 2013	(r919)
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Fixes errors kindly reported by Ștefan Cioc.
+ * After saving his text file, first change its encoding to UTF-8. You can do this with emacs: C-x C-m f utf-8, then save.
+ */
+
+define('FILE_NAME', __DIR__ . '/../../corectii DEXOnline.txt');
+
+require_once __DIR__ . '/../../phplib/util.php';
+require_once __DIR__ . '/../../phplib/simplediff.php';
+util_assertModerator(PRIV_EDIT);
+util_assertNotMirror();
+
+$lines = file(FILE_NAME);
+$lines = array_slice($lines, 1); // First line contains the column descriptions
+
+$data = array();
+foreach ($lines as $i => $line) {
+  $parts = explode("\t", trim($line));
+  if (count($parts) != 4) {
+    printf("Linia %d conține %d părți: [%s]\n", $i, count($parts), $line);
+    exit;
+  }
+
+  list($id, $wrong, $right, $code) = $parts;
+  $def = Definition::get_by_id($id);
+  if (!$def) {
+    printf("[ID:$id] definiția nu există\n");
+  }
+
+  if ($def->internalRep != $right) {
+    $data[] = array('def' => $def,
+                    'diff' => htmlDiff($def->internalRep, $right));
+  }  
+}
+
+SmartyWrap::assign('data', $data);
+SmartyWrap::assign('recentLinks', RecentLink::loadForUser());
+SmartyWrap::assign('sectionTitle', 'Corectare erori raportate');
+SmartyWrap::assign('sectionCount', count($lines));
+SmartyWrap::addJs('jquery');
+SmartyWrap::displayAdminPage('admin/fixDexErrors.ihtml');
+
+?>

Added: wwwbase/ajax/fixDexError.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ wwwbase/ajax/fixDexError.php	Wed Jul 31 13:48:35 2013	(r919)
@@ -0,0 +1,29 @@
+<?php
+
+define('FILE_NAME', __DIR__ . '/../../corectii DEXOnline.txt');
+
+require_once __DIR__ . '/../../phplib/util.php';
+util_assertModerator(PRIV_EDIT);
+util_assertNotMirror();
+
+$id = util_getRequestParameter('id');
+$def = Definition::get_by_id($id);
+assert($def);
+
+$lines = file(FILE_NAME);
+$lines = array_slice($lines, 1); // First line contains the column descriptions
+
+foreach ($lines as $line) {
+  $parts = explode("\t", trim($line));
+  assert(count($parts) == 4);
+  list($id, $wrong, $right, $code) = $parts;
+  if ($id == $def->id) {
+    $def->internalRep = $right;
+    $def->htmlRep = AdminStringUtil::htmlize($right, $def->sourceId);
+    $def->lexicon = AdminStringUtil::extractLexicon($def);
+    $def->save();
+    break; // I know. Shut up.
+  }
+}
+
+?>


More information about the Dev mailing list