private function getRelatedWikihowsFromSource($title, $num)
 {
     global $wgParser;
     $whow = WikihowArticleEditor::newFromTitle($title);
     if (!$whow) {
         return '';
     }
     $related = $whow->getSection('related wikihows');
     $preg = "/\\|[^\\]]*/";
     $related = preg_replace($preg, "", $related);
     //splice and dice
     $rarray = split("\n", $related);
     $related = implode("\n", array_splice($rarray, 0, $num));
     $options = new ParserOptions();
     $output = $wgParser->parse($related, $title, $options);
     $ra = $this->addTargetBlank($output->getText());
     return $ra;
 }
 private static function checkForRecipeMicrodata()
 {
     global $wgTitle, $wgUser, $wgRequest;
     static $calculated = false;
     if ($calculated) {
         return;
     }
     $calculated = true;
     if ($wgTitle && $wgTitle->getNamespace() == NS_MAIN && $wgTitle->exists() && $wgRequest->getVal('oldid') == '' && ($wgRequest->getVal('action') == '' || $wgRequest->getVal('action') == 'view')) {
         if (true || wikihowAds::$mCategories['Recipes'] != null) {
             $wikihow = WikihowArticleEditor::newFromTitle($wgTitle);
             $index = $wikihow->getSectionNumber('ingredients');
             if ($index != -1) {
                 self::$showRecipeTags = true;
                 //our hRecipe subset
                 if (stripos($wgTitle->getText(), 'muffin') > 0) {
                     self::$showhRecipeTags = true;
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Executes the Easyimageupload special page and all its sub-calls
  */
 public function execute($par)
 {
     global $wgRequest, $wgUser, $wgOut, $wgLang, $wgServer;
     wfLoadExtensionMessages('Easyimageupload');
     self::setTemplatePath();
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $wgOut->setArticleBodyOnly(true);
     if ($wgRequest->getVal('getuploadform')) {
         $wgOut->addHTML(self::getUploadBox());
     } elseif ($wgRequest->getVal('uploadform1')) {
         $wgOut->addHTML(EasyTemplate::html('eiu_error_box.tmpl.php'));
         $this->uploadImage($wgRequest->getVal('src'));
     } elseif ($wgRequest->getVal('uploadform2')) {
         $wgOut->addHTML(EasyTemplate::html('eiu_error_box.tmpl.php'));
         $type = $wgRequest->getVal('type');
         $name = $wgRequest->getVal('name');
         $mwname = $wgRequest->getVal('mwname');
         $error = $this->insertImage($type, $name, $mwname);
         $vars = !empty($error) ? array('error' => $error) : array();
         $wgOut->addHTML(EasyTemplate::html('eiu_add_error.tmpl.php', $vars));
     } elseif ($wgRequest->getVal('ImageIsConflict')) {
         $wgOut->addHTML(EasyTemplate::html('eiu_error_box.tmpl.php'));
         if ($wgRequest->getVal('ImageUploadUseExisting')) {
             $name = $wgRequest->getVal('ImageUploadExistingName');
             $wgRequest->setVal('type', 'existing');
         } elseif ($wgRequest->getVal('ImageUploadRename')) {
             $name = $wgRequest->getVal('ImageUploadRenameName') . '.' . $wgRequest->getVal('ImageUploadRenameExtension');
             $wgRequest->setVal('type', 'overwrite');
         }
         $wgRequest->setVal('name', $name);
         $type = $wgRequest->getVal('type');
         $name = $wgRequest->getVal('name');
         $mwname = $wgRequest->getVal('mwname');
         $error = $this->insertImage($type, $name, $mwname);
         $vars = !empty($error) ? array('error' => $error) : array();
         $wgOut->addHTML(EasyTemplate::html('eiu_add_error.tmpl.php', $vars));
     } elseif ($wgRequest->getVal('preview-resize')) {
         $url = $wgRequest->getVal('url');
         self::resizeAndDisplayImage($url);
     } elseif ($wgRequest->getVal('intro-image-adder')) {
         $separator = EasyTemplate::html('eiu_separator.tmpl.php');
         $articleTitle = $wgRequest->getVal('article-title');
         $searchterms = $wgRequest->getVal('searchterms');
         $t = Title::newFromText($articleTitle);
         $whow = WikihowArticleEditor::newFromTitle($t);
         $intro = $whow->getSection("summary");
         $intro = WikihowArticleEditor::removeWikitext($intro);
         $articleTitleLink = $t->getLocalURL();
         $vars = array('title' => $articleTitle, 'titlelink' => $articleTitleLink, 'searchterms' => $searchterms, 'intro' => $intro);
         $html = EasyTemplate::html('iia_eiu_header.tmpl.php', $vars);
         $wgOut->addHTML($html);
         $wgOut->addHTML(EasyTemplate::html('eiu_error_box.tmpl.php'));
         $wgOut->addHTML(EasyTemplate::html('iia_eiu_find_box.tmpl.php', $vars));
         $wgOut->addHTML($html);
         $html = EasyTemplate::html('eiu_footer.tmpl.php');
         $wgOut->addHTML($html);
     } elseif ($wgRequest->getVal('intro-image-adder2')) {
         $this->uploadImage($wgRequest->getVal('src'), true);
     } else {
         // initial menu
         $separator = EasyTemplate::html('eiu_separator.tmpl.php');
         $articleTitle = $wgRequest->getVal('article-title');
         $vars = array('title' => $articleTitle);
         $html = EasyTemplate::html('eiu_header.tmpl.php', $vars);
         $wgOut->addHTML($html);
         $wgOut->addHTML(EasyTemplate::html('eiu_error_box.tmpl.php'));
         // assert wgRequest->wasPosted() == false;
         $wgOut->addHTML(self::getCurrentStepBox());
         $wgOut->addHTML(self::getFindBox($articleTitle));
         $html = EasyTemplate::html('eiu_find_box_end.tmpl.php');
         $wgOut->addHTML($html);
         $html = EasyTemplate::html('eiu_footer.tmpl.php');
         $wgOut->addHTML($html);
     }
 }
 static function processArticleHTML($body, $opts = array())
 {
     global $wgUser, $wgTitle, $wgLanguageCode;
     $doc = PHPQuery::newDocument($body);
     $featurestar = pq("div#featurestar");
     if ($featurestar) {
         $clearelement = pq($featurestar)->next();
         $clearelement->remove();
         $featurestar->remove();
     }
     $ads = $wgUser->isAnon() && !@$opts['no-ads'] && wikihowAds::isEligibleForAds();
     // Remove __TOC__ resulting html from all pages other than User pages
     if (@$opts['ns'] != NS_USER && pq('div#toc')->length) {
         $toc = pq('div#toc');
         //in upgrade, it's no longer preceded by an h2, so deleting the intro instead :(
         //maybe this will change so leaving in for now.
         //$toc->prev()->remove();
         $toc->remove();
     }
     $sticky = "";
     if (@$opts['sticky-headers']) {
         $sticky = " sticky ";
     }
     // Remove originators for titles that don't exist
     if ($wgTitle->getArticleId() == 0) {
         pq('#originators')->remove();
     }
     //move firstHeading to inside the intro
     $firstH2 = pq("h2:first");
     if (pq($firstH2)->length() == 0) {
         try {
             pq("#bodycontents")->children(":first")->wrapAll("<div class='section wh_block'></div>");
         } catch (Exception $e) {
         }
     } else {
         try {
             pq($firstH2)->prevAll()->reverse()->wrapAll("<div id='intro' class='section {$sticky}'></div>");
         } catch (Exception $e) {
         }
     }
     //add a clearall to the end of the intro
     pq("#intro")->append("<div class='clearall'></div>");
     //removing any stray br tags at the start of the intro
     foreach (pq("#intro #originators")->next()->children() as $child) {
         if (pq($child)->is("br")) {
             pq($child)->remove();
         } else {
             break;
         }
     }
     //add the pimpedheader to our h3s!
     pq('h3, h4')->prepend('<div class="altblock"></div>');
     foreach (pq("h2") as $node) {
         $h2Parent = pq($node)->parent();
         if (@$opts['ns'] == NS_USER && pq($h2Parent)->attr("id") == "toctitle") {
             pq("#toc")->wrapAll("<div class='section'></div>");
             pq("#toc ul:first")->addClass("section_text");
             continue;
         }
         //find each section
         //first grab the name
         $sectionName = mb_strtolower(pq("span.mw-headline", $node)->html());
         //Remove all non-letters and numbers in all languges
         if ($wgLanguageCode == 'en') {
             $sectionName = preg_replace("/[^A-Za-z0-9]/u", '', $sectionName);
         } elseif ($wgLanguageCode == 'hi') {
             $sectionName = str_replace(' ', '', $sectionName);
         } else {
             $sectionName = preg_replace("/[^\\p{L}\\p{N}]/u", '', $sectionName);
         }
         //now find all the elements prior to the next h2
         $set = array();
         $h3Tags = array();
         $h3Elements = array();
         $priorToH3Set = array();
         $h3Count = 0;
         foreach (pq($node)->nextAll() as $sibling) {
             if (pq($sibling)->is("h2")) {
                 break;
             }
             if (pq($sibling)->is("h3")) {
                 $h3Count++;
                 $h3Tags[$h3Count] = $sibling;
                 $h3Elements[$h3Count] = array();
             } else {
                 if ($h3Count > 0) {
                     $h3Elements[$h3Count][] = $sibling;
                 } else {
                     $priorToH3Set[] = $sibling;
                 }
             }
             $set[] = $sibling;
         }
         if (mb_strtolower($sectionName) == mb_strtolower(wfMessage('steps')->text())) {
             if ($h3Count > 0) {
                 //has alternate methods
                 $altMethodNames = array();
                 $altMethodAnchors = array();
                 if (count($priorToH3Set) > 0) {
                     //needs to have a steps section prior to the
                     //alt method
                     try {
                         pq($priorToH3Set)->wrapAll("<div id='{$sectionName}' class='section_text'></div>");
                     } catch (Exception $e) {
                     }
                     $overallSet = array();
                     $overallSet[] = $node;
                     foreach (pq("div#{$sectionName}:first") as $temp) {
                         $overallSet[] = $temp;
                     }
                     try {
                         pq($overallSet)->wrapAll("<div class='section steps {$sticky}'></div>");
                     } catch (Exception $e) {
                     }
                 } else {
                     //hide the h2 tag
                     pq($node)->addClass("hidden");
                 }
                 $stepsEditUrl = pq('.editsection', $node)->attr("href");
                 $displayMethodCount = $h3Count;
                 $isSample = array();
                 for ($i = 1; $i <= $h3Count; $i++) {
                     $isSampleItem = false;
                     if (!is_array($h3Elements[$i]) || count($h3Elements[$i]) < 1) {
                         $isSampleItem = false;
                     } else {
                         //the sd_container isn't always the first element, need to look through all
                         foreach ($h3Elements[$i] as $node) {
                             //not the most efficient way to do this, but couldn't get the find function to work.
                             if (pq($node)->attr("id") == "sd_container") {
                                 $isSampleItem = true;
                                 break;
                             }
                         }
                     }
                     if ($isSampleItem) {
                         $isSample[$i] = true;
                         $displayMethodCount--;
                     } else {
                         $isSample[$i] = false;
                     }
                 }
                 if ($ads) {
                     wikihowAds::setAltMethods($displayMethodCount > 1);
                 }
                 //[sc] ***INTERMEDIATE STEP (remove line below)
                 $wikihowArticle = WikihowArticleEditor::newFromTitle($wgTitle);
                 $hasParts = $opts['magic-word'] == MagicWord::get('parts');
                 $displayMethod = 1;
                 for ($i = 1; $i <= $h3Count; $i++) {
                     //change the method title
                     $methodTitle = pq("span.mw-headline", $h3Tags[$i])->html();
                     //[sc] ***INTERMEDIATE STEP (remove line below)
                     $removeRet = WikihowArticleEditor::removeMethodNamePrefix($methodTitle);
                     $altMethodNames[] = $methodTitle;
                     $altMethodAnchors[] = pq("span.mw-headline", $h3Tags[$i])->attr("id");
                     //[sc] ***INTERMEDIATE STEP (swap if logic below)
                     //if ($displayMethodCount > 1 && $hasParts && $opts['ns'] == NS_MAIN) {
                     if ($displayMethodCount > 1 && !$isSample[$i] && ($removeRet['has_parts'] || $hasParts) && $opts['ns'] == NS_MAIN) {
                         if ($methodTitle) {
                             $methodTitle = wfMessage("part_2", $displayMethod, $displayMethodCount, $methodTitle)->text();
                         } else {
                             $methodTitle = wfMessage("part_1", $displayMethod, $displayMethodCount)->text();
                         }
                         $displayMethod++;
                     } elseif ($displayMethodCount > 1 && !$isSample[$i] && $opts['ns'] == NS_MAIN) {
                         if ($methodTitle) {
                             $methodTitle = wfMessage("method_2", $displayMethod, $displayMethodCount, $methodTitle)->text();
                         } else {
                             $methodTitle = wfMessage("method_1", $displayMethod, $displayMethodCount)->text();
                         }
                         $displayMethod++;
                     }
                     pq("span.mw-headline", $h3Tags[$i])->html($methodTitle);
                     //add our custom anchors
                     $anchor_name = pq("span.mw-headline", $h3Tags[$i])->attr('id') . '_sub';
                     try {
                         pq($h3Tags[$i])->before('<a name="' . $anchor_name . '" class="anchor"></a>');
                     } catch (Exception $e) {
                     }
                     //want to change the url for the edit link to
                     //edit the whole steps section, not just the
                     //alternate method
                     pq(".editsection", $h3Tags[$i])->attr("href", $stepsEditUrl);
                     $sample = $isSample[$i] ? "sample" : "";
                     //only wrap if there's stuff there to wrap.
                     //This happens when people put two sub methods on top of each other without
                     //any content between.
                     if (count($h3Elements[$i]) > 0) {
                         pq($h3Elements[$i])->wrapAll("<div id='{$sectionName}_{$i}' class='section_text'></div>");
                     }
                     $overallSet = array();
                     $overallSet[] = $h3Tags[$i];
                     foreach (pq("div#{$sectionName}_{$i}:first") as $temp) {
                         $overallSet[] = $temp;
                     }
                     try {
                         pq($overallSet)->wrapAll("<div class='section steps {$sample} {$sticky}'></div>");
                     } catch (Exception $e) {
                     }
                 }
                 //BEBETH - not sure we need this anymore, but not sure yet
                 //fix for Chrome -- wrap first anchor name so it detects the spacing
                 try {
                     pq(".section.steps:first")->prev()->children(".anchor")->after('<br class="clearall" />')->wrapAll('<div></div>');
                 } catch (Exception $e) {
                 }
                 //now we should have all the alt methods,
                 //let's create the links to them under the headline
                 $charCount = 0;
                 $maxCount = 80000;
                 //temporarily turning off hidden headers
                 $hiddenCount = 0;
                 $anchorList = "";
                 for ($i = 0; $i < count($altMethodAnchors); $i++) {
                     $methodName = pq('<div>' . $altMethodNames[$i] . '</div>')->text();
                     // remove any reference notes
                     $methodName = preg_replace("@\\[\\d{1,3}\\]\$@", "", $methodName);
                     $charCount += strlen($methodName);
                     $class = "";
                     if ($charCount > $maxCount) {
                         $class = "hidden excess";
                         $hiddenCount++;
                     }
                     if ($methodName == "") {
                         continue;
                     }
                     $anchorList .= "<a href='#{$altMethodAnchors[$i]}_sub' class='{$class}'>{$methodName}</a>";
                 }
                 $hiddentext = "";
                 if ($hiddenCount > 0) {
                     $hiddenText = "<a href='#' id='method_toc_unhide'>{$hiddenCount} more method" . ($hiddenCount > 1 ? "s" : "") . "</a>";
                     $hiddenText .= "<a href='#' id='method_toc_hide' class='hidden'>show less methods</a>";
                 } else {
                     $hiddenText = '';
                 }
                 //add our little list header
                 if ($hasParts) {
                     //ucwords
                     $anchorList = '<span>' . ucwords(Misc::numToWord(count($altMethodAnchors), 10)) . ' ' . wfMessage('part_3')->text() . ':</span>' . $anchorList;
                 } else {
                     $anchorList = '<span>' . ucwords(Misc::numToWord(count($altMethodAnchors), 10)) . ' ' . wfMessage('method_3')->text() . ':</span>' . $anchorList;
                 }
                 //chance to reformat the alt method_toc before output
                 //using for running tests
                 $bAfter = false;
                 wfRunHooks('BeforeOutputAltMethodTOC', array($wgTitle, &$anchorList, &$bAfter));
                 $bAfter = true;
                 if ($bAfter) {
                     pq("#originators")->after("<p id='method_toc' style='margin-top:-10px'>{$anchorList}{$hiddenText}</p>");
                 } else {
                     pq(".firstHeading")->after("<p id='method_toc'>{$anchorList}{$hiddenText}</p>");
                 }
             } else {
                 //only 1 method
                 if ($ads) {
                     wikihowAds::setAltMethods(false);
                 }
                 if ($set) {
                     try {
                         pq($set)->wrapAll("<div id='{$sectionName}' class='section_text'></div>");
                     } catch (Exception $e) {
                     }
                 }
                 $overallSet = array();
                 $overallSet[] = $node;
                 foreach (pq("div#{$sectionName}:first") as $temp) {
                     $overallSet[] = $temp;
                 }
                 try {
                     pq($overallSet)->wrapAll("<div class='section steps {$sticky}'></div>");
                 } catch (Exception $e) {
                 }
             }
         } else {
             //not a steps section
             if ($set) {
                 $sec_id = @$opts['list-page'] ? '' : 'id="' . $sectionName . '"';
                 try {
                     $new_set = pq($set)->wrapAll("<div {$sec_id} class='section_text'></div>");
                 } catch (Exception $e) {
                 }
             }
             $overallSet = array();
             $overallSet[] = $node;
             foreach (pq("div#{$sectionName}:first") as $temp) {
                 $overallSet[] = $temp;
             }
             try {
                 pq($overallSet)->wrapAll("<div class='section {$sectionName} {$sticky}'></div>");
             } catch (Exception $e) {
             }
             if (@$opts['list-page']) {
                 //gotta pull those dangling divs into the same space as the h2
                 try {
                     pq($overallSet)->parent()->append(pq($new_set));
                 } catch (Exception $e) {
                 }
             }
             // commenting this out because it's causing the following error:
             // "Couldn't add newnode as the previous sibling of refnode"
             // // format edit links for non-steps sections
             // // pq('span', $node)->prepend(pq('a.edit', $node));
             //remove the edit link from subheaders if we're not in the steps section
             try {
                 pq(".{$sectionName} h3 .editsection")->remove();
             } catch (Exception $e) {
             }
         }
     }
     //add a clear to the end of each section_text to make sure
     //images don't bleed across the bottom
     pq(".section_text")->append("<div class='clearall'></div>");
     // Add checkboxes to Ingredients and 'Things You Need' sections, but only to the top-most li
     $lis = pq('#ingredients > ul > li, #thingsyoullneed > ul > li');
     foreach ($lis as $li) {
         $id = md5(pq($li)->html() . mt_rand(1, 100));
         pq($li)->html("<input id='item_{$id}' class='css-checkbox' type='checkbox'/><label for='item_{$id}' name='item_{$id}_lbl' class='css-checkbox-label'></label><div class='checkbox-text'>" . pq($li)->html() . '</div>');
     }
     // Move templates above article body contents and style appropriately
     foreach (pq('.template_top') as $template) {
         pq($template)->addClass('sidebox');
         if (pq($template)->parent()->hasClass('tmp_li')) {
             pq($template)->addClass('tmp_li');
         }
         if ($wgUser->isAnon()) {
             pq($template)->addClass('notice_bgcolor_lo');
         } else {
             pq($template)->addClass('notice_bgcolor_important');
         }
     }
     // put templates after the intro div
     pq('.template_top')->insertAfter('#intro');
     //now put the step numbers in
     foreach (pq("div.steps .section_text > ol") as $list) {
         pq($list)->addClass("steps_list_2");
         $stepNum = 1;
         foreach (pq($list)->children() as $step) {
             $boldStep = WikihowArticleHTML::boldFirstSentence(pq($step)->html());
             pq($step)->html($boldStep);
             pq($step)->prepend("<div class='step_num'>{$stepNum}</div>");
             pq($step)->append("<div class='clearall'></div>");
             $stepNum++;
         }
     }
     foreach (pq(".steps:last .steps_list_2")->children(":last-child") as $step) {
         pq($step)->addClass("final_li");
     }
     //move each of the large images to the top
     foreach (pq(".steps_list_2 li .mwimg.largeimage") as $image) {
         //delete any previous <br>
         foreach (pq($image)->prevAll() as $node) {
             if (pq($node)->is("br")) {
                 pq($node)->remove();
             } else {
                 break;
             }
         }
         //first handle the special case where the image
         //ends up inside the bold tag by accident
         if (pq($image)->parent()->is("b")) {
             pq($image)->insertBefore(pq($image)->parent());
         }
         if (pq($image)->parent()->parent()->is(".steps_list_2")) {
             pq($image)->parent()->prepend($image);
         }
     }
     //move each of the large images to the top
     foreach (pq(".steps_list_2 li .whvid_cont") as $vid) {
         //delete any previous <br>
         foreach (pq($vid)->prevAll() as $node) {
             if (pq($node)->is("br")) {
                 pq($node)->remove();
             } else {
                 break;
             }
         }
         if (pq($vid)->parent()->parent()->is(".steps_list_2")) {
             pq($vid)->parent()->prepend($vid);
         }
     }
     //if there's a related articles section, make it have images
     $relatedSection = pq("#relatedwikihows");
     if ($relatedSection) {
         foreach (pq("li a", $relatedSection) as $related) {
             $titleText = pq($related)->attr("title");
             $title = Title::newFromText($titleText);
             if ($title) {
                 $image = SkinWikihowskin::getArticleThumb($title, 127, 120);
                 pq($relatedSection)->prepend($image);
             }
             pq($related)->remove();
         }
         pq("ul", $relatedSection)->remove();
         pq($relatedSection)->append("<div class='clearall'></div>");
     }
     //remove all images in the intro that aren't
     //marked with the class "introimage"
     pq("#intro .mwimg:not(.introimage)")->remove();
     //let's mark all the <p> tags that aren't inside a step.
     //they need special padding
     foreach (pq(".section.steps p") as $p) {
         if (pq($p)->parents(".steps_list_2")->count() == 0 && pq($p)->children(".anchor")->count() == 0) {
             pq($p)->addClass("lone_p");
         }
     }
     // Add alt method adder cta
     if (class_exists("AltMethodAdder") && $wgTitle && $wgUser && $wgUser->isAnon()) {
         $cta = AltMethodAdder::getCTA($wgTitle);
         if (!is_null($cta)) {
             pq("div.steps:last")->after($cta);
         }
     }
     //add line breaks between the p tags
     foreach (pq("p") as $paragraph) {
         $sibling = pq($paragraph)->next();
         if (!pq($sibling)->is("p")) {
             continue;
         }
         if (pq($sibling)->children(":first")->hasClass("anchor")) {
             continue;
         }
         $id = pq($paragraph)->attr("id");
         if ($id == "originators" || $id == "method_toc") {
             continue;
         }
         pq($paragraph)->after("<br />");
     }
     if ($ads) {
         pq(".#intro")->append(wikihowAds::getAdUnitPlaceholder('intro'));
         pq(".steps_list_2:first li:first")->append(wikihowAds::getAdUnitPlaceholder(0));
         pq(".final_li")->append(wikihowAds::getAdUnitPlaceholder(1));
         $tipsClass = mb_strtolower(wfMessage("tips")->text());
         //grabs the tips section by name, but internationalized
         pq(".{$tipsClass} .section_text")->children()->filter("ul:last")->after(wikihowAds::getAdUnitPlaceholder('2a'));
         //add in the Taboola ads
         if ($wgLanguageCode == "en") {
             $sourcesClass = mb_strtolower(wfMessage("sources")->text());
             //grabs the sources and citations section by name, but internationalized
             $sourcesClass = str_replace(' ', '', $sourcesClass);
             if (pq(".section.{$sourcesClass}")->length) {
                 //put above Sources & Citations if it exists
                 pq(".section.{$sourcesClass}")->before(wikihowAds::getAdUnitTaboola());
             } else {
                 // put above Article Info
                 pq("#bodycontents")->after(wikihowAds::getAdUnitTaboola());
             }
         }
     }
     $markPatrolledLink = self::getMarkPatrolledLink();
     if ($markPatrolledLink) {
         pq('#bodycontents')->append($markPatrolledLink);
     }
     // //TEST - no intro
     // global $wgRequest;
     // $article_ids = explode("\n",ConfigStorage::dbGetConfig('wikihow-nointro-test'));
     // if ($wgTitle && $wgTitle->getNamespace() == NS_MAIN && $wgRequest->getVal('action') == '' && in_array($wgTitle->getArticleID(),$article_ids)) {
     // pq('#intro p:last')->remove();
     // }
     return $doc->htmlOuter();
 }
    function execute($par)
    {
        global $wgRequest, $wgSitename, $wgLanguageCode, $IP;
        global $wgDeferredUpdateList, $wgOut, $wgUser, $wgServer;
        $this->setHeaders();
        if ($wgUser->isBlocked()) {
            $wgOut->blockedPage();
            return;
        }
        $target = isset($par) ? $par : $wgRequest->getVal('target');
        if (!$target) {
            $wgOut->addHTML(wfMsg('notarget'));
            return;
        }
        $titleObj = Title::newFromUrl(urldecode($target));
        if (!$titleObj || !$titleObj->exists()) {
            $wgOut->addHTML('Error: bad target');
            return;
        }
        $whow = WikihowArticleEditor::newFromTitle($titleObj);
        $rev = Revision::newFromTitle($titleObj);
        $article = Article::newFromTitle($titleObj, $this->getContext());
        $text = $rev->getText();
        if ($wgRequest->wasPosted()) {
            // protect from users who can't edit
            if (!$titleObj->userCan('edit')) {
                $wgOut->readOnlyPage($article->getContent(), true);
                return;
            }
            // construct the related wikihow section
            $rel_array = split("\\|", $wgRequest->getVal('related_list'));
            $result = "";
            foreach ($rel_array as $rel) {
                $rel = urldecode(trim($rel));
                if (!$rel) {
                    continue;
                }
                $result .= "*  [[" . $rel . "|" . wfMsg('howto', $rel) . "]]\n";
            }
            if (strpos($text, "\n== " . wfMsg('relatedwikihows') . " ==\n") !== false) {
                // no newline neeeded to start with
                $result = "== " . wfMsg('relatedwikihows') . " ==\n" . $result;
            } else {
                $result = "\n== " . wfMsg('relatedwikihows') . " ==\n" . $result;
            }
            $text = "";
            $index = 0;
            $content = $article->getContent();
            $last_heading = "";
            $inserted = false;
            $section = -1;
            $ext_links_section = -1;
            if ($article->getSection($content, $index) == null) {
                $index++;
                // weird where there's no summary
            }
            while (($sectiontext = $article->getSection($content, $index)) != null) {
                $i = strpos($sectiontext, "\n");
                if ($i > 0) {
                    $heading = substr($sectiontext, 0, $i);
                    $heading = trim(str_replace("==", "", $heading));
                    if ($heading == wfMsg('relatedwikihows')) {
                        $section = $index;
                        break;
                    }
                    if ($heading == wfMsg('sources')) {
                        $ext_links_section = $index;
                    }
                }
                $index++;
            }
            $text = $result;
            $tail = '';
            $text = $article->getContent();
            // figure out which section to replace if related wikihows
            // don't exist
            $just_append = false;
            if ($section <= 0) {
                if ($ext_links_section > 0) {
                    // related wikihows have to go before external links
                    $section = $ext_links_section;
                    // glue external links and related wikihows together
                    // and replace external links
                    $result = $result . "\n" . $article->getSection($content, $section);
                } else {
                    $section = $index;
                    $result = "\n" . $result;
                    // make it a bit prettier
                    $just_append = true;
                }
            } else {
                $s = $article->getSection($content, $section);
                $lines = split("\n", $s);
                for ($i = 1; $i < sizeof($lines); $i++) {
                    $line = $lines[$i];
                    if (strpos($line, "*") !== 0) {
                        // not a list item
                        $tail .= "\n" . $line;
                    }
                }
            }
            $result .= $tail;
            $summary = '';
            if (!$just_append) {
                $text = $article->replaceSection($section, $result, $summary);
            } else {
                $text = $text . $result;
            }
            $watch = false;
            $minor = false;
            $forceBot = false;
            if ($wgUser->getID() > 0) {
                $watch = $wgUser->isWatched($titleObj);
            }
            $summary = wfMsg('relatedwikihows');
            // summary for the edit
            $article->updateArticle($text, $summary, $minor, $watch, $forceBot);
            $this->getContext()->getOutput()->redirect($article->getTitle()->getFullURL());
        }
        // MW should handle editing extensions better, duplication of code sucks
        if ($titleObj->isProtected('edit')) {
            if ($titleObj->isSemiProtected()) {
                $notice = wfMsg('semiprotectedpagewarning');
            } else {
                $notice = wfMsg('protectedpagewarning');
            }
            $wgOut->addWikiText($notice);
        }
        $relatedHTML = "";
        $text = $article->getContent();
        $relwh = $whow->getSection("related wikihows");
        if ($relwh != "") {
            $related_vis = "show";
            $relatedHTML = $relwh;
            $relatedHTML = str_replace("*", "", $relatedHTML);
            $relatedHTML = str_replace("[[", "", $relatedHTML);
            $relatedHTML = str_replace("]]", "", $relatedHTML);
            $lines = split("\n", $relatedHTML);
            $relatedHTML = "";
            foreach ($lines as $line) {
                $xx = strpos($line, "|");
                if ($xx !== false) {
                    $line = substr($line, 0, $xx);
                }
                $line = trim($line);
                if ($line == "") {
                    continue;
                }
                $relatedHTML .= "<option value=\"" . str_replace("\"", "&quote", $line) . "\">{$line}</option>\n";
            }
        }
        $me = Title::makeTitle(NS_SPECIAL, "ManageRelated");
        $cssFile = wfGetPad('/extensions/min/f/extensions/wikihow/ManageRelated/managerelated.css?rev=') . WH_SITEREV;
        $jsFile = wfGetPad('/extensions/min/?f=extensions/wikihow/ManageRelated/managerelated.js,extensions/wikihow/common/jquery.scrollTo/jquery.scrollTo.js&rev=') . WH_SITEREV;
        $targetEnc = htmlspecialchars($target, ENT_QUOTES);
        $wgOut->addHTML(<<<EOHTML
\t<style type='text/css' media='all'>/*<![CDATA[*/ @import '{$cssFile}'; /*]]>*/</style>
\t<script type='text/javascript'>
\t\tvar wgServer = "{$wgServer}";
\t</script>
\t<script type='text/javascript' src='{$jsFile}'></script>

\t<form method='POST' action='{$me->getFullURL()}' name='temp' onsubmit='return WH.ManageRelated.check();'>

\tYou are currently editing related wikiHows for the article
\t<a href='{$titleObj->getFullURL()}' target='new'>How to {$titleObj->getFullText()}</a>.<br/>

\t<table style='padding: 10px 5px 25px 5px;'>
\t<tr><td valign='top'>
\t<ol><li>Enter some search terms to find related wikiHows and press 'Search'.</li></ol>
\t<input type='hidden' name='target' value='{$targetEnc}'/>
\t<input type='hidden' name='related_list'/>
\t<input type='text' name='q'/>
\t<input type='button' class='btn' onclick='WH.ManageRelated.check();' value='Search' style="margin-top: 5px;" />
\t</td>
\t<td valign='top' style='padding-left: 10px; border-left: 1px solid #ddd;'>
\t<div style='width: 175px; float: left;'>
\t<u>Related wikiHows</u>
\t</div>
\t<div style='width: 175px; float: right; text-align: right; margin-bottom:5px;'>
\tMove <input type=button value='Up &uarr;' class='btn' onclick='WH.ManageRelated.moveRelated("up");'/> <input type=button value='Down &darr;' class='btn' onclick='WH.ManageRelated.moveRelated("down");'/>
\t</div>
\t<select size='5' id='related' ondblclick='WH.ManageRelated.viewRelated();'>
\t\t{$relatedHTML}
\t</select>
\t<br/><br/>
\t<div style='width: 205px; float: left; text-align: left; font-size: xx-small; font-style: italic;'>
\t(double click item to open wikiHow in new window)
\t</div>
\t<div style='width: 175px; float: right; text-align: right;'>
\t<input type=button onclick='WH.ManageRelated.removeRelated();' value='Remove' class='btn'/>
\t<input type=button value='Save' onclick='WH.ManageRelated.submitForm();' class='btn'/>
\t</div>
\t</td></tr>
\t<tr>
\t\t<td id='lucene_results' colspan='2' valign='top' class='lucene_results' style="padding-top: 10px;"></td>
\t</tr><tr>
\t\t<td id='previewold' colspan='2' valign='top'></td>
\t</tr></table>

\t</form>

\t<div id='preview'></div>
EOHTML
);
    }
 function showEditForm($formCallback = null)
 {
     global $wgOut, $wgLanguageCode, $wgRequest, $wgTitle, $wgUser, $wgLang;
     global $wgScriptPath;
     $whow = null;
     // conflict resolution
     if (!$wgRequest->wasPosted()) {
         EditPage::showEditForm();
     }
     $wgOut->clearHTML();
     //echo $this->textbox1; exit;
     wfRunHooks('EditPage::showEditForm:initial', array(&$this));
     if ($this->showHeader() === false) {
         return;
     }
     // are we called with just action=edit and no title?
     $newArticle = false;
     if (($wgRequest->getVal("title") == "" || $wgTitle->getArticleID() == 0) && !$this->preview) {
         $newArticle = true;
     }
     $sk = $wgUser->getSkin();
     if (!$this->mTitle->getArticleID() && !$this->preview) {
         # new article
         $wgOut->addHTML(wfMsg("newarticletext"));
     }
     // do we have a new article? if so, format the title if it's English
     $new_article = $wgRequest->getVal("new_article");
     if ($new_article && $wgLanguageCode == "en") {
         $title = $this->mTitle->getText();
         $old_title = $title;
         $title = $this->formatTitle($title);
         $titleObj = Title::newFromText($title);
         $this->mTitle = $titleObj;
         $this->mArticle = new Article($titleObj);
     }
     $conflictWikiHow = null;
     $conflictTitle = false;
     if ($this->isConflict) {
         $s = wfMsg("editconflict", $this->mTitle->getPrefixedText());
         $wgOut->setPageTitle($s);
         if ($new_article) {
             $wgOut->addHTML("<b><font color=red>" . wfMsg('page-name-exists') . "</b></font><br/><br/>");
             $conflictTitle = true;
         } else {
             $this->edittime = $this->mArticle->getTimestamp();
             $wgOut->addHTML(wfMsg("explainconflict"));
             // let the advanced editor handle the situation
             if ($this->isConflict) {
                 EditPage::showEditForm();
                 return;
             }
         }
         $this->textbox2 = $this->textbox1;
         $conflictWikiHow = WikihowArticleEditor::newFromText($this->textbox1);
         $this->textbox1 = $this->mArticle->getContent(true, true);
         $this->edittime = $this->mArticle->getTimestamp();
     } else {
         if ($this->mTitle->getArticleID() == 0) {
             $s = wfMsg('creating', "\"" . wfMsg('howto', $this->mTitle->getPrefixedText()) . "\"");
         } else {
             $s = wfMsg('editing', "\"" . wfMsg('howto', $this->mTitle->getPrefixedText()) . "\"");
         }
         if ($this->section != "") {
             if ($this->section == "new") {
                 $s .= wfMsg("commentedit");
             } else {
                 $s .= wfMsg("sectionedit");
             }
             if (!$this->preview) {
                 $sectitle = preg_match("/^=+(.*?)=+/mi", $this->textbox1, $matches);
                 if (!empty($matches[1])) {
                     $this->summary = "/* " . trim($matches[1]) . " */ ";
                 }
             }
         }
         $wgOut->setPageTitle($s);
         if ($this->oldid) {
             $this->mArticle->setOldSubtitle($this->oldid);
             //message already displayed so commenting this out [sc - 1/29/2014]
             //$wgOut->addHTML( wfMsg( "editingold" ) );
         }
     }
     if (wfReadOnly()) {
         $wgOut->addHTML("<strong>" . wfMsg("readonlywarning") . "</strong>");
     } elseif ($isCssJsSubpage and "preview" != $formtype) {
         $wgOut->addHTML(wfMsg("usercssjsyoucanpreview"));
     }
     if (!$newArticle && $this->mTitle->isProtected('edit')) {
         if ($this->mTitle->isSemiProtected()) {
             $notice = wfMsg('semiprotectedpagewarning');
             if (wfEmptyMsg('semiprotectedpagewarning', $notice) || $notice == '-') {
                 $notice = '';
             }
         } else {
             $notice = wfMsg('protectedpagewarning');
         }
         $wgOut->addHTML("<div class='article_inner'>\n ");
         $wgOut->addWikiText($notice);
         $wgOut->addHTML("</div>\n");
     }
     $q = "action=submit2&override=yes";
     #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
     $action = $this->mTitle->escapeLocalURL($q);
     if ($newArticle) {
         $main = str_replace(' ', '-', wfMsg('mainpage'));
         $action = str_replace("&title=" . $main, "", $action);
     }
     $summary = wfMsg("summary");
     $subject = wfMsg("subject");
     $minor = wfMsg("minoredit");
     $watchthis = wfMsg("watchthis");
     $save = wfMsg("savearticle");
     $prev = wfMsg("showpreview");
     $cancel = $sk->link($this->mTitle->getPrefixedText(), wfMsg("cancel"));
     $edithelpurl = Skin::makeInternalOrExternalUrl(wfMsgForContent('edithelppage'));
     $edithelp = '<a target="helpwindow" href="' . $edithelpurl . '">' . htmlspecialchars(wfMsg('edithelp')) . '</a> ' . htmlspecialchars(wfMsg('newwindow'));
     $copywarn = wfMsg("copyrightwarning", $sk->link(wfMsg("copyrightpage")));
     $minoredithtml = '';
     if ($wgUser->isAllowed('minoredit')) {
         $minoredithtml = "<input tabindex='11' type='checkbox' value='1' name='wpMinoredit'" . ($this->minoredit ? " checked='checked'" : "") . " accesskey='" . wfMsg('accesskey-minoredit') . "' id='wpMinoredit' />\n" . "<label for='wpMinoredit' title='" . wfMsg('tooltip-minoredit') . "'>{$minor}</label>\n";
     }
     $watchhtml = '';
     if ($wgUser->isLoggedIn()) {
         $watchhtml = "<input tabindex='12' type='checkbox' name='wpWatchthis'" . ($this->watchthis ? " checked='checked'" : "") . " accesskey=\"" . htmlspecialchars(wfMsg('accesskey-watch')) . "\" id='wpWatchthis'  />\n" . "<label for='wpWatchthis' title=\"" . htmlspecialchars(wfMsg('tooltip-watch')) . "\">{$watchthis}</label>\n";
     }
     $checkboxhtml = $minoredithtml . $watchhtml;
     $tabindex = 14;
     $buttons = $this->getEditButtons($tabindex);
     $footerbuttons = "";
     $buttons['preview'] = "<span id='gatGuidedPreview'>{$buttons['preview']}</span>";
     if ($wgUser->getOption('hidepersistantsavebar', 0) == 0) {
         $footerbuttons .= "<span id='gatPSBSave'>{$buttons['save']}</span>";
         $footerbuttons .= "<span id='gatPSBPreview'>{$buttons['preview']}</span>";
     }
     $saveBtn = str_replace('accesskey="s"', "", $buttons['save']);
     $buttons['save'] = "<span id='gatGuidedSave'>{$saveBtn}</span>";
     $buttonshtml = implode($buttons, "\n");
     # if this is a comment, show a subject line at the top, which is also the edit summary.
     # Otherwise, show a summary field at the bottom
     $summarytext = htmlspecialchars($wgLang->recodeForEdit($this->summary));
     # FIXME
     $editsummary1 = "";
     if ($wgRequest->getVal('suggestion')) {
         $summarytext .= ($summarytext == "" ? "" : ", ") . wfMsg('suggestion_edit_summary');
     }
     if ($this->section == "new") {
         $commentsubject = "{$subject}: <input tabindex='1' type='text' value=\"{$summarytext}\" name=\"wpSummary\" id='wpSummary' maxlength='200' size='60' />";
         $editsummary = "";
     } else {
         $commentsubject = "";
         if ($wgTitle->getArticleID() == 0 && $wgTitle->getNamespace() == NS_MAIN && $summarytext == "") {
             $summarytext = wfMsg('creating_new_article');
         }
         $editsummary = "<input tabindex='10' type='text' value=\"{$summarytext}\" name=\"wpSummary\" id='wpSummary' maxlength='200' size='60' /><br />";
         $editsummary1 = "<input tabindex='10' type='text' value=\"{$summarytext}\" name=\"wpSummary1\" id='wpSummary1' maxlength='200' size='60' /><br />";
     }
     // create the wikiHow
     if ($conflictWikiHow == null) {
         if ($this->textbox1 != "") {
             $whow = WikihowArticleEditor::newFromText($this->textbox1);
         } else {
             $whow = WikihowArticleEditor::newFromTitle($this->mArticle->getTitle());
         }
     } else {
         $whow = $conflictWikiHow;
     }
     //********** SETTING UP THE FORM
     //
     //
     //
     //
     $confirm = "window.onbeforeunload = confirmExit;";
     if ($wgUser->getOption('useeditwarning') == '0') {
         $confirm = "";
     }
     $wgOut->addHTML("<script language=\"JavaScript\">\n\t\t\t\tvar isGuided = true;\n\t\t\t\tvar needToConfirm = false;\n\t\t\t\tvar checkMinLength = true;\n\t\t\t\t{$confirm}\n\t\t\t\tfunction confirmExit() {\n\t\t\t\t\tif (needToConfirm)\n\t\t\t\t\t\treturn \"" . wfMsg('all-changes-lost') . "\";\n\t\t\t\t}\n\t\t\t\tfunction addrows(element) {\n\t\t\t\t\tif (element.rows < 32)  {\n\t\t\t\t\t\telement.rows += 4;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfunction removerows(element) {\n\t\t\t\t\tif (element.rows > 4)  {\n\t\t\t\t\t\telement.rows -= 4;\n\t\t\t\t\t} else {\n\t\t\t\t\t\telement.rows = 4;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfunction saveandpublish() {\n\t\t\t\t\twindow.onbeforeunload = null;\n\t\t\t\t\tdocument.editform.submit();\n\t\t\t\t}\n\t\t\t\t(function (\$) {\n\t\t\t\t\t\$(document).ready(function() {\n\t\t\t\t\t\t\$('.button').click(function () {\n\t\t\t\t\t\t\tvar button = \$(this).not('.submit_button');\n\t\t\t\t\t\t\tif (button.length) {\n\t\t\t\t\t\t\t\tneedToConfirm = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\$('textarea').focus(function () {\n\t\t\t\t\t\t\tneedToConfirm = true;\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\t\$('#ep_cat').live('click', function(e) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tvar title = 'Categorize ' + wgTitle;\n\t\t\t\t\t\tif (title.length > 54) {\n\t\t\t\t\t\t\ttitle = title.substr(0, 54) + '...';\n\t\t\t\t\t\t}\n\t\t\t\t\t\tjQuery('#dialog-box').html('');\n\t\t\t\t\t\t\n\t\t\t\t\t\tjQuery('#dialog-box').load('/Special:Categorizer?a=editpage&id=' + wgArticleId, function() {\n\t\t\t\t\t\t\tjQuery('#dialog-box').dialog({\n\t\t\t\t\t\t\t\twidth: 673,\n\t\t\t\t\t\t\t\theight: 600,\n\t\t\t\t\t\t\t\tmodal: true,\n\t\t\t\t\t\t\t\ttitle: title,\n\t\t\t\t\t\t\t\tcloseText: 'Close',\t\n\t\t\t\t\t\t\t\tdialogClass: 'modal2',\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treCenter = function() {\n\t\t\t\t\t\t\t\tjQuery('#dialog-box').dialog('option', 'position', 'center');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsetTimeout('reCenter()', 100);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t})(jQuery);\n\t\t\t</script>\n\t\t\t<script type=\"text/javascript\" src=\"" . wfGetPad('/extensions/min/f/skins/common/clientscript.js,/skins/common/ac.js,/extensions/wikihow/video/importvideo.js&rev=') . WH_SITEREV . "\"></script>\n\n\t\t");
     if (!$this->preview) {
         # Don't select the edit box on preview; this interferes with seeing what's going on.
         //BEBETH: commenting this out b/c haven't figured out a new function for it
         //$wgOut->setOnloadHandler( "document.editform.title.focus(); load_cats();" );
     }
     $title = "";
     //$wgOut->setOnloadHandler( "' onbeforeunload='return confirm(\"Are you sure you want to navigate away from this page? All changes will be lost!\");" );
     $suggested_title = "";
     if (isset($_GET["requested"])) {
         $t = Title::makeTitle(NS_MAIN, $_GET["requested"]);
         $suggested_title = $t->getText();
     }
     if ($wgRequest->getVal('title', null) == null || $conflictTitle || $suggested_title != "") {
         $title = "<div id='title'><h3>" . wfMsg('title') . "</h3><br/>" . wfMsg('howto', '') . " &nbsp;&nbsp;&nbsp;\n\t\t\t<input autocomplete=\"off\" size=60 type=\"text\" name=\"title\" id=category tabindex=\"1\" value=\"{$suggested_title}\"></div>";
     }
     $steps = htmlspecialchars($wgLang->recodeForEdit($whow->getSteps(true)), ENT_QUOTES);
     $video = htmlspecialchars($wgLang->recodeForEdit($whow->getSection(wfMsg('video'))));
     $tips = htmlspecialchars($wgLang->recodeForEdit($whow->getSection(wfMsg('tips'))));
     $warns = htmlspecialchars($wgLang->recodeForEdit($whow->getSection(wfMsg('warnings'))));
     $related_text = htmlspecialchars($wgLang->recodeForEdit($whow->getSection(wfMsg('relatedwikihows'))));
     $summary = htmlspecialchars($wgLang->recodeForEdit($whow->getSummary()));
     if ($newArticle || $whow->mIsNew) {
         if ($steps == "") {
             $steps = "#  ";
         }
         if ($tips == "") {
             $tips = "*  ";
         }
         if ($warns == "") {
             $warns = "*  ";
         }
         if ($ingredients == "") {
             $ingredients = "*  ";
         }
     }
     $cat = $whow->getCategoryString();
     $advanced = "";
     $cat_array = explode("|", $whow->getCategoryString());
     $i = 0;
     $cat_string = "";
     foreach ($cat_array as $cat) {
         if ($cat == "") {
             continue;
         }
         if ($i != 0) {
             $cat_string .= "," . $cat;
         } else {
             $cat_string = $cat;
         }
         $i++;
     }
     $removeButton = "";
     $cat_advisory = "";
     if ($cat_string != "") {
         $removeButton = "<input type=\"button\" name=\"change_cats\" onclick=\"removeCategories();\" value=\"" . wfMsg('remove-categories') . "\">";
     } else {
         $cat_advisory = wfMsg('categorization-optional');
     }
     //$cat_string = str_replace("|", ", ", $whow->getCategoryString());
     //$cat_string = implode(", ", $raa);
     if (!$newArticle && !$whow->mIsNew && !$conflictTitle) {
         $oldparameters = "";
         if ($wgRequest->getVal("oldid") != "") {
             $oldparameters = "&oldid=" . $wgRequest->getVal("oldid");
         }
         if (!$this->preview) {
             $advanced = "<a class='' href='{$wgScript}?title=" . $wgTitle->getPrefixedURL() . "&action=edit&advanced=true{$oldparameters}'>" . wfMsg('advanced-editing') . "</a>";
         }
     } elseif ($newArticle && $wgRequest->getVal('title', null) != null) {
         $t = Title::newFromText("CreatePage", NS_SPECIAL);
         //$advanced = str_replace("href=", "class='guided-button' href=", $sk->makeLinkObj($t, wfMsg('advanced-editing'))) . " |";
         //$advanced = "<a href='{$wgScript}?title=" . $wgTitle->getPrefixedURL() . "&action=edit&advanced=true$oldparameters';\">".wfMsg('advanced-editing')."</a>";
         $advanced = "<a class='button secondary' style='float:left;' href='{$wgScript}?title=" . $wgTitle->getPrefixedURL() . "&action=edit&advanced=true{$oldparameters}'>" . wfMsg('advanced-editing') . "</a>";
     }
     $section_class = 'minor_section';
     // MODIFIED FOR POPUP
     $categoryHTML = "";
     if ($wgUser->getID() > 0) {
         $ctitle = $this->mTitle->getText();
         $css = HtmlSnips::makeUrlTags('css', array('categoriespopup.css'), 'extensions/wikihow', false);
         if ($wgLanguageCode == 'en') {
             $editCatMore = "<a href=\"{$wgScriptPath}/Writer%27s-Guide?section=2#" . wfMsg('more-info-categorization') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>";
             $editCatHtml = "<a href='#' id='ep_cat'>[" . wfMsg('editcategory') . "]</a><strong>{$editCatLink}</strong>";
         }
         $categoryHTML = "\n\t\t\t\t{$css}\n\t\t\t\t<div id='categories'>\n\t\t\t\t\t<h5>" . wfMsg('add-optional-categories') . "{$editCatMore}</h5>\n\t\t\t\t\t<div id='option_cats'>\n\t\t\t\t\t{$editCatHtml}" . Categoryhelper::getCategoryOptionsForm2($cat_string, $whow->mCategories) . "\t</div>\n\t\t\t\t</div>";
     }
     $requested = "";
     if (isset($_GET['requested'])) {
         $requested = $_GET['requested'];
     }
     $related_vis = "hide";
     $related_checked = "";
     $relatedHTML = "";
     if ($whow->getSection(wfMsg('relatedwikihows')) != "") {
         $related_vis = "show";
         $relatedHTML = $whow->getSection(wfMsg('relatedwikihows'));
         $relatedHTML = str_replace("*", "", $relatedHTML);
         $relatedHTML = str_replace("[[", "", $relatedHTML);
         $relatedHTML = str_replace("]]", "", $relatedHTML);
         $lines = explode("\n", $relatedHTML);
         $relatedHTML = "";
         foreach ($lines as $line) {
             $xx = strpos($line, "|");
             if ($xx !== false) {
                 $line = substr($line, 0, $xx);
             }
             // Google+ hack.  We don't normally allow + but will for the Goog
             if (false === stripos($line, 'Google+')) {
                 $line = trim(urldecode($line));
             }
             if ($line == "") {
                 continue;
             }
             $relatedHTML .= "<OPTION VALUE=\"" . htmlspecialchars($line) . "\">{$line}</OPTION>\n";
         }
         $related_checked = " CHECKED ";
     }
     $vidpreview_vis = "hide";
     $vidbtn_vis = "show";
     $vidpreview = "<img src='" . wfGetPad('/extensions/wikihow/rotate.gif') . "'/>";
     if ($whow->getSection(wfMsg('video')) != "") {
         $vidpreview_vis = "show";
         $vidbtn_vis = "hide";
         try {
             #$vt = Title::makeTitle(NS_VIDEO, $this->mTitle->getText());
             #$r = Revision::newFromTitle($vt);
             $vidtext = $whow->getSection(wfMsg('video'));
             $vidpreview = $wgOut->parse($vidtext);
         } catch (Exception $e) {
             $vidpreview = "Sorry, preview is currently not available.";
         }
     } else {
         $vidpreview = wfMsg('video_novideoyet');
     }
     $video_disabled = "";
     $vid_alt = "";
     $video_msg = "";
     $wasNew = "false";
     if ($newArticle) {
         $wasNew = "true";
     }
     $video_button = "<a id='gatVideoImportEdit' type='button' onclick=\"changeVideo('" . urlencode($wgTitle->getDBKey()) . "', " . $wasNew . "); return false;\" href='#' id='show_preview_button' class='button secondary'  >" . wfMsg('video_change') . "</a>";
     if ($wgUser->getID() == 0) {
         $video_disabled = "disabled";
         $video_alt = "<input type='hidden' name='video' value=\"" . htmlspecialchars($video) . "\"/>";
         $video_msg = wfMsg('video_loggedin');
         $video_button = "";
     }
     $things_vis = "hide";
     $things = "*  ";
     $things_checked = "";
     $tyn = $whow->getSection(wfMsg("thingsyoullneed"));
     if ($tyn != '') {
         $things_vis = "show";
         $things = $tyn;
         $things_checked = " CHECKED ";
     }
     $ingredients_vis = "hide";
     $section = $whow->getSection(wfMsg("ingredients"));
     $ingredients_checked = "";
     if ($section != '') {
         $ingredients_vis = "show";
         $ingredients = $section;
         $ingredients_checked = " CHECKED ";
     }
     $sources_vis = "hide";
     $sources = "*  ";
     $sources_checked = "";
     $sources = $whow->getSection(wfMsg("sources"));
     $sources = str_replace('<div class="references-small"><references/></div>', '', $sources);
     $sources = str_replace('{{reflist}}', '', $sources);
     if ($sources != "") {
         $sources_vis = "show";
         $sources_checked = " CHECKED ";
     }
     $new_field = "";
     if ($newArticle || $new_article) {
         $new_field = "<input type=hidden name=new_article value=true>";
     }
     $lang_links = htmlspecialchars($whow->getLangLinks());
     $vt = Title::makeTitle(NS_VIDEO, $this->mTitle->getText());
     $vp = SpecialPage::getTitleFor("Previewvideo", $vt->getFullText());
     $newArticleWarn = '<script type="text/javascript" src="' . wfGetPad('/extensions/min/f/extensions/wikihow/winpop.js?') . WH_SITEREV . '"></script>';
     $popup = Title::newFromText("UploadPopup", NS_SPECIAL);
     if ($wgUser->isLoggedIn()) {
         $token = htmlspecialchars($wgUser->editToken());
     } else {
         $token = EDIT_TOKEN_SUFFIX;
     }
     $show_weave = false;
     if ('preview' == $this->formtype) {
         $previewOutput = $this->getPreviewText();
         $this->showPreview($previewOutput);
         $show_weave = true;
     } else {
         $wgOut->addHTML('<div id="wikiPreview"></div>');
     }
     if ('diff' == $this->formtype) {
         $wgOut->addCSScode('diffc');
         $this->showDiff();
         $show_weave = true;
     }
     $weave_links = '';
     if ($show_weave) {
         $relBtn = $wgLanguageCode == 'en' ? PopBox::getGuidedEditorButton() : '';
         $relHTML = PopBox::getPopBoxJSGuided() . PopBox::getPopBoxDiv() . PopBox::getPopBoxCSS();
         $weave_links = $relHTML . '<div class="wh_block editpage_sublinks">' . $relBtn . '</div>';
     }
     $undo = '';
     if ($wgRequest->getVal('undo', null) != null) {
         $undo_id = $wgRequest->getVal('undo', null);
         $undo = "\n<input type='hidden' value=\"{$undo_id}\" name=\"wpUndoEdit\" />\n";
     }
     $wgOut->addHTML(Easyimageupload::getUploadBoxJS());
     $wgOut->addHTML("\t\n{$newArticleWarn}\n\n<div id='editpage'>\n<form id=\"editform\" name=\"editform\" method=\"post\" action=\"{$action}\"\nenctype=\"application/x-www-form-urlencoded\"  onSubmit=\"return checkForm();\">\t\t");
     if (is_callable($formCallback)) {
         call_user_func_array($formCallback, array(&$wgOut));
     }
     $hidden_cats = "";
     if (!$wgUser->isLoggedIn()) {
         $hidden_cats = "<input type=\"hidden\" name=\"categories22\" value=\"{$cat_string}\">";
     }
     $token1 = md5($wgUser->getName() . $this->mTitle->getArticleID() . time());
     wfTrackEditToken($wgUser, $token1, $this->mTitle, $this instanceof EditPageWrapper);
     $wgOut->addHTML("\n\t\t{$new_field}\n\t\t{$hidden_cats}\n\t\t<input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n\n\t\t<input type=\"hidden\" name=\"requested\" value=\"{$requested}\">\n\t\t<input type=\"hidden\" name=\"langlinks\" value=\"{$lang_links}\">\n\t\t<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n\n\n\t\t{$commentsubject}\n\t\t{$title}\n\t\t<br clear='all'/>\n<script language='javascript'>\n\tvar vp_URL = '{$vp->getLocalUrl()}';\n</script>\n<script language='javascript' src='" . wfGetPad('/extensions/min/f/extensions/wikihow/previewvideo.js?rev=') . "'></script>\n<style type='text/css' media='all'>/*<![CDATA[*/ @import '" . wfGetPad('/extensions/min/f/extensions/wikihow/editpagewrapper.css,/extensions/wikihow/winpop.css,/extensions/wikihow/video/importvideo.css,/extensions/wikihow/cattool/categorizer.css,/extensions/wikihow/cattool/categorizer_editpage.css&rev=') . WH_SITEREV . "'; /*]]>*/</style>\n\n\t{$weave_links}\n\n\t<div id='introduction' class='{$section_class}'>\n\t\t<h2>" . wfMsg('introduction') . "\n\t\t\t<div class='head_details'>" . wfMsg('summaryinfo') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('introduction-url') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea rows='4' cols='100' name='summary' id='summary' tabindex=\"2\" wrap=virtual>{$summary}</textarea>\n\t\t<!--a href='#' class='button secondary add_image_button' onclick='easyImageUpload.doEIUModal(\"intro\"); return false;'>" . wfMsg('eiu-add-image-to-introduction') . "</a-->\n\t\t<div class='clearall'></div>\n\t</div>\n\n\n\t<div id='ingredients' class='{$ingredients_vis} {$section_class}'>\n\t\t<h2>" . wfMsg('ingredients') . "\n\t\t\t<div class='head_details'>" . wfMsg('ingredients_tooltip') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('ingredients') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='ingredients' rows='4' cols='100' onKeyUp=\"addStars(event, document.editform.ingredients);\" tabindex='3' id='ingredients_text'>{$ingredients}</textarea>\n\t\t<a href='#' class='button secondary add_image_button'  onclick='easyImageUpload.doEIUModal(\"ingredients\"); return false;'>" . wfMsg('eiu-add-image-to-ingredients') . "</a>\n\t</div>\n\n\t<div id='steps' class='{$section_class}'>\n\t\t<h2>" . wfMsg('steps') . "\n\t\t\t<div class='head_details'>" . wfMsg('stepsinfo') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('steps') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='steps' rows='{$wgRequest->getVal('txtarea_steps_text', 12)}' cols='100' wrap='virtual' onKeyUp=\"addNumToSteps(event);\" tabindex='4' id='steps_text'>{$steps}</textarea>\n\t\t<a href='#' class='button secondary add_image_button' onclick='easyImageUpload.doEIUModal(\"steps\", 0); return false;'>" . wfMsg('eiu-add-image-to-steps') . "</a>\n\t</div>");
     $wgOut->addHTML("<div id='video' class='{$section_class}'>\n\t\t<h2>" . wfMsg('video') . "\n\t\t\t<div class='head_details'>" . wfMsg('videoinfo') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('video') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t{$video_alt}\n\t\t<input type='text' name='video{$video_disabled}' size='60' id='video_text' style='float:left;' value=\"{$video}\" {$video_disabled}/><br />\n\t\t{$video_button}\n\t\t<a href='javascript:showHideVideoPreview();' id='show_preview_button' class='button secondary {$vidbtn_vis}'>" . wfMsg('show_preview') . "</a>\n\t\t{$video_msg}\n\t</div>\n\t<div id='viewpreview' class='{$vidpreview_vis} {$section_class}' style='text-align: center; margin-top: 5px;'>\n\t\t<center><a onclick='showHideVideoPreview();'>" . wfMsg('ep_hide_preview') . "</a></center><br/>\n\t\t<div id='viewpreview_innards'>{$vidpreview}</div>\n\t</div>\n\n\t<div id='tips' class='{$section_class}'>\n\t\t<h2>" . wfMsg('tips') . "\n\t\t\t<div class='head_details'>" . wfMsg('listhints') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('tips') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='tips' rows='{$wgRequest->getVal('txtarea_tips_text', 12)}' cols='100' wrap='virtual' onKeyUp='addStars(event, document.editform.tips);' tabindex='5' id='tips_text'>{$tips}</textarea>\n\t\t<a href='#' class='button secondary add_image_button' onclick='easyImageUpload.doEIUModal(\"tips\"); return false;'>" . wfMsg('eiu-add-image-to-tips') . "</a>\n\t</div>\n\n\t<div id='warnings' class='{$section_class}'>\n\t\t<h2>" . wfMsg('warnings') . "\n\t\t\t<div class='head_details'>" . wfMsg('optionallist') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=3#" . wfMsg('warnings') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='warnings' rows='{$wgRequest->getVal('txtarea_warnings_text', 4)}' cols='100' wrap='virtual' onKeyUp='addStars(event, document.editform.warnings);' id='warnings_text' tabindex=\"6\" id='warnings_text'>{$warns}</textarea>\n\t\t<a href='#' class='button secondary add_image_button' onclick='easyImageUpload.doEIUModal(\"warnings\"); return false;'>" . wfMsg('eiu-add-image-to-warnings') . "</a>\n\t</div>\n\n\t<div id='thingsyoullneed' class='{$things_vis} {$section_class}'>\n\t\t<h2>" . wfMsg('thingsyoullneed') . "\n\t\t\t<div class='head_details'>" . wfMsg('items') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=4#" . wfMsg('thingsyoullneed') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='thingsyoullneed' rows='4' cols='65' wrap='virtual' onKeyUp='addStars(event, document.editform.thingsyoullneed);' tabindex='7' id='thingsyoullneed_text'>{$things}</textarea>\n\t\t<a href='#' class='button secondary add_image_button' onclick='easyImageUpload.doEIUModal(\"thingsyoullneed\"); return false;'>" . wfMsg('eiu-add-image-to-thingsyoullneed') . "</a>\n\t</div>\n\n\t<div id='relatedwikihows' class='{$related_vis} {$section_class}'>\n\t\t<h2>" . wfMsg('relatedarticlestext') . "\n\t\t\t<div class='head_details'>" . wfMsg('relatedlist') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=5#" . wfMsg('related-wikihows-url') . "\" target=\"new\">" . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<div id='related_buttons'>\n\t\t\t<a href='#'  class='button secondary' onclick='moveRelated(true);return false;' >" . wfMsg('epw_move_up') . "</a>\n\t\t\t<a href='#' class='button secondary' onclick='moveRelated(false);return false;'>" . wfMsg('epw_move_down') . "</a>\n\t\t\t<a href='#' class='button red' onclick='removeRelated(); return false;'>" . wfMsg('epw_remove') . "</a>\n\t\t\t<br />\n\t\t\t<br />\n\t\t</div>\n\t\t<input type=hidden value=\"\" name=\"related_list\">\n\t\t<select size='4' name='related' id='related_select' ondblclick='viewRelated();'>\n\t\t\t{$relatedHTML}\n\t\t</select>\n\t\t<br />\n\t\t<br />\n\t\t<br class='clearall'/>\n\t\t<div>\n\t\t\t<b>" . wfMsg('addtitle') . "</b><br />\n\t\t\t<input type='text' autocomplete=\"off\" maxLength='256' name='q' value='' onKeyPress=\"return keyxxx(event);\" tabindex='8'>\n\t\t</div>\n\t\t<a href='#' id='add_button' class='button secondary' onclick='add_related();return false;'>" . wfMsg('epw_add') . "</a>\n\t\t<br class='clearall'/>\n\t</div>\n\n<script language=\"JavaScript\">\n\tvar js_enabled = document.getElementById('related');\n\t\t if (js_enabled != null) {\n\t\t\t\t js_enabled.className = 'display';\n\t\t\t}\n\t</script>\n\t<noscript>\n\t\t<input type='hidden' name='no_js' value='true'>\n\t\t<div id='related'>\n\t\t\t<textarea name='related_no_js' rows='4' cols='65' wrap='virtual' onKeyUp='addStars(event, document.editform.related_no_js);' id='related_no_js' tabindex='8'>{$related_text}</textarea>\n\t\t</div>\n\t</noscript>\n\n\t<div id='sources' class='{$sources_vis} {$section_class}'>\n\t\t<h2>" . wfMsg('sources') . "\n\t\t\t<div class='head_details'>" . wfMsg('linkstosites') . "</div>\n\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('sources-links-url') . "\" target=\"new\"> " . wfMsg('moreinfo') . "</a>\n\t\t</h2>\n\t\t<textarea name='sources' rows='3' cols='100' wrap='virtual' onKeyUp='addStars(event, document.editform.sources);' id='sources' tabindex='9'>{$sources}</textarea>\n\t</div>\n\n\t<div class='{$section_class}'>\n\t\t<h2>" . wfMsg('optional_options') . "</h2>\n\t\t{$categoryHTML}\n\n\t\t<div id='optional_sections'>\n\t\t\t<h5>" . wfMsg('optionalsections') . "</h5>\n\t\t\t<ul>\n\t\t\t\t<li><input type='checkbox' id='thingsyoullneed_checkbox' name='thingsyoullneed_checkbox' onclick='showhiderow(\"thingsyoullneed\", \"thingsyoullneed_checkbox\");' {$things_checked} /> <label for='thingsyoullneed_checkbox'>" . wfMsg('thingsyoullneed') . "</label></li>\n\t\t\t\t<li><input type='checkbox' id='related_checkbox' name='related_checkbox' onclick='showhiderow(\"relatedwikihows\", \"related_checkbox\");' {$related_checked} > <label for='related_checkbox'>" . wfMsg('relatedwikihows') . "</label></li>\n\t\t\t\t<li><input type='checkbox' id='sources_checkbox' name='sources_checkbox' onclick='showhiderow(\"sources\", \"sources_checkbox\");' {$sources_checked} > <label for='sources_checkbox'>" . wfMsg('sources') . "</label></li>\n\t\t\t\t<li><input type='checkbox' id='ingredients_checkbox' name='ingredients_checkbox' onclick='showhiderow(\"ingredients\", \"ingredients_checkbox\");' {$ingredients_checked} > <label for='ingredients_checkbox'>" . wfMsg('ingredients_checkbox') . "</label></li>\n\t\t\t</ul>\n\t\t</div>\n\t</div>\n\t\n\t<div class='{$section_class}'>\n\t\t<div class='editOptions'>\n\t\t\t<h2>" . wfMsg('editdetails') . "\n\t\t\t\t<div class='head_details'>" . wfMsg('summaryedit') . "</div>\n\t\t\t\t<a href=\"{$wgScriptPath}/" . wfMsg('writers-guide-url') . "?section=2#" . wfMsg('summary') . "\" target=\"new\"> " . wfMsg('moreinfo') . "</a>\n\t\t\t</h2>\n\t\t\t{$editsummary}\n\t\t\t{$checkboxhtml}\n\t\t\t{$undo}\n\t\t\t<input type='hidden' value=\"{$token}\" name=\"wpEditToken\" />\n\t\t\t<input type='hidden' value=\"{$token1}\" name=\"wpEditTokenTrack\" />\n\t\t\t<div class='editButtons'>\n\t\t\t\t<a href=\"javascript:history.back()\" id=\"wpCancel\" class=\"button secondary\">" . wfMsg('cancel') . "</a>\n\t\t\t\t{$buttonshtml}\n\t\t\t</div>\n\t\t\t{$copywarn}\n\t\t</div>\n\t</div>\n\t<input type='hidden' value=\"" . htmlspecialchars($this->section) . "\" name=\"wpSection\" />\n");
     if ($this->isConflict) {
         require_once "DifferenceEngine.php";
         $wgOut->addCSScode('diffc');
         $wgOut->addHTML("<h2>" . wfMsg("yourdiff") . "</h2>\n");
         DifferenceEngine::showDiff($this->textbox2, $this->textbox1, wfMsg("yourtext"), wfMsg("storedversion"));
     }
     if ($wgUser->getOption('hidepersistantsavebar', 0) == 0) {
         $wgOut->addHTML(" <div id='edit_page_footer'>\n\t\t\t\t<table class='edit_footer'><tr><td class='summary'>\n\t\t\t\t" . wfMsg('editsummary') . ": &nbsp; {$editsummary1}</td>\n\t\t\t\t<td class='buttons'>{$footerbuttons}</td></tr></table>\n\t\t\t\t</div> ");
     }
     $wgOut->addHTML("</form></div>\n");
 }
Example #7
0
 static function getDeleteReasonFromCode($article, $outputPage, &$defaultReason)
 {
     $whArticle = WikihowArticleEditor::newFromTitle($article->getTitle());
     $intro = $whArticle->getSummary();
     $matches = array();
     preg_match('/{{nfd.*}}/i', $intro, $matches);
     if ($matches[0] != null) {
         $loc = stripos($matches[0], "|", 4);
         if ($loc) {
             //there is a reason
             $loc2 = stripos($matches[0], "|", $loc + 1);
             if (!$loc2) {
                 $loc2 = stripos($matches[0], "}", $loc + 1);
             }
             //ok now grab the reason
             $nfdreason = substr($matches[0], $loc + 1, $loc2 - $loc - 1);
             switch ($nfdreason) {
                 case 'acc':
                     $defaultReason = "Accuracy";
                     break;
                 case 'adv':
                     $defaultReason = "Advertising";
                     break;
                 case 'cha':
                     $defaultReason = "Character";
                     break;
                 case 'dan':
                     $defaultReason = "Extremely Dangerous";
                     break;
                 case 'dru':
                     $defaultReason = "Drug focused";
                     break;
                 case 'hat':
                     $defaultReason = "Hate/racist";
                     break;
                 case 'imp':
                     $defaultReason = "Impossible";
                     break;
                 case 'inc':
                     $defaultReason = "Incomplete";
                     break;
                 case 'jok':
                     $defaultReason = "Joke";
                     break;
                 case 'mea':
                     $defaultReason = "Mean-spirited";
                     break;
                 case 'not':
                     $defaultReason = "Not a how-to";
                     break;
                 case 'pol':
                     $defaultReason = "Political opinion";
                     break;
                 case 'pot':
                     $defaultReason = "Potty humor";
                     break;
                 case 'sar':
                     $defaultReason = "Sarcastic";
                     break;
                 case 'sex':
                     $defaultReason = "Sexually explicit";
                     break;
                 case 'soc':
                     $defaultReason = "Societal Instructions";
                     break;
                 case 'ill':
                     $defaultReason = "Universally illegal";
                     break;
                 case 'van':
                     $defaultReason = "Vanity pages";
                     break;
                 case 'jok':
                     $defaultReason = "Joke";
                     break;
                 case 'dup':
                     $defaultReason = "Duplicate";
                     break;
             }
         }
     }
     return true;
 }
Example #8
0
 static function processArticleHTML($body, $opts = array())
 {
     global $wgUser, $wgTitle, $wgLanguageCode;
     $skin = $wgUser->getSkin();
     $doc = PHPQuery::newDocument($body);
     $featurestar = pq("div#featurestar");
     if ($featurestar) {
         $clearelement = pq($featurestar)->next();
         $clearelement->remove();
         $featurestar->remove();
     }
     $ads = $wgUser->isAnon() && !@$opts['no-ads'] && wikihowAds::isEligibleForAds();
     // Remove __TOC__ resulting html from all pages other than User pages
     if (@$opts['ns'] != NS_USER && pq('table#toc')->length) {
         $toc = pq('table#toc');
         $toc->prev()->remove();
         $toc->remove();
     }
     $sticky = "";
     if (@$opts['sticky-headers']) {
         $sticky = " sticky ";
     }
     // Remove originators for titles that don't exist
     if ($wgTitle->getArticleId() == 0) {
         pq('#originators')->remove();
     }
     //move firstHeading to inside the intro
     $firstH2 = pq("h2:first");
     if (pq($firstH2)->length() == 0) {
         try {
             pq("#bodycontents")->children(":first")->wrapAll("<div class='section wh_block'></div>");
         } catch (Exception $e) {
         }
     } else {
         try {
             pq($firstH2)->prevAll()->reverse()->wrapAll("<div id='intro' class='section {$sticky}'></div>");
         } catch (Exception $e) {
         }
     }
     //add a clearall to the end of the intro
     pq("#intro")->append("<div class='clearall'></div>");
     //removing any stray br tags at the start of the intro
     foreach (pq("#intro #originators")->next()->children() as $child) {
         if (pq($child)->is("br")) {
             pq($child)->remove();
         } else {
             break;
         }
     }
     //add the pimpedheader to our h3s!
     pq('h3, h4')->prepend('<div class="altblock"></div>');
     foreach (pq("h2") as $node) {
         //find each section
         //first grab the name
         $sectionName = mb_strtolower(pq("span", $node)->html());
         //Remove all non-letters and numbers in all languges
         if ($wgLanguageCode == 'en') {
             $sectionName = preg_replace("/[^A-Za-z0-9]/u", '', $sectionName);
         } elseif ($wgLanguageCode == 'hi') {
             $sectionName = str_replace(' ', '', $sectionName);
         } else {
             $sectionName = preg_replace("/[^\\p{L}\\p{N}]/u", '', $sectionName);
         }
         //now find all the elements prior to the next h2
         $set = array();
         $h3Tags = array();
         $h3Elements = array();
         $priorToH3Set = array();
         $h3Count = 0;
         foreach (pq($node)->nextAll() as $sibling) {
             if (pq($sibling)->is("h2")) {
                 break;
             }
             if (pq($sibling)->is("h3")) {
                 $h3Count++;
                 $h3Tags[$h3Count] = $sibling;
                 $h3Elements[$h3Count] = array();
             } else {
                 if ($h3Count > 0) {
                     $h3Elements[$h3Count][] = $sibling;
                 } else {
                     $priorToH3Set[] = $sibling;
                 }
             }
             $set[] = $sibling;
         }
         if (mb_strtolower($sectionName) == mb_strtolower(wfMsg('steps'))) {
             if ($h3Count > 0) {
                 //has alternate methods
                 $altMethodNames = array();
                 $altMethodAnchors = array();
                 if (count($priorToH3Set) > 1) {
                     //if there are alt methods, then there will at least be a <p> tag with a link inside, so that doesn't count
                     //needs to have a steps section prior to the
                     //alt method
                     try {
                         pq($priorToH3Set)->wrapAll("<div id='{$sectionName}' class='section_text'></div>");
                     } catch (Exception $e) {
                     }
                     $overallSet = array();
                     $overallSet[] = $node;
                     foreach (pq("div#{$sectionName}:first") as $temp) {
                         $overallSet[] = $temp;
                     }
                     try {
                         pq($overallSet)->wrapAll("<div class='section steps {$sticky}'></div>");
                     } catch (Exception $e) {
                     }
                 } else {
                     //hide the h2 tag
                     pq($node)->addClass("hidden");
                 }
                 $displayMethodCount = $h3Count;
                 $isSample = array();
                 for ($i = 1; $i <= $h3Count; $i++) {
                     $isSampleItem = false;
                     if (!is_array($h3Elements[$i]) || count($h3Elements[$i]) < 1) {
                         $isSampleItem = false;
                     } else {
                         //the sd_container isn't always the first element, need to look through all
                         foreach ($h3Elements[$i] as $node) {
                             //not the most efficient way to do this, but couldn't get the find function to work.
                             if (pq($node)->attr("id") == "sd_container") {
                                 $isSampleItem = true;
                                 break;
                             }
                         }
                     }
                     if ($isSampleItem) {
                         $isSample[$i] = true;
                         $displayMethodCount--;
                     } else {
                         $isSample[$i] = false;
                     }
                 }
                 if ($ads) {
                     wikihowAds::setAltMethods($displayMethodCount > 1);
                 }
                 $wikihowArticle = WikihowArticleEditor::newFromTitle($wgTitle);
                 $editLink = $skin->editSectionLink($wgTitle, $wikihowArticle->getSectionNumber("steps"));
                 $displayMethod = 1;
                 for ($i = 1; $i <= $h3Count; $i++) {
                     //change the method title
                     $methodTitle = pq("span", $h3Tags[$i])->html();
                     $removeRet = WikihowArticleEditor::removeMethodNamePrefix($methodTitle);
                     $altMethodNames[] = $methodTitle;
                     if ($displayMethodCount > 1 && !$isSample[$i] && $removeRet['has_parts'] && $opts['ns'] == NS_MAIN) {
                         if ($methodTitle) {
                             $methodTitle = wfMsg("part_2", $displayMethod, $displayMethodCount, $methodTitle);
                         } else {
                             $methodTitle = wfMsg("part_1", $displayMethod, $displayMethodCount);
                         }
                         $displayMethod++;
                     } elseif ($displayMethodCount > 1 && !$isSample[$i] && $opts['ns'] == NS_MAIN) {
                         if ($methodTitle) {
                             $methodTitle = wfMsg("method_2", $displayMethod, $displayMethodCount, $methodTitle);
                         } else {
                             $methodTitle = wfMsg("method_1", $displayMethod, $displayMethodCount);
                         }
                         $displayMethod++;
                     }
                     pq("span", $h3Tags[$i])->html($methodTitle);
                     //add an edit link to each sub method
                     pq("span", $h3Tags[$i])->prepend($editLink);
                     $sample = $isSample[$i] ? "sample" : "";
                     pq($h3Elements[$i])->wrapAll("<div id='{$sectionName}_{$i}' class='section_text'></div>");
                     $overallSet = array();
                     $overallSet[] = $h3Tags[$i];
                     foreach (pq("div#{$sectionName}_{$i}:first") as $temp) {
                         $overallSet[] = $temp;
                     }
                     try {
                         pq($overallSet)->wrapAll("<div class='section steps {$sample} {$sticky}'></div>");
                     } catch (Exception $e) {
                     }
                 }
                 $i = 1;
                 // Pull out the top-level anchors
                 foreach (pq(".section.steps") as $steps) {
                     // Only grab last anchor. There may be other anchors for subsections
                     // but we'll ignore those
                     $anchor = pq('.anchor:last', $steps);
                     $altMethodAnchors[$i] = pq($anchor)->attr("name");
                     $i++;
                 }
                 //now grab the one prior to the first step
                 $altMethodAnchors[0] = pq(".section.steps:first")->prev()->children(".anchor")->attr("name");
                 // Sometimes there isn't an anchor prior to first step, so get rid of it
                 if (empty($altMethodAnchors[0])) {
                     $altMethodAnchors = array_splice($altMethodAnchors, 0);
                 }
                 //fix for Chrome -- wrap first anchor name so it detects the spacing
                 try {
                     pq(".section.steps:first")->prev()->children(".anchor")->after('<br class="clearall" />')->wrapAll('<div></div>');
                 } catch (Exception $e) {
                 }
                 //now we should have all the alt methods,
                 //let's create the links to them under the headline
                 $charCount = 0;
                 $maxCount = 80000;
                 //temporairily turning off hidden headers
                 $hiddenCount = 0;
                 $anchorList = "";
                 //don't use the last altMethodAnchor b/c it links to the first non-step section
                 for ($i = 0; $i < count($altMethodAnchors) - 1; $i++) {
                     $methodName = pq('<div>' . $altMethodNames[$i] . '</div>')->text();
                     // remove any reference notes
                     $methodName = preg_replace("@\\[\\d{1,3}\\]\$@", "", $methodName);
                     $charCount += strlen($methodName);
                     $class = "";
                     if ($charCount > $maxCount) {
                         $class = "hidden excess";
                         $hiddenCount++;
                     }
                     if ($methodName == "") {
                         continue;
                     }
                     $anchorList .= "<a href='#{$altMethodAnchors[$i]}' class='{$class}'>{$methodName}</a>";
                 }
                 $hiddentext = "";
                 if ($hiddenCount > 0) {
                     $hiddenText = "<a href='#' id='method_toc_unhide'>{$hiddenCount} more method" . ($hiddenCount > 1 ? "s" : "") . "</a>";
                     $hiddenText .= "<a href='#' id='method_toc_hide' class='hidden'>show less methods</a>";
                 }
                 pq(".firstHeading")->after("<p id='method_toc'>{$anchorList}{$hiddenText}</p>");
             } else {
                 //only 1 method
                 if ($ads) {
                     wikihowAds::setAltMethods(false);
                 }
                 if ($set) {
                     try {
                         pq($set)->wrapAll("<div id='{$sectionName}' class='section_text'></div>");
                     } catch (Exception $e) {
                     }
                 }
                 $overallSet = array();
                 $overallSet[] = $node;
                 foreach (pq("div#{$sectionName}:first") as $temp) {
                     $overallSet[] = $temp;
                 }
                 try {
                     pq($overallSet)->wrapAll("<div class='section steps {$sticky}'></div>");
                 } catch (Exception $e) {
                 }
             }
         } else {
             //not a steps section
             if ($set) {
                 $sec_id = @$opts['list-page'] ? '' : 'id="' . $sectionName . '"';
                 try {
                     $new_set = pq($set)->wrapAll("<div {$sec_id} class='section_text'></div>");
                 } catch (Exception $e) {
                 }
             }
             $overallSet = array();
             $overallSet[] = $node;
             foreach (pq("div#{$sectionName}:first") as $temp) {
                 $overallSet[] = $temp;
             }
             try {
                 pq($overallSet)->wrapAll("<div class='section {$sectionName} {$sticky}'></div>");
             } catch (Exception $e) {
             }
             if (@$opts['list-page']) {
                 //gotta pull those dangling divs into the same space as the h2
                 pq($overallSet)->parent()->append(pq($new_set));
             }
             // commenting this out because it's causing the following error:
             // "Couldn't add newnode as the previous sibling of refnode"
             // // format edit links for non-steps sections
             // // pq('span', $node)->prepend(pq('a.edit', $node));
         }
     }
     //add a clear to the end of each section_text to make sure
     //images don't bleed across the bottom
     pq(".section_text")->append("<div class='clearall'></div>");
     // Add checkboxes to Ingredients and 'Things You Need' sections, but only to the top-most li
     $lis = pq('#ingredients > ul > li, #thingsyoullneed > ul > li');
     foreach ($lis as $li) {
         $id = md5(pq($li)->html() . mt_rand(1, 100));
         pq($li)->html("<input id='item_{$id}' class='css-checkbox' type='checkbox'/><label for='item_{$id}' name='item_{$id}_lbl' class='css-checkbox-label'></label><div class='checkbox-text'>" . pq($li)->html() . '</div>');
     }
     // Move templates above article body contents and style appropriately
     foreach (pq('.template_top') as $template) {
         pq($template)->addClass('sidebox');
         if (pq($template)->parent()->hasClass('tmp_li')) {
             pq($template)->addClass('tmp_li');
         }
         if ($wgUser->isAnon()) {
             pq($template)->addClass('notice_bgcolor_lo');
         } else {
             pq($template)->addClass('notice_bgcolor_important');
         }
     }
     // put templates after the intro div
     pq('.template_top')->insertAfter('#intro');
     //now put the step numbers in
     foreach (pq("div.steps .section_text > ol") as $list) {
         pq($list)->addClass("steps_list_2");
         $stepNum = 1;
         foreach (pq($list)->children() as $step) {
             $boldStep = WikihowArticleHTML::boldFirstSentence(pq($step)->html());
             pq($step)->html($boldStep);
             pq($step)->prepend("<div class='step_num'>{$stepNum}</div>");
             pq($step)->append("<div class='clearall'></div>");
             $stepNum++;
         }
     }
     foreach (pq(".steps:last .steps_list_2")->children(":last-child") as $step) {
         pq($step)->addClass("final_li");
     }
     //move each of the large images to the top
     foreach (pq(".steps_list_2 li .mwimg.largeimage") as $image) {
         //delete any previous <br>
         foreach (pq($image)->prevAll() as $node) {
             if (pq($node)->is("br")) {
                 pq($node)->remove();
             } else {
                 break;
             }
         }
         //first handle the special case where the image
         //ends up inside the bold tag by accident
         if (pq($image)->parent()->is("b")) {
             pq($image)->insertBefore(pq($image)->parent());
         }
         if (pq($image)->parent()->parent()->is(".steps_list_2")) {
             pq($image)->parent()->prepend($image);
         }
     }
     //move each of the large images to the top
     foreach (pq(".steps_list_2 li .whvid_cont") as $vid) {
         //delete any previous <br>
         foreach (pq($vid)->prevAll() as $node) {
             if (pq($node)->is("br")) {
                 pq($node)->remove();
             } else {
                 break;
             }
         }
         if (pq($vid)->parent()->parent()->is(".steps_list_2")) {
             pq($vid)->parent()->prepend($vid);
         }
     }
     //if there's a related articles section, make it have images
     $relatedSection = pq("#relatedwikihows");
     if ($relatedSection) {
         foreach (pq("li a", $relatedSection) as $related) {
             $titleText = pq($related)->attr("title");
             $title = Title::newFromText($titleText);
             if ($title) {
                 $image = $skin->getArticleThumb($title, 127, 120);
                 pq($relatedSection)->prepend($image);
             }
             pq($related)->remove();
         }
         pq("ul", $relatedSection)->remove();
         pq($relatedSection)->append("<div class='clearall'></div>");
     }
     //remove all images in the intro that aren't
     //marked with the class "introimage"
     pq("#intro .mwimg:not(.introimage)")->remove();
     //let's mark all the <p> tags that aren't inside a step.
     //they need special padding
     foreach (pq(".section.steps p") as $p) {
         if (pq($p)->parents(".steps_list_2")->count() == 0 && pq($p)->children(".anchor")->count() == 0) {
             pq($p)->addClass("lone_p");
         }
     }
     // Add alt method adder cta
     if (class_exists("AltMethodAdder") && $wgTitle && $wgUser && $wgUser->isAnon()) {
         $cta = AltMethodAdder::getCTA($wgTitle);
         if (!is_null($cta)) {
             pq("div.steps:last")->after($cta);
         }
     }
     //add line breaks between the p tags
     foreach (pq("p") as $paragraph) {
         $sibling = pq($paragraph)->next();
         if (!pq($sibling)->is("p")) {
             continue;
         }
         if (pq($sibling)->children(":first")->hasClass("anchor")) {
             continue;
         }
         $id = pq($paragraph)->attr("id");
         if ($id == "originators" || $id == "method_toc") {
             continue;
         }
         pq($paragraph)->after("<br />");
     }
     if ($ads) {
         pq("#intro")->append(wikihowAds::getAdUnitPlaceholder('intro'));
         pq(".steps_list_2:first li:first")->append(wikihowAds::getAdUnitPlaceholder(0));
         pq(".final_li")->append(wikihowAds::getAdUnitPlaceholder(1));
         $tipsClass = mb_strtolower(wfMsg("tips"));
         //grabs the tips section by name, but internationalized
         pq(".{$tipsClass} ul:last")->after(wikihowAds::getAdUnitPlaceholder('2a'));
     }
     return $doc->htmlOuter();
 }