Преглед изворни кода

버그 수정 및 역링크와 분류 작동 변경

ㅇㅇ
2DU пре 8 година
родитељ
комит
4bf37045a3
3 измењених фајлова са 72 додато и 96 уклоњено
  1. 43 69
      app.py
  2. 1 1
      func.py
  3. 28 26
      mark.py

+ 43 - 69
app.py

@@ -659,17 +659,16 @@ def xref_reset():
     )
     curs = conn.cursor(pymysql.cursors.DictCursor)
 
-    if(admin_check(None) == 1):
-        i = 0
-        
+    if(admin_check(None) == 1):        
         curs.execute("delete from back")
+        curs.execute("delete from cat")
         conn.commit()
         
         curs.execute("select title, data from data")
         data = curs.fetchall()
-        if(data):
-            for end in data:
-                namumark(end['title'], end['data'])
+        for end in data:
+            print(end['title'])
+            namumark(end['title'], end['data'], 1)
         
         conn.close()
         return(redirect('/'))
@@ -1105,7 +1104,7 @@ def old_view(name = None, num = None):
                 title = name, 
                 logo = set_data['name'], 
                 page = url_pas(name), 
-                data = namumark(name, rows[0]['data']), 
+                data = namumark(name, rows[0]['data'], 0), 
                 sub = '옛 문서'
             )
         )
@@ -1218,6 +1217,10 @@ def revert(name = None, num = None):
             conn.close()
             return(redirect('/ban'))
         else:
+            curs.execute("delete from back where link = '" + db_pas(name) + "'")
+            curs.execute("delete from cat where cat = '" + db_pas(name) + "'")
+            conn.commit()
+
             curs.execute("select * from history where title = '" + db_pas(name) + "' and id = '" + str(num) + "'")
             rows = curs.fetchall()
             if(rows):                                
@@ -1300,6 +1303,9 @@ def many_del():
                     curs.execute("select data from data where title = '" + db_pas(g[0]) + "'")
                     rows = curs.fetchall()
                     if(rows):
+                        curs.execute("delete from back where title = '" + db_pas(g[0]) + "'")
+                        curs.execute("delete from cat where title = '" + db_pas(g[0]) + "'")
+
                         leng = '-' + str(len(rows[0]['data']))
                         curs.execute("delete from data where title = '" + db_pas(g[0]) + "'")
                         history_plus(
@@ -1356,9 +1362,10 @@ def section_edit(name = None, num = None):
             
             content = savemark(request.forms.content)
 
-            curs.execute("delete from back where title = '" + db_pas(name) + "'")
+            curs.execute("delete from back where link = '" + db_pas(name) + "'")
+            curs.execute("delete from cat where cat = '" + db_pas(name) + "'")
             conn.commit()
-            
+
             curs.execute("select * from data where title = '" + db_pas(name) + "'")
             rows = curs.fetchall()
             if(rows):
@@ -1468,7 +1475,8 @@ def edit(name = None):
             
             content = savemark(request.forms.content)
 
-            curs.execute("delete from back where title = '" + db_pas(name) + "'")
+            curs.execute("delete from back where link = '" + db_pas(name) + "'")
+            curs.execute("delete from cat where cat = '" + db_pas(name) + "'")
             conn.commit()
             
             curs.execute("select * from data where title = '" + db_pas(name) + "'")
@@ -1561,7 +1569,7 @@ def section_preview(name = None, num = None):
     else:            
         newdata = request.forms.content
         newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
-        enddata = namumark(name, newdata)
+        enddata = namumark(name, newdata, 0)
             
         conn.close()
         return(
@@ -1601,7 +1609,7 @@ def preview(name = None):
     else:            
         newdata = request.forms.content
         newdata = re.sub('^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
-        enddata = namumark(name, newdata)
+        enddata = namumark(name, newdata, 0)
             
         conn.close()
         return(
@@ -1641,6 +1649,9 @@ def delete(name = None):
                 return(redirect('/ban'))
             else:
                 today = get_time()
+
+                curs.execute("delete from back where link = '" + db_pas(name) + "'")
+                curs.execute("delete from cat where cat = '" + db_pas(name) + "'")
                 
                 leng = '-' + str(len(rows[0]['data']))
                 history_plus(
@@ -1726,6 +1737,9 @@ def move(name = None):
                 if(rows):
                     curs.execute("update data set title = '" + db_pas(request.forms.title) + "' where title = '" + db_pas(name) + "'")
 
+                    curs.execute("delete from back where link = '" + db_pas(name) + "'")
+                    curs.execute("delete from cat where cat = '" + db_pas(name) + "'")
+
                 curs.execute("update history set title = '" + db_pas(request.forms.title) + "' where title = '" + db_pas(name) + "'")
                 conn.commit()
                 
@@ -1793,7 +1807,7 @@ def manager(num = None):
                         <li><a href="/manager/5">관리자 권한 주기</a></li> \
                         <li><a href="/mdel">많은 문서 삭제</a></li> \
                         <h2>소유자</h2> \
-                        <li><a href="/backreset">모든 역링크 재 생성</a></li> \
+                        <li><a href="/backreset">역링크, 분류 다시 생성</a></li> \
                         <li><a href="/manager/8">관리 그룹 생성</a></li> \
                         <h2>기타</h2> \
                         <li>이 메뉴에 없는 기능은 해당 문서의 역사나 토론에서 바로 사용 가능함</li>'
@@ -2281,7 +2295,7 @@ def topic(name = None, sub = None):
 
         if(top):
             for dain in top:                     
-                top_data = namumark('', dain['data'])
+                top_data = namumark('', dain['data'], 0)
                 top_data = re.sub("(?P<in>#(?:[0-9]*))", '<a href="\g<in>">\g<in></a>', top_data)
                         
                 ip = ip_pas(dain['ip'], 1)
@@ -2305,7 +2319,7 @@ def topic(name = None, sub = None):
             if(i == 0):
                 start = dain['ip']
                 
-            indata = namumark('', dain['data'])
+            indata = namumark('', dain['data'], 0)
             indata = re.sub("(?P<in>#(?:[0-9]*))", '<a href="\g<in>">\g<in></a>', indata)
             
             if(dain['block'] == 'O'):
@@ -2410,7 +2424,7 @@ def close_topic_list(name = None):
         curs.execute("select * from topic where title = '" + db_pas(name) + "' and sub = '" + db_pas(data['sub']) + "' and id = '1'")
         row = curs.fetchall()
         if(row):
-            indata = namumark(name, row[0]['data'])
+            indata = namumark(name, row[0]['data'], 0)
             
             if(row[0]['block'] == 'O'):
                 indata = '<br>'
@@ -2474,7 +2488,7 @@ def agree_topic_list(name = None):
         curs.execute("select * from topic where title = '" + db_pas(name) + "' and sub = '" + db_pas(data['sub']) + "' and id = '1'")
         topic_data = curs.fetchall()
         if(topic_data):
-            indata = namumark(name, topic_data[0]['data'])
+            indata = namumark(name, topic_data[0]['data'], 0)
             
             if(topic_data[0]['block'] == 'O'):
                 indata = '<br>'
@@ -2541,7 +2555,7 @@ def topic_list(name = None):
             curs.execute("select * from topic where title = '" + db_pas(data['title']) + "' and sub = '" + db_pas(data['sub']) + "' and id = '1' order by sub asc")
             aa = curs.fetchall()
             
-            indata = namumark(name, aa[0]['data'])
+            indata = namumark(name, aa[0]['data'], 0)
             
             if(aa[0]['block'] == 'O'):
                 indata = '<br>'
@@ -3226,23 +3240,16 @@ def read_view(name = None, redirect = None):
     sub = None
     acl = ''
     div = ''
+    topic = ''
     
     i = 0
     curs.execute("select sub from rd where title = '" + db_pas(name) + "' order by date asc")
     rows = curs.fetchall()
-    while(True):
-        try:            
-            curs.execute("select title from stop where title = '" + db_pas(name) + "' and sub = '" + db_pas(rows[i]['sub']) + "' and close = 'O'")
-            row = curs.fetchall()
-            if(not row):
-                topic = "open"
-                
-                break
-
-            i += 1
-        except:
-            topic = ""
-            
+    for data in rows:
+        curs.execute("select title from stop where title = '" + db_pas(name) + "' and sub = '" + db_pas(data['sub']) + "' and close = 'O'")
+        row = curs.fetchall()
+        if(not row):
+            topic = "open"
             break
             
     curs.execute("select title from data where title like '%" + db_pas(name) + "/%'")
@@ -3264,6 +3271,9 @@ def read_view(name = None, redirect = None):
         admin_memu = ''
     
     if(re.search("^분류:", name)):
+        curs.execute("delete from cat where title = '" + db_pas(name) + "' and cat = ''")
+        conn.commit()
+        
         curs.execute("select * from cat where title = '" + db_pas(name) + "' order by cat asc")
         rows = curs.fetchall()
         if(rows):
@@ -3271,43 +3281,7 @@ def read_view(name = None, redirect = None):
             i = 0
             
             for data in rows:       
-                curs.execute("select * from data where title = '" + db_pas(data['cat']) + "'")
-                row = curs.fetchall()
-                if(row):
-                    aa = row[0]['data']                  
-                    aa = namumark('', aa)
-                    bb = re.search('<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류:((?:(?!<\/div>).)*)<\/div>', aa)
-                    if(bb):
-                        cc = bb.groups()
-                        
-                        mm = re.search("^분류:(.*)", name)
-                        if(mm):
-                            ee = mm.groups()
-                            
-                            if(re.search("<a (class=\"not_thing\")? href=\"\/w\/" + url_pas(name) + "\">" + ee[0] + "<\/a>", cc[0])):
-                                div += '<li><a href="/w/' + url_pas(data['cat']) + '">' + data['cat'] + '</a></li>'
-                                
-                                i += 1
-                            else:
-                                curs.execute("delete from cat where title = '" + db_pas(name) + "' and cat = '" + db_pas(data['cat']) + "'")
-                                conn.commit()
-                                
-                                i += 1
-                        else:
-                            curs.execute("delete from cat where title = '" + db_pas(name) + "' and cat = '" + db_pas(data['cat']) + "'")
-                            conn.commit()
-                            
-                            i += 1
-                    else:
-                        curs.execute("delete from cat where title = '" + db_pas(name) + "' and cat = '" + db_pas(data['cat']) + "'")
-                        conn.commit()
-                        
-                        i += 1
-                else:
-                    curs.execute("delete from cat where title = '" + db_pas(name) + "' and cat = '" + db_pas(data['cat']) + "'")
-                    conn.commit()
-                    
-                    i += 1
+                div += '<li><a href="/w/' + url_pas(data['cat']) + '">' + data['cat'] + '</a></li>'
     
     curs.execute("select * from data where title = '" + db_pas(name) + "'")
     rows = curs.fetchall()
@@ -3340,7 +3314,7 @@ def read_view(name = None, redirect = None):
     if(redirect):
         elsedata = re.sub("^#(?:redirect|넘겨주기)\s(?P<in>[^\n]*)", " * [[\g<in>]] 문서로 넘겨주기", elsedata)
             
-    enddata = namumark(name, elsedata)
+    enddata = namumark(name, elsedata, 1)
         
     conn.close()
     return(

+ 1 - 1
func.py

@@ -114,7 +114,7 @@ def include_check(name, data):
         curs.execute("select link from back where title = '" + db_pas(name) + "' and type = 'include'")
         back = curs.fetchall()
         for backp in back:
-            namumark(backp['link'], data)
+            namumark(backp['link'], data, 1)
     
     conn.close()
     

+ 28 - 26
mark.py

@@ -313,31 +313,33 @@ def toc_pas(data, title):
 
     return(data)
 
-def backlink_plus(name, link, backtype):
-    conn = pymysql.connect(user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4', db = set_data['db'])
-    curs = conn.cursor(pymysql.cursors.DictCursor)
-    
-    curs.execute("select title from back where title = '" + db_pas(link) + "' and link = '" + db_pas(name) + "' and type = '" + backtype + "'")
-    y = curs.fetchall()
-    if(not y):
-        curs.execute("insert into back (title, link, type) value ('" + db_pas(link) + "', '" + db_pas(name) + "',  '" + backtype + "')")
-        conn.commit()
+def backlink_plus(name, link, backtype, num):
+    if(num == 1):
+        conn = pymysql.connect(user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4', db = set_data['db'])
+        curs = conn.cursor(pymysql.cursors.DictCursor)
         
-    conn.close()
+        curs.execute("select title from back where title = '" + db_pas(link) + "' and link = '" + db_pas(name) + "' and type = '" + backtype + "'")
+        y = curs.fetchall()
+        if(not y):
+            curs.execute("insert into back (title, link, type) value ('" + db_pas(link) + "', '" + db_pas(name) + "',  '" + backtype + "')")
+            conn.commit()
+            
+        conn.close()
 
-def cat_plus(name, link):
-    conn = pymysql.connect(user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4', db = set_data['db'])
-    curs = conn.cursor(pymysql.cursors.DictCursor)
-    
-    curs.execute("select title from cat where title = '" + db_pas(link) + "' and cat = '" + db_pas(name) + "'")
-    y = curs.fetchall()
-    if(not y):
-        curs.execute("insert into cat (title, cat) value ('" + db_pas(link) + "', '" + db_pas(name) + "')")
-        conn.commit()
+def cat_plus(name, link, num):
+    if(num == 1):
+        conn = pymysql.connect(user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4', db = set_data['db'])
+        curs = conn.cursor(pymysql.cursors.DictCursor)
         
-    conn.close()
+        curs.execute("select title from cat where title = '" + db_pas(link) + "' and cat = '" + db_pas(name) + "'")
+        y = curs.fetchall()
+        if(not y):
+            curs.execute("insert into cat (title, cat) value ('" + db_pas(link) + "', '" + db_pas(name) + "')")
+            conn.commit()
+            
+        conn.close()
 
-def namumark(title, data):
+def namumark(title, data, num):
     conn = pymysql.connect(user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4', db = set_data['db'])
     curs = conn.cursor(pymysql.cursors.DictCursor)
     
@@ -363,7 +365,7 @@ def namumark(title, data):
                 curs.execute("select * from data where title = '" + db_pas(results[0]) + "'")
                 in_con = curs.fetchall()
                 
-                backlink_plus(title, results[0], 'include')
+                backlink_plus(title, results[0], 'include', num)
                 if(in_con):                        
                     in_data = in_con[0]['data']
                     in_data = include.sub("", in_data)
@@ -404,7 +406,7 @@ def namumark(title, data):
                 nosharp = re.sub("<sharp>", "#", g)
                 data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(nosharp) + '/from/' + url_pas(title) + '" />', data, 1)
             
-            backlink_plus(title, results[0], 'redirect')
+            backlink_plus(title, results[0], 'redirect', num)
         else:
             break
             
@@ -438,7 +440,7 @@ def namumark(title, data):
             g = m.groups()
             
             if(not title == g[0]):
-                cat_plus(title, g[0])
+                cat_plus(title, g[0], num)
                     
                 if(category == ''):
                     curs.execute("select title from data where title = '" + db_pas(g[0]) + "'")
@@ -494,7 +496,7 @@ def namumark(title, data):
 
             if(c):
                 if(not re.search("^파일:([^\n]*)", title)):
-                    backlink_plus(title, '파일:' + c[0], 'file')
+                    backlink_plus(title, '파일:' + c[0], 'file', num)
                     
                 comp = re.compile("^(.+)(\.(?:jpg|gif|png|jpeg))$", re.I)
                 if(c[1]):
@@ -647,7 +649,7 @@ def namumark(title, data):
                     
                     data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + g + '</a>', data, 1)
 
-                    backlink_plus(title, results[0], '')
+                    backlink_plus(title, results[0], '', num)
         else:
             break