public function parseArticle_02($article) { global $wgWikiHowSections, $wgTitle, $wgUser; $ads = $wgUser->getID() == 0; $sk = new SkinWikihowskin(); $sectionMap = array(wfMsg('Intro') => 'intro', wfMsg('Ingredients') => 'ingredients', wfMsg('Steps') => 'steps', wfMsg('Video') => 'video', wfMsg('Tips') => 'tips', wfMsg('Warnings') => 'warnings', wfMsg('relatedwikihows') => 'relatedwikihows', wfMsg('sourcescitations') => 'sources', wfMsg('thingsyoullneed') => 'thingsyoullneed'); foreach ($wgWikiHowSections as $section) { $reverse_msgs[wfMsg($section)] = $section; } $parts = preg_split("@(<h2.*</h2>)@im", $article, 0, PREG_SPLIT_DELIM_CAPTURE); $body = ''; $intro_img = ''; for ($i = 0; $i < sizeof($parts); $i++) { if ($i == 0) { //intro preg_match("/Image:(.*)\">/", $parts[$i], $matches); if (count($matches) > 0) { $img = $matches[1]; $img = preg_replace('@%27@', "'", $img); $image = Title::makeTitle(NS_IMAGE, $img); if ($image) { $file = wfFindFile($image); if ($file) { $thumb = $file->getThumbnail(200, -1, true, true); $intro_img = '<a href="' . $image->getFullUrl() . '"><img border="0" width="200" class="mwimage101" src="' . wfGetPad($thumb->url) . '" alt="" /></a>'; } } } if ($intro_img == '') { $intro_img = '<img border="0" width="200" class="mwimage101" src="' . wfGetPad('/skins/WikiHow/images/wikihow_sq_200.png') . '" alt="" />'; } $r = Revision::newFromTitle($wgTitle); $intro_text = Wikitext::getIntro($r->getText()); $intro_text = trim(Wikitext::flatten($intro_text)); $body .= '<br /><div id="color_div"></div><br />'; $body .= '<div id="article_intro">' . $intro_text . '</div>'; if ($ads) { $body .= '<div class="ad_noimage intro_ad">' . wikihowAds::getAdUnitPlaceholder('intro') . '</div>'; } } else { if (stripos($parts[$i], "<h2") === 0 && $i < sizeof($parts) - 1) { preg_match("@<span>.*</span>@", $parts[$i], $matches); $rev = ""; if (sizeof($matches) > 0) { $h2 = trim(strip_tags($matches[0])); $rev = isset($reverse_msgs[$h2]) ? $reverse_msgs[$h2] : ""; } if ($rev !== 'steps') { $body .= $parts[$i]; } $i++; if ($rev == "steps") { $body .= "\n<div id=\"steps\" class='editable'>{$parts[$i]}</div>\n"; } else { if ($rev != "") { $body .= "\n<div id=\"{$rev}\" class='article_inner editable'>{$parts[$i]}</div>\n"; } else { $body .= "\n<div class='article_inner editable'>{$parts[$i]}</div>\n"; } } } else { $body .= $parts[$i]; } } } $punct = "!\\.\\?\\:"; # valid ways of ending a sentence for bolding $i = strpos($body, '<div id="steps"'); if ($i !== false) { $j = strpos($body, '<div id=', $i + 5); } if ($j === false) { $j = strlen($body); } if ($j !== false && $i !== false) { $steps = substr($body, $i, $j - $i); $parts = preg_split("@(<[/]?ul>|<[/]?ol>|<[/]?li>)@im", $steps, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $numsteps = preg_match_all('/<li>/m', $steps, $matches); $level = 0; $steps = ""; $upper_tag = ""; $levelstack = array(); $tagstack = array(); $current_tag = ""; $current_li = 1; $donefirst = false; // used for ads to tell when we've put the ad after the first step if ($numsteps < 100) { while ($p = array_shift($parts)) { switch (strtolower($p)) { case "<ol>": $level++; if ($level == 1) { $p = '<ol class="steps_list">'; $upper_tag = "ol"; } else { $p = " <div class='listbody'>{$p}"; } if ($current_tag != "") { $tagstack[] = $current_tag; } $current_tag = "ol"; $levelstack[] = $current_li; $current_li = 1; break; case "<ul>": if ($current_tag != "") { $tagstack[] = $current_tag; } $current_tag = "ul"; $levelstack[] = $current_li; $level++; break; case "</ol>": $p .= '<div id="steps_end"></div>'; case "</ul>": $level--; if ($level == 0) { $upper_tag = ""; } $current_tag = array_pop($tagstack); $current_li = array_pop($levelstack); break; case "<li>": $closecount = 0; if ($level == 1 && $upper_tag == "ol") { $li_number = $current_li++; //$p = '<li>'. str_pad($li_number,2,'0',STR_PAD_LEFT); $p = '<li>'; # this is where things get interesting. Want to make first sentence bold! # but we need to handle cases where there are tags in the first sentence # split based on HTML tags $next = array_shift($parts); $htmlparts = preg_split("@(<[^>]*>)@im", $next, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $dummy = 0; $incaption = false; $apply_b = false; while ($x = array_shift($htmlparts)) { # if it's a tag, just append it and keep going if (preg_match("@(<[^>]*>)@im", $x)) { //tag $p .= $x; if ($x == "<span class='caption'>") { $incaption = true; } else { if ($x == "</span>" && $incaption) { $incaption = false; } } continue; } # put the closing </b> in if we hit the end of the sentence if (!$incaption) { if (!$apply_b && trim($x) != "") { $p .= '<p class="step_head"><span>' . str_pad($li_number, 2, '0', STR_PAD_LEFT) . '</span>'; $apply_b = true; } if ($apply_b) { $x = preg_replace("@([{$punct}])@im", "\$1</p>", $x, 1, &$closecount); } } $p .= $x; if ($closecount > 0) { break; } else { #echo "\n\n-----$x----\n\n"; } $dummy++; } # get anything left over $p .= implode("", $htmlparts); if ($closecount == 0) { $p .= "</b>"; } // close the bold tag if we didn't already if ($level == 1 && $current_li == 2 && $ads && !$donefirst) { $p .= '<br class="clearall" />' . wikihowAds::getAdUnitPlaceholder(0); $donefirst = true; } } break; case "</li>": $p = "<div class='clearall'></div>{$p}"; //changed BR to DIV b/c IE doesn't work with the BR clear tag break; } // switch $steps .= $p; } // while } else { $steps = substr($body, $i, $j - $i); $steps = "<div id='steps_notmunged'>\n" . $steps . "\n</div>\n"; } // we have to put the final_li in the last OL LI step, so reverse the walk of the tokens $parts = preg_split("@(<[/]?ul>|<[/]?ol>|<[/]?li>)@im", $steps, 0, PREG_SPLIT_DELIM_CAPTURE); $parts = array_reverse($parts); $steps = ""; $level = 0; $gotit = false; $donelast = false; foreach ($parts as $p) { $lp = strtolower($p); if ($lp == "</ol>") { $level++; $gotit = false; } else { if ($lp == "</ul>") { $level++; } else { if (strpos($lp, "<li") !== false && $level == 1 && !$gotit) { /// last OL step list f****r //$p = preg_replace("@<li[^>]*>@i", '<li class="steps_li final_li">', $p); $gotit = true; } else { if (strpos($lp, "<ul") !== false) { $level--; } else { if (strpos($lp, "<ol") !== false) { $level--; } else { if ($lp == "</li>" && !$donelast) { // ads after the last step if ($ads) { if (substr($body, $j) == "") { $p = "<script>missing_last_ads = true;</script>" . wikihowAds::getAdUnitPlaceholder(1) . $p; $no_third_ad = true; } else { $p = '<br />' . wikihowAds::getAdUnitPlaceholder(2) . $p; } } $donelast = true; } } } } } } $steps = $p . $steps; } $body = substr($body, 0, $i) . $steps . substr($body, $j); } /// if numsteps == 100? /// ads below tips, walk the sections and put them after the tips if ($ads) { $foundtips = false; $anchorTag = ""; foreach ($wgWikiHowSections as $s) { $isAtEnd = false; if ($s == "ingredients" || $s == "steps") { continue; } // we skip these two top sections $i = strpos($body, '<div id="' . $s . '"'); if ($i !== false) { $j = strpos($body, '<h2>', $i + strlen($s)); } else { continue; // we didnt' find this section } if ($j === false) { $j = strlen($body); // go to the end $isAtEnd = true; } if ($j !== false && $i !== false) { $section = substr($body, $i, $j - $i); if ($s == "video") { // special case for video $newsection = "<div id='video'><center>{$section}</center></div>"; $body = str_replace($section, $newsection, $body); continue; } else { if ($s == "tips") { //tip ad is now at the bottom of the tips section //need to account for the possibility of no sections below this and therefor //no anchor tag if ($isAtEnd) { $anchorTag = "<p></p>"; } $body = str_replace($section, $section . $anchorTag . wikihowAds::getAdUnitPlaceholder('2a') . '<p><br /></p>', $body); $foundtips = true; break; } else { $foundtips = true; if ($isAtEnd) { $anchorTag = "<p></p>"; } $body = str_replace($section, $section . $anchorTag . wikihowAds::getAdUnitPlaceholder(2), $body); break; } } } } if (!$foundtips && !$no_third_ad) { //must be the video section //need to put in the empty <p> tag since all the other sections have them for the anchor tags. $body .= "<p class='video_spacing'></p>" . wikihowAds::getAdUnitPlaceholder(2); } } $catlinks = $sk->getCategoryLinks($false); $authors = $sk->getAuthorFooter(); if ($authors != "" || is_array($this->data['language_urls']) || $catlinks != "") { //k, now grab the bottom stuff $article_bottom .= '<br />' . wfGetSuggestedTitles($wgTitle) . '<br /> <h2 class="section_head" id="article_info_header">' . wfMsg('article_info') . '</h2> <div id="article_info" class="article_inner"> <p>' . self::getLastEdited() . '</p> <p>' . wfMsg('categories') . ':<br/>' . $catlinks . '</p> <p>' . $authors . '</p> </div><!--end article_info-->'; } if ($wgUser->getID() == 0 && !$isMainPage && $action != 'edit' && $wgTitle->getNamespace() == NS_MAIN) { $article_bottom .= '<div class="final_ad">' . wikihowAds::getAdUnitPlaceholder(7) . '</div>'; } $article_bottom .= ' <div id="final_question"> ' . $userstats . ' <p><b>' . $sk->pageStats() . '</b></p> <div id="page_rating">' . RateArticle::showForm() . '</div> <p></p> </div> <!--end last_question--> </div> <!-- article -->'; //share buttons $url = urlencode($wgServer . "/" . $wgTitle->getPrefixedURL()); $fb = '<div class="like_button"><fb:like href="' . $url . '" send="false" layout="button_count" width="86" show_faces="false"></fb:like></div>'; $gp1 = '<div class="gplus1_button"><g:plusone size="medium" callback="plusone_vote"></g:plusone></div>'; // $fb_share = '<div class="like_button like_tools"><fb:like href="' . $url . '" send="false" layout="button_count" width="86" show_faces="false"></fb:like></div>'; $tb_admin = '<div class="admin_state"><a href="http://twitter.com/share" data-lang="' . $wgLanguageCode . '" style="display:none; background-image: none; color: #ffffff;" class="twitter-share-button" data-count="horizontal" data-via="wikiHow" data-text="How to ' . htmlspecialchars($wgTitle->getText()) . '" data-related="JackHerrick:Founder of wikiHow">Tweet</a></div>'; $tb = '<a href="http://twitter.com/share" data-lang="' . $wgLanguageCode . '" style="display:none; background-image: none; color: #ffffff;" class="twitter-share-button" data-count="horizontal" data-via="wikiHow" data-text="How to ' . htmlspecialchars($wgTitle->getText()) . '" data-related="JackHerrick:Founder of wikiHow">Tweet</a>'; $the_buttons = '<div id="share_buttons_top">' . $fb; if ($wgUser->isSysop() && $wgTitle->userCan('delete')) { $the_buttons .= $tb_admin; } else { $the_buttons .= $tb; } $the_buttons .= $gp1 . '</div>'; $title = '<h1>How to ' . $wgTitle->getText() . '</h1>'; $edited = $sk->getAuthorHeader(); $sidebar = '<div id="sidenav"><div id="showslideshow"></div><div id="pp_big_space">' . $intro_img . '</div></div>'; $main = '<div id="article_main">' . $title . $the_buttons . $edited . $body . $article_bottom . '</div>'; $article = '<div id="article_layout_' . self::ARTICLE_LAYOUT . '">' . $sidebar . $main . '</div>'; return $article; }