Exemplo n.º 1
0
function getMenu()
{
    global $wgRequest, $wgMemc, $wgScript;
    $content = '';
    $id = $wgRequest->getVal('id');
    if ($id) {
        $menuArray = $wgMemc->get($id);
        if (!empty($menuArray['magicWords'])) {
            $JSurl = Xml::encodeJsVar($wgScript . '?action=ajax&rs=getMenu&v=' . $wgRequest->getVal('v') . '&words=' . urlencode(implode(',', $menuArray['magicWords'])));
            $content .= "wsl.loadScriptAjax({$JSurl}, function() {\n";
            unset($menuArray['magicWords']);
            $usingCallback = true;
        }
        // fallback (RT #20893)
        if ($menuArray === null) {
            $menuArray = array('mainMenu' => array());
        }
        $content .= 'window.menuArray = ' . json_encode($menuArray) . ';$("#navigation_widget").mouseover(menuInit);$(function() { menuInit(); });';
        $duration = 60 * 60 * 24 * 7;
        // one week
        // close JS code
        if (!empty($usingCallback)) {
            $content .= "\n});";
        }
    }
    $words = urldecode($wgRequest->getVal('words'));
    if ($words) {
        $magicWords = array();
        $map = array('voted' => array('highest_ratings', 'GetTopVotedArticles'), 'popular' => array('most_popular', 'GetMostPopularArticles'), 'visited' => array('most_visited', 'GetMostVisitedArticles'), 'newlychanged' => array('newly_changed', 'GetNewlyChangedArticles'), 'topusers' => array('community', 'GetTopFiveUsers'));
        $words = explode(',', $words);
        foreach ($words as $word) {
            if (isset($map[$word])) {
                $magicWords[$word] = DataProvider::$map[$word][1]();
                $magicWords[$word][] = array('className' => 'Monaco-sidebar_more', 'url' => Title::makeTitle(NS_SPECIAL, 'Top/' . $map[$word][0])->getLocalURL(), 'text' => '-more-');
                if ($word == 'popular') {
                    $magicWords[$word][] = array('className' => 'Monaco-sidebar_edit', 'url' => Title::makeTitle(NS_MEDIAWIKI, 'Most popular articles')->getLocalUrl(), 'text' => '-edit-');
                }
            } else {
                if (substr($word, 0, 8) == 'category') {
                    $name = substr($word, 8);
                    $articles = getMenuHelper($name);
                    foreach ($articles as $key => $val) {
                        $title = Title::newFromId($val);
                        if (is_object($title)) {
                            $magicWords[$word][] = array('text' => $title->getText(), 'url' => $title->getLocalUrl());
                        }
                    }
                    $magicWords[$word][] = array('className' => 'Monaco-sidebar_more', 'url' => Title::makeTitle(NS_CATEGORY, $name)->getLocalURL(), 'text' => '-more-');
                }
            }
        }
        $content .= 'window.magicWords = ' . json_encode($magicWords) . ';';
        $duration = 60 * 60 * 12;
        // two days
    }
    if (!empty($content)) {
        header("Content-Type: text/javascript");
        //		header("Content-Length: " . strlen($content) );
        header("Cache-Control: s-maxage={$duration}, must-revalidate, max-age=0");
        header("X-Pass-Cache-Control: max-age={$duration}");
        echo $content;
        exit;
    }
}
Exemplo n.º 2
0
 /**
  * @author: Inez Korczyński
  *
  * Return false when given submenu should not be added in a given place
  */
 private function handleExtraWords(&$node, &$nodes, $depth)
 {
     wfProfileIn(__METHOD__);
     $originalLower = strtolower($node[self::ORIGINAL]);
     if (substr($originalLower, 0, 9) == '#category') {
         // ignore magic words in Level 1 (BugId:15240)
         if ($depth == 1) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $param = trim(substr($node[self::ORIGINAL], 9), '#');
         if (is_numeric($param)) {
             $category = $this->getBiggestCategory($param);
             $name = $category['name'];
         } else {
             $name = substr($param, 1);
         }
         //if the name is still empty abort and display it to user
         //so he/she can fix it
         //most it was something like: #category or #category_
         if (!empty($name)) {
             $node[self::HREF] = Title::makeTitle(NS_CATEGORY, $name)->getLocalURL();
             if (strpos($node[self::TEXT], '#') === 0) {
                 $node[self::TEXT] = str_replace('_', ' ', $name);
             }
             $data = getMenuHelper($name);
             foreach ($data as $val) {
                 $title = Title::newFromId($val);
                 if (is_object($title)) {
                     $this->addChildNode($node, $nodes, $title->getText(), $title->getLocalUrl());
                 }
             }
         }
     } else {
         $extraWord = trim($originalLower, '#');
         if (isset($this->extraWordsMap[$extraWord])) {
             if ($node[self::TEXT][0] == '#') {
                 $node[self::TEXT] = wfMsg(trim($node[self::ORIGINAL], ' *'));
             }
             $fname = $this->extraWordsMap[$extraWord];
             $data = DataProvider::$fname();
             //http://bugs.php.net/bug.php?id=46322 count(false) == 1
             if (!empty($data)) {
                 // ignore magic words in Level 1 (BugId:15240)
                 if ($depth == 1) {
                     wfProfileOut(__METHOD__);
                     return false;
                 }
                 foreach ($data as $val) {
                     $this->addChildNode($node, $nodes, $val[self::TEXT], $val['url']);
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }