Esempio n. 1
0
	<div id="last_question">
			<?php 
echo $userstats;
?>
            <p>Thanks to all authors for creating a page that has been read<br />
				
			<span><?php 
echo $wgLang->formatNum($wgArticle->getCount());
?>
 times.</span> </p>
				


			<div id='page_rating'>
			<?php 
echo RateArticle::showForm();
?>
           	</div>
            <p></p>
   </div>  <!--end last_question-->
</div> <!-- article -->
    
	


</div>  <!--end article_shell-->

    <div id="sidebar">
        <div id="randomizer" class="sidebox_shell">
            <!--<a href="/Special:Createpage" class="button button136" style="float: left;" id="gatWriteAnArticle" onmouseover="button_swap(this);" onmouseout="button_unswap(this);"><?php 
echo wfMsg('writearticle');
Esempio n. 2
0
 function execute($par)
 {
     global $wgOut, $wgUser, $wgShowRatings, $wgRequest, $wgLang;
     $err = "";
     $target = isset($par) ? $par : $wgRequest->getVal('target');
     $restore = $wgRequest->getVal('restore', null);
     $sk = $wgUser->getSkin();
     $wgOut->setHTMLTitle('Clear Ratings - Accuracy Patrol');
     $t = Title::newFromText($target);
     if ($t == '') {
         $wgOut->addHTML(wfMsg('clearratings_notitle'));
         $this->addClearForm($target);
         return;
     }
     $me = SpecialPage::getTitleFor('Clearratings', $t->getText());
     if ($wgUser->getID() == 0) {
         return;
     }
     if ($wgRequest->wasPosted()) {
         // clearing ratings
         $clear = $wgRequest->getVal('clear', null);
         $confirm = $wgRequest->getVal('confirm', null);
         if ($clear != null && $confirm == null && false) {
             $id = $t->getArticleID();
             $wgOut->addHTML(wfMsg('clearratings_clear_confirm_prompt', $sk->makeLinkObj($t, $t->getFullText())) . "\n\t\t\t\t\t\t<br/><br/>\n\t\t\t\t\t\t<form  id='clear_ratings' method='POST'>\n\t\t\t\t\t\t\t<input type=hidden value='{$id}' name='clear'>\n\t\t\t\t\t\t\t<input type=hidden value='true' name='confirm'>\n\t\t\t\t\t\t\t<input type=hidden value='" . htmlspecialchars($target) . "' name='target'>\n\t\t\t\t\t\t\t<input type=submit value='" . wfMsg('clearratings_clear_confirm') . "'>\n\t\t\t\t\t\t</form>");
             return;
         } else {
             if ($clear != null) {
                 RateArticle::clearRatingForPage($clear, $t, $wgUser);
                 $wgOut->addHTML(wfMsg('clearratings_clear_finished') . "<br/><br/>");
             }
         }
     }
     if ($restore != null && $wgRequest->getVal('reason', null) == null) {
         $wgOut->addHTML(wfMsg('clearreating_reason_restore') . "<br/><br/>");
         $wgOut->addHTML("<form  id='clear_ratings' method='POST' action='{$me->getFullURL()}'>");
         $wgOut->addHTML(wfMsg('clearratings_reason') . " <input type='text' name='reason' size='40'><br/><br/>");
         foreach ($_GET as $k => $v) {
             $wgOut->addHTML("<input type='hidden' value='{$v}' name='{$k}'/>");
         }
         $wgOut->addHTML("<input type='submit' value='" . wfMsg('clearratings_submit') . "'/>");
         $wgOut->addHTML("</form>");
         return;
     } else {
         if ($restore != null) {
             $dbw =& wfGetDB(DB_MASTER);
             $user = $wgRequest->getVal('user');
             $page = $wgRequest->getVal('page');
             $u = new User();
             $u->setID($user);
             $up = $u->getUserPage();
             $hi = $wgRequest->getVal('hi');
             $low = $wgRequest->getVal('low');
             $count = $dbw->selectField('rating', 'count(*)', array("rat_page={$page}", "rat_isdeleted=1"));
             $sql = "update rating set rat_isdeleted= 0 where rat_user_deleted = {$user} and rat_page={$page} and rat_id <= {$hi} and rat_id >= {$low};";
             $dbw->query($sql);
             $wgOut->addHTML("<br/><br/>" . wfMsg('clearratings_clear_restored', $sk->makeLinkObj($up, $u->getName()), $when) . "<br/><br/>");
             // add the log entry
             $t = Title::newFromId($page);
             $params = array($page, $min, $max);
             $log = new LogPage('accuracy', true);
             $reason = $wgRequest->getVal('reason');
             $log->addEntry('accuracy', $t, wfMsg('clearratings_logrestore', $reason, $t->getFullText(), $count), $params);
         }
     }
     if ($target != null) {
         $t = Title::newFromText($target);
         $id = $t->getArticleID();
         if ($id == 0) {
             $err = wfMsg('clearratings_no_such_title', $wgRequest->getVal('target'));
         } else {
             if ($t->getNamespace() != NS_MAIN) {
                 $err = wfMsg('clearratings_only_main', $wgRequest->getVal('target'));
             } else {
                 // clearing info
                 $dbr =& wfGetDB(DB_MASTER);
                 //  get log
                 $res = $dbr->select(array('logging'), array('log_timestamp', 'log_user', 'log_comment', 'log_params'), array('log_type' => 'accuracy', "log_title" => $t->getDBKey()), "wfSpecialClearratings");
                 $count = 0;
                 $wgOut->addHTML(wfMsg('clearratings_previous_clearings') . "<ul>");
                 while ($row = $dbr->fetchObject($res)) {
                     $d = $wgLang->date($row->log_timestamp);
                     $u = new User();
                     $u->setID($row->log_user);
                     $up = $u->getUserPage();
                     $params = split("\n", $row->log_params);
                     $wgOut->addHTML("<li>" . $sk->makeLinkObj($up, $u->getName()) . " ({$d}): ");
                     $wgOut->addHTML(preg_replace('/<?p>/', '', $wgOut->parse($row->log_comment)));
                     $wgOut->addHTML("</i>");
                     if (strpos($row->log_comment, wfMsg('clearratings_restore')) === false) {
                         $wgOut->addHTML("(" . $sk->makeLinkObj($me, wfMsg('clearratings_previous_clearings_restore'), "page={$id}&hi={$params[2]}&low={$params[1]}&target={$target}&user={$row->log_user}&restore=1") . ")");
                     }
                     $wgOut->addHTML("</li>");
                     $count++;
                 }
                 $wgOut->addHTML("</ul>");
                 if ($count == 0) {
                     $wgOut->addHTML(wfMsg('clearratings_previous_clearings_none') . "<br/><br/>");
                 }
                 $dbr->freeResult($res);
                 $res = $dbr->select(array("rating"), array("COUNT(*) AS C", "AVG(rat_rating) AS R"), array("rat_page" => $id, "rat_isdeleted" => "0"), __METHOD__);
                 if ($row = $dbr->fetchObject($res)) {
                     $percent = $row->R * 100;
                     $wgOut->addHTML($sk->makeLinkObj($t, $t->getFullText()) . "<br/><br/>" . wfMsg('clearratings_number_votes') . " {$row->C}<br/>" . wfMsg('clearratings_avg_rating') . " {$percent} %<br/><br/>\n\t\t\t\t\t\t<form  id='clear_ratings' method='POST' action='{$me->getFullURL()}'>\n\t\t\t\t\t\t\t<input type=hidden value='{$id}' name='clear'>\n\t\t\t\t\t\t\t<input type=hidden value='" . htmlspecialchars($target) . "' name='target'>\n\t\t\t\t\t\t\t" . wfMsg('clearratings_reason') . " <input type='text' name='reason' size='40'><br/><br/>\n\t\t\t\t\t\t\t<input type=submit value='" . wfMsg('clearratings_clear_submit') . "'>\n\t\t\t\t\t\t</form><br/><br/>\n\t\t\t\t\t\t");
                 }
                 $dbr->freeResult($res);
                 $ap = Title::makeTitle(NS_SPECIAL, "AccuracyPatrol");
                 $wgOut->addHTML($sk->makeLinkObj($ap, "Return to accuracy patrol"));
             }
         }
     }
     $this->addClearForm($target);
 }
Esempio n. 3
0
    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 = "&nbsp;<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;
    }