function synthesizeSummary($wikitext, $maxSteps, $fullURL) { $stepsSec = Wikitext::getStepsSection($wikitext, true); if (!$stepsSec) { return ''; } $stepsText = Wikitext::stripHeader($stepsSec[0]); if (Wikitext::countAltMethods($stepsText) > 0) { $altMethods = Wikitext::splitAltMethods($stepsText); foreach ($altMethods as $method) { if (Wikitext::isAltMethod($method) && Wikitext::countSteps($method) > 0) { $stepsText = $method; break; } } } $countSteps = Wikitext::countSteps($stepsText); $summaryOut = ''; $steps = Wikitext::splitSteps($stepsText); $count = 0; foreach ($steps as $step) { if (Wikitext::isStepSimple($step, false)) { $summary = Wikitext::summarizeStep($step); $summary = Wikitext::removeRefsFromFlattened($summary); if ($summary) { $count++; $break = $count > 1 ? "<br>" : ''; if ($count > $maxSteps) { $remaining = $countSteps - $maxSteps; $text = ''; if ($remaining >= 2) { $text = "{$remaining} more steps at wikiHow"; } elseif ($remaining == 1) { $text = "Another step at wikiHow"; } if ($text) { $href = htmlspecialchars($fullURL); $link = "<a href='{$href}'>{$text}</a>"; $summaryOut .= "{$break}{$link}"; } break; } else { $summaryOut .= "{$break}{$count}. {$summary}"; } } } } return $summaryOut; }
function getStepText($r, $image) { global $wgParser; $stepsMsg = wfMsg('steps'); //grab only the filename $image_name = preg_split('@/@', $image); $image_name = $image_name[count($image_name) - 1]; //removing -crop-... stuff $image_name = preg_replace('@-crop-600--600px-@', '', $image_name); //remove spaces $image_name = preg_replace('@ @', '-', $image_name); $the_text = $r->getText(); for ($i = 1; $i < 10; $i++) { $section = $wgParser->getSection($the_text, $i); if (empty($section)) { break; } if (preg_match('@==\\s*' . $stepsMsg . '\\s*==@', $section)) { $steps = preg_replace('@== ' . $stepsMsg . ' ==@', '', $section); break; } } $stepnums = preg_split('/^#[^*#]/m', $steps); //array of only the actual numbered steps $steps = Wikitext::splitSteps($steps); //array includes steps w/in steps foreach ($steps as $s) { $s_comp = preg_replace('@ @', '-', $s); //strip dashes for the compare if (stripos($s_comp, $image_name)) { //get step number for ($i = 1; $i < count($stepnums); $i++) { $the_step = preg_replace('@ @', '-', $stepnums[$i]); //strip dashes for the compare if (stripos($the_step, $image_name)) { $stepnum = $i; break; } } $text = WikihowArticleEditor::textify($s); $text = preg_replace("@\\'\\'\\'@", "", $text); //remove bold $text = preg_replace("/http?:\\/\\/[^ ]+ /", " ", $text); //remove urls if ($this->bNewLayout_02) { $text = '<div id="gs_text">From Step ' . $stepnum . '</div>'; } else { $text = '<span>From Step ' . $stepnum . '</span><br /><br />' . $text; } break; } } if (!$text && !$this->bNewLayout_02) { //oh, is this the intro image? $intro = Wikitext::getIntro($the_text); $image_name = preg_replace('@-@', ' ', $image_name); if (stripos($intro, $image_name)) { //$text = Wikitext::flatten($intro); } } if (strlen($text) > 250) { $text = substr($text, 0, 250) . '...'; } return $text; }