Hi,

I have one change to the code from before - it was unfortunately saving the semantic data twice for pages that are newly-created. The new version of smwfUpdateSemanticData() is:

function smwfUpdateSemanticData($links_update) {
        $title = $links_update->mTitle;
        if ( smwfIsSemanticsProcessed($title->getNamespace()) && ! SMWFactbox::isNewArticle() ) {
                SMWFactbox::storeData(true);
        }
        return true;
}

On the bright side, I do have more confidence now that this is a correct solution in general.

-Yaron


On Tue, May 13, 2008 at 11:27 AM, Yaron Koren <yaron57@gmail.com> wrote:
Hi,

I may have found a fix for the problem of pages not having their semantic data refreshed when templates they include get their own semantic markup changed. As you may know, this has been a fairly big problem for users, and constitutes (I think) most of the need for the "refreshData" script.

I discovered MediaWiki "jobs" recently, while working on my Replace Text extension. They're the MediaWiki equivalent of cron jobs, and it turns out that they are how automatic updating of categories happens - if the set of categories that a template includes is changed, a "job" is created for each page that uses that template, to update that page's category links when the server has time. (If you ever switch the category on a template, you can see the new category slowly getting filled up if you keep refreshing that category's page.)

Anyway, the code for this job can be found at /includes/RefreshLinksJob.php and /includes/LinksUpdate.php, and there's a hook there, 'LinksUpdateConstructed', that's called for every page that's refreshed when a template is saved. I added some code to use this hook to do semantic-data refreshing, and it works for me. In the SMW code, in /includes/SMW_GlobalFunctions.php, where the hooks are registered (around line 166), I added the following:

        $wgHooks['LinksUpdateConstructed'][] = 'smwfUpdateSemanticData';

Then, below that, among the other function declarations, I added this:

/**
 * Update the semantic data for a single page
 */
function smwfUpdateSemanticData($links_update) {
        $title = $links_update->mTitle;
        if ( smwfIsSemanticsProcessed($title->getNamespace()) ) {
                SMWFactbox::storeData($title, true);
        }
        return true;
}

There may be some performance or other issues that I'm missing; I'm curious to hear what other people have to say. If everything looks fine, please add this into the code - feel free to make any changes you want, of course.

-Yaron