示例#1
0
    def page_open(self, title):

        if self.new_tab:
            view = sublime.active_window().new_file()
            view.settings().set('mediawiker_site', self.site_active)
        else:
            view = self.view

        is_writable = False
        sitecon = mw.get_connect()
        page = mw.get_page(sitecon, title)
        is_writable, text = mw.get_page_text(page)

        if is_writable or text:

            if is_writable and not text:
                mw.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
            view.run_command('mediawiker_insert_text', {'position': 0, 'text': text, 'with_erase': True})
            mw.status_message('Page [[%s]] was opened successfully from "%s".' % (title, mw.get_view_site()), replace=['[', ']'])
            mw.set_syntax(page=page)
            view.settings().set('mediawiker_is_here', True)
            view.settings().set('mediawiker_wiki_instead_editor', mw.get_setting('mediawiker_wiki_instead_editor'))
            view.set_name(title)

            view.set_scratch(True)
            # own is_changed flag instead of is_dirty for possib. to reset..
            view.settings().set('is_changed', False)
        else:
            sublime.message_dialog('You have not rights to view this page.')
            view.close()
示例#2
0
    def run(self, edit):
        is_process_post = True
        is_skip_summary = mw.get_setting('mediawiker_skip_summary', False)
        self.sitecon = mw.get_connect()
        self.title = mw.get_title()
        if self.title:
            self.page = mw.get_page(self.sitecon, self.title)

            if self.page.can('edit'):

                if mw.get_setting('mediawiki_validate_revision_on_post', True) and self.view.settings().get('page_revision', 0) != self.page.revision:
                    is_process_post = sublime.ok_cancel_dialog('Page was changed on server, post page anyway? If not, new revision will be opened in new tab.')

                if is_process_post:
                    self.current_text = self.view.substr(sublime.Region(0, self.view.size()))
                    if not is_skip_summary:
                        summary_message = 'Changes summary (%s):' % mw.get_view_site()
                        mw.set_timeout_async(self.view.window().show_input_panel(summary_message, '', self.on_done, None, None), 0)
                    else:
                        mw.set_timeout_async(self.on_done, 0)
                else:
                    self.view.window().run_command('mediawiker_page', {'action': 'mediawiker_reopen_page', 'new_tab': True})
            else:
                mw.status_message('You have not rights to edit this page')
        else:
            mw.status_message('Can\'t publish page with empty title')
            return
示例#3
0
    def on_query_completions(self, view, prefix, locations):
        if view.settings().get('mediawiker_is_here', False):
            INTERNAL_LINK_SPLITTER = u'|'
            NAMESPACE_SPLITTER = u':'
            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 INTERNAL_LINK_SPLITTER in internal_link:
                # cursor at custom url text zone..
                return []

            completions = []
            if internal_link:
                word_cursor_min_len = mw.get_setting('mediawiker_page_prefix_min_length', 3)
                ns_text = None
                ns_text_number = None

                if NAMESPACE_SPLITTER in internal_link:
                    ns_text, internal_link = internal_link.split(NAMESPACE_SPLITTER)

                if len(internal_link) >= word_cursor_min_len:
                    namespaces_search = [ns.strip() for ns in mw.get_setting('mediawiker_search_namespaces').split(',')]
                    self.sitecon = mw.get_connect()
                    if ns_text:
                        ns_text_number = self.get_ns_number(ns_text)

                    pages = []
                    for ns in namespaces_search:
                        if not ns_text or ns_text_number and int(ns_text_number) == int(ns):
                            pages = self.sitecon.allpages(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 = p.name.split(':')[0]
                                    page_name = p.name if not self.is_equal_ns(ns_text, ns_name) else p.name.split(':')[1]
                                    if ns in ('6', '14'):  # file, category
                                        page_insert = page_name
                                    else:
                                        page_insert = '%s|%s' % (page_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
        return []