Exemplo n.º 1
0
 function getRelatedArticlesBox($e, $isBoxShape = false)
 {
     global $wgTitle, $wgContLang, $wgRequest, $wgMemc;
     if (!$wgTitle || $wgTitle->getNamespace() != NS_MAIN || $wgTitle->getFullText() == wfMessage('mainpage')->text() || $wgRequest->getVal('action') != '') {
         return '';
     }
     $cachekey = wfMemcKey('relarticles_box', intval($isBoxShape), $wgTitle->getArticleID());
     $val = $wgMemc->get($cachekey);
     if ($val) {
         return $val;
     }
     $cats = Categoryhelper::getCurrentParentCategories();
     $cat = '';
     if (is_array($cats) && sizeof($cats) > 0) {
         $keys = array_keys($cats);
         $templates = wfMessage('categories_to_ignore')->inContentLanguage()->text();
         $templates = explode("\n", $templates);
         $templates = str_replace("http://www.wikihow.com/Category:", "", $templates);
         $templates = array_flip($templates);
         // make the array associative.
         for ($i = 0; $i < sizeof($keys); $i++) {
             $t = Title::newFromText($keys[$i]);
             if (isset($templates[urldecode($t->getPartialURL())])) {
                 continue;
             } else {
                 $cat = $t->getDBKey();
                 break;
             }
         }
     }
     // Populate related articles box with other articles in the category,
     // displaying the featured articles first
     $result = "";
     if (!empty($cat)) {
         $dbr = wfGetDB(DB_SLAVE);
         $num = intval(wfMessage('num_related_articles_to_display')->inContentLanguage()->text());
         $res = $dbr->select(array('categorylinks', 'page'), array('cl_from', 'page_is_featured, page_title'), array('cl_from = page_id', 'cl_to' => $cat, 'page_namespace' => 0, 'page_is_redirect' => 0, '(page_is_featured = 1 OR page_random > ' . wfRandom() . ')'), __METHOD__, array('ORDER BY' => 'page_is_featured DESC'));
         if ($isBoxShape) {
             $result .= '<div class="related_square_row">';
         }
         $count = 0;
         foreach ($res as $row) {
             if ($count >= $num) {
                 break;
             }
             if ($row->cl_from == $wgTitle->getArticleID()) {
                 continue;
             }
             $t = Title::newFromDBkey($row->page_title);
             if (!$t || $this->needsFurtherEditing($t)) {
                 continue;
             }
             if ($isBoxShape) {
                 //exit if there's a word that will be too long
                 $word_array = explode(' ', $t->getText());
                 foreach ($word_array as $word) {
                     if (strlen($word) > 7) {
                         continue;
                     }
                 }
                 $data = self::featuredArticlesAttrs($t, $t->getFullText(), 200, 162);
                 $result .= $this->relatedArticlesBox($data, $num_cols);
                 if ($count == 1) {
                     $result .= '</div><div class="related_square_row">';
                 }
             } else {
                 //$data = self::featuredArticlesAttrs($t, $t->getFullText());
                 $result .= self::getArticleThumb($t, 127, 140);
             }
             $count++;
         }
         if ($isBoxShape) {
             $result .= '</div>';
         }
         if (!empty($result)) {
             if ($isBoxShape) {
                 $result = "<div id='related_squares'>{$result}\n</div>";
             } else {
                 $result = "<h3>" . wfMessage('relatedarticles')->text() . "</h3>{$result}<div class='clearall'></div>\n";
             }
         }
     }
     $wgMemc->set($cachekey, $result);
     return $result;
 }