Quellcode durchsuchen

편집 기록 관련 수정

https://github.com/openNAMU/openNAMU/issues/1657
잉여개발기 (SPDV) vor 2 Jahren
Ursprung
Commit
e6f2ffc52b
4 geänderte Dateien mit 113 neuen und 96 gelöschten Zeilen
  1. 8 2
      app.py
  2. 101 93
      route/recent_change.py
  3. 4 0
      route/tool/func.py
  4. 0 1
      route/tool/func_render_namumark.py

+ 8 - 2
app.py

@@ -382,14 +382,20 @@ app.route('/block_log/<regex("user"):tool>/<name>')(recent_block_2)
 app.route('/block_log/<regex("admin"):tool>/<name>')(recent_block_2)
 
 # Func-history
-app.route('/recent_change')(recent_change)
-app.route('/recent_changes')(recent_change)
+app.route('/recent_change', defaults = { 'tool' : 'recent' })(recent_change)
+app.route('/recent_change/<int:num>/<set_type>', defaults = { 'tool' : 'recent' })(recent_change)
+app.route('/recent_changes', defaults = { 'tool' : 'recent' })(recent_change)
+app.route('/recent_changes/<int:num>/<set_type>', defaults = { 'tool' : 'recent' })(recent_change)
 
 app.route('/record/<name>', defaults = { 'tool' : 'record' })(recent_change)
+app.route('/record/<int:num>/<set_type>/<name>', defaults = { 'tool' : 'record' })(recent_change)
+
 app.route('/record/reset/<name>', methods = ['POST', 'GET'])(recent_record_reset)
 app.route('/record/topic/<name>')(recent_record_topic)
 
 app.route('/history/<everything:name>', defaults = { 'tool' : 'history' }, methods = ['POST', 'GET'])(recent_change)
+app.route('/history_page/<int:num>/<set_type>/<everything:name>', defaults = { 'tool' : 'history' }, methods = ['POST', 'GET'])(recent_change)
+
 app.route('/history_tool/<int(signed = True):rev>/<everything:name>')(recent_history_tool)
 app.route('/history_delete/<int(signed = True):rev>/<everything:name>', methods = ['POST', 'GET'])(recent_history_delete)
 app.route('/history_hidden/<int(signed = True):rev>/<everything:name>')(recent_history_hidden)

+ 101 - 93
route/recent_change.py

@@ -15,72 +15,59 @@ def recent_change_send_render(data):
 
     return data
 
-def recent_change(name = None, tool = ''):
+def recent_change(name = '', tool = '', num = 1, set_type = 'normal'):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
+        ip = ip_check()
+        all_admin = admin_check('all', None, ip)
+        owner = admin_check(None, None, ip)
+
         if flask.request.method == 'POST':
-            return redirect(
-                '/diff' + 
-                '/' + flask.request.form.get('b', '1') +
-                '/' + flask.request.form.get('a', '1') +
-                '/' + url_pas(name)
-            )
+            return redirect('/diff/' + flask.request.form.get('b', '1') + '/' + flask.request.form.get('a', '1') + '/' + url_pas(name))
         else:
             ban = ''
             select = ''
             sub = ''
-            admin = admin_check()
+            admin = owner
             div = '''
                 <table id="main_table_set">
                     <tbody>
                         <tr id="main_table_top_tr">
             '''
 
-            num = int(number_check(flask.request.args.get('num', '1')))
             sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-            if name:
-                if tool == 'history':
-                    sub += ' (' + load_lang('history') + ')'
-
-                    div += '''
-                        <td id="main_table_width">''' + load_lang('version') + '''</td>
-                        <td id="main_table_width">''' + load_lang('editor') + '''</td>
-                        <td id="main_table_width">''' + load_lang('time') + '''</td>
-                    '''
+            if tool == 'history':
+                div += '''
+                    <td id="main_table_width">''' + load_lang('version') + '''</td>
+                    <td id="main_table_width">''' + load_lang('editor') + '''</td>
+                    <td id="main_table_width">''' + load_lang('time') + '''</td>
+                '''
+                sub = '(' + load_lang('history') + ')'
 
-                    set_type = flask.request.args.get('set', 'normal')
-                    set_type = '' if set_type == 'edit' else set_type
+                set_type = '' if set_type == 'edit' else set_type
+                if set_type != 'normal':
+                    curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? and type = ? order by id + 0 desc limit ?, 50'), [name, set_type, sql_num])
+                else:
+                    curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? order by id + 0 desc limit ?, 50'), [name, sql_num])
 
-                    if set_type != 'normal':
-                        curs.execute(db_change('' + \
-                            'select id, title, date, ip, send, leng, hide from history ' + \
-                            'where title = ? and type = ? ' + \
-                            'order by id + 0 desc ' + \
-                            "limit ?, 50" + \
-                        ''), [name, set_type, sql_num])
-                    else:
-                        curs.execute(db_change('' + \
-                            'select id, title, date, ip, send, leng, hide from history ' + \
-                            'where title = ? ' + \
-                            'order by id + 0 desc ' + \
-                            "limit ?, 50" + \
-                        ''), [name, sql_num])
+                data_list = curs.fetchall()
+            elif tool == 'record':
+                div +=  '''
+                    <td id="main_table_width">''' + load_lang('document_name') + '''</td>
+                    <td id="main_table_width">''' + load_lang('editor') + '''</td>
+                    <td id="main_table_width">''' + load_lang('time') + '''</td>
+                '''
+                sub = '(' + load_lang('edit_record') + ')'
+                set_type = '' if set_type == 'edit' else set_type
 
-                    data_list = curs.fetchall()
+                if set_type != 'normal':
+                    curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where ip = ? and type = ? order by date desc limit ?, 50'), [name, set_type, sql_num])
                 else:
-                    div +=  '''
-                        <td id="main_table_width">''' + load_lang('document_name') + '''</td>
-                        <td id="main_table_width">''' + load_lang('editor') + '''</td>
-                        <td id="main_table_width">''' + load_lang('time') + '''</td>
-                    '''
-
-                    curs.execute(db_change('' + \
-                        'select id, title, date, ip, send, leng, hide from history ' + \
-                        "where ip = ? order by date desc limit ?, 50" + \
-                    ''), [name, sql_num])
-                    data_list = curs.fetchall()
+                    curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where ip = ? order by date desc limit ?, 50'), [name, sql_num])
+                
+                data_list = curs.fetchall()
             else:
                 div +=  '''
                     <td id="main_table_width">''' + load_lang('document_name') + '''</td>
@@ -88,14 +75,22 @@ def recent_change(name = None, tool = ''):
                     <td id="main_table_width">''' + load_lang('time') + '''</td>
                 '''
                 sub = ''
-                set_type = flask.request.args.get('set', 'normal')
                 set_type = '' if set_type == 'edit' else set_type
 
                 data_list = []
-                curs.execute(db_change('select title, id from rc where type = ? order by date desc limit 50'), [set_type])
-                for i in curs.fetchall():
-                    curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? and id = ?'), i)
-                    data_list += curs.fetchall()
+
+                if num == 1 or all_admin != 1:
+                    curs.execute(db_change('select title, id from rc where type = ? order by date desc limit 50'), [set_type])
+                    for for_a in curs.fetchall():
+                        curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? and id = ?'), for_a)
+                        data_list += curs.fetchall()
+                else:
+                    if set_type != 'normal':
+                        curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where type = ? order by date desc limit ?, 50'), [sql_num])
+                    else:
+                        curs.execute(db_change('select id, title, date, ip, send, leng, hide from history order by date desc limit ?, 50'), [sql_num])
+
+                    data_list = curs.fetchall()
 
             div += '</tr>'
 
@@ -155,57 +150,70 @@ def recent_change(name = None, tool = ''):
                 </table>
             '''
 
-            if name:
-                if tool == 'history':
-                    div = '' + \
-                        '<a href="?set=normal">(' + load_lang('normal') + ')</a> ' + \
-                        '<a href="?set=edit">(' + load_lang('edit') + ')</a> ' + \
-                        '<a href="?set=move">(' + load_lang('move') + ')</a> ' + \
-                        '<a href="?set=delete">(' + load_lang('delete') + ')</a> ' + \
-                        '<a href="?set=revert">(' + load_lang('revert') + ')</a>' + \
-                        '<hr class="main_hr">' + div + \
-                    ''
-                    menu = [['w/' + url_pas(name), load_lang('return')]]
-
-                    if set_type == 'normal':
-                        div = '''
-                            <form method="post">
-                                <select name="a">''' + select + '''</select> <select name="b">''' + select + '''</select>
-                                <button type="submit">''' + load_lang('compare') + '''</button>
-                            </form>
-                            <hr class="main_hr">
-                        ''' + div
-
-                        if admin == 1:
-                            menu += [
-                                ['history_add/' + url_pas(name), load_lang('history_add')],
-                                ['history_reset/' + url_pas(name), load_lang('history_reset')]
-                            ]
-
-                    title = name
-                    div += next_fix('/history/' + url_pas(name) + '?tool=' + set_type + '&num=', num, data_list)
-                else:
-                    title = load_lang('edit_record')
-                    menu = [
-                        ['other', load_lang('other')], 
-                        ['user', load_lang('user')],
-                        ['record/reset/' + url_pas(name), load_lang('record_reset')]
+            if tool == 'history':
+                div = '' + \
+                    '<a href="/history_page/1/normal/' + url_pas(name) + '">(' + load_lang('normal') + ')</a> ' + \
+                    '<a href="/history_page/1/edit/' + url_pas(name) + '">(' + load_lang('edit') + ')</a> ' + \
+                    '<a href="/history_page/1/move/' + url_pas(name) + '">(' + load_lang('move') + ')</a> ' + \
+                    '<a href="/history_page/1/delete/' + url_pas(name) + '">(' + load_lang('delete') + ')</a> ' + \
+                    '<a href="/history_page/1/revert/' + url_pas(name) + '">(' + load_lang('revert') + ')</a>' + \
+                    '<hr class="main_hr">' + div + \
+                ''
+                menu = [['w/' + url_pas(name), load_lang('return')]]
+
+                if set_type == 'normal':
+                    div = '''
+                        <form method="post">
+                            <select name="a">''' + select + '''</select> <select name="b">''' + select + '''</select>
+                            <button type="submit">''' + load_lang('compare') + '''</button>
+                        </form>
+                        <hr class="main_hr">
+                    ''' + div
+
+                if admin == 1:
+                    menu += [
+                        ['history_add/' + url_pas(name), load_lang('history_add')],
+                        ['history_reset/' + url_pas(name), load_lang('history_reset')]
                     ]
-                    div += next_fix('/record/' + url_pas(name) + '?num=', num, data_list)
+
+                title = name
+                div += get_next_page_bottom('/history_page/{}/' + set_type + '/' + url_pas(name), num, data_list)
+            elif tool == 'record':
+                div = '' + \
+                    '<a href="/record/1/normal/' + url_pas(name) + '">(' + load_lang('normal') + ')</a> ' + \
+                    '<a href="/record/1/edit/' + url_pas(name) + '">(' + load_lang('edit') + ')</a> ' + \
+                    '<a href="/record/1/move/' + url_pas(name) + '">(' + load_lang('move') + ')</a> ' + \
+                    '<a href="/record/1/delete/' + url_pas(name) + '">(' + load_lang('delete') + ')</a> ' + \
+                    '<a href="/record/1/revert/' + url_pas(name) + '">(' + load_lang('revert') + ')</a>' + \
+                    '<hr class="main_hr">' + div + \
+                ''
+
+                title = name
+                menu = [
+                    ['other', load_lang('other')], 
+                    ['user', load_lang('user')]
+                ]
+                if admin == 1:
+                    menu += [['record/reset/' + url_pas(name), load_lang('record_reset')]]
+
+                div += get_next_page_bottom('/record/{}/' + url_pas(name), num, data_list)
             else:
                 div = '' + \
-                    '<a href="?set=normal">(' + load_lang('normal') + ')</a> ' + \
-                    '<a href="?set=edit">(' + load_lang('edit') + ')</a> ' + \
-                    '<a href="?set=user">(' + load_lang('user_document') + ')</a> ' + \
-                    '<a href="?set=move">(' + load_lang('move') + ')</a> ' + \
-                    '<a href="?set=delete">(' + load_lang('delete') + ')</a> ' + \
-                    '<a href="?set=revert">(' + load_lang('revert') + ')</a>' + \
+                    '<a href="/recent_change/1/normal">(' + load_lang('normal') + ')</a> ' + \
+                    '<a href="/recent_change/1/edit">(' + load_lang('edit') + ')</a> ' + \
+                    '<a href="/recent_change/1/user">(' + load_lang('user_document') + ')</a> ' + \
+                    '<a href="/recent_change/1/move">(' + load_lang('move') + ')</a> ' + \
+                    '<a href="/recent_change/1/delete">(' + load_lang('delete') + ')</a> ' + \
+                    '<a href="/recent_change/1/revert">(' + load_lang('revert') + ')</a>' + \
                     '<hr class="main_hr">' + div + \
                 ''
 
                 menu = [['other', load_lang('return')]]
                 title = load_lang('recent_change')
 
+                if all_admin == 1:
+                    div += get_next_page_bottom('/recent_change/{}/' + set_type, num, data_list)
+
             if sub == '':
                 sub = 0
 

+ 4 - 0
route/tool/func.py

@@ -1651,6 +1651,10 @@ def do_user_name_check(user_name):
         # IP와 혼동 방지 
         if ip_or_user(user_name) == 1:
             return 1
+        
+        # 슬래시 불가능
+        if user_name.find('/') != -1:
+            return 1
 
         # ID 필터
         curs.execute(db_change('select html from html_filter where kind = "name"'))

+ 0 - 1
route/tool/func_render_namumark.py

@@ -1890,7 +1890,6 @@ class class_do_render_namumark:
                             continue
 
                         wiki_data = re.sub(r'^#!(dark|white)( |\n)', '', middle_data)
-                        print(self.darkmode)
                         if middle_name == '#!dark' and self.darkmode == '1':
                             middle_data_pass = wiki_data
                         elif middle_name == '#!white' and self.darkmode == '0':