Exemplo n.º 1
0
    def run(self, edit):
        if mw.get_setting('offline_mode'):
            return

        is_process_post = True
        is_skip_summary = mw.get_setting('skip_summary', False)
        self.title = mw.get_title()
        if self.title:
            self.page = mw.api.get_page(self.title)

            if mw.api.page_can_edit(self.page):

                if mw.get_setting('validate_revision_on_post', True) and mw.props.get_view_setting(self.view, 'page_revision', 0) != mw.api.page_attr(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(mw.cmd('page'), {
                        'action': mw.cmd('show_page'),
                        'action_params': {'title': self.title, '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
Exemplo n.º 2
0
    def on_done_reason(self, reason):
        self.reason = reason

        message = '''
        Old name: "%s"
        New name: "%s"
        Reason: %s

        Leave a redirect behind?
        ''' % (self.title, self.new_title, self.reason)

        is_make_redirect = sublime.yes_no_cancel_dialog(message, 'Yes', 'No')

        if is_make_redirect != sublime.DIALOG_CANCEL:
            no_redirect = True if is_make_redirect == sublime.DIALOG_NO else False
            mw.api.page_move(self.page, self.new_title, self.reason, no_redirect)
            mw.status_message('Page [[%s]] was moved successfully to [[%s]], leave redirect: %s' % (self.title, self.new_title, not no_redirect))

            if not no_redirect:
                mw.status_message('Refreshing old page (redirect): [[%s]]' % self.title)
                self.view.window().run_command(mw.cmd('reopen_page'))
            else:
                mw.status_message('Closing old page: [[%s]]' % self.title)
                self.view.close()

            mw.status_message('Opening new page: [[%s]]' % self.new_title)
            sublime.set_timeout(
                lambda: sublime.active_window().run_command(mw.cmd('page'), {
                    'action': mw.cmd('show_page'),
                    'action_params': {'title': self.new_title, 'new_tab': True}
                }), 2)
Exemplo n.º 3
0
    def on_done_reason(self, reason):
        self.reason = reason

        message = '''
        Old name: "%s"
        New name: "%s"
        Reason: %s

        Leave a redirect behind?
        ''' % (self.title, self.new_title, self.reason)

        is_make_redirect = sublime.yes_no_cancel_dialog(message, 'Yes', 'No')

        if is_make_redirect != sublime.DIALOG_CANCEL:
            no_redirect = True if is_make_redirect == sublime.DIALOG_NO else False
            utils.api.page_move(self.page, self.new_title, self.reason, no_redirect)
            utils.status_message('Page [[%s]] was moved successfully to [[%s]], leave redirect: %s' % (self.title, self.new_title, not no_redirect))

            if not no_redirect:
                utils.status_message('Refreshing old page (redirect): [[%s]]' % self.title)
                self.view.window().run_command(utils.cmd('reopen_page'))
            else:
                utils.status_message('Closing old page: [[%s]]' % self.title)
                self.view.close()

            utils.status_message('Opening new page: [[%s]]' % self.new_title)
            sublime.set_timeout(
                lambda: sublime.active_window().run_command(utils.cmd('page'), {
                    'action': utils.cmd('show_page'),
                    'action_params': {'title': self.new_title, 'new_tab': True}
                }), 2)
Exemplo n.º 4
0
 def run(self):
     title = utils.get_title()
     section = utils.props.get_view_setting(self.window.active_view(), 'section', None)
     self.window.run_command(utils.cmd('page'), {
         'action': utils.cmd('show_page'),
         'action_params': {'title': title, 'new_tab': False, 'section': section}
     })
Exemplo n.º 5
0
    def run(self, edit):
        if utils.props.get_setting('offline_mode'):
            return

        is_process_post = True
        is_skip_summary = utils.props.get_setting('skip_summary', False)
        self.title = utils.get_title()
        if self.title:
            self.page = utils.api.get_page(self.title)

            if utils.api.page_can_edit(self.page):

                if utils.props.get_setting('validate_revision_on_post', True) and utils.props.get_view_setting(self.view, 'page_revision', 0) != utils.api.page_attr(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):' % utils.get_view_site()
                        utils.set_timeout_async(self.view.window().show_input_panel(summary_message, '', self.on_done, None, None), 0)
                    else:
                        utils.set_timeout_async(self.on_done, 0)
                else:
                    self.view.window().run_command(utils.cmd('page'), {
                        'action': utils.cmd('show_page'),
                        'action_params': {'title': self.title, 'new_tab': True}
                    })
            else:
                utils.status_message(utils.api.PAGE_CANNOT_EDIT_MESSAGE)
        else:
            utils.status_message('Can\'t publish page with empty title')
            return
Exemplo n.º 6
0
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        title = mw.get_title()
        self.window.run_command(mw.cmd('page'), {
            'action': mw.cmd('show_page'),
            'action_params': {'title': title, 'new_tab': False}
        })
Exemplo n.º 7
0
    def run(self):
        page = utils.api.get_page(utils.get_title())
        page_talk = utils.api.get_page_talk_page(page)

        if utils.api.page_attr(page, 'name') == utils.api.page_attr(page_talk, 'name'):
            sublime.message_dialog('There is a talk page already.')

        sublime.set_timeout(
            lambda: sublime.active_window().run_command(
                utils.cmd('page'), {
                    'action': utils.cmd('show_page'),
                    'action_params': {'title': utils.api.page_attr(page_talk, 'name'), 'new_tab': True}
                }
            ), 2)
Exemplo n.º 8
0
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        page = mw.api.get_page(mw.get_title())
        page_talk = mw.api.get_page_talk_page(page)

        if mw.api.page_attr(page, 'name') == mw.api.page_attr(page_talk, 'name'):
            sublime.message_dialog('There is a talk page already.')

        sublime.set_timeout(
            lambda: sublime.active_window().run_command(
                mw.cmd('page'), {
                    'action': mw.cmd('show_page'),
                    'action_params': {'title': mw.api.page_attr(page_talk, 'name'), 'new_tab': True}
                }
            ), 2)
Exemplo n.º 9
0
    def page_open(self, title):
        self.title = title

        if self.new_tab:
            view = sublime.active_window().new_file()
            utils.props.set_view_setting(view, 'site', self.site_active)
        else:
            view = self.view

        page = utils.api.call('get_page', title=self.title)
        utils.props.set_view_setting(view, 'section', self.section if self.section is not None else 0)

        if utils.api.page_can_edit(page):
            # can read and edit
            utils.props.set_view_setting(view, 'page_revision', utils.api.page_attr(page, 'revision'))
        elif not utils.api.page_can_read(page):
            # can not read and edit
            sublime.message_dialog(utils.api.PAGE_CANNOT_READ_MESSAGE)
            view.close()
            return
        elif not sublime.ok_cancel_dialog('%s Click OK button to view its source.' % utils.api.PAGE_CANNOT_EDIT_MESSAGE):
            # can not edit, but can read, but not want
            view.close()
            return

        text = utils.api.page_get_text(page, self.section)
        page_namespace = utils.api.page_attr(page, 'namespace')

        if not text:
            utils.status_message('Page [[%s]] is not exists. You can create new..' % (self.title))
            text = '<!-- New wiki page: Remove this with text of the new page -->'

        view.run_command(utils.cmd('insert_text'), {'position': 0, 'text': text, 'with_erase': True})

        if utils.props.get_site_setting(self.site_active, 'show_red_links'):
            utils.show_red_links(view, page)
        utils.status_message('Page [[%s]] was opened successfully from "%s".' % (self.title, utils.get_view_site()), replace=['[', ']'])
        utils.set_syntax(self.title, page_namespace)
        utils.props.set_view_setting(view, 'is_here', True)
        utils.props.set_view_setting(view, 'wiki_instead_editor', utils.props.get_setting('wiki_instead_editor'))
        view.set_name(self.title)
        view.set_scratch(True)
        # own is_changed flag instead of is_dirty for possib. to reset..
        utils.props.set_view_setting(view, 'is_changed', False)

        try:
            self.get_notifications()
        except Exception as e:
            utils.status_message('%s notifications exception: %s' % (p.PM, e))
Exemplo n.º 10
0
    def page_open(self, title):

        if self.new_tab:
            view = sublime.active_window().new_file()
            mw.props.set_view_setting(view, 'site', self.site_active)
        else:
            view = self.view

        page = mw.api.call('get_page', title=title)

        if mw.api.page_can_edit(page):
            # can read and edit
            mw.props.set_view_setting(view, 'page_revision', mw.api.page_attr(page, 'revision'))
        elif not mw.api.page_can_read(page):
            # can not read and edit
            sublime.message_dialog(mw.api.PAGE_CANNOT_READ_MESSAGE)
            view.close()
            return
        elif not sublime.ok_cancel_dialog('%s Click OK button to view its source.' % mw.api.PAGE_CANNOT_EDIT_MESSAGE):
            # can not edit, but can read, but not want
            view.close()
            return

        text = mw.api.page_get_text(page)
        page_namespace = mw.api.page_attr(page, 'namespace')

        if not text:
            mw.status_message('Page [[%s]] is not exists. You can create new..' % (title))
            text = '<!-- New wiki page: Remove this with text of the new page -->'

        view.run_command(mw.cmd('insert_text'), {'position': 0, 'text': text, 'with_erase': True})

        if mw.props.get_site_setting(self.site_active, 'show_red_links'):
            mw.show_red_links(view, page)
        mw.status_message('Page [[%s]] was opened successfully from "%s".' % (title, mw.get_view_site()), replace=['[', ']'])
        mw.set_syntax(title, page_namespace)
        mw.props.set_view_setting(view, 'is_here', True)
        mw.props.set_view_setting(view, 'wiki_instead_editor', mw.get_setting('wiki_instead_editor'))
        view.set_name(title)

        view.set_scratch(True)
        # own is_changed flag instead of is_dirty for possib. to reset..
        mw.props.set_view_setting(view, 'is_changed', False)

        try:
            self.get_notifications()
        except Exception as e:
            mw.status_message('%s notifications exception: %s' % (mw.PM, e))
Exemplo n.º 11
0
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        self.window.run_command(mw.cmd('page'), {"action": mw.cmd('publish_page')})
Exemplo n.º 12
0
 def get_notifications(self):
     is_unread_notify_exists = mw.api.exists_unread_notifications()
     if is_unread_notify_exists and sublime.ok_cancel_dialog('You have new notifications.'):
         self.view.window().run_command(mw.cmd('notifications'))
Exemplo n.º 13
0
 def run(self):
     self.window.run_command(utils.cmd('page'), {"action": utils.cmd('publish_page')})
Exemplo n.º 14
0
 def run(self):
     self.window.run_command(utils.cmd('page'), {
         "action": utils.cmd('show_page'),
         'action_params': {'by_section': True}
     })
Exemplo n.º 15
0
 def get_notifications(self):
     is_unread_notify_exists = utils.api.exists_unread_notifications()
     if is_unread_notify_exists and sublime.ok_cancel_dialog('You have new notifications.'):
         self.view.window().run_command(utils.cmd('notifications'))