/**
  * 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!";
         }
     }
 }
Example #2
0
 /**
  * This hook copies SMW's custom data from the given ParserOutput object to
  * the given OutputPage object, since otherwise it is not possible to access
  * it later on to build a Factbox.
  * 
  * @param OutputPage $outputpage
  * @param ParserOutput $parseroutput
  * 
  * @return true
  */
 public static function onOutputPageParserOutput(OutputPage $outputpage, ParserOutput $parseroutput)
 {
     global $wgParser;
     $factbox = SMWFactbox::getFactboxTextFromOutput($parseroutput, $outputpage->getTitle());
     if ($factbox !== '') {
         $popts = new ParserOptions();
         $po = $wgParser->parse($factbox, $outputpage->getTitle(), $popts);
         $outputpage->mSMWFactboxText = $po->getText();
         // do not forget to grab the outputs header items
         SMWOutputs::requireFromParserOutput($po);
         SMWOutputs::commitToOutputPage($outputpage);
     }
     // else: nothing shown, don't even set any text
     return true;
 }
            $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";