Ejemplo n.º 1
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";
        //}
    }
}
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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();
 }