Modify

Opened 7 years ago

Closed 7 years ago

Last modified 8 months ago

#1877 closed enhancement (fixed)

Take only last version of wiki pages

Reported by: ebzao+trac@… Owned by: anonymous
Priority: normal Component: WantedPagesMacro
Severity: minor Keywords:
Cc: Trac Release: 0.10

Description

Hi,

I've made this little patch to take only last version of wiki pages when searching for wanted pages. I think it's non-sense to make links used only in old version of wiki pages.

Perhaps there is a better SQL query to have this, I haven't found it ;-)

Index: wanted_pages.py
===================================================================
--- wanted_pages.py     (révision 2539)
+++ wanted_pages.py     (copie de travail)
@@ -13,7 +13,7 @@
 fancy_re = re.compile(FANCY)
 exclude_re = re.compile(EXCLUDE)

-wiki_sql = "SELECT name, text FROM wiki ORDER BY version"
+wiki_sql = "SELECT name, text FROM wiki ORDER BY version DESC"
 ticket_sql= """SELECT id, description FROM ticket
     UNION
     SELECT ticket, newvalue FROM ticket_change WHERE field='comment'
@@ -55,11 +55,14 @@
     def buildWikiText(self, showReferrers=False):
         texts = [] # list of referrer link, wiki-able text tuples
         wantedPages = {} # referrers indexed by page
+       wikiPages = [] # list of wikiPages seen
         db = self.env.get_db_cnx()

         for name, text in exec_wiki_sql(db):
-            self.index[name] = name
-            texts.append(('[wiki:%s]' % name, text))
+           if name not in wikiPages:
+              wikiPages.append(name)
+              self.index[name] = name
+              texts.append(('[wiki:%s]' % name, text))

         for id, text in exec_ticket_sql(db):
             texts.append(('#%s' % id, text))

Attachments (0)

Change History (5)

comment:1 Changed 7 years ago by jfrancis

  • Owner changed from jfrancis to anonymous
  • Status changed from new to assigned

Thanks for patch. I'll write some unit tests to expose the bug and integrate the patch in the next week.

comment:2 Changed 7 years ago by anonymous

  • Resolution set to fixed
  • Status changed from assigned to closed

integrated in [2725]. It took a while, but hey, I'm lazy

comment:3 Changed 7 years ago by kamil@…

  • Resolution fixed deleted
  • Status changed from closed to reopened

The implemented version is incorrect. The indentation level on the last two lines of the fix is wrong, so the plugin still adds all pages.
Currently it looks like this:

if name not in wikiPages:
    wikiPages.append(name)
self.index[name] = name
texts.append(('[wiki:%s]' % name, text))

but it should look like this:

if name not in wikiPages:
    wikiPages.append(name)
    self.index[name] = name
    texts.append(('[wiki:%s]' % name, text))

comment:4 Changed 7 years ago by jfrancis

  • Resolution set to fixed
  • Status changed from reopened to closed

Hmmmm. It appears it was my mistake. My editor inserted tabs when I needed space-tabs. There was a mixture of spaces and tabs that resulted in this code still running, but exactly was it was before.

In any case, it has been fixed in [2873]

comment:5 Changed 8 months ago by rjollos

  • Component changed from WantedPagesPlugin to WantedPagesMacro

Renaming plugin from WantedPagesPlugin to WantedPagesMacro.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.