def run(self): # self.site_active = mw.get_setting('mediawiki_site_active') self.site_active = mw.get_view_site() sites = mw.get_setting('mediawiki_site') # self.site_keys = map(self.is_checked, list(sites.keys())) self.site_keys = [self.is_checked(x) for x in sites.keys()] sublime.set_timeout(lambda: self.window.show_quick_panel(self.site_keys, self.on_done), 1)
def run(self, edit, title, password): self.password = password if self.category_path: category_root = mw.get_category(self.get_category_current())[1] else: category_root = mw.get_category(mw.get_setting('mediawiker_category_root'))[1] sublime.active_window().show_input_panel('Wiki root category:', category_root, self.show_list, None, None)
def show_results(self, search_value=''): # TODO: paging? self.pages_names = [] self.search_limit = mw.get_setting('mediawiker_search_results_count') if search_value: self.search_result = self.do_search(search_value) if self.search_result: for i in range(self.search_limit): try: page_data = self.search_result.next() self.pages_names.append([page_data['title'], page_data['snippet']]) except: pass te = '' search_number = 1 for pa in self.pages_names: te += '### %s. %s\n* [%s](%s)\n\n%s\n' % (search_number, pa[0], pa[0], mw.get_page_url(pa[0]), self.antispan(pa[1])) search_number += 1 if te: self.view = sublime.active_window().new_file() self.view.set_syntax_file('Packages/Markdown/Markdown.tmLanguage') self.view.set_name('Wiki search results: %s' % search_value) self.view.run_command('mediawiker_insert_text', {'position': 0, 'text': te}) elif search_value: sublime.message_dialog('No results for: %s' % search_value)
def drawtable(self, table_list): ''' draw wiki table ''' TBL_START = '{|' TBL_STOP = '|}' TBL_ROW_START = '|-' CELL_FIRST_DELIM = '|' CELL_DELIM = '||' CELL_HEAD_FIRST_DELIM = '!' CELL_HEAD_DELIM = '!!' REPLACE_STR = ':::' text_wikitable = '' table_properties = ' '.join(['%s="%s"' % (prop, value) for prop, value in mw.get_setting('mediawiker_wikitable_properties', {}).items()]) need_header = table_list[0][0]['is_header'] is_first_line = True for row in table_list: if need_header or is_first_line: text_wikitable += '%s\n%s' % (TBL_ROW_START, CELL_HEAD_FIRST_DELIM) text_wikitable += self.getrow(CELL_HEAD_DELIM, row) is_first_line = False need_header = False else: text_wikitable += '\n%s\n%s' % (TBL_ROW_START, CELL_FIRST_DELIM) text_wikitable += self.getrow(CELL_DELIM, row) text_wikitable = text_wikitable.replace(REPLACE_STR, '|') return '%s %s\n%s\n%s' % (TBL_START, table_properties, text_wikitable, TBL_STOP)
def on_done(self, summary): summary = '%s%s' % (summary, mw.get_setting('mediawiker_summary_postfix', ' (by SublimeText.Mediawiker)')) mark_as_minor = mw.get_setting('mediawiker_mark_as_minor') try: if self.page.can('edit'): # invert minor settings command '!' if summary[0] == '!': mark_as_minor = not mark_as_minor summary = summary[1:] self.page.save(self.current_text, summary=summary.strip(), minor=mark_as_minor) self.view.set_scratch(True) self.view.settings().set('is_changed', False) # reset is_changed flag sublime.status_message('Wiki page %s was successfully published to wiki.' % (self.title)) mw.save_mypages(self.title) else: sublime.status_message('You have not rights to edit this page') except mw.mwclient.EditError as e: sublime.status_message('Can\'t publish page %s (%s)' % (self.title, e))
def getrow(self, delimiter, rowlist=None): if rowlist is None: rowlist = [] cell_properties = ' '.join(['%s="%s"' % (prop, value) for prop, value in mw.get_setting('mediawiker_wikitable_cell_properties', {}).items()]) cell_properties = '%s | ' % cell_properties if cell_properties else '' try: return delimiter.join(' %s%s ' % (cell_properties, cell['cell_data'].strip()) for cell in rowlist) except Exception as e: print('Error in data: %s' % e)
def on_activated(self, view): current_syntax = view.settings().get('syntax') current_site = mw.get_view_site() # TODO: move method to check mediawiker view to mwutils if current_syntax is not None and current_syntax.endswith('Mediawiker/Mediawiki.tmLanguage'): # Mediawiki mode view.settings().set('mediawiker_is_here', True) view.settings().set('mediawiker_wiki_instead_editor', mw.get_setting('mediawiker_wiki_instead_editor')) view.settings().set('mediawiker_site', current_site)
def run(self, storage_name='mediawiker_pagelist'): # site_name_active = mw.get_setting('mediawiki_site_active') site_name_active = mw.get_view_site() mediawiker_pagelist = mw.get_setting(storage_name, {}) self.my_pages = mediawiker_pagelist.get(site_name_active, []) if self.my_pages: self.my_pages.reverse() # error 'Quick panel unavailable' fix with timeout.. sublime.set_timeout(lambda: self.window.show_quick_panel(self.my_pages, self.on_done), 1) else: sublime.status_message('List of pages for wiki "%s" is empty.' % (site_name_active))
def run(self, edit): self.delimiter = mw.get_setting('mediawiker_csvtable_delimiter', '|') table_header = '{|' table_footer = '|}' table_properties = ' '.join(['%s="%s"' % (prop, value) for prop, value in mw.get_setting('mediawiker_wikitable_properties', {}).items()]) cell_properties = ' '.join(['%s="%s"' % (prop, value) for prop, value in mw.get_setting('mediawiker_wikitable_cell_properties', {}).items()]) if cell_properties: cell_properties = ' %s | ' % cell_properties for region in self.view.sel(): table_data_dic_tmp = [] table_data = '' # table_data_dic_tmp = map(self.get_table_data, self.view.substr(region).split('\n')) table_data_dic_tmp = [self.get_table_data(x) for x in self.view.substr(region).split('\n')] # verify and fix columns count in rows if table_data_dic_tmp: cols_cnt = len(max(table_data_dic_tmp, key=len)) for row in table_data_dic_tmp: if row: while cols_cnt - len(row): row.append('') for row in table_data_dic_tmp: if row: if table_data: table_data += '\n|-\n' column_separator = '||' else: table_data += '|-\n' column_separator = '!!' for col in row: col_sep = column_separator if row.index(col) else column_separator[0] table_data += '%s%s%s ' % (col_sep, cell_properties, col) self.view.replace(edit, region, '%s %s\n%s\n%s' % (table_header, table_properties, table_data, table_footer))
def on_query_completions(self, view, prefix, locations): if view.settings().get('mediawiker_is_here', False): view = sublime.active_window().active_view() # internal links completions cursor_position = view.sel()[0].begin() line_region = view.line(view.sel()[0]) line_before_position = view.substr(sublime.Region(line_region.a, cursor_position)) internal_link = '' if line_before_position.rfind('[[') > line_before_position.rfind(']]'): internal_link = line_before_position[line_before_position.rfind('[[') + 2:] completions = [] if internal_link: word_cursor_min_len = mw.get_setting('mediawiker_page_prefix_min_length', 3) if len(internal_link) >= word_cursor_min_len: namespaces = [ns.strip() for ns in mw.get_setting('mediawiker_search_namespaces').split(',')] sitecon = mw.get_connect() pages = [] for ns in namespaces: pages = sitecon.allpages(prefix=internal_link, namespace=ns) for p in pages: print(p.name) # name - full page name with namespace # page_title - title of the page wo namespace # For (Main) namespace, shows [page_title (Main)], makes [[page_title]] # For other namespace, shows [page_title namespace], makes [[name|page_title]] if int(ns): ns_name = p.name.split(':')[0] page_insert = '%s|%s' % (p.name, p.page_title) else: ns_name = '(Main)' page_insert = p.page_title page_show = '%s\t%s' % (p.page_title, ns_name) completions.append((page_show, page_insert)) return completions
def run(self, action, title='', site_active=None): self.site_active = site_active self.action = action if self.action == 'mediawiker_show_page': if mw.get_setting('mediawiker_newtab_ongetpage'): self.run_in_new_window = True panel = mw.InputPanelPageTitle() panel.on_done = self.on_done panel.get_title(title) else: if self.action == 'mediawiker_reopen_page': self.action = 'mediawiker_show_page' title = title if title else mw.get_title() self.on_done(title)
def run(self, edit, title, password): is_skip_summary = mw.get_setting('mediawiker_skip_summary', False) sitecon = mw.get_connect(password) self.title = mw.get_title() if self.title: self.page = sitecon.Pages[self.title] if self.page.can('edit'): self.current_text = self.view.substr(sublime.Region(0, self.view.size())) if not is_skip_summary: # summary_message = 'Changes summary (%s):' % mw.get_setting('mediawiki_site_active') summary_message = 'Changes summary (%s):' % mw.get_view_site() self.view.window().show_input_panel(summary_message, '', self.on_done, None, None) else: self.on_done('') else: sublime.status_message('You have not rights to edit this page') else: sublime.status_message('Can\'t publish page with empty title') return
def run(self, edit, title, password): is_writable = False sitecon = mw.get_connect(password) is_writable, text = mw.get_page_text(sitecon, title) self.view.set_syntax_file('Packages/Mediawiker/Mediawiki.tmLanguage') self.view.settings().set('mediawiker_is_here', True) self.view.settings().set('mediawiker_wiki_instead_editor', mw.get_setting('mediawiker_wiki_instead_editor')) self.view.set_name(title) if is_writable: if not text: sublime.status_message('Wiki page %s is not exists. You can create new..' % (title)) text = '<!-- New wiki page: Remove this with text of the new page -->' # insert text self.view.erase(edit, sublime.Region(0, self.view.size())) self.view.run_command('mediawiker_insert_text', {'position': 0, 'text': text}) sublime.status_message('Page %s was opened successfully from %s.' % (title, mw.get_view_site())) self.view.set_scratch(True) # own is_changed flag instead of is_dirty for possib. to reset.. self.view.settings().set('is_changed', False)
def process(self, index): if index == 0: site_active_new = None site_active = mw.get_view_site() sites = mw.get_setting('mediawiki_site') host = sites[site_active]['host'] domain_first = '.'.join(host.split('.')[-2:]) # NOTE: only links like lang_prefix.site.com supported.. (like en.wikipedia.org) host_new = '%s.%s' % (self.lang_prefix, domain_first) # if host_new exists in settings we can open page for site in sites: if sites[site]['host'] == host_new: site_active_new = site break if site_active_new: # open page with force site_active_new sublime.active_window().run_command("mediawiker_page", {"title": self.page_name, "action": "mediawiker_show_page", "site_active": site_active_new}) else: sublime.status_message('Settings not found for host %s.' % (host_new)) elif index == 1: self.view.run_command('mediawiker_replace_text', {'text': self.page_name})
def run(self): self.is_hide_password = mw.get_setting('mediawiker_password_input_hide') self.hosts = mw.get_setting('mediawiki_site', {}) self.window.show_input_panel('Internal site name:', '', self.get_host, None, None)
def run(self): self.is_hide_password = mw.get_setting( 'mediawiker_password_input_hide') self.hosts = mw.get_setting('mediawiki_site', {}) self.window.show_input_panel('Internal site name:', '', self.get_host, None, None)
def run(self, edit, password, title=''): self.password = password self.image_prefix_min_lenght = mw.get_setting('mediawiker_image_prefix_min_length', 4) sublime.active_window().show_input_panel('Wiki image prefix (min %s):' % self.image_prefix_min_lenght, '', self.show_list, None, None)
def do_search(self, string_value): sitecon = mw.get_connect(self.password) namespace = mw.get_setting('mediawiker_search_namespaces') return sitecon.search(search=string_value, what='text', limit=self.search_limit, namespace=namespace)
def run(self): self.SNIPPET_CHAR = mw.get_setting('mediawiker_snippet_char') self.options = mw.get_setting('mediawiker_panel', {}) if self.options: office_panel_list = ['\t%s' % val['caption'] if val['type'] != 'snippet' else '\t%s %s' % (self.SNIPPET_CHAR, val['caption']) for val in self.options] self.window.show_quick_panel(office_panel_list, self.on_done)
def run(self, edit, title, password): self.sitecon = mw.get_connect(password) self.category_root = mw.get_category(mw.get_setting('mediawiker_category_root'))[1] sublime.active_window().show_input_panel('Wiki root category:', self.category_root, self.get_category_menu, None, None)