def run(self, edit): if mw.get_setting('offline_mode'): return text = self.view.substr(sublime.Region(0, self.view.size())) # site = mw.get_setting('site').get(mw.get_view_site()) site = mw.conman.get_site() page_css = mw.api.call('get_page', title='MediaWiki:Common.css') text_css = mw.api.page_get_text(page_css) if text_css: common_css = ''' <style type="text/css"> %s </style> ''' % text_css else: common_css = '' host = site['host'] path = site['path'] head = '\n'.join(site['preview_custom_head'] or mw.get_setting('preview_head')) lang = mw.get_setting('preview_lang') self.page_id = '%s: %s' % (host, mw.get_title()) self.preview_file = mw.from_package('%s_preview_file.html' % mw.PML, name='User', posix=False, is_abs=True) site_http = 'https' if site['https'] else 'http' html_header_lines = [ '<!DOCTYPE html>', '<html>', '<head>', '%(head)s', '%(common_css)s' '</head>', '<body style="margin:20px;">' ] geshi_css = self.get_geshi_langs() head_tpl = Template(head) head_str = head_tpl.render(http=site_http, host=host, path=path, lang=lang, geshi_css=geshi_css) html_header = '\n'.join(html_header_lines) % {'head': head_str, 'common_css': common_css} html_footer = '</body></html>' html = mw.api.call('get_parse_result', text=text, title=mw.get_title()) html = html.replace('"//', '"%s://' % site_http) # internal links: images,.. html = html.replace('"/', '"%s://%s/' % (site_http, host)) # internal local links: images,.. page_id_old = self.get_page_id() page = self.generate_preview(html_header, html, html_footer) if self.page_id != page_id_old or mw.props.get_view_setting(self.view, 'autoreload') == 0: webbrowser.open('file:///%s' % page)
def run(self, edit): if utils.props.get_setting('offline_mode'): return text = self.view.substr(sublime.Region(0, self.view.size())) # site = utils.props.get_setting('site').get(utils.get_view_site()) site = utils.conman.get_site() page_css = utils.api.call('get_page', title='MediaWiki:Common.css') text_css = utils.api.page_get_text(page_css) if text_css: common_css = ''' <style type="text/css"> %s </style> ''' % text_css else: common_css = '' host = site['host'] path = site['path'] head = '\n'.join(site['preview_custom_head'] or utils.props.get_setting('preview_head')) lang = utils.props.get_setting('preview_lang') self.page_id = '%s: %s' % (host, utils.get_title()) self.preview_file = utils.p.from_package('%s_preview_file.html' % utils.p.PML, name='User', posix=False, is_abs=True) site_http = 'https' if site['https'] else 'http' html_header_lines = [ '<!DOCTYPE html>', '<html>', '<head>', '%(head)s', '%(common_css)s' '</head>', '<body style="margin:20px;">' ] geshi_css = self.get_geshi_langs() head_tpl = Template(head) head_str = head_tpl.render(http=site_http, host=host, path=path, lang=lang, geshi_css=geshi_css) html_header = '\n'.join(html_header_lines) % {'head': head_str, 'common_css': common_css} html_footer = '</body></html>' html = utils.api.call('get_parse_result', text=text, title=utils.get_title()) html = html.replace('"//', '"%s://' % site_http) # internal links: images,.. html = html.replace('"/', '"%s://%s/' % (site_http, host)) # internal local links: images,.. page_id_old = self.get_page_id() page = self.generate_preview(html_header, html, html_footer) if self.page_id != page_id_old or utils.props.get_view_setting(self.view, 'autoreload') == 0: webbrowser.open('file:///%s' % page)
def run(self, edit): self.item = None red_link_icon = utils.props.get_setting('red_link_icon') page = utils.api.get_page(utils.get_title()) linksgen = utils.api.get_page_links(page, generator=True) self.p = par.Parser(self.view) self.p.register_all(par.Comment, par.Pre, par.Source, par.Nowiki, par.Link, par.TemplateAttribute, par.Template) if not self.p.parse(): return self.menu_items = [ '%s %s' % (utils.api.page_attr( v, 'name'), red_link_icon if not v.exists else ' ') for v in linksgen ] self.find_items = [ v.strip_namespace(utils.api.page_attr(v, 'name')) for v in linksgen ] self.open_items = [utils.api.page_attr(v, 'name') for v in linksgen] self.ns_items = [utils.api.page_attr(v, 'namespace') for v in linksgen] if self.menu_items: sublime.set_timeout( lambda: self.view.window().show_quick_panel( self.menu_items, self.on_select), 1) else: utils.status_message('Internal links was not found.')
def run(self, edit): if utils.props.get_setting('offline_mode'): return title = utils.get_title() view_text = self.view.substr(sublime.Region(0, self.view.size())) page = utils.api.call('get_page', title=title) text = utils.api.page_get_text(page) if not text: # Uh, well, what if it does exist, but it is empty? msg = 'Wiki page %s does not exists.' % (title, ) utils.status_message(msg) else: new_lines = view_text.splitlines(True) old_lines = text.splitlines(True) diff_lines = difflib.unified_diff(old_lines, new_lines, fromfile="Server revision", tofile="Buffer view") diff_text = ''.join(diff_lines) if not diff_text: utils.status_message('Page versions has no differencies') else: syntax_filename = 'Diff.sublime-syntax' if pythonver >= 3 else 'Diff.tmLanguage' syntax = utils.p.from_package(syntax_filename, name='Diff') utils.status_message(diff_text, panel_name='Show differences', syntax=syntax, new=True)
def run(self, edit): if mw.get_setting('offline_mode'): return title = mw.get_title() view_text = self.view.substr(sublime.Region(0, self.view.size())) page = mw.api.call('get_page', title=title) text = mw.api.page_get_text(page) if not text: # Uh, well, what if it does exist, but it is empty? msg = 'Wiki page %s does not exists.' % (title,) mw.status_message(msg) else: new_lines = view_text.splitlines(True) old_lines = text.splitlines(True) diff_lines = difflib.unified_diff(old_lines, new_lines, fromfile="Server revision", tofile="Buffer view") diff_text = ''.join(diff_lines) if not diff_text: mw.status_message('Page versions has no differencies') else: syntax_filename = 'Diff.sublime-syntax' if pythonver >= 3 else 'Diff.tmLanguage' syntax = mw.from_package(syntax_filename, name='Diff') mw.status_message(diff_text, panel_name='Show differences', syntax=syntax, new=True)
def run(self, edit): title = mw.get_title() sitecon = mw.get_connect() self.mw_get_page_backlinks(sitecon, title) if self.links: sublime.active_window().show_quick_panel(self.links, self.on_done) else: mw.status_message("Unable to find links to this page")
def run(self, edit): if mw.get_setting('offline_mode'): return title = mw.get_title() self.mw_get_page_backlinks(title) if self.links: sublime.active_window().show_quick_panel(self.links, self.on_done) else: mw.status_message('Unable to find links to this page')
def run(self, edit): if utils.props.get_setting('offline_mode'): return title = utils.get_title() self.mw_get_page_backlinks(title) if self.links: sublime.active_window().show_quick_panel(self.links, self.on_done) else: utils.status_message('Unable to find links to this page')
def run(self, edit): sitecon = mw.get_connect() selected_text = self.view.substr(self.view.sel()[0]).strip() title = selected_text if selected_text else mw.get_title() self.mw_get_page_langlinks(sitecon, title) self.lang_prefixes = [] for lang_prefix in self.links.keys(): self.lang_prefixes.append(lang_prefix) self.links_names = ['%s: %s' % (lp, self.links[lp]) for lp in self.lang_prefixes] if self.links_names: sublime.active_window().show_quick_panel(self.links_names, self.on_done) else: mw.status_message('Unable to find laguage links for "%s"' % title)
def run(self, edit): self.item = None page = utils.api.get_page(utils.get_title()) linksgen = utils.api.get_page_extlinks(page) self.p = par.Parser(self.view) self.p.register_all(par.Comment, par.Pre, par.Source, par.Nowiki, par.Link, par.ExternalLink) if not self.p.parse(): return self.items_menu = [self.link_for_menu(l) for l in linksgen] self.items_find = [l.split('#')[0] for l in linksgen] self.items_open = [l for l in linksgen] if self.items_menu: sublime.set_timeout(lambda: self.view.window().show_quick_panel(self.items_menu, self.on_select), 1) else: utils.status_message('No external links was found.')
def run(self, edit): if mw.get_setting('offline_mode'): return self.item = None page = mw.api.get_page(mw.get_title()) linksgen = mw.api.get_page_extlinks(page) self.p = par.Parser(self.view) self.p.register_all(par.Comment, par.Pre, par.Source, par.Link, par.ExternalLink) if not self.p.parse(): return self.items_menu = [self.link_for_menu(l) for l in linksgen] self.items_find = [l.split('#')[0] for l in linksgen] self.items_open = [l for l in linksgen] if self.items_menu: sublime.set_timeout(lambda: self.view.window().show_quick_panel(self.items_menu, self.on_select), 1) else: mw.status_message('No external links was found.')
def run(self, edit): if utils.props.get_setting('offline_mode'): return selected_text = self.view.substr(self.view.sel()[0]).strip() title = selected_text if selected_text else utils.get_title() self.mw_get_page_langlinks(title) self.lang_prefixes = [] for lang_prefix in self.links.keys(): self.lang_prefixes.append(lang_prefix) self.links_names = [ '%s: %s' % (lp, self.links[lp]) for lp in self.lang_prefixes ] if self.links_names: sublime.active_window().show_quick_panel(self.links_names, self.on_done) else: utils.status_message('Unable to find laguage links for "%s"' % title)
def run(self, edit): if mw.get_setting('offline_mode'): return self.item = None red_link_icon = mw.get_setting('red_link_icon') page = mw.api.get_page(mw.get_title()) linksgen = mw.api.get_page_links(page, generator=True) self.p = par.Parser(self.view) self.p.register_all(par.Comment, par.Pre, par.Source, par.Link, par.TemplateAttribute, par.Template) if not self.p.parse(): return self.menu_items = ['%s %s' % (mw.api.page_attr(v, 'name'), red_link_icon if not v.exists else ' ') for v in linksgen] self.find_items = [v.strip_namespace(mw.api.page_attr(v, 'name')) for v in linksgen] self.open_items = [mw.api.page_attr(v, 'name') for v in linksgen] self.ns_items = [mw.api.page_attr(v, 'namespace') for v in linksgen] if self.menu_items: sublime.set_timeout(lambda: self.view.window().show_quick_panel(self.menu_items, self.on_select), 1) else: mw.status_message('Internal links was not found.')
def run(self, edit): page = utils.api.get_page(utils.get_title()) utils.process_red_links(self.view, page)
def run(self, edit): sitecon = mw.get_connect() text = self.view.substr(sublime.Region(0, self.view.size())) site_active = mw.get_view_site() site_list = mw.get_setting('mediawiki_site') host = site_list[site_active]['host'] path = site_list[site_active]['path'] head_default = mw.get_setting('mediawiki_preview_head') head = '\n'.join(site_list[site_active].get('preview_custom_head', head_default)) lang = mw.get_setting('mediawiki_preview_lang', 'en') preview_file = mw.get_setting('mediawiki_preview_file', 'Wiki_page_preview_') site_http = 'https' if site_list[site_active].get('https', False) else 'http' html_header_lines = [ '<!DOCTYPE html>', '<html>', '<head>', '%(head)s', '</head>', '<body style="margin:20px;">' ] geshi_css = self.get_geshi_langs() head_tpl = Template(head) head_str = head_tpl.render(http=site_http, host=host, path=path, lang=lang, geshi_css=geshi_css) html_header = '\n'.join(html_header_lines) % {'head': head_str} html_footer = '</body></html>' html = sitecon.parse(text=text, title=mw.get_title(), disableeditsection=True).get('text', {}).get('*', '') html = html.replace('"//', '"%s://' % site_http) # internal links: images,.. html = html.replace('"/', '"%s://%s/' % (site_http, host)) # internal local links: images,.. if preview_file.endswith('.html'): preview_file = os.path.join(sublime.packages_path(), 'User', preview_file) # fixed file in User folder if pythonver >= 3: with open(preview_file, 'w', encoding='utf-8') as tf: tf.write(html_header) tf.write(html) tf.write(html_footer) else: with open(preview_file, 'w') as tf: tf.write(html_header) tf.write(html.encode('utf-8')) tf.write(html_footer) html_view = sublime.active_window().find_open_file(preview_file) if html_view: sublime.active_window().focus_view(html_view) else: sublime.active_window().open_file(preview_file) webbrowser.open(tf.name) else: # temporary file if pythonver >= 3: with tempfile.NamedTemporaryFile(mode='w+t', suffix='.html', prefix=preview_file, dir=None, delete=False, encoding='utf-8') as tf: tf.write(html_header) tf.write(html) tf.write(html_footer) else: with tempfile.NamedTemporaryFile(mode='w+t', suffix='.html', prefix=preview_file, dir=None, delete=False) as tf: tf.write(html_header) tf.write(html.encode('utf-8')) tf.write(html_footer) webbrowser.open(tf.name)
def on_query_completions(self, view, prefix, locations): if utils.props.get_view_setting( view, 'is_here') and not utils.props.get_setting('offline_mode'): view = sublime.active_window().active_view() # internal links completions cursor_position = locations[0] # 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:] if utils.api.INTERNAL_LINK_SPLITTER in internal_link: # cursor at custom url text zone.. return [] completions = [] if internal_link: word_cursor_min_len = utils.props.get_setting( 'page_prefix_min_length', 3) ns_text = None ns_text_number = None if utils.api.NAMESPACE_SPLITTER in internal_link: ns_text, internal_link = internal_link.split( utils.api.NAMESPACE_SPLITTER) if len(internal_link) >= word_cursor_min_len: namespaces_search = [ ns.strip() for ns in utils.props.get_setting( 'search_namespaces').split(',') ] if ns_text: ns_text_number = utils.api.call('get_namespace_number', name=ns_text) if internal_link.startswith('/'): internal_link = '%s%s' % (utils.get_title(), internal_link) # TODO: recheck completions pages = [] for ns in namespaces_search: if not ns_text or ns_text_number and int( ns_text_number) == int(ns): pages = utils.api.call('get_pages', prefix=internal_link, namespace=ns) for p in pages: # 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 Image, Category namespaces, shows [page_title namespace], makes [[name]] # For other namespace, shows [page_title namespace], makes [[name|page_title]] if int(ns): ns_name = utils.api.page_attr( p, 'namespace_name') page_name = utils.api.page_attr( p, 'name') if not utils.api.is_equal_ns( ns_text, ns_name) else utils.api.page_attr( p, 'page_title') if int(ns) in ( utils.api.CATEGORY_NAMESPACE, utils.api.IMAGE_NAMESPACE): page_insert = page_name else: page_insert = '%s|%s' % ( page_name, utils.api.page_attr( p, 'page_title')) else: ns_name = '(Main)' page_insert = utils.api.page_attr( p, 'page_title') page_show = '%s\t%s' % (utils.api.page_attr( p, 'page_title'), ns_name) completions.append((page_show, page_insert)) return completions return []
def run(self): title = utils.get_title() utils.save_mypages(title=title, storage_name='favorites')
def on_hover_internal_link(view, point): def on_navigate(link): page_name = link.split(':', 1)[-1].replace(' ', '_') if link.startswith('open'): view.window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': page_name } }) elif link.startswith('browse'): url = utils.get_page_url(page_name) webbrowser.open(url) elif link.startswith('get_image'): webbrowser.open(page_name) popup_flags = get_popup_flags(view) if popup_flags is None: return p = par.Parser(view) p.register_all(par.Comment, par.Link, par.Pre, par.Source, par.Nowiki) if not p.parse(): return links = p.links for l in links: if l.region.contains(point): if l.name: page_name = l.name if l.name.startswith('/'): # subpage page_name = '%s%s' % (utils.get_title(), l.name) page = utils.api.get_page(page_name) css_class = None if page.exists else 'redlink' page_talk = utils.api.get_page_talk_page(page) css_class_talk = None if page_talk.exists else 'redlink' img_data = None if utils.props.get_setting('show_image_in_popup'): try: img_data, img_size, img_url = utils.api.call( 'get_image', title=page_name, thumb_size=utils.props.get_setting( 'popup_image_size')) except: pass h = 'Page "%s"' % html.span( page_name, css_class=css_class ) if not img_data else 'File "%s"' % utils.api.page_attr( page, 'page_title') content = [ html.h(lvl=4, title=h), html.img(uri=img_data) if img_data else '', html.br(cnt=2) if img_data else '', html.join(html.link('open:%s' % page_name, 'Open' if page.exists else 'Create', css_class=css_class), html.link('browse:%s' % page_name, 'View in browser', css_class=css_class), html.link('get_image:%s' % img_url, 'View image in browser') if img_data else '', char=html.span('|', css_class='wide')), html.br(cnt=1), html.join(html.link( 'open:%s' % utils.api.page_attr(page_talk, 'name'), 'Open talk page' if page_talk.exists else 'Create talk page', css_class=css_class_talk), html.link('browse:%s' % utils.api.page_attr(page_talk, 'name'), 'View talk page in browser', css_class=css_class_talk), char=html.span('|', css_class='wide')) ] content_html = html.build(content) view.show_popup(content=content_html, location=point, max_width=img_size + 150 if img_data else 800, max_height=img_size + 150 if img_data else 600, flags=popup_flags, on_navigate=on_navigate) return True return False
def run(self): title = mw.get_title() mw.save_mypages(title=title, storage_name='mediawiker_favorites')