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; }