0

I would like to update the Main_Page of our wiki from a script run by cron.

Apart from the page content itself, in pagecontent.old_text, what else do I need to update?

If I only update the "old_text" field, the new content is not displayed. I get the previous content, presumably from a cache somewhere. In LocalSettings.php I have $wgMainCacheType = CACHE_NONE;. So I guess that I need to also update something else in the Mediawiki database?

(In case it matters, this is with Mediawiki 1.31.10 on Debian 10 with Apache and PostgreSQL)

mivk
  • 13,452
  • 5
  • 76
  • 69

2 Answers2

1

Use maintenance/edit.php, the edit API, Pywikibot etc. Trying to do changes via direct DB manipulation is a rather bad idea.

Tgr
  • 27,442
  • 12
  • 81
  • 118
  • Yes, it might be risky to use the DB directly, particularly if an update changes something in the DB structure. But using the edit API or similar would create a new page revision at every update, which I don't want in this case of a daily update. – mivk Apr 10 '22 at 10:35
  • Just delete the old revision, there are scripts for that. – Tgr Apr 10 '22 at 11:54
1

Updating the timestamp in page.page_touched works to have the wiki show the new content.

This example is using a PostgreSQL database, so it might need some adjustments if used with the more common MySQL DB.

To update the text of a page identified by it's name, it is necessary to join the page, revision and pagecontent tables. This example updates a page named "Drafts":

UPDATE pagecontent
SET old_text = 'New page content'
FROM page, revision
WHERE page.page_title='Drafts'
  AND pagecontent.old_id=revision.rev_text_id
  AND page.page_latest=revision.rev_id;

And to update the page timestamp so that the wiki shows the new content:

UPDATE "page"
SET page_touched = now()
WHERE page_namespace = '0'
  AND page_title = 'Drafts';

An alternative which avoids tinkering with the database directly, is to use an extension like External Data. There are examples here to embed a text file in a page, and here to embed the output of a database query.

mivk
  • 13,452
  • 5
  • 76
  • 69