Exemplo n.º 1
0
 /**
  * Add meta descriptions for all pages on site.  Convert all to the
  * given style.
  *
  * Commenting out this function because it's dangerous.  It could delete
  * all user-generated descriptions from the table.
  *
  */
 public static function reprocessAllArticles($style)
 {
     // pull all pages from DB
     $dbw = wfGetDB(DB_MASTER);
     $rows = $dbw->select('page', 'page_title', array('page_is_redirect' => 0, 'page_namespace' => NS_MAIN), __METHOD__);
     //array('LIMIT' => 100));
     $pages = array();
     foreach ($rows as $obj) {
         $pages[] = $obj->page_title;
     }
     // delete all existing meta descriptions not of the chosen style
     //$dbw->delete('article_meta_info', '*', __METHOD__);
     //$dbw->update('article_meta_info',
     //  array('ami_desc_style = ' . $style,
     //      "ami_desc = ''"),
     //  array('ami_desc_style <> ' . $style),
     //  __METHOD__);
     // process all pages, adding then chosen style description to them
     foreach ($pages as $page) {
         $title = Title::newFromDBkey($page);
         if ($title) {
             $ami = new ArticleMetaInfo($title, true);
             $ami->refreshMetaData($style);
             if (@$count++ % 10000 == 0 && $count > 0) {
                 print date('r') . " done {$count}\n";
             }
             sleep(2);
             // roll out slowly to prevent overwhelming servers with new image requests
         } else {
             print "title not found: {$page}\n";
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Add meta descriptions for all the article URLs listed (in CSV format)
  * in $filename.  The $style style of format will be created.
  *
  * Commenting out this function because it's dangerous.  It could delete
  * all user-generated descriptions from the table.
  *
  */
 public static function processArticleDescriptionList($filename, $style)
 {
     $fp = fopen($filename, 'r');
     if (!$fp) {
         throw new Exception('unable to open file: ' . $filename);
     }
     while (($line = fgetcsv($fp)) !== false) {
         $url = $line[0];
         $partialURL = preg_replace('@^(http://[a-z]+\\.wikihow\\.com\\/)?(.*)$@', '$2', $url);
         $title = Title::newFromURL($partialURL);
         if ($title) {
             $ami = new ArticleMetaInfo($title);
             if ($ami->populateDescription($style)) {
                 $ami->saveInfo();
             }
             print "desc added: {$title}\n";
         } else {
             print "title not found: {$partialURL}\n";
         }
     }
     fclose($fp);
 }
Exemplo n.º 3
0
 /**
  * Event called when a recent change is patrolled in Special:Recentchanges,
  * Special:RCPatrol or auto-patrolled
  */
 public static function onMarkPatrolled($rcid, &$article)
 {
     $title = null;
     if ($article) {
         $title = $article->getTitle();
     }
     if ($title && $rcid) {
         $goodRev = self::newFromTitle($title);
         if ($goodRev) {
             $rev = self::getRevFromRC($goodRev->articleID, $rcid);
             $goodRev->updateRev($rev);
             // Refresh the article meta info once a good revision is updated
             ArticleMetaInfo::refreshMetaDataCallback($article);
             $title->purgeSquid();
         }
     }
     return true;
 }
Exemplo n.º 4
0
 private static function genMetaDescription($title, $test)
 {
     // no more tests -- always use site default for meta desription
     $ami = new ArticleMetaInfo($title);
     $desc = $ami->getDescription();
     return $desc;
 }
Exemplo n.º 5
0
 public static function getBottomShareButtons_redesign($isIndexed = true)
 {
     global $wgLanguageCode, $wgTitle, $wgServer;
     $action = self::getAction();
     if (!$wgTitle->exists() || $wgTitle->getNamespace() != NS_MAIN || $action != "view" || self::isMainPage($action)) {
         return "";
     }
     $url = $wgServer . "/" . urlencode($wgTitle->getPrefixedURL());
     $img = urlencode(self::getPinterestImage($wgTitle));
     $desc = urlencode(wfMessage('Pinterest_text', $wgTitle->getText())->text());
     $fb = '<div class="fb-like like_button like_tools"><fb:like href="' . $url . '" send="false" layout="button_count" width="86" show_faces="false"></fb:like></div>';
     // German includes "how to " in the title text
     $howto = $wgLanguageCode != 'de' ? wfMessage('Twitter_text', htmlspecialchars($wgTitle->getText()))->text() : htmlspecialchars($wgTitle->getText());
     $tb = '<a href="https://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="' . $howto . '" data-related="JackH:Founder of wikiHow">Tweet</a>';
     if ($isIndexed) {
         $gp1 = '<div class="gplus1_button"><g:plusone callback="plusone_vote"></g:plusone></div>';
     } else {
         $gp1 = "";
     }
     // Reuben added to remove certain images from pinterest sharing where
     // we are having video thumbnail / Google index CTR problems. We
     // override the $img variable to be '' so that the thumbnail image
     // for the video isn't shared.
     if (ArticleMetaInfo::isImageExclusionArticle()) {
         $img = '';
     }
     $pinterest = '<div id="pinterest"><a data-pin-config="beside" href="http://pinterest.com/pin/create/button/?url=' . $url . '&media=' . $img . '&description=' . $desc . '" class="pin-it-button" data-pin-do="buttonPin">Pin It</a></div>';
     if ($wgLanguageCode != 'en') {
         return $gp1 . $tb . $fb;
     } else {
         return $gp1 . $pinterest . $fb;
     }
 }
Exemplo n.º 6
0
 function outputPage(OutputPage $out = null)
 {
     global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
     global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode;
     global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages;
     global $wgRequest, $wgUseNewInterlanguage;
     global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
     global $wgMaxCredits, $wgShowCreditsIfMax, $wgHideInterlanguageLinks;
     global $wgServer;
     global $wgSquidMaxage, $IP;
     $fname = __METHOD__;
     wfProfileIn($fname);
     wfRunHooks('BeforePageDisplay', array(&$wgOut, &$this));
     $this->mTitle = $wgTitle;
     extract($wgRequest->getValues('oldid', 'diff'));
     wfProfileIn("{$fname}-init");
     //$this->initPage( $out );
     $tpl = $this->setupTemplate('WikiHowTemplate', 'skins');
     $tpl->setTranslator(new MediaWiki_I18N());
     wfProfileOut("{$fname}-init");
     wfProfileIn("{$fname}-stuff");
     $this->thispage = $wgTitle->getPrefixedDbKey();
     $this->thisurl = $wgTitle->getPrefixedURL();
     $this->loggedin = $wgUser->getID() != 0;
     $this->iscontent = $wgTitle->getNamespace() != NS_SPECIAL;
     $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
     $this->username = $wgUser->getName();
     $this->userpage = $wgContLang->getNsText(NS_USER) . ":" . $wgUser->getName();
     $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
     $this->usercss = $this->userjs = $this->userjsprev = false;
     //$this->setupUserCss();
     //$this->setupUserJs(false);
     $this->titletxt = $wgTitle->getPrefixedText();
     wfProfileOut("{$fname}-stuff");
     // add utm
     wfProfileIn("{$fname}-stuff2");
     $tpl->set('title', $wgOut->getPageTitle());
     $tpl->setRef("thispage", $this->thispage);
     $undelete = $this->getUndeleteLink();
     $tpl->set("undelete", !empty($undelete) ? '<span class="subpages">' . $undelete . '</span>' : '');
     $tpl->set('headscripts', $out->getHeadScripts() . $out->getHeadItems());
     $description = ArticleMetaInfo::getCurrentTitleMetaDescription();
     if ($description) {
         $wgOut->addMeta('description', $description);
     }
     $keywords = ArticleMetaInfo::getCurrentTitleMetaKeywords();
     if ($keywords) {
         $wgOut->mKeywords = array();
         $wgOut->addMeta('keywords', $keywords);
     }
     ArticleMetaInfo::addFacebookMetaProperties($tpl->data['title']);
     ArticleMetaInfo::addTwitterMetaProperties();
     if ($wgOut->isSyndicated()) {
         $feeds = array();
         foreach ($wgFeedClasses as $format => $class) {
             $feeds[$format] = array('text' => $format, 'href' => $wgRequest->appendQuery("feed={$format}"), 'ttip' => wfMessage('tooltip-' . $format)->text());
         }
         $tpl->setRef('feeds', $feeds);
     } else {
         $tpl->set('feeds', false);
     }
     $tpl->setRef('mimetype', $wgMimeType);
     $tpl->setRef('charset', $wgOutputEncoding);
     $tpl->set('headlinks', $out->getHeadLinks());
     $tpl->setRef('wgScript', $wgScript);
     $tpl->setRef('skinname', $this->skinname);
     $tpl->setRef('stylename', $this->stylename);
     $tpl->setRef('loggedin', $this->loggedin);
     $tpl->set('nsclass', 'ns-' . $wgTitle->getNamespace());
     $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL);
     /* XXX currently unused, might get useful later
     		$tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
     		$tpl->set( "exists", $wgTitle->getArticleID() != 0 );
     		$tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
     		$tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
     		$tpl->set( "helppage", wfMessage('helppage')->text());
     		*/
     $tpl->set('searchaction', $this->escapeSearchLink());
     $tpl->set('search', trim($wgRequest->getVal('search')));
     $tpl->setRef('stylepath', $wgStylePath);
     $tpl->setRef('logopath', $wgLogo);
     $tpl->setRef("lang", $wgContLanguageCode);
     $tpl->set('dir', $wgContLang->isRTL() ? "rtl" : "ltr");
     $tpl->set('rtl', $wgContLang->isRTL());
     $tpl->set('langname', $wgContLang->getLanguageName($wgContLanguageCode));
     $tpl->setRef('username', $this->username);
     $tpl->setRef('userpage', $this->userpage);
     $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']);
     $tpl->setRef('usercss', $this->usercss);
     $tpl->setRef('userjs', $this->userjs);
     $tpl->setRef('userjsprev', $this->userjsprev);
     if ($this->iseditable && $wgUser->getOption('editsectiononrightclick')) {
         $tpl->set('body_onload', 'setupRightClickEdit()');
     } else {
         $tpl->set('body_onload', false);
     }
     global $wgUseSiteJs;
     if ($wgUseSiteJs) {
         if ($this->loggedin) {
             $tpl->set('jsvarurl', $this->makeUrl($this->userpage . '/-', 'action=raw&gen=js&maxage=' . $wgSquidMaxage));
         } else {
             $tpl->set('jsvarurl', $this->makeUrl('-', 'action=raw&gen=js'));
         }
     } else {
         $tpl->set('jsvarurl', false);
     }
     wfProfileOut("{$fname}-stuff2");
     wfProfileIn("{$fname}-stuff3");
     $tpl->setRef('newtalk', $ntl);
     $tpl->setRef('skin', $this);
     $tpl->set('logo', $this->logoText());
     if ($wgOut->isArticle() and (!isset($oldid) or isset($diff)) and $this->getContext()->canUseWikiPage() && 0 != $this->getContext()->getWikiPage()->getId()) {
         if (!$wgDisableCounters) {
             $viewcount = $this->getContext()->getWikiPage()->getCount();
             if ($viewcount) {
                 $tpl->set('viewcount', wfMessage("viewcount", $viewcount)->text());
             } else {
                 $tpl->set('viewcount', false);
             }
         } else {
             $tpl->set('viewcount', false);
         }
         $tpl->set('lastmod', $this->lastModified());
         $tpl->set('copyright', $this->getCopyright());
         $this->credits = false;
         if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
             require_once "{$IP}/includes/Credits.php";
             $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
         }
         $tpl->setRef('credits', $this->credits);
     } elseif (isset($oldid) && !isset($diff)) {
         $tpl->set('copyright', $this->getCopyright());
         $tpl->set('viewcount', false);
         $tpl->set('lastmod', false);
         $tpl->set('credits', false);
     } else {
         $tpl->set('copyright', false);
         $tpl->set('viewcount', false);
         $tpl->set('lastmod', false);
         $tpl->set('credits', false);
     }
     wfProfileOut("{$fname}-stuff3");
     wfProfileIn("{$fname}-stuff4");
     $tpl->set('copyrightico', $this->getCopyrightIcon());
     $tpl->set('poweredbyico', $this->getPoweredBy());
     $tpl->set('disclaimer', $this->disclaimerLink());
     $tpl->set('about', $this->aboutLink());
     $tpl->setRef('debug', $out->mDebugtext);
     //$out->addHTML($printfooter);
     $tpl->set('bottomscripts', $this->bottomScripts());
     if ($wgTitle->getNamespace() == NS_USER && $wgUser->getId() == 0 && !UserPagePolicy::isGoodUserPage($wgTitle->getDBKey())) {
         $txt = $out->parse(wfMessage('noarticletext_user')->text());
         $tpl->setRef('bodytext', $txt);
         header('HTTP/1.1 404 Not Found');
     } else {
         if (!is_null($out)) {
             $tpl->setRef('bodytext', $out->getHTML());
         }
     }
     # Language links
     $language_urls = array();
     if (!$wgHideInterlanguageLinks) {
         foreach ($wgOut->getLanguageLinks() as $l) {
             $tmp = explode(':', $l, 2);
             $class = 'interwiki-' . $tmp[0];
             $code = $tmp[0];
             $lTitle = $tmp[1];
             unset($tmp);
             $nt = Title::newFromText($l);
             $language = $wgContLang->fetchLanguageName($nt->getInterwiki(), $wgLanguageCode);
             $language_urls[] = array('code' => $code, 'href' => $nt->getFullURL(), 'text' => $lTitle, 'class' => $class, 'language' => ($language != '' ? Misc::capitalize($language) : $l) . ": ");
         }
     }
     if (count($language_urls)) {
         $tpl->setRef('language_urls', $language_urls);
     } else {
         $tpl->set('language_urls', false);
     }
     wfProfileOut("{$fname}-stuff4");
     # Personal toolbar
     //$tpl->set('personal_urls', $this->buildPersonalUrls());
     /*$content_actions = $this->buildContentActionUrls();
     		$tpl->setRef('content_actions', $content_actions);
     
     		// XXX: attach this from javascript, same with section editing
     		if($this->iseditable && $wgUser->getOption("editondblclick") ) {
     			$tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
     		} else {
     			$tpl->set('body_ondblclick', false);
     		}
     		*/
     //$tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
     //$tpl->set( 'nav_urls', $this->buildNavUrls() );
     // execute template
     wfProfileIn("{$fname}-execute");
     $res = $tpl->execute();
     wfProfileOut("{$fname}-execute");
     // result may be an error
     $this->printOrError($res);
     wfProfileOut($fname);
 }
Exemplo n.º 7
0
function printDDGdata(&$titles)
{
    global $baseMemory;
    foreach ($titles as $title) {
        $rev = Revision::newFromTitle($title);
        if (!$rev) {
            continue;
        }
        $full_url = $title->getFullURL();
        $wikitext = $rev->getText();
        // pull out intro
        $intro = Article::getSection($wikitext, 0);
        // try to generate the abstract using a couple different ways
        $abstract = synthesizeSummary($wikitext, 3, $full_url);
        if (!$abstract) {
            // meta description
            $ami = new ArticleMetaInfo($title);
            if ($ami) {
                $abstract = $ami->getDescription();
            }
        }
        if (!$abstract) {
            $abstract = $intro;
        }
        // intro image
        $photo = "";
        preg_match_all("@\\[\\[Image:[^\\]]*\\]\\]@", $wikitext, $matches);
        if (sizeof($matches) > 0) {
            $img = preg_replace("@.*Image:@", "", $matches[0][0]);
            $img = ucfirst(preg_replace("@[\\|].*\\]\\]@", "", $img));
            $img = Title::makeTitle(NS_IMAGE, $img);
            $file = wfFindFile($img);
            if ($file) {
                $photo = wfGetPad($file->getURL());
            }
        }
        $images = $photo ? '[[Image:' . $photo . ']]' : '';
        // category info
        $cats = $title->getParentCategories();
        $cat_strs = array();
        $bad_cats = array('Featured Articles');
        foreach ($cats as $cat => $a) {
            if ($cat) {
                $cat_title = Title::newFromURL($cat);
                if ($cat_title && $cat_title->getNamespace() == NS_CATEGORY) {
                    $cat_text = $cat_title->getText();
                    if (!in_array($cat_text, $bad_cats)) {
                        $cat_strs[] = $cat_text;
                    }
                }
            }
        }
        $categories = implode("\\\\n", $cat_strs);
        $regular_title = $title->getText();
        $howto_title = wfMsg('howto', $regular_title);
        print "{$howto_title}\tA\t\t\t{$categories}\t\t\t\t\t\t{$images}\t{$abstract}\t{$full_url}\n";
        //if (@$index++ % 1000 == 0) {
        //	print "#" . date("r") . " - " . (memory_get_usage() - $baseMemory) . "\n";
        //}
    }
}
Exemplo n.º 8
0
 /**
  * Save the description for a page as either default or edited.
  *
  * @param string $type 'default' or 'edited'
  * @param int $page page ID
  * @param string $desc new meta descript if $type is 'edited'
  * @return string the actual new meta description that was saved (html
  *   removed, possibly truncated, etc)
  */
 private static function savePageDesc($type, $page, $desc)
 {
     $title = Title::newFromID($page);
     if (!$title) {
         return '';
     }
     $desc = trim($desc);
     $meta = new ArticleMetaInfo($title);
     if ('default' == $type) {
         $meta->resetMetaData();
     } elseif ('edited' == $type && $desc) {
         $meta->setEditedDescription($desc);
     } else {
         return '';
     }
     return $meta->getDescription();
 }
Exemplo n.º 9
0
 private static function getAbstract($title)
 {
     $abstract = '';
     $ami = new ArticleMetaInfo($title);
     if ($ami) {
         // meta description
         $abstract = $ami->getFacebookDescription();
     }
     if (!$abstract) {
         $rev = Revision::newFromTitle($title);
         if ($rev) {
             $wikitext = $rev->getText();
             $abstract = Article::getSection($wikitext, 0);
         }
     }
     return $abstract;
 }
Exemplo n.º 10
0
 static function getCurrentTitleMetaDescription()
 {
     global $wgTitle;
     static $titleTest = null;
     $return = '';
     if ($wgTitle->getNamespace() == NS_MAIN && $wgTitle->getFullText() == wfMsg('mainpage')) {
         $return = wfMsg('mainpage_meta_description');
     } elseif ($wgTitle->getNamespace() == NS_MAIN) {
         $desc = '';
         if (!$titleTest) {
             $titleTest = TitleTests::newFromTitle($wgTitle);
             if ($titleTest) {
                 $desc = $titleTest->getMetaDescription();
             }
         }
         if (!$desc) {
             if (!self::$wgTitleAMIcache) {
                 self::$wgTitleAMIcache = new ArticleMetaInfo($wgTitle);
             }
             $ami = self::$wgTitleAMIcache;
             $desc = $ami->getDescription();
         }
         if (!$desc) {
             $return = wfMsg('article_meta_description', $wgTitle->getText());
         } else {
             $return = $desc;
         }
     } elseif ($wgTitle->getNamespace() == NS_CATEGORY) {
         // get keywords
         $subcats = self::getMetaSubcategories($wgTitle, 3);
         $keywords = implode(", ", $subcats);
         if ($keywords) {
             $return = wfMsg('category_meta_description', $wgTitle->getText(), $keywords);
         } else {
             $return = wfMsg('subcategory_meta_description', $wgTitle->getText(), $keywords);
         }
     } elseif ($wgTitle->getNamespace() == NS_USER) {
         $desc = ProfileBox::getMetaDesc();
         $return = $desc;
     } elseif ($wgTitle->getNamespace() == NS_IMAGE) {
         $articles = ImageHelper::getLinkedArticles($wgTitle);
         if (count($articles) && $articles[0]) {
             $articleTitle = wfMsg('howto', $articles[0]);
             if (preg_match('@Step (\\d+)@', $wgTitle->getText(), $m)) {
                 $imageNum = '#' . $m[1];
             } else {
                 $imageNum = '';
             }
             $return = wfMsg('image_meta_description', $articleTitle, $imageNum);
         } else {
             $return = wfMsg('image_meta_description_no_article', $wgTitle->getText());
         }
     } elseif ($wgTitle->getNamespace() == NS_SPECIAL && $wgTitle->getText() == "Popularpages") {
         $return = wfMsg('popularpages_meta_description');
     }
     return $return;
 }
Exemplo n.º 11
0
 static function addTwitterMetaProperties()
 {
     global $wgTitle, $wgRequest, $wgOut, $wgLanguageCode, $wgServer;
     $action = $wgRequest->getVal('action', 'view');
     if ($wgTitle->getNamespace() != NS_MAIN || $action != "view") {
         return;
     }
     $isMainPage = $wgTitle && $wgTitle->getNamespace() == NS_MAIN && $wgTitle->getText() == wfMessage('mainpage')->inContentLanguage()->text() && $action == 'view';
     if (!self::$wgTitleAMIcache) {
         self::$wgTitleAMIcache = new ArticleMetaInfo($wgTitle);
     }
     $ami = self::$wgTitleAMIcache;
     if ($isMainPage) {
         $twitterTitle = "wikiHow";
     } else {
         $twitterTitle = wfMessage('howto', $ami->titleText)->text();
     }
     if ($isMainPage) {
         $twitterDesc = "wikiHow - How to do anything";
     } else {
         $twitterDesc = $ami->getFacebookDescription();
     }
     if ($isMainPage) {
         $twitterImg = "/images/7/71/Wh-logo.jpg";
     } else {
         $twitterImg = $ami->getImage();
     }
     if ($wgLanguageCode == 'en') {
         $twitterImg = $wgServer . $twitterImg;
     } else {
         $twitterImg = wfGetPad('http://www.wikihow.com' . $twitterImg);
     }
     $wgOut->addHeadItem('tcard', '<meta name="twitter:card" content="summary_large_image"/>' . "\n");
     if (!self::isImageExclusionArticle()) {
         $wgOut->addHeadItem('timage', '<meta name="twitter:image:src" content="' . $twitterImg . '"/>' . "\n");
     }
     $wgOut->addHeadItem('tsite', '<meta name="twitter:site" content="@wikihow"/>' . "\n");
     $wgOut->addHeadItem('tdesc', '<meta name="twitter:description" content="' . htmlentities($twitterDesc) . '"/>' . "\n");
     $wgOut->addHeadItem('ttitle', '<meta name="twitter:title" content="' . htmlentities($twitterTitle) . '"/>' . "\n");
     $wgOut->addHeadItem('turl', '<meta name="twitter:url" content="' . $wgTitle->getFullURL() . '"/>' . "\n");
 }