changeset 499:25702a913bdd

CheckTranslation: added supplying list of pages with the same master-page special comment for every page in page set.
author Eugene Syromyatnikov <evgsyr@gmail.com>
date Wed, 17 Feb 2010 04:22:17 +0300
parents c5ffd7c05b90
children de15d700d553
files data/plugin/action/CheckTranslation.py
diffstat 1 files changed, 48 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/CheckTranslation.py	Fri Feb 12 18:16:33 2010 +0300
+++ b/data/plugin/action/CheckTranslation.py	Wed Feb 17 04:22:17 2010 +0300
@@ -36,6 +36,8 @@
     'not_in_i18n_strings_pages': True,
 }
 
+master_meta_names = ['page', 'date', 'revision']
+
 special_comment_re = r'(?im)^##master-%(meta)s[ :][ \t]*(?P<%(meta)s>[^\n]*)[ \t]*$'
 
 date_format_guesses = [
@@ -44,6 +46,16 @@
     '%Y-%m-%d',
 ]
 
+def _get_master_metas(text):
+    result = {}
+
+    for meta in master_meta_names:
+        m = re.search(special_comment_re % {'meta': meta}, text)
+        if m:
+            result[meta] = m.group(meta)
+
+    return result
+
 def execute(pagename, request):
     _ = request.getText
 
@@ -80,10 +92,34 @@
     edit_attrs = {'name': 'editlink', 'rel': 'nofollow', }
     raw_querystr = {'action': 'raw'}
 
+    search_results = set([p.page_name for p in search.searchPages(request, 'lang:%s' % lang,
+                                     titlesearch=1, sort='page_name').hits])
+
+    all_page_trans_set = set([trans(p) for p in i18n.strings.all_pages])
+    all_related_page_set = search_results | all_page_trans_set
+    not_listed_page_list = list(search_results - all_page_trans_set)
+
+    not_listed_page_list.sort()
+
+    page_objs = {}
+    page_metas = {}
+    page_translations = {}
+
+    for page_name in all_related_page_set:
+        page_objs[page_name] = Page(request, page_name)
+        page_metas[page_name] = _get_master_metas(page_objs[page_name].body)
+
+    for page_name, page_meta in page_metas.iteritems():
+        if 'page' in page_meta and page_name != trans(page_meta['page']):
+            if page_meta['page'] in page_translations:
+                page_translations[page_meta['page']].append(page_name)
+            else:
+                page_translations[page_meta['page']] = [page_name]
+
     for orig_page_name in pageset:
         trans_page_name = trans(orig_page_name)
         orig_page = Page(request, orig_page_name)
-        trans_page = Page(request, trans_page_name)
+        trans_page = page_objs[trans_page_name]
 
         orig_status = [
             orig_page.link_to(request, orig_page_name) + " " +
@@ -118,13 +154,7 @@
                         'page_lang': request.formatter.text(trans_page.pi['language']),
                     })
 
-                master_meta_names = ['page', 'date', 'revision']
-                master_metas = {}
-
-                for meta in master_meta_names:
-                    m = re.search(special_comment_re % {'meta': meta}, trans_page.body)
-                    if m:
-                        master_metas[meta] = m.group(meta)
+                master_metas = page_metas[trans_page_name]
 
                 if 'page' in master_metas:
                     if master_metas['page'] != orig_page_name and translation_warnings['wrong_master_page']:
@@ -183,14 +213,17 @@
                                     }) + request.formatter.text(_("Diff of original page")) + orig_page.link_to(request, on=0),
                             })
 
+        if orig_page_name in page_translations:
+            trans_list = []
+
+            for page in page_translations[orig_page_name]:
+                trans_list.append(page_objs[page].link_to(request, page))
+
+            trans_status.append(_('<!> List of pages with same #master-page:', wiki=True) + " " + ", ".join(trans_list))
+
         data.addRow(("<br>".join(orig_status), "<br>".join(trans_status)))
 
 
-    search_results = set([p.page_name for p in search.searchPages(request, 'lang:%s' % lang,
-                                     titlesearch=1, sort='page_name').hits])
-    search_results = list(search_results - set([trans(p) for p in i18n.strings.all_pages]))
-    search_results.sort()
-
     not_listed = []
 
     if search_results and translation_warnings['not_in_i18n_strings_pages']:
@@ -201,12 +234,10 @@
                       ]
 
         not_listed.append(request.formatter.number_list(1))
-        for page in search_results:
+        for page in not_listed_page_list:
             not_listed += [
                            request.formatter.listitem(1),
-                           request.formatter.pagelink(1, page),
-                           request.formatter.text(page),
-                           request.formatter.pagelink(0),
+                           page_objs[page].link_to(request, page),
                            request.formatter.listitem(0),
                           ]
         not_listed.append(request.formatter.number_list(0))