/** * Replaces annotations of $redirectProperty with $targetProperty on page * $title. * * @param $title Title * @param $redirectProperty string * @param $targetProperty string * @param $verbose boolean */ private function replaceProperties($title, $redirectProperty, $targetProperty, $verbose) { global $wgParser; $options = new ParserOptions(); $rev = Revision::newFromTitle($title); if ($rev == NULL) { return; } $a = new Article($title); if ($a == NULL) { return; } $matches = array(); $text = $rev->getText(); preg_match_all('/\\[\\[\\s*' . preg_quote(str_replace("_", " ", $redirectProperty)) . '\\s*:[:|=]([^]]*)\\]\\]/i', $text, $matches); $newtext = NULL; foreach ($matches[1] as $m) { $repl = "[[" . str_replace("_", " ", $targetProperty) . "::" . $m . "]]"; $newtext = preg_replace('/\\[\\[\\s*' . preg_quote(str_replace("_", " ", $redirectProperty)) . '\\s*:[:|=]' . preg_quote($m) . '\\]\\]/i', $repl, $text); } if ($newtext != NULL && $text != $newtext) { if ($verbose) { echo "\n - Replacing annotated redirects on " . $title->getText() . "..."; } $a->doEdit($newtext, $rev->getComment(), EDIT_UPDATE); $wgParser->parse($newtext, $title, $options, true, true, $rev->getID()); SMWFactbox::storeData(true); if ($verbose) { echo "done!"; } } }
$doit = true; } if (!$doit) { continue; } } if ($verbose) { print "({$num_files}) Processing page with ID " . $id . " ...\n"; } if (smwfIsSemanticsProcessed($title->getNamespace())) { $revision = Revision::newFromTitle($title); if ($revision === NULL) { continue; } $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getID()); SMWFactbox::storeData($title, true); // sleep to be nice to the server if ($delay !== false && ($num_files + 1) % 100 === 0) { usleep($delay); } } else { smwfGetStore()->deleteSubject($title); // sleep to be nice to the server // (for this case, sleep only every 1000 pages, so that large chunks of e.g. messages are processed more quickly) if ($delay !== false && ($num_files + 1) % 1000 === 0) { usleep($delay); } } $num_files++; } print "{$num_files} pages refreshed.\n";