Exemple #1
0
 def process(self, index):
     if index == 0:
         site_active_new = None
         site_active = utils.get_view_site()
         sites = utils.props.get_setting('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(
                 utils.cmd('page'), {
                     'action': utils.cmd('show_page'),
                     'action_params': {
                         'title': self.page_name,
                         'site_active': site_active_new
                     }
                 })
         else:
             utils.status_message('Settings not found for host %s.' %
                                  (host_new))
     elif index == 1:
         self.view.run_command(utils.cmd('replace_text'),
                               {'text': self.page_name})
Exemple #2
0
 def run(self):
     url = utils.get_page_url()
     if url:
         webbrowser.open(url)
     else:
         utils.status_message('Can\'t open page with empty title')
         return
Exemple #3
0
 def run(self):
     url = mw.get_page_url()
     if url:
         webbrowser.open(url)
     else:
         mw.status_message('Can\'t open page with empty title')
         return
Exemple #4
0
    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.')
Exemple #5
0
    def setup_finish(self):
        self.hosts[self.site_name] = self.site
        mw.set_setting('mediawiki_site', self.hosts)

        if sublime.ok_cancel_dialog('Activate this host?'):
            mw.set_setting("mediawiki_site_active", self.site_name)

        mw.status_message('Setup finished.')
Exemple #6
0
    def run(self, edit):
        if pythonver < 3:
            utils.status_message(
                'Commands "Show red links/Hide red links" supported in Sublime text 3 only.'
            )
            return

        self.view.erase_phantoms('redlink')
Exemple #7
0
 def run(self, storage_name='pagelist'):
     site_name_active = utils.get_view_site()
     pagelist = utils.props.get_setting(storage_name, {})
     self.my_pages = pagelist.get(site_name_active, [])
     if self.my_pages:
         self.my_pages.reverse()
         sublime.set_timeout(lambda: self.window.show_quick_panel(self.my_pages, self.on_done), 1)
     else:
         utils.status_message('List of pages for wiki "%s" is empty.' % (site_name_active))
Exemple #8
0
 def run(self, edit):
     self.items = []
     self.regions = []
     self.regions = mw.get_internal_links_regions(self.view)
     self.items = [x[0] for x in self.regions]
     if self.items:
         sublime.set_timeout(lambda: self.view.window().show_quick_panel(self.items, self.on_select), 1)
     else:
         mw.status_message('No internal links was found.')
Exemple #9
0
 def run(self, storage_name='pagelist'):
     site_name_active = mw.get_view_site()
     pagelist = mw.get_setting(storage_name, {})
     self.my_pages = pagelist.get(site_name_active, [])
     if self.my_pages:
         self.my_pages.reverse()
         sublime.set_timeout(lambda: self.window.show_quick_panel(self.my_pages, self.on_done), 1)
     else:
         mw.status_message('List of pages for wiki "%s" is empty.' % (site_name_active))
Exemple #10
0
 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:
         mw.status_message('Error in data: %s' % e)
    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):
        if mw.get_setting('offline_mode'):
            return

        url = mw.get_page_url()
        if url:
            webbrowser.open(url)
        else:
            mw.status_message('Can\'t open page with empty title')
            return
Exemple #13
0
 def run(self, edit):
     # TODO: use API..
     self.items = []
     self.regions = []
     self.regions = self.view.find_all(self.pattern)
     self.items = [self.get_header(x) for x in self.regions]
     self.urls = [self.get_url(x) for x in self.regions]
     if self.items:
         sublime.set_timeout(lambda: self.view.window().show_quick_panel(self.items, self.on_select), 1)
     else:
         mw.status_message('No external links was found.')
 def on_done(self, idx):
     if idx >= 0:
         template = mw.api.get_page('Template:%s' % self.templates_names[idx])
         if mw.api.page_can_read(template):
             text = mw.api.page_get_text(page=template)
             params_text = self.get_template_params(text)
             index_of_cursor = self.view.sel()[0].begin()
             template_text = '{{%s%s}}' % (self.templates_names[idx], params_text)
             self.view.run_command(mw.cmd('insert_text'), {'position': index_of_cursor, 'text': template_text})
         else:
             mw.status_message('')
Exemple #15
0
    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')
Exemple #16
0
    def command_run(self):

        pre_sitecon = mw.get_connect()
        # TODO: refact.. now: setup connection here.. next steps will reuse it.. else exit..
        #   otherwise we have trying to connect 2 times if connection unavailable (command, then notif..)
        if pre_sitecon:
            self.window.active_view().run_command(self.action, self.action_params)
            try:
                self.get_notifications()
            except Exception as e:
                mw.status_message('Mediawiker exception: %s' % e)
    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')
Exemple #18
0
 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:
         mw.status_message('List of pages for wiki "%s" is empty.' % (site_name_active))
Exemple #19
0
 def on_done(self, file_descr=''):
     if file_descr:
         self.file_descr = file_descr
     else:
         self.file_descr = '%s as %s' % (os.path.basename(self.file_path), self.file_destname)
     try:
         with open(self.file_path, 'rb') as f:
             mw.api.call('process_upload', file_handler=f, filename=self.file_destname, description=self.file_descr)
         mw.status_message('File %s successfully uploaded to wiki as %s' % (self.file_path, self.file_destname))
     except IOError as e:
         sublime.message_dialog('Upload io error: %s' % e)
     except Exception as e:
         sublime.message_dialog('Upload error: %s' % e)
Exemple #20
0
 def on_done(self, file_descr=''):
     sitecon = mw.get_connect()
     if file_descr:
         self.file_descr = file_descr
     else:
         self.file_descr = '%s as %s' % (os.path.basename(self.file_path), self.file_destname)
     try:
         with open(self.file_path, 'rb') as f:
             sitecon.upload(f, self.file_destname, self.file_descr)
         mw.status_message('File %s successfully uploaded to wiki as %s' % (self.file_path, self.file_destname))
     except IOError as e:
         sublime.message_dialog('Upload io error: %s' % e)
     except Exception as e:
         sublime.message_dialog('Upload error: %s' % e)
Exemple #21
0
    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)
Exemple #22
0
 def getrow(self, delimiter, rowlist=None):
     if rowlist is None:
         rowlist = []
     cell_properties = ' '.join([
         '%s="%s"' % (prop, value)
         for prop, value in utils.props.get_setting(
             '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:
         utils.status_message('Error in data: %s' % e)
Exemple #23
0
 def on_done(self, idx):
     if idx >= 0:
         template = utils.api.get_page('Template:%s' %
                                       self.templates_names[idx])
         if utils.api.page_can_read(template):
             text = utils.api.page_get_text(page=template)
             params_text = self.get_template_params(text)
             index_of_cursor = self.view.sel()[0].begin()
             template_text = '{{%s%s}}' % (self.templates_names[idx],
                                           params_text)
             self.view.run_command(utils.cmd('insert_text'), {
                 'position': index_of_cursor,
                 'text': template_text
             })
         else:
             utils.status_message('')
Exemple #24
0
 def on_done(self, index):
     if index >= 0:
         # escape from quick panel return -1
         try:
             action_type = self.options[index]['type']
             action_value = self.options[index]['value']
             if action_type == 'snippet':
                 # run snippet
                 self.window.active_view().run_command("insert_snippet", {"name": action_value})
             elif action_type == 'window_command':
                 # run window command
                 self.window.run_command(action_value)
             elif action_type == 'text_command':
                 # run text command
                 self.window.active_view().run_command(action_value)
         except ValueError as e:
             utils.status_message(e)
Exemple #25
0
 def on_done(self, index):
     if index >= 0:
         # escape from quick panel return -1
         try:
             action_type = self.options[index]['type']
             action_value = self.options[index]['value']
             if action_type == 'snippet':
                 # run snippet
                 self.window.active_view().run_command("insert_snippet", {"name": action_value})
             elif action_type == 'window_command':
                 # run window command
                 self.window.run_command(action_value)
             elif action_type == 'text_command':
                 # run text command
                 self.window.active_view().run_command(action_value)
         except ValueError as e:
             mw.status_message(e)
Exemple #26
0
    def run(self, edit):
        selection = self.view.sel()
        table_region = None

        if not self.view.substr(selection[0]):
            table_region = self.table_getregion()
        else:
            table_region = selection[0]  # only first region will be proceed..

        if table_region:
            text = self.view.substr(table_region)
            text = self.table_fixer(text)
            self.view.replace(edit, table_region, self.table_get(text))
            # Turn on TableEditor
            try:
                self.view.run_command('table_editor_enable_for_current_view', {'prop': 'enable_table_editor'})
            except Exception as e:
                mw.status_message('Need to correct install plugin TableEditor: %s' % e)
Exemple #27
0
    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.')
Exemple #28
0
        def on_modified(self):
            if mw.props.get_view_setting(self.view, 'is_here'):
                self.view.hide_popup()
                try:
                    ch_cnt = mw.props.get_view_setting(self.view, 'autoreload')
                    if ch_cnt:
                        if not self.cnt:
                            self.cnt = self.view.change_count()

                        cnt_delta = self.view.change_count() - self.cnt
                        if cnt_delta > ch_cnt:
                            sublime.status_message('Autoreload: Generating preview..')
                            sublime.active_window().run_command(mw.cmd('preview'))
                            self.cnt = None
                        else:
                            sublime.status_message('\nAutoreload: change %s of %s..' % (cnt_delta, ch_cnt))
                except Exception as e:
                    mw.status_message('Preview exception: %s' % e)
Exemple #29
0
 def on_done(self, file_descr=''):
     if file_descr:
         self.file_descr = file_descr
     else:
         self.file_descr = '%s as %s' % (os.path.basename(
             self.file_path), self.file_destname)
     try:
         is_success = self.upload()
         if is_success:
             utils.status_message(
                 'File %s successfully uploaded to wiki as %s' %
                 (self.file_path, self.file_destname))
         else:
             utils.status_message(
                 'Error while trying to upload file %s to wiki as %s' %
                 (self.file_path, self.file_destname))
     except IOError as e:
         sublime.message_dialog('Upload io error: %s' % e)
     except Exception as e:
         sublime.message_dialog('Upload error: %s' % e)
Exemple #30
0
    def run(self, edit):
        selection = self.view.sel()
        table_region = None

        if not self.view.substr(selection[0]):
            table_region = self.table_getregion()
        else:
            table_region = selection[0]  # only first region will be proceed..

        if table_region:
            text = self.view.substr(table_region)
            text = self.table_fixer(text)
            self.view.replace(edit, table_region, self.table_get(text))
            # Turn on TableEditor
            try:
                self.view.run_command('table_editor_enable_for_current_view',
                                      {'prop': 'enable_table_editor'})
            except Exception as e:
                utils.status_message(
                    'Need to correct install plugin TableEditor: %s' % e)
Exemple #31
0
    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
        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.')
Exemple #33
0
    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)
Exemple #34
0
    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):
        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.')
Exemple #36
0
 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", {
                 'action': 'mediawiker_show_page',
                 'action_params': {'title': self.page_name, 'site_active': site_active_new}
             })
         else:
             mw.status_message('Settings not found for host %s.' % (host_new))
     elif index == 1:
         self.view.run_command('mediawiker_replace_text', {'text': self.page_name})
Exemple #37
0
        def on_modified(self):
            if utils.props.get_view_setting(self.view, 'is_here'):
                self.view.hide_popup()
                try:
                    ch_cnt = utils.props.get_view_setting(
                        self.view, 'autoreload')
                    if ch_cnt:
                        if not self.cnt:
                            self.cnt = self.view.change_count()

                        cnt_delta = self.view.change_count() - self.cnt
                        if cnt_delta > ch_cnt:
                            utils.status_message(
                                'Autoreload: Generating preview..')
                            sublime.active_window().run_command(
                                utils.cmd('preview'))
                            self.cnt = None
                        else:
                            utils.status_message(
                                '\nAutoreload: change %s of %s..' %
                                (cnt_delta, ch_cnt))
                except Exception as e:
                    utils.status_message('Preview exception: %s' % e)
Exemple #38
0
    def on_site_selected(self, index):
        if index < 0:
            return
        self.src_site_name = self.site_keys[index]

        # get remote page
        src_api = utils.PreAPI(conman=utils.conman,
                               site_name=self.src_site_name)
        src_page = src_api.call('get_page', title=self.title)
        if not src_api.page_can_read(src_page):
            sublime.message_dialog(utils.api.PAGE_CANNOT_READ_MESSAGE)
            return
        text = src_api.page_get_text(src_page)

        cnt = len([i for i in src_page.images()])
        if sublime.ok_cancel_dialog('Copy %s images from source page?' % cnt):
            images = src_page.images()
            for image in images:
                file_name = src_api.page_attr(image, 'page_title')
                is_success = utils.api.call(
                    'process_upload',
                    url=image.imageinfo['url'],
                    filename=file_name,
                    description='Image for page "%s", copied from "%s"' %
                    (self.title, self.src_site_name))
                if is_success:
                    utils.status_message(
                        'File %s successfully copied to wiki' % (file_name))
                else:
                    utils.status_message(
                        'Error while trying to copy file %s to wiki' %
                        (file_name))

        cnt = len([i for i in src_page.templates()])
        if sublime.ok_cancel_dialog(
                'Copy %s templates (only first level) from source page?' %
                cnt):
            templates = src_page.templates()
            for template in templates:
                template_name = src_api.page_attr(template, 'page_title')
                template_text = src_api.page_get_text(template)
                is_success = utils.api.save_page(
                    page=template,
                    text=template_text,
                    summary='Template copy from %s for page %s' %
                    (self.src_site_name, self.title),
                    mark_as_minor=False)
                if not is_success:
                    utils.status_message(
                        'There was an error while trying to copy template [[%s]] to wiki "%s".'
                        % (template_name, utils.get_view_site()),
                        replace=['[', ']'])
                else:
                    utils.status_message(
                        'Template [[%s]] was successfully copied to wiki "%s".'
                        % (self.title, utils.get_view_site()),
                        replace=['[', ']'])

        # get local page
        page = utils.api.call('get_page', title=self.title)
        is_success = utils.api.save_page(page=page,
                                         text=text,
                                         summary='Page copy from %s' %
                                         self.src_site_name,
                                         mark_as_minor=False)
        if not is_success:
            utils.status_message(
                'There was an error while trying to copy page [[%s]] to wiki "%s".'
                % (self.title, utils.get_view_site()),
                replace=['[', ']'])
            return
        else:
            utils.status_message(
                'Page [[%s]] was successfully copied to wiki "%s".' %
                (self.title, utils.get_view_site()),
                replace=['[', ']'])

        self.view.window().run_command(
            utils.cmd('page'), {
                'action': utils.cmd('show_page'),
                'action_params': {
                    'title': self.title,
                    'new_tab': True
                }
            })