public static function parserBeforeStrip(&$parser, &$text, &$stripState) { #wfDebug( 'HIPP: ' . __METHOD__ . "\n" ); # if revisionid is 0 this is not an article chunk if (isset($parser->mDymFirstChunk) || !$parser->getVariableValue('revisionid') || $parser->getVariableValue('namespace')) { return true; } $parser->mDymFirstChunk = 'done'; $title = $parser->getTitle(); $parser->mDymSees = DidYouMean::lookup($title->getArticleID(), $title->getText()); if (preg_match("/{{[sS]ee\\|([^}]*)}}/", $text, $see)) { wfDebug("HIPP: see Hit\n"); $hasTemplate = true; $sees = explode("|", $see[1]); } elseif (preg_match("/{{[xX]see(\\|[^}]*)}}/", $text, $see)) { wfDebug("HIPP: xsee Hit\n"); $hasTemplate = true; preg_match_all("/\\|\\[\\[([^]|]*)(?:\\|([^|]*))?\\]\\](?: \\(([^)]*)\\))?/", $see[1], $ma); $sees = $ma[1]; } else { wfDebug("HIPP: (x)see Miss\n"); # there's no {{see}} in this chunk of wikitext # if this is the 1st chunk of the article itself we can put an empty {{see}} there. $hasTemplate = false; $sees = array(); } # normalize entities and urlencoding to pure utf-8 foreach ($sees as &$value) { $value = rawurldecode(html_entity_decode($value, ENT_QUOTES, 'UTF-8')); } wfDebug('HIPP: Parser: ' . implode(', ', $sees) . "\n"); wfDebug('HIPP: DBase: ' . implode(', ', $parser->mDymSees) . "\n"); # add in the stuff from the database lookup $sees = array_unique(array_merge($sees, $parser->mDymSees)); sort($sees); wfDebug('HIPP: Merged: ' . implode(', ', $sees) . "\n"); # TODO is it better to use $parser->insertStripItem() ? if (count($sees)) { if (!$hasTemplate) { // We need to squish in a fresh copy of the template... $text = "{{see|}}\n" . $text; } $built_sees = DidYouMean::build_sees($sees); } else { $built_sees = ''; } $text = preg_replace('/{{[xX]?[sS]ee\\|[^}]*}}/', $built_sees, $text); return true; }