/**
 * Prepare the toolbox link
 *
 * @var $skintemplate SkinTemplate
 */
function efContributorsNavigation(&$skintemplate, &$nav_urls, &$oldid, &$revid)
{
    if ($skintemplate->getTitle()->getNamespace() === NS_MAIN && $revid !== 0) {
        $nav_urls['contributors'] = array('text' => wfMsg('contributors-toolbox'), 'href' => $skintemplate->makeSpecialUrl('Contributors', "target=" . wfUrlEncode("{$skintemplate->thispage}")));
    }
    return true;
}
/**
 * Build the link to be shown in the toolbox if appropriate
 * @param $skin Skin
 */
function efDuplicatorNavigation(&$skin, &$nav_urls, &$oldid, &$revid)
{
    global $wgUser;
    $ns = $skin->getTitle()->getNamespace();
    if (($ns === NS_MAIN || $ns === NS_TALK) && $wgUser->isAllowed('duplicate')) {
        $nav_urls['duplicator'] = array('text' => wfMsg('duplicator-toolbox'), 'href' => $skin->makeSpecialUrl('Duplicator', "source=" . wfUrlEncode("{$skin->thispage}")));
    }
    return true;
}
 /**
  * @param integer $namespace (Default NS_MAIN)
  * @param string $from list all pages from this name (default FALSE)
  */
 function showChunk($namespace = NS_MAIN, $prefix, $including = false, $from = null)
 {
     global $wgOut, $wgUser, $wgContLang;
     $fname = 'indexShowChunk';
     $sk = $wgUser->getSkin();
     if (!isset($from)) {
         $from = $prefix;
     }
     $fromList = $this->getNamespaceKeyAndText($namespace, $from);
     $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
     $namespaces = $wgContLang->getNamespaces();
     $align = $wgContLang->isRtl() ? 'left' : 'right';
     if (!$prefixList || !$fromList) {
         $out = wfMsgWikiHtml('allpagesbadtitle');
     } elseif (!in_array($namespace, array_keys($namespaces))) {
         // Show errormessage and reset to NS_MAIN
         $out = wfMsgExt('allpages-bad-ns', array('parseinline'), $namespace);
         $namespace = NS_MAIN;
     } else {
         list($namespace, $prefixKey, $prefix) = $prefixList;
         list(, $fromKey, $from) = $fromList;
         ### FIXME: should complain if $fromNs != $namespace
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_is_redirect'), array('page_namespace' => $namespace, 'page_title LIKE \'' . $dbr->escapeLike($prefixKey) . '%\'', 'page_title >= ' . $dbr->addQuotes($fromKey)), $fname, array('ORDER BY' => 'page_title', 'LIMIT' => $this->maxPerPage + 1, 'USE INDEX' => 'name_title'));
         ### FIXME: side link to previous
         $n = 0;
         $out = '<table style="background: inherit;" border="0" width="100%">';
         while ($n < $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
             $t = Title::makeTitle($s->page_namespace, $s->page_title);
             if ($t) {
                 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '') . $sk->makeKnownLinkObj($t, htmlspecialchars($t->getText()), false, false) . ($s->page_is_redirect ? '</div>' : '');
             } else {
                 $link = '[[' . htmlspecialchars($s->page_title) . ']]';
             }
             if ($n % 3 == 0) {
                 $out .= '<tr>';
             }
             $out .= "<td>{$link}</td>";
             $n++;
             if ($n % 3 == 0) {
                 $out .= '</tr>';
             }
         }
         if ($n % 3 != 0) {
             $out .= '</tr>';
         }
         $out .= '</table>';
     }
     if ($including) {
         $out2 = '';
     } else {
         $nsForm = $this->namespaceForm($namespace, $prefix);
         $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
         $out2 .= '<tr valign="top"><td>' . $nsForm;
         $out2 .= '</td><td align="' . $align . '" style="font-size: smaller; margin-bottom: 1em;">' . $sk->makeKnownLink($wgContLang->specialPage($this->name), wfMsg('allpages'));
         if (isset($dbr) && $dbr && $n == $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
             $namespaceparam = $namespace ? "&namespace={$namespace}" : "";
             $out2 .= " | " . $sk->makeKnownLink($wgContLang->specialPage($this->name), wfMsg('nextpage', $s->page_title), "from=" . wfUrlEncode($s->page_title) . "&prefix=" . wfUrlEncode($prefix) . $namespaceparam);
         }
         $out2 .= "</td></tr></table><hr />";
     }
     $wgOut->addHtml($out2 . $out);
 }
/**
 * Special page "user contributions".
 * Shows a list of the contributions of a user.
 *
 * @return	none
 * @param	string	$par	(optional) user name of the user for which to show the contributions
 */
function wfSpecialContributions($par = null)
{
    global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgTitle, $wgScript;
    $fname = 'wfSpecialContributions';
    $target = isset($par) ? $par : $wgRequest->getVal('target');
    if (!strlen($target)) {
        $wgOut->errorpage('notargettitle', 'notargettext');
        return;
    }
    $nt = Title::newFromURL($target);
    if (!$nt) {
        $wgOut->errorpage('notargettitle', 'notargettext');
        return;
    }
    $nt =& Title::makeTitle(NS_USER, $nt->getDBkey());
    list($limit, $offset) = wfCheckLimits();
    $offset = $wgRequest->getVal('offset');
    /* Offset must be an integral. */
    if (!strlen($offset) || !preg_match("/^[0-9]+\$/", $offset)) {
        $offset = 0;
    }
    $title = Title::makeTitle(NS_SPECIAL, "Contributions");
    $urlbits = "target=" . wfUrlEncode($target);
    $myurl = $title->escapeLocalURL($urlbits);
    $finder = new contribs_finder($target == 'newbies' ? 'newbies' : $nt->getText());
    $finder->set_limit($limit);
    $finder->set_offset($offset);
    $nsurl = $xnsurl = "";
    if (($ns = $wgRequest->getVal('namespace', null)) !== null) {
        $nsurl = "&namespace={$ns}";
        $xnsurl = htmlspecialchars($nsurl);
        $finder->set_namespace($ns);
    }
    if ($wgRequest->getText('go') == "prev") {
        $prevts = $finder->get_previous_offset_for_paging();
        $prevurl = $title->getLocalURL($urlbits . "&offset={$prevts}&limit={$limit}{$nsurl}");
        $wgOut->redirect($prevurl);
        return;
    }
    if ($wgRequest->getText('go') == "first") {
        $prevts = $finder->get_first_offset_for_paging();
        $prevurl = $title->getLocalURL($urlbits . "&offset={$prevts}&limit={$limit}{$nsurl}");
        $wgOut->redirect($prevurl);
        return;
    }
    $sk = $wgUser->getSkin();
    $id = User::idFromName($nt->getText());
    if (0 == $id) {
        $ul = $nt->getText();
    } else {
        $ul = $sk->makeLinkObj($nt, htmlspecialchars($nt->getText()));
        $userCond = '=' . $id;
    }
    $talk = $nt->getTalkPage();
    if ($talk) {
        $ul .= ' (' . $sk->makeLinkObj($talk, $wgLang->getNsText(NS_TALK)) . ')';
    }
    if ($target == 'newbies') {
        $ul = wfMsg('newbies');
    }
    $wgOut->setSubtitle(wfMsgHtml('contribsub', $ul));
    wfRunHooks('SpecialContributionsBeforeMainOutput', $id);
    $arr = $wgContLang->getFormattedNamespaces();
    $nsform = "<form method='get' action=\"{$wgScript}\">\n";
    $nsform .= wfElement("input", array("name" => "title", "type" => "hidden", "value" => $wgTitle->getPrefixedText()));
    $nsform .= wfElement("input", array("name" => "offset", "type" => "hidden", "value" => $offset));
    $nsform .= wfElement("input", array("name" => "limit", "type" => "hidden", "value" => $limit));
    $nsform .= wfElement("input", array("name" => "target", "type" => "hidden", "value" => $target));
    $nsform .= "<p>";
    $nsform .= wfMsgHtml('namespace');
    $nsform .= HTMLnamespaceselector($ns, '');
    $nsform .= wfElement("input", array("type" => "submit", "value" => wfMsg('allpagessubmit')));
    $nsform .= "</p></form>\n";
    $wgOut->addHTML($nsform);
    $contribsPage = Title::makeTitle(NS_SPECIAL, 'Contributions');
    $contribs = $finder->find();
    if (count($contribs) == 0) {
        $wgOut->addWikiText(wfMsg("nocontribs"));
        return;
    }
    list($early, $late) = $finder->get_edit_limits();
    $lastts = count($contribs) ? $contribs[count($contribs) - 1]->rev_timestamp : 0;
    $atstart = !count($contribs) || $late == $contribs[0]->rev_timestamp;
    $atend = !count($contribs) || $early == $lastts;
    $lasturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}");
    $firsttext = wfMsgHtml("histfirst");
    $lasttext = wfMsgHtml("histlast");
    $prevtext = wfMsg("prevn", $limit);
    if ($atstart) {
        $lastlink = $lasttext;
        $prevlink = $prevtext;
    } else {
        $lastlink = "<a href=\"{$myurl}&amp;limit={$limit}{$xnsurl}\">{$lasttext}</a>";
        $prevlink = "<a href=\"{$myurl}&amp;offset={$offset}&amp;limit={$limit}{$xnsurl}&amp;go=prev\">{$prevtext}</a>";
    }
    $nexttext = wfMsg("nextn", $limit);
    if ($atend) {
        $firstlink = $firsttext;
        $nextlink = $nexttext;
    } else {
        $firstlink = "<a href=\"{$myurl}&amp;limit={$limit}{$xnsurl}&amp;go=first\">{$firsttext}</a>";
        $nextlink = "<a href=\"{$myurl}&amp;offset={$lastts}&amp;limit={$limit}{$xnsurl}\">{$nexttext}</a>";
    }
    $firstlast = "({$lastlink} | {$firstlink})";
    $urls = array();
    foreach (array(20, 50, 100, 250, 500) as $num) {
        $urls[] = "<a href=\"{$myurl}&amp;offset={$offset}&amp;limit={$num}{$xnsurl}\">" . $wgLang->formatNum($num) . "</a>";
    }
    $bits = implode($urls, ' | ');
    $prevnextbits = "{$firstlast} " . wfMsgHtml("viewprevnext", $prevlink, $nextlink, $bits);
    $wgOut->addHTML("<p>{$prevnextbits}</p>\n");
    $wgOut->addHTML("<ul>\n");
    foreach ($contribs as $contrib) {
        $wgOut->addHTML(ucListEdit($sk, $contrib));
    }
    $wgOut->addHTML("</ul>\n");
    $wgOut->addHTML("<p>{$prevnextbits}</p>\n");
}
Esempio n. 5
0
function wfSajaxSearch($term)
{
    global $wgContLang, $wgUser, $wgRequest, $wgAjaxCachePolicy;
    $limit = 16;
    $l = new Linker();
    $term = str_replace(' ', '_', $wgContLang->ucfirst($wgContLang->checkTitleEncoding($wgContLang->recodeInput(js_unescape($term)))));
    if (strlen(str_replace('_', '', $term)) < 3) {
        return;
    }
    $wgAjaxCachePolicy->setPolicy(30 * 60);
    $db =& wfGetDB(DB_SLAVE);
    $res = $db->select('page', 'page_title', array('page_namespace' => 0, "page_title LIKE '" . $db->strencode($term) . "%'"), "wfSajaxSearch", array('LIMIT' => $limit + 1));
    $r = "";
    $i = 0;
    while (($row = $db->fetchObject($res)) && ++$i <= $limit) {
        $nt = Title::newFromDBkey($row->page_title);
        $r .= '<li>' . $l->makeKnownLinkObj($nt) . "</li>\n";
    }
    if ($i > $limit) {
        $more = '<i>' . $l->makeKnownLink($wgContLang->specialPage("Allpages"), wfMsg('moredotdotdot'), "namespace=0&from=" . wfUrlEncode($term)) . '</i>';
    } else {
        $more = '';
    }
    $term = htmlspecialchars($term);
    return '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">' . wfMsg('hideresults') . '</a></div>' . '<h1 class="firstHeading">' . wfMsg('search') . '</h1><div id="contentSub">' . wfMsg('searchquery', $term) . '</div><ul><li>' . $l->makeKnownLink($wgContLang->specialPage('Search'), wfMsg('searchcontaining', $term), "search={$term}&fulltext=Search") . '</li><li>' . $l->makeKnownLink($wgContLang->specialPage('Search'), wfMsg('searchnamed', $term), "search={$term}&go=Go") . "</li></ul><h2>" . wfMsg('articletitles', $term) . "</h2>" . '<ul>' . $r . '</ul>' . $more;
}
Esempio n. 6
0
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgTitle, $wgContLang, $wgUser, $wgScriptPath, $wgLuceneDisableTitleMatches, $wgLuceneDisableSuggestions, $wgUser;
     global $wgGoToEdit;
     wfLoadExtensionMessages('LuceneSearch');
     $fname = 'LuceneSearch::execute';
     wfProfileIn($fname);
     $this->setHeaders();
     $wgOut->addHTML('<!-- titlens = ' . $wgTitle->getNamespace() . '-->');
     foreach (SearchEngine::searchableNamespaces() as $ns => $name) {
         if ($wgRequest->getCheck('ns' . $ns)) {
             $this->namespaces[] = $ns;
         }
     }
     if (count($this->namespaces) == 0) {
         foreach (SearchEngine::searchableNamespaces() as $ns => $name) {
             if ($wgUser->getOption('searchNs' . $ns)) {
                 $this->namespaces[] = $ns;
             }
         }
         if (count($this->namespaces) == 0) {
             global $wgNamespacesToBeSearchedDefault;
             foreach ($wgNamespacesToBeSearchedDefault as $ns => $searchit) {
                 if ($searchit) {
                     $this->namespaces[] = $ns;
                 }
             }
         }
     }
     $bits = split('/', $wgRequest->getVal('title'), 2);
     if (!empty($bits[1])) {
         $q = str_replace('_', ' ', $bits[1]);
     } else {
         $q = $wgRequest->getText('search');
     }
     list($limit, $offset) = $wgRequest->getLimitOffset(LS_PER_PAGE, 'searchlimit');
     if ($wgRequest->getVal('gen') == 'titlematch') {
         $this->sendTitlePrefixes($q, $limit);
         wfProfileOut($fname);
         return;
     }
     $this->mSkin =& $wgUser->getSkin();
     if (!$wgLuceneDisableSuggestions) {
         $wgOut->addHTML($this->makeSuggestJS());
     }
     $wgOut->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen,projection', 'href' => $wgScriptPath . '/extensions/LuceneSearch/lucenesearch.css'));
     $wgOut->addWikiText(wfMsg('searchresulttext'));
     $wgOut->addHTML($this->showShortDialog($q));
     if ($q === false || strlen($q) == 0) {
         // No search active. Put input focus in the search box.
         $wgOut->addHTML($this->makeFocusJS());
     } else {
         if (!$wgRequest->getText('fulltext')) {
             $t = SearchEngine::getNearMatch($q);
             if (!is_null($t)) {
                 $wgOut->redirect($t->getFullURL());
                 wfProfileOut($fname);
                 return;
             }
         }
         # No match, generate an edit URL
         $t = Title::newFromText($q);
         if (!$wgRequest->getText('go') || is_null($t)) {
             $editurl = '';
             # hrm...
         } else {
             wfRunHooks('SpecialSearchNogomatch', array(&$t));
             # If the feature is enabled, go straight to the edit page
             if ($wgGoToEdit) {
                 $wgOut->redirect($t->getFullURL('action=edit'));
                 return;
             }
             if ($t->quickUserCan('create') && $t->quickUserCan('edit')) {
                 $wgOut->addWikiText(wfMsg('noexactmatch', $t->getPrefixedText()));
             } else {
                 $wgOut->addWikiText(wfMsg('noexactmatch-nocreate', $t->getPrefixedText()));
             }
         }
         $case = 'ignore';
         # Replace localized namespace prefixes (from lucene-search 2.0)
         global $wgLuceneSearchVersion;
         if ($wgLuceneSearchVersion >= 2) {
             $searchq = $this->replacePrefixes($q);
             if ($wgRequest->getText('fulltext') == wfMsg('searchexactcase')) {
                 $case = 'exact';
             }
         } else {
             $searchq = $q;
         }
         global $wgDisableTextSearch;
         if (!$wgDisableTextSearch) {
             $results = LuceneSearchSet::newFromQuery('search', $searchq, $this->namespaces, $limit, $offset, $case);
         }
         if ($wgDisableTextSearch || $results === false) {
             if ($wgDisableTextSearch) {
                 $wgOut->addHTML(wfMsg('searchdisabled'));
             } else {
                 $wgOut->addWikiText(wfMsg('lucenefallback'));
             }
             $wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($q), 'utf-8', htmlspecialchars(wfMsg('search'))));
             wfProfileOut($fname);
             return;
         }
         $subtitleMsg = is_object(Title::newFromText($q)) ? 'searchsubtitle' : 'searchsubtitleinvalid';
         $wgOut->setSubtitle($wgOut->parse(wfMsg($subtitleMsg, wfEscapeWikiText($q))));
         // If the search returned no results, an alternate fuzzy search
         // match may be displayed as a suggested search. Link it.
         if ($results->hasSuggestion()) {
             $suggestion = $results->getSuggestion();
             $o = ' ' . wfMsg('searchdidyoumean', $this->makeLink($suggestion, $offset, $limit, $case), htmlspecialchars($suggestion));
             $wgOut->addHTML('<div style="text-align: center;">' . $o . '</div>');
         }
         $nmtext = '';
         if ($offset == 0 && !$wgLuceneDisableTitleMatches) {
             $titles = LuceneSearchSet::newFromQuery('titlematch', $q, $this->namespaces, 5, $case);
             if ($titles && $titles->hasResults()) {
                 $nmtext = '<p>' . wfMsg('searchnearmatches') . '</p>';
                 $nmtext .= '<ul>';
                 $nmtext .= implode("\n", $titles->iterateResults(array(&$this, 'formatNearMatch')));
                 $nmtext .= '</ul>';
                 $nmtext .= '<hr />';
             }
         }
         $wgOut->addHTML($nmtext);
         if (!$results->hasResults()) {
             # Pass search terms back in a few different formats
             # $1: Plain search terms
             # $2: Search terms with s/ /_/
             # $3: URL-encoded search terms
             $tmsg = array(htmlspecialchars($q), htmlspecialchars(str_replace(' ', '_', $q)), wfUrlEncode($q));
             $wgOut->addHtml(wfMsgWikiHtml('searchnoresults', $tmsg[0], $tmsg[1], $tmsg[2]));
         } else {
             #$showresults = min($limit, count($results)-$numresults);
             $i = $offset;
             $resq = trim(preg_replace("/[ |\\[\\]()\"{}+]+/", " ", $q));
             $contextWords = implode("|", array_map(array(&$this, 'regexQuote'), $wgContLang->convertForSearchResult(split(" ", $resq))));
             $top = wfMsg('searchnumber', $offset + 1, min($results->getTotalHits(), $offset + $limit), $results->getTotalHits());
             $out = '<ul id="lucene-results">';
             $numchunks = ceil($results->getTotalHits() / $limit);
             $whichchunk = $offset / $limit;
             $prevnext = "";
             if ($whichchunk > 0) {
                 $prevnext .= '<a href="' . $this->makelink($q, $offset - $limit, $limit, $case) . '">' . wfMsg('searchprev') . '</a> ';
             }
             $first = max($whichchunk - 11, 0);
             $last = min($numchunks, $whichchunk + 11);
             //$wgOut->addWikiText("whichchunk=$whichchunk numchunks=$numchunks first=$first last=$last num=".count($chunks)." limit=$limit offset=$offset results=".count($results)."\n\n");
             if ($last - $first > 1) {
                 for ($i = $first; $i < $last; $i++) {
                     if ($i === $whichchunk) {
                         $prevnext .= '<strong>' . ($i + 1) . '</strong> ';
                     } else {
                         $prevnext .= '<a href="' . $this->makelink($q, $limit * $i, $limit, $case) . '">' . ($i + 1) . '</a> ';
                     }
                 }
             }
             if ($whichchunk < $last - 1) {
                 $prevnext .= '<a href="' . $this->makelink($q, $offset + $limit, $limit, $case) . '">' . wfMsg('searchnext') . '</a> ';
             }
             $prevnext = '<div style="text-align: center;">' . $prevnext . '</div>';
             $top .= $prevnext;
             $out .= implode("\n", $results->iterateResults(array(&$this, 'showHit'), $contextWords));
             $out .= '</ul>';
         }
         #$wgOut->addHTML('<hr />');
         if (isset($top)) {
             $wgOut->addHTML($top);
         }
         if (isset($out)) {
             $wgOut->addHTML($out);
         }
         #if( isset( $prevnext ) ) $wgOut->addHTML('<hr />' . $prevnext);
         if (isset($prevnext)) {
             $wgOut->addHTML($prevnext);
         }
         $wgOut->addHTML($this->showFullDialog($q));
     }
     $wgOut->setRobotpolicy('noindex,nofollow');
     $wgOut->setArticleRelated(false);
     wfProfileOut($fname);
 }
Esempio n. 7
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  */
 function getVariableValue($index)
 {
     global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
     /**
      * Some of these require message or data lookups and can be
      * expensive to check many times.
      */
     if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$this->mVarCache))) {
         if (isset($this->mVarCache[$index])) {
             return $this->mVarCache[$index];
         }
     }
     $ts = wfTimestamp(TS_UNIX, $this->mOptions->getTimestamp());
     wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts));
     # Use the time zone
     global $wgLocaltimezone;
     if (isset($wgLocaltimezone)) {
         $oldtz = getenv('TZ');
         putenv('TZ=' . $wgLocaltimezone);
     }
     wfSuppressWarnings();
     // E_STRICT system time bitching
     $localTimestamp = date('YmdHis', $ts);
     $localMonth = date('m', $ts);
     $localMonthName = date('n', $ts);
     $localDay = date('j', $ts);
     $localDay2 = date('d', $ts);
     $localDayOfWeek = date('w', $ts);
     $localWeek = date('W', $ts);
     $localYear = date('Y', $ts);
     $localHour = date('H', $ts);
     if (isset($wgLocaltimezone)) {
         putenv('TZ=' . $oldtz);
     }
     wfRestoreWarnings();
     switch ($index) {
         case 'currentmonth':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('m', $ts));
         case 'currentmonthname':
             return $this->mVarCache[$index] = $wgContLang->getMonthName(gmdate('n', $ts));
         case 'currentmonthnamegen':
             return $this->mVarCache[$index] = $wgContLang->getMonthNameGen(gmdate('n', $ts));
         case 'currentmonthabbrev':
             return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation(gmdate('n', $ts));
         case 'currentday':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('j', $ts));
         case 'currentday2':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('d', $ts));
         case 'localmonth':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localMonth);
         case 'localmonthname':
             return $this->mVarCache[$index] = $wgContLang->getMonthName($localMonthName);
         case 'localmonthnamegen':
             return $this->mVarCache[$index] = $wgContLang->getMonthNameGen($localMonthName);
         case 'localmonthabbrev':
             return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation($localMonthName);
         case 'localday':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localDay);
         case 'localday2':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localDay2);
         case 'pagename':
             return wfEscapeWikiText($this->mTitle->getText());
         case 'pagenamee':
             return $this->mTitle->getPartialURL();
         case 'fullpagename':
             return wfEscapeWikiText($this->mTitle->getPrefixedText());
         case 'fullpagenamee':
             return $this->mTitle->getPrefixedURL();
         case 'subpagename':
             return wfEscapeWikiText($this->mTitle->getSubpageText());
         case 'subpagenamee':
             return $this->mTitle->getSubpageUrlForm();
         case 'basepagename':
             return wfEscapeWikiText($this->mTitle->getBaseText());
         case 'basepagenamee':
             return wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText()));
         case 'talkpagename':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return wfEscapeWikiText($talkPage->getPrefixedText());
             } else {
                 return '';
             }
         case 'talkpagenamee':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return $talkPage->getPrefixedUrl();
             } else {
                 return '';
             }
         case 'subjectpagename':
             $subjPage = $this->mTitle->getSubjectPage();
             return wfEscapeWikiText($subjPage->getPrefixedText());
         case 'subjectpagenamee':
             $subjPage = $this->mTitle->getSubjectPage();
             return $subjPage->getPrefixedUrl();
         case 'revisionid':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n");
             return $this->mRevisionId;
         case 'revisionday':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n");
             return intval(substr($this->getRevisionTimestamp(), 6, 2));
         case 'revisionday2':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n");
             return substr($this->getRevisionTimestamp(), 6, 2);
         case 'revisionmonth':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n");
             return intval(substr($this->getRevisionTimestamp(), 4, 2));
         case 'revisionyear':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n");
             return substr($this->getRevisionTimestamp(), 0, 4);
         case 'revisiontimestamp':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n");
             return $this->getRevisionTimestamp();
         case 'revisionuser':
             // Let the edit saving system know we should parse the page
             // *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n");
             return $this->getRevisionUser();
         case 'namespace':
             return str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace()));
         case 'namespacee':
             return wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace()));
         case 'talkspace':
             return $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '';
         case 'talkspacee':
             return $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '';
         case 'subjectspace':
             return $this->mTitle->getSubjectNsText();
         case 'subjectspacee':
             return wfUrlencode($this->mTitle->getSubjectNsText());
         case 'currentdayname':
             return $this->mVarCache[$index] = $wgContLang->getWeekdayName(gmdate('w', $ts) + 1);
         case 'currentyear':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('Y', $ts), true);
         case 'currenttime':
             return $this->mVarCache[$index] = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false);
         case 'currenthour':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('H', $ts), true);
         case 'currentweek':
             // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             // int to remove the padding
             return $this->mVarCache[$index] = $wgContLang->formatNum((int) gmdate('W', $ts));
         case 'currentdow':
             return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('w', $ts));
         case 'localdayname':
             return $this->mVarCache[$index] = $wgContLang->getWeekdayName($localDayOfWeek + 1);
         case 'localyear':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localYear, true);
         case 'localtime':
             return $this->mVarCache[$index] = $wgContLang->time($localTimestamp, false, false);
         case 'localhour':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localHour, true);
         case 'localweek':
             // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             // int to remove the padding
             return $this->mVarCache[$index] = $wgContLang->formatNum((int) $localWeek);
         case 'localdow':
             return $this->mVarCache[$index] = $wgContLang->formatNum($localDayOfWeek);
         case 'numberofarticles':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::articles());
         case 'numberoffiles':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::images());
         case 'numberofusers':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::users());
         case 'numberofactiveusers':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::activeUsers());
         case 'numberofpages':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::pages());
         case 'numberofadmins':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::numberingroup('sysop'));
         case 'numberofedits':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::edits());
         case 'numberofviews':
             return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::views());
         case 'currenttimestamp':
             return $this->mVarCache[$index] = wfTimestamp(TS_MW, $ts);
         case 'localtimestamp':
             return $this->mVarCache[$index] = $localTimestamp;
         case 'currentversion':
             return $this->mVarCache[$index] = SpecialVersion::getVersion();
         case 'sitename':
             return $wgSitename;
         case 'server':
             return $wgServer;
         case 'servername':
             return $wgServerName;
         case 'scriptpath':
             return $wgScriptPath;
         case 'directionmark':
             return $wgContLang->getDirMark();
         case 'contentlanguage':
             global $wgContLanguageCode;
             return $wgContLanguageCode;
         default:
             $ret = null;
             if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$this->mVarCache, &$index, &$ret))) {
                 return $ret;
             } else {
                 return null;
             }
     }
 }
Esempio n. 8
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  *
  * @param $index integer
  * @param $frame PPFrame
  *
  * @return string
  */
 function getVariableValue($index, $frame = false)
 {
     global $wgContLang, $wgSitename, $wgServer;
     global $wgArticlePath, $wgScriptPath, $wgStylePath;
     if (is_null($this->mTitle)) {
         // If no title set, bad things are going to happen
         // later. Title should always be set since this
         // should only be called in the middle of a parse
         // operation (but the unit-tests do funky stuff)
         throw new MWException(__METHOD__ . ' Should only be ' . ' called while parsing (no title set)');
     }
     /**
      * Some of these require message or data lookups and can be
      * expensive to check many times.
      */
     if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$this->mVarCache))) {
         if (isset($this->mVarCache[$index])) {
             return $this->mVarCache[$index];
         }
     }
     $ts = wfTimestamp(TS_UNIX, $this->mOptions->getTimestamp());
     wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts));
     # Use the time zone
     global $wgLocaltimezone;
     if (isset($wgLocaltimezone)) {
         $oldtz = date_default_timezone_get();
         date_default_timezone_set($wgLocaltimezone);
     }
     $localTimestamp = date('YmdHis', $ts);
     $localMonth = date('m', $ts);
     $localMonth1 = date('n', $ts);
     $localMonthName = date('n', $ts);
     $localDay = date('j', $ts);
     $localDay2 = date('d', $ts);
     $localDayOfWeek = date('w', $ts);
     $localWeek = date('W', $ts);
     $localYear = date('Y', $ts);
     $localHour = date('H', $ts);
     if (isset($wgLocaltimezone)) {
         date_default_timezone_set($oldtz);
     }
     $pageLang = $this->getFunctionLang();
     switch ($index) {
         case 'currentmonth':
             $value = $pageLang->formatNum(gmdate('m', $ts));
             break;
         case 'currentmonth1':
             $value = $pageLang->formatNum(gmdate('n', $ts));
             break;
         case 'currentmonthname':
             $value = $pageLang->getMonthName(gmdate('n', $ts));
             break;
         case 'currentmonthnamegen':
             $value = $pageLang->getMonthNameGen(gmdate('n', $ts));
             break;
         case 'currentmonthabbrev':
             $value = $pageLang->getMonthAbbreviation(gmdate('n', $ts));
             break;
         case 'currentday':
             $value = $pageLang->formatNum(gmdate('j', $ts));
             break;
         case 'currentday2':
             $value = $pageLang->formatNum(gmdate('d', $ts));
             break;
         case 'localmonth':
             $value = $pageLang->formatNum($localMonth);
             break;
         case 'localmonth1':
             $value = $pageLang->formatNum($localMonth1);
             break;
         case 'localmonthname':
             $value = $pageLang->getMonthName($localMonthName);
             break;
         case 'localmonthnamegen':
             $value = $pageLang->getMonthNameGen($localMonthName);
             break;
         case 'localmonthabbrev':
             $value = $pageLang->getMonthAbbreviation($localMonthName);
             break;
         case 'localday':
             $value = $pageLang->formatNum($localDay);
             break;
         case 'localday2':
             $value = $pageLang->formatNum($localDay2);
             break;
         case 'pagename':
             $value = wfEscapeWikiText($this->mTitle->getText());
             break;
         case 'pagenamee':
             $value = wfEscapeWikiText($this->mTitle->getPartialURL());
             break;
         case 'fullpagename':
             $value = wfEscapeWikiText($this->mTitle->getPrefixedText());
             break;
         case 'fullpagenamee':
             $value = wfEscapeWikiText($this->mTitle->getPrefixedURL());
             break;
         case 'subpagename':
             $value = wfEscapeWikiText($this->mTitle->getSubpageText());
             break;
         case 'subpagenamee':
             $value = wfEscapeWikiText($this->mTitle->getSubpageUrlForm());
             break;
         case 'basepagename':
             $value = wfEscapeWikiText($this->mTitle->getBaseText());
             break;
         case 'basepagenamee':
             $value = wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText())));
             break;
         case 'talkpagename':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 $value = wfEscapeWikiText($talkPage->getPrefixedText());
             } else {
                 $value = '';
             }
             break;
         case 'talkpagenamee':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 $value = wfEscapeWikiText($talkPage->getPrefixedUrl());
             } else {
                 $value = '';
             }
             break;
         case 'subjectpagename':
             $subjPage = $this->mTitle->getSubjectPage();
             $value = wfEscapeWikiText($subjPage->getPrefixedText());
             break;
         case 'subjectpagenamee':
             $subjPage = $this->mTitle->getSubjectPage();
             $value = wfEscapeWikiText($subjPage->getPrefixedUrl());
             break;
         case 'revisionid':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n");
             $value = $this->mRevisionId;
             break;
         case 'revisionday':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n");
             $value = intval(substr($this->getRevisionTimestamp(), 6, 2));
             break;
         case 'revisionday2':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 6, 2);
             break;
         case 'revisionmonth':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 4, 2);
             break;
         case 'revisionmonth1':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONMONTH1}} used, setting vary-revision...\n");
             $value = intval(substr($this->getRevisionTimestamp(), 4, 2));
             break;
         case 'revisionyear':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 0, 4);
             break;
         case 'revisiontimestamp':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n");
             $value = $this->getRevisionTimestamp();
             break;
         case 'revisionuser':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n");
             $value = $this->getRevisionUser();
             break;
         case 'namespace':
             $value = str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace()));
             break;
         case 'namespacee':
             $value = wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace()));
             break;
         case 'talkspace':
             $value = $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '';
             break;
         case 'talkspacee':
             $value = $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '';
             break;
         case 'subjectspace':
             $value = $this->mTitle->getSubjectNsText();
             break;
         case 'subjectspacee':
             $value = wfUrlencode($this->mTitle->getSubjectNsText());
             break;
         case 'currentdayname':
             $value = $pageLang->getWeekdayName(gmdate('w', $ts) + 1);
             break;
         case 'currentyear':
             $value = $pageLang->formatNum(gmdate('Y', $ts), true);
             break;
         case 'currenttime':
             $value = $pageLang->time(wfTimestamp(TS_MW, $ts), false, false);
             break;
         case 'currenthour':
             $value = $pageLang->formatNum(gmdate('H', $ts), true);
             break;
         case 'currentweek':
             # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             # int to remove the padding
             $value = $pageLang->formatNum((int) gmdate('W', $ts));
             break;
         case 'currentdow':
             $value = $pageLang->formatNum(gmdate('w', $ts));
             break;
         case 'localdayname':
             $value = $pageLang->getWeekdayName($localDayOfWeek + 1);
             break;
         case 'localyear':
             $value = $pageLang->formatNum($localYear, true);
             break;
         case 'localtime':
             $value = $pageLang->time($localTimestamp, false, false);
             break;
         case 'localhour':
             $value = $pageLang->formatNum($localHour, true);
             break;
         case 'localweek':
             # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             # int to remove the padding
             $value = $pageLang->formatNum((int) $localWeek);
             break;
         case 'localdow':
             $value = $pageLang->formatNum($localDayOfWeek);
             break;
         case 'numberofarticles':
             $value = $pageLang->formatNum(SiteStats::articles());
             break;
         case 'numberoffiles':
             $value = $pageLang->formatNum(SiteStats::images());
             break;
         case 'numberofusers':
             $value = $pageLang->formatNum(SiteStats::users());
             break;
         case 'numberofactiveusers':
             $value = $pageLang->formatNum(SiteStats::activeUsers());
             break;
         case 'numberofpages':
             $value = $pageLang->formatNum(SiteStats::pages());
             break;
         case 'numberofadmins':
             $value = $pageLang->formatNum(SiteStats::numberingroup('sysop'));
             break;
         case 'numberofedits':
             $value = $pageLang->formatNum(SiteStats::edits());
             break;
         case 'numberofviews':
             $value = $pageLang->formatNum(SiteStats::views());
             break;
         case 'currenttimestamp':
             $value = wfTimestamp(TS_MW, $ts);
             break;
         case 'localtimestamp':
             $value = $localTimestamp;
             break;
         case 'currentversion':
             $value = SpecialVersion::getVersion();
             break;
         case 'articlepath':
             return $wgArticlePath;
         case 'sitename':
             return $wgSitename;
         case 'server':
             return $wgServer;
         case 'servername':
             $serverParts = wfParseUrl($wgServer);
             return $serverParts && isset($serverParts['host']) ? $serverParts['host'] : $wgServer;
         case 'scriptpath':
             return $wgScriptPath;
         case 'stylepath':
             return $wgStylePath;
         case 'directionmark':
             return $pageLang->getDirMark();
         case 'contentlanguage':
             global $wgLanguageCode;
             return $wgLanguageCode;
         default:
             $ret = null;
             if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$this->mVarCache, &$index, &$ret, &$frame))) {
                 return $ret;
             } else {
                 return null;
             }
     }
     if ($index) {
         $this->mVarCache[$index] = $value;
     }
     return $value;
 }
Esempio n. 9
0
 public static function basepagenamee($parser, $title = null)
 {
     $t = Title::newFromText($title);
     if (is_null($t)) {
         return '';
     }
     return wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $t->getBaseText())));
 }
Esempio n. 10
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  */
 function getVariableValue($index)
 {
     global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
     /**
      * Some of these require message or data lookups and can be
      * expensive to check many times.
      */
     static $varCache = array();
     if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$varCache))) {
         if (isset($varCache[$index])) {
             return $varCache[$index];
         }
     }
     $ts = time();
     wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts));
     # Use the time zone
     global $wgLocaltimezone;
     if (isset($wgLocaltimezone)) {
         $oldtz = getenv('TZ');
         putenv('TZ=' . $wgLocaltimezone);
     }
     $localTimestamp = date('YmdHis', $ts);
     $localMonth = date('m', $ts);
     $localMonthName = date('n', $ts);
     $localDay = date('j', $ts);
     $localDay2 = date('d', $ts);
     $localDayOfWeek = date('w', $ts);
     $localWeek = date('W', $ts);
     $localYear = date('Y', $ts);
     $localHour = date('H', $ts);
     if (isset($wgLocaltimezone)) {
         putenv('TZ=' . $oldtz);
     }
     switch ($index) {
         case 'currentmonth':
             return $varCache[$index] = $wgContLang->formatNum(date('m', $ts));
         case 'currentmonthname':
             return $varCache[$index] = $wgContLang->getMonthName(date('n', $ts));
         case 'currentmonthnamegen':
             return $varCache[$index] = $wgContLang->getMonthNameGen(date('n', $ts));
         case 'currentmonthabbrev':
             return $varCache[$index] = $wgContLang->getMonthAbbreviation(date('n', $ts));
         case 'currentday':
             return $varCache[$index] = $wgContLang->formatNum(date('j', $ts));
         case 'currentday2':
             return $varCache[$index] = $wgContLang->formatNum(date('d', $ts));
         case 'localmonth':
             return $varCache[$index] = $wgContLang->formatNum($localMonth);
         case 'localmonthname':
             return $varCache[$index] = $wgContLang->getMonthName($localMonthName);
         case 'localmonthnamegen':
             return $varCache[$index] = $wgContLang->getMonthNameGen($localMonthName);
         case 'localmonthabbrev':
             return $varCache[$index] = $wgContLang->getMonthAbbreviation($localMonthName);
         case 'localday':
             return $varCache[$index] = $wgContLang->formatNum($localDay);
         case 'localday2':
             return $varCache[$index] = $wgContLang->formatNum($localDay2);
         case 'pagename':
             return $this->mTitle->getText();
         case 'pagenamee':
             return $this->mTitle->getPartialURL();
         case 'fullpagename':
             return $this->mTitle->getPrefixedText();
         case 'fullpagenamee':
             return $this->mTitle->getPrefixedURL();
         case 'subpagename':
             return $this->mTitle->getSubpageText();
         case 'subpagenamee':
             return $this->mTitle->getSubpageUrlForm();
         case 'basepagename':
             return $this->mTitle->getBaseText();
         case 'basepagenamee':
             return wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText()));
         case 'talkpagename':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return $talkPage->getPrefixedText();
             } else {
                 return '';
             }
         case 'talkpagenamee':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return $talkPage->getPrefixedUrl();
             } else {
                 return '';
             }
         case 'subjectpagename':
             $subjPage = $this->mTitle->getSubjectPage();
             return $subjPage->getPrefixedText();
         case 'subjectpagenamee':
             $subjPage = $this->mTitle->getSubjectPage();
             return $subjPage->getPrefixedUrl();
         case 'revisionid':
             return $this->mRevisionId;
         case 'revisionday':
             return intval(substr(wfRevisionTimestamp($this->mRevisionId), 6, 2));
         case 'revisionday2':
             return substr(wfRevisionTimestamp($this->mRevisionId), 6, 2);
         case 'revisionmonth':
             return intval(substr(wfRevisionTimestamp($this->mRevisionId), 4, 2));
         case 'revisionyear':
             return substr(wfRevisionTimestamp($this->mRevisionId), 0, 4);
         case 'revisiontimestamp':
             return wfRevisionTimestamp($this->mRevisionId);
         case 'namespace':
             return str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace()));
         case 'namespacee':
             return wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace()));
         case 'talkspace':
             return $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '';
         case 'talkspacee':
             return $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '';
         case 'subjectspace':
             return $this->mTitle->getSubjectNsText();
         case 'subjectspacee':
             return wfUrlencode($this->mTitle->getSubjectNsText());
         case 'currentdayname':
             return $varCache[$index] = $wgContLang->getWeekdayName(date('w', $ts) + 1);
         case 'currentyear':
             return $varCache[$index] = $wgContLang->formatNum(date('Y', $ts), true);
         case 'currenttime':
             return $varCache[$index] = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false);
         case 'currenthour':
             return $varCache[$index] = $wgContLang->formatNum(date('H', $ts), true);
         case 'currentweek':
             // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             // int to remove the padding
             return $varCache[$index] = $wgContLang->formatNum((int) date('W', $ts));
         case 'currentdow':
             return $varCache[$index] = $wgContLang->formatNum(date('w', $ts));
         case 'localdayname':
             return $varCache[$index] = $wgContLang->getWeekdayName($localDayOfWeek + 1);
         case 'localyear':
             return $varCache[$index] = $wgContLang->formatNum($localYear, true);
         case 'localtime':
             return $varCache[$index] = $wgContLang->time($localTimestamp, false, false);
         case 'localhour':
             return $varCache[$index] = $wgContLang->formatNum($localHour, true);
         case 'localweek':
             // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             // int to remove the padding
             return $varCache[$index] = $wgContLang->formatNum((int) $localWeek);
         case 'localdow':
             return $varCache[$index] = $wgContLang->formatNum($localDayOfWeek);
         case 'numberofarticles':
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfArticles());
         case 'numberoffiles':
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfFiles());
         case 'numberofusers':
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfUsers());
         case 'numberofpages':
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfPages());
         case 'numberofadmins':
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfAdmins());
         case 'currenttimestamp':
             return $varCache[$index] = wfTimestampNow();
         case 'localtimestamp':
             return $varCache[$index] = $localTimestamp;
         case 'currentversion':
             return $varCache[$index] = SpecialVersion::getVersion();
         case 'sitename':
             return $wgSitename;
         case 'server':
             return $wgServer;
         case 'servername':
             return $wgServerName;
         case 'scriptpath':
             return $wgScriptPath;
         case 'directionmark':
             return $wgContLang->getDirMark();
         case 'contentlanguage':
             global $wgContLanguageCode;
             return $wgContLanguageCode;
         default:
             $ret = null;
             if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$varCache, &$index, &$ret))) {
                 return $ret;
             } else {
                 return null;
             }
     }
 }
Esempio n. 11
0
 private function showUserNetwork()
 {
     global $wgUser, $wgOut, $wgContLang;
     $wgOut->setPageTitle(wfMsg('networkusercontent', $this->username, $this->otherUsername));
     $wgOut->setRobotpolicy('noindex,nofollow');
     $wgOut->setArticleRelated(false);
     $sk = $wgUser->getSkin();
     $wgOut->addHtml('<p>&nbsp;&nbsp;&nbsp;&lt; ' . $sk->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'Network'), ' Show full network') . '</p>');
     $title = null;
     if ($this->from) {
         $title = Title::newFromText($this->from);
     }
     // issue db query to get the family trees
     $dbr =& wfGetDB(DB_SLAVE);
     $sql = 'SELECT w1.wl_namespace AS namespace, w1.wl_title AS title FROM watchlist AS w1, watchlist AS w2, user WHERE user_name=' . $dbr->addQuotes($this->otherUsername) . ' AND w1.wl_user='******' AND w2.wl_user=user_id AND w1.wl_namespace in (108,110) AND w1.wl_namespace=w2.wl_namespace AND w1.wl_title=w2.wl_title';
     if ($title) {
         $sql .= ' AND ((w1.wl_namespace = ' . $dbr->addQuotes($title->getNamespace()) . ' AND w1.wl_title >= ' . $dbr->addQuotes($title->getDBkey()) . ')' . ' OR w1.wl_namespace > ' . $dbr->addQuotes($title->getNamespace()) . ')';
     }
     $sql .= ' ORDER BY w1.wl_namespace, w1.wl_title LIMIT ' . ($this->maxPerPage + 1);
     $res = $dbr->query($sql, 'ShowUserNetwork');
     ### FIXME: side link to previous
     $n = 0;
     $out = '<table style="background: inherit;" border="0" width="100%">';
     while ($n < $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
         $title = Title::makeTitle($s->namespace, $s->title);
         $link = $sk->makeKnownLinkObj($title, htmlspecialchars($title->getPrefixedText()));
         if ($n % 3 == 0) {
             $out .= '<tr>';
         }
         $out .= "<td>{$link}</td>";
         $n++;
         if ($n % 3 == 0) {
             $out .= '</tr>';
         }
     }
     if ($n % 3 != 0) {
         $out .= '</tr>';
     }
     $out .= '</table>';
     $form = $this->getForm($this->from);
     $users = 'user='******'relateduser='******'<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
     $out2 .= '<tr valign="top"><td align="left">' . $form;
     if (isset($dbr) && $dbr && $n == $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
         $title = Title::makeTitle($s->namespace, $s->title);
         $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' . $sk->makeKnownLink($wgContLang->specialPage("Network"), wfMsgHtml('nextpage', $title->getPrefixedText()), $users . '&from=' . wfUrlEncode($title->getPrefixedText()));
     }
     $out2 .= "</td></tr></table><hr />";
     $wgOut->addHtml($out2 . $out);
     $dbr->freeResult($res);
 }
 static function randomchaptere(&$parser, $text = null)
 {
     $t = self::pageText($parser, $text, 'rand');
     return wfUrlEncode($t);
 }
Esempio n. 13
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  */
 function getVariableValue($index)
 {
     global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
     /**
      * Some of these require message or data lookups and can be
      * expensive to check many times.
      */
     static $varCache = array();
     if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$varCache))) {
         if (isset($varCache[$index])) {
             return $varCache[$index];
         }
     }
     $ts = time();
     wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts));
     switch ($index) {
         case MAG_CURRENTMONTH:
             return $varCache[$index] = $wgContLang->formatNum(date('m', $ts));
         case MAG_CURRENTMONTHNAME:
             return $varCache[$index] = $wgContLang->getMonthName(date('n', $ts));
         case MAG_CURRENTMONTHNAMEGEN:
             return $varCache[$index] = $wgContLang->getMonthNameGen(date('n', $ts));
         case MAG_CURRENTMONTHABBREV:
             return $varCache[$index] = $wgContLang->getMonthAbbreviation(date('n', $ts));
         case MAG_CURRENTDAY:
             return $varCache[$index] = $wgContLang->formatNum(date('j', $ts));
         case MAG_CURRENTDAY2:
             return $varCache[$index] = $wgContLang->formatNum(date('d', $ts));
         case MAG_PAGENAME:
             return $this->mTitle->getText();
         case MAG_PAGENAMEE:
             return $this->mTitle->getPartialURL();
         case MAG_FULLPAGENAME:
             return $this->mTitle->getPrefixedText();
         case MAG_FULLPAGENAMEE:
             return $this->mTitle->getPrefixedURL();
         case MAG_SUBPAGENAME:
             return $this->mTitle->getSubpageText();
         case MAG_SUBPAGENAMEE:
             return $this->mTitle->getSubpageUrlForm();
         case MAG_BASEPAGENAME:
             return $this->mTitle->getBaseText();
         case MAG_BASEPAGENAMEE:
             return wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText()));
         case MAG_TALKPAGENAME:
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return $talkPage->getPrefixedText();
             } else {
                 return '';
             }
         case MAG_TALKPAGENAMEE:
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 return $talkPage->getPrefixedUrl();
             } else {
                 return '';
             }
         case MAG_SUBJECTPAGENAME:
             $subjPage = $this->mTitle->getSubjectPage();
             return $subjPage->getPrefixedText();
         case MAG_SUBJECTPAGENAMEE:
             $subjPage = $this->mTitle->getSubjectPage();
             return $subjPage->getPrefixedUrl();
         case MAG_REVISIONID:
             return $this->mRevisionId;
         case MAG_NAMESPACE:
             return str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace()));
         case MAG_NAMESPACEE:
             return wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace()));
         case MAG_TALKSPACE:
             return $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '';
         case MAG_TALKSPACEE:
             return $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '';
         case MAG_SUBJECTSPACE:
             return $this->mTitle->getSubjectNsText();
         case MAG_SUBJECTSPACEE:
             return wfUrlencode($this->mTitle->getSubjectNsText());
         case MAG_CURRENTDAYNAME:
             return $varCache[$index] = $wgContLang->getWeekdayName(date('w', $ts) + 1);
         case MAG_CURRENTYEAR:
             return $varCache[$index] = $wgContLang->formatNum(date('Y', $ts), true);
         case MAG_CURRENTTIME:
             return $varCache[$index] = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false);
         case MAG_CURRENTWEEK:
             // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             // int to remove the padding
             return $varCache[$index] = $wgContLang->formatNum((int) date('W', $ts));
         case MAG_CURRENTDOW:
             return $varCache[$index] = $wgContLang->formatNum(date('w', $ts));
         case MAG_NUMBEROFARTICLES:
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfArticles());
         case MAG_NUMBEROFFILES:
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfFiles());
         case MAG_NUMBEROFUSERS:
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfUsers());
         case MAG_NUMBEROFPAGES:
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfPages());
         case MAG_NUMBEROFADMINS:
             return $varCache[$index] = $wgContLang->formatNum(wfNumberOfAdmins());
         case MAG_CURRENTTIMESTAMP:
             return $varCache[$index] = wfTimestampNow();
         case MAG_CURRENTVERSION:
             global $wgVersion;
             return $wgVersion;
         case MAG_SITENAME:
             return $wgSitename;
         case MAG_SERVER:
             return $wgServer;
         case MAG_SERVERNAME:
             return $wgServerName;
         case MAG_SCRIPTPATH:
             return $wgScriptPath;
         case MAG_DIRECTIONMARK:
             return $wgContLang->getDirMark();
         case MAG_CONTENTLANGUAGE:
             global $wgContLanguageCode;
             return $wgContLanguageCode;
         default:
             $ret = null;
             if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$varCache, &$index, &$ret))) {
                 return $ret;
             } else {
                 return null;
             }
     }
 }
Esempio n. 14
0
 private function addMap()
 {
     global $wrHostName;
     return '<div id="placemap"></div>' . '<div class="plainlinks">[http://' . $wrHostName . '/wiki/Special:PlaceMap?pagetitle=' . wfUrlEncode($this->titleString) . ' Larger map]</div>';
 }
 /**
  * @param integer $namespace (Default NS_MAIN)
  * @param string $from list all pages from this name (default FALSE)
  */
 function showChunk($namespace = NS_MAIN, $from, $including = false)
 {
     global $wgOut, $wgUser, $wgContLang;
     $fname = 'indexShowChunk';
     $sk = $wgUser->getSkin();
     $fromTitle = Title::newFromURL($from);
     if ($namespace == NS_MAIN and $fromTitle) {
         $namespace = $fromTitle->getNamespace();
     }
     $fromKey = is_null($fromTitle) ? '' : $fromTitle->getDBkey();
     $dbr =& wfGetDB(DB_SLAVE);
     $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_is_redirect'), array('page_namespace' => $namespace, 'page_title LIKE \'' . $dbr->escapeLike($fromKey) . '%\''), $fname, array('ORDER BY' => 'page_title', 'LIMIT' => $this->maxPerPage + 1, 'USE INDEX' => 'name_title'));
     ### FIXME: side link to previous
     $n = 0;
     $out = '<table style="background: inherit;" border="0" width="100%">';
     $namespaces = $wgContLang->getFormattedNamespaces();
     while ($n < $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
         $t = Title::makeTitle($s->page_namespace, $s->page_title);
         if ($t) {
             $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '') . $sk->makeKnownLinkObj($t, htmlspecialchars($t->getText()), false, false) . ($s->page_is_redirect ? '</div>' : '');
         } else {
             $link = '[[' . htmlspecialchars($s->page_title) . ']]';
         }
         if ($n % 3 == 0) {
             $out .= '<tr>';
         }
         $out .= "<td>{$link}</td>";
         $n++;
         if ($n % 3 == 0) {
             $out .= '</tr>';
         }
     }
     if ($n % 3 != 0) {
         $out .= '</tr>';
     }
     $out .= '</table>';
     if ($including) {
         $out2 = '';
     } else {
         $nsForm = $this->namespaceForm($namespace, $from);
         $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
         $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
         $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' . $sk->makeKnownLink($wgContLang->specialPage($this->name), wfMsg('allpages'));
         if ($n == $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
             $namespaceparam = $namespace ? "&namespace={$namespace}" : "";
             $out2 .= " | " . $sk->makeKnownLink($wgContLang->specialPage($this->name), wfMsg('nextpage', $s->page_title), "from=" . wfUrlEncode($s->page_title) . $namespaceparam);
         }
         $out2 .= "</td></tr></table><hr />";
     }
     $wgOut->addHtml($out2 . $out);
 }
Esempio n. 16
0
 /**
  * Helper function for getUrl()
  *
  * @todo FIXME: This may be generalized...
  * @param string $page Page name (must be normalised before calling this function!)
  * @return string Url fragment
  */
 private function getLocalUrl($page)
 {
     return str_replace('$1', wfUrlEncode(str_replace(' ', '_', $page)), $this->mPath);
 }
Esempio n. 17
0
    /**
     * @param integer $namespace (Default NS_MAIN)
     * @param string $from list all pages from this name (default FALSE)
     */
    function showPrefixChunk($namespace = NS_MAIN, $prefix, $from = null)
    {
        global $wgOut, $wgUser, $wgContLang, $wgLang;
        $sk = $wgUser->getSkin();
        if (!isset($from)) {
            $from = $prefix;
        }
        $fromList = $this->getNamespaceKeyAndText($namespace, $from);
        $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
        $namespaces = $wgContLang->getNamespaces();
        if (!$prefixList || !$fromList) {
            $out = wfMsgWikiHtml('allpagesbadtitle');
        } elseif (!in_array($namespace, array_keys($namespaces))) {
            // Show errormessage and reset to NS_MAIN
            $out = wfMsgExt('allpages-bad-ns', array('parseinline'), $namespace);
            $namespace = NS_MAIN;
        } else {
            list($namespace, $prefixKey, $prefix) = $prefixList;
            list(, $fromKey, $from) = $fromList;
            ### FIXME: should complain if $fromNs != $namespace
            $dbr = wfGetDB(DB_SLAVE);
            $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_is_redirect'), array('page_namespace' => $namespace, 'page_title LIKE \'' . $dbr->escapeLike($prefixKey) . '%\'', 'page_title >= ' . $dbr->addQuotes($fromKey)), __METHOD__, array('ORDER BY' => 'page_title', 'LIMIT' => $this->maxPerPage + 1, 'USE INDEX' => 'name_title'));
            ### FIXME: side link to previous
            $n = 0;
            if ($res->numRows() > 0) {
                $out = Xml::openElement('table', array('border' => '0', 'id' => 'mw-prefixindex-list-table'));
                while ($n < $this->maxPerPage && ($s = $res->fetchObject())) {
                    $t = Title::makeTitle($s->page_namespace, $s->page_title);
                    if ($t) {
                        $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '') . $sk->makeKnownLinkObj($t, htmlspecialchars($t->getText()), false, false) . ($s->page_is_redirect ? '</div>' : '');
                    } else {
                        $link = '[[' . htmlspecialchars($s->page_title) . ']]';
                    }
                    if ($n % 3 == 0) {
                        $out .= '<tr>';
                    }
                    $out .= "<td>{$link}</td>";
                    $n++;
                    if ($n % 3 == 0) {
                        $out .= '</tr>';
                    }
                }
                if ($n % 3 != 0) {
                    $out .= '</tr>';
                }
                $out .= Xml::closeElement('table');
            } else {
                $out = '';
            }
        }
        if ($this->including()) {
            $out2 = '';
        } else {
            $nsForm = $this->namespacePrefixForm($namespace, $prefix);
            $self = $this->getTitle();
            $out2 = Xml::openElement('table', array('border' => '0', 'id' => 'mw-prefixindex-nav-table')) . '<tr>
					<td>' . $nsForm . '</td>
					<td id="mw-prefixindex-nav-form">' . $sk->makeKnownLinkObj($self, wfMsg('allpages'));
            if (isset($res) && $res && $n == $this->maxPerPage && ($s = $res->fetchObject())) {
                $namespaceparam = $namespace ? "&namespace={$namespace}" : "";
                $out2 = $wgLang->pipeList(array($out2, $sk->makeKnownLinkObj($self, wfMsgHtml('nextpage', str_replace('_', ' ', htmlspecialchars($s->page_title))), "from=" . wfUrlEncode($s->page_title) . "&prefix=" . wfUrlEncode($prefix) . $namespaceparam)));
            }
            $out2 .= "</td></tr>" . Xml::closeElement('table');
        }
        $wgOut->addHTML($out2 . $out);
    }
Esempio n. 18
0
 /**
  * @param $path
  * @param $rev
  * @param $message
  * @return string
  */
 protected function formatImgCell($path, $rev, $message)
 {
     $viewvc = $this->mRepo->getViewVcBase();
     $safePath = wfUrlEncode($path);
     $url = "{$viewvc}{$safePath}?&pathrev={$rev}&revision={$rev}";
     $alt = wfMsg($message);
     return Xml::tags('td', array(), Xml::tags('a', array('href' => $url), Xml::element('img', array('src' => $url, 'alt' => $alt, 'title' => $alt, 'border' => '0'))));
 }
Esempio n. 19
0
 /**
  * Helper function for getUrl()
  *
  * @todo FIXME: This may be generalized...
  *
  * @param string $page Page name (must be normalised before calling this function!
  *  May contain a section part.)
  * @param string|null $fragmentId
  *
  * @return string relative URL, without the server part.
  */
 private function getLocalUrl($page, $fragmentId = null)
 {
     $page = wfUrlEncode(str_replace(' ', '_', $page));
     if (is_string($fragmentId) && $fragmentId !== '') {
         $page .= '#' . wfUrlEncode($fragmentId);
     }
     return str_replace('$1', $page, $this->mPath);
 }
 function OutputListPage($transParams)
 {
     global $wgOut;
     # check all the parameters before we put them in the page
     foreach ($transParams as $key => $value) {
         $transParams[$key] = wfUrlEncode(htmlentities(preg_replace("/\\<.*?\\>/", "", $value)));
     }
     # First, see if we have a custom list setup
     $bstitle = Title::makeTitleSafe(NS_PROJECT, wfMsg($this->Prefix . '_ListPage'));
     if ($bstitle) {
         $revision = Revision::newFromTitle($bstitle);
         if ($revision) {
             $bstext = $revision->getText();
             if ($bstext) {
                 $bstext = strtr($bstext, $transParams);
                 $wgOut->addWikiText($bstext);
             }
         } else {
             $bstext = wfMsg($this->Prefix . '_DataList');
             $bstext = strtr($bstext, $transParams);
             $wgOut->addHTML($bstext);
         }
     }
 }
Esempio n. 21
0
 function showChunk($from)
 {
     global $wgUser, $wgContLang, $wgOut;
     $sk = $wgUser->getSkin();
     // issue db query to get the family trees
     $dbr =& wfGetDB(DB_SLAVE);
     $res = $dbr->select('familytree', array('ft_user', 'ft_name'), $from ? array('ft_user >= ' . $dbr->addQuotes($from)) : '', 'ShowFamilyTrees', array('ORDER BY' => 'ft_user, ft_name', 'LIMIT' => $this->maxPerPage + 1));
     ### FIXME: side link to previous
     $n = 0;
     $out = '<table style="background: inherit;" border="0" width="100%">';
     $title = Title::makeTitle(NS_SPECIAL, 'ShowFamilyTree');
     while ($n < $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
         $link = $sk->makeKnownLinkObj($title, htmlspecialchars("{$s->ft_user}:{$s->ft_name}"), 'user='******'&name=' . wfUrlEncode($s->ft_name));
         if ($n % 3 == 0) {
             $out .= '<tr>';
         }
         $out .= "<td>{$link}</td>";
         $n++;
         if ($n % 3 == 0) {
             $out .= '</tr>';
         }
     }
     if ($n % 3 != 0) {
         $out .= '</tr>';
     }
     $out .= '</table>';
     $form = $this->getForm($from);
     $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
     $out2 .= '<tr valign="top"><td align="left">' . $form;
     $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' . $sk->makeKnownLink($wgContLang->specialPage("ShowFamilyTree"), 'Show Family Trees');
     if (isset($dbr) && $dbr && $n == $this->maxPerPage && ($s = $dbr->fetchObject($res))) {
         $out2 .= " | " . $sk->makeKnownLink($wgContLang->specialPage("ShowFamilyTree"), wfMsgHtml('nextpage', $s->ft_user), "from=" . wfUrlEncode($s->ft_user));
     }
     $out2 .= "</td></tr></table><hr />";
     $wgOut->addHtml($out2 . $out);
     $dbr->freeResult($res);
 }
Esempio n. 22
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  *
  * @param $index integer
  * @param bool|\PPFrame $frame
  *
  * @throws MWException
  * @return string
  */
 function getVariableValue($index, $frame = false)
 {
     global $wgContLang, $wgSitename, $wgServer;
     global $wgArticlePath, $wgScriptPath, $wgStylePath;
     if (is_null($this->mTitle)) {
         // If no title set, bad things are going to happen
         // later. Title should always be set since this
         // should only be called in the middle of a parse
         // operation (but the unit-tests do funky stuff)
         throw new MWException(__METHOD__ . ' Should only be ' . ' called while parsing (no title set)');
     }
     /**
      * Some of these require message or data lookups and can be
      * expensive to check many times.
      */
     if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$this->mVarCache))) {
         if (isset($this->mVarCache[$index])) {
             return $this->mVarCache[$index];
         }
     }
     $ts = wfTimestamp(TS_UNIX, $this->mOptions->getTimestamp());
     wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts));
     $pageLang = $this->getFunctionLang();
     switch ($index) {
         case 'currentmonth':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('m'));
             break;
         case 'currentmonth1':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('n'));
             break;
         case 'currentmonthname':
             $value = $pageLang->getMonthName(MWTimestamp::getInstance($ts)->format('n'));
             break;
         case 'currentmonthnamegen':
             $value = $pageLang->getMonthNameGen(MWTimestamp::getInstance($ts)->format('n'));
             break;
         case 'currentmonthabbrev':
             $value = $pageLang->getMonthAbbreviation(MWTimestamp::getInstance($ts)->format('n'));
             break;
         case 'currentday':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('j'));
             break;
         case 'currentday2':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('d'));
             break;
         case 'localmonth':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('m'));
             break;
         case 'localmonth1':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('n'));
             break;
         case 'localmonthname':
             $value = $pageLang->getMonthName(MWTimestamp::getLocalInstance($ts)->format('n'));
             break;
         case 'localmonthnamegen':
             $value = $pageLang->getMonthNameGen(MWTimestamp::getLocalInstance($ts)->format('n'));
             break;
         case 'localmonthabbrev':
             $value = $pageLang->getMonthAbbreviation(MWTimestamp::getLocalInstance($ts)->format('n'));
             break;
         case 'localday':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('j'));
             break;
         case 'localday2':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('d'));
             break;
         case 'pagename':
             $value = wfEscapeWikiText($this->mTitle->getText());
             break;
         case 'pagenamee':
             $value = wfEscapeWikiText($this->mTitle->getPartialURL());
             break;
         case 'fullpagename':
             $value = wfEscapeWikiText($this->mTitle->getPrefixedText());
             break;
         case 'fullpagenamee':
             $value = wfEscapeWikiText($this->mTitle->getPrefixedURL());
             break;
         case 'subpagename':
             $value = wfEscapeWikiText($this->mTitle->getSubpageText());
             break;
         case 'subpagenamee':
             $value = wfEscapeWikiText($this->mTitle->getSubpageUrlForm());
             break;
         case 'rootpagename':
             $value = wfEscapeWikiText($this->mTitle->getRootText());
             break;
         case 'rootpagenamee':
             $value = wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $this->mTitle->getRootText())));
             break;
         case 'basepagename':
             $value = wfEscapeWikiText($this->mTitle->getBaseText());
             break;
         case 'basepagenamee':
             $value = wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText())));
             break;
         case 'talkpagename':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 $value = wfEscapeWikiText($talkPage->getPrefixedText());
             } else {
                 $value = '';
             }
             break;
         case 'talkpagenamee':
             if ($this->mTitle->canTalk()) {
                 $talkPage = $this->mTitle->getTalkPage();
                 $value = wfEscapeWikiText($talkPage->getPrefixedURL());
             } else {
                 $value = '';
             }
             break;
         case 'subjectpagename':
             $subjPage = $this->mTitle->getSubjectPage();
             $value = wfEscapeWikiText($subjPage->getPrefixedText());
             break;
         case 'subjectpagenamee':
             $subjPage = $this->mTitle->getSubjectPage();
             $value = wfEscapeWikiText($subjPage->getPrefixedURL());
             break;
         case 'pageid':
             // requested in bug 23427
             $pageid = $this->getTitle()->getArticleID();
             if ($pageid == 0) {
                 # 0 means the page doesn't exist in the database,
                 # which means the user is previewing a new page.
                 # The vary-revision flag must be set, because the magic word
                 # will have a different value once the page is saved.
                 $this->mOutput->setFlag('vary-revision');
                 wfDebug(__METHOD__ . ": {{PAGEID}} used in a new page, setting vary-revision...\n");
             }
             $value = $pageid ? $pageid : null;
             break;
         case 'revisionid':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n");
             $value = $this->mRevisionId;
             break;
         case 'revisionday':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n");
             $value = intval(substr($this->getRevisionTimestamp(), 6, 2));
             break;
         case 'revisionday2':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 6, 2);
             break;
         case 'revisionmonth':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 4, 2);
             break;
         case 'revisionmonth1':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONMONTH1}} used, setting vary-revision...\n");
             $value = intval(substr($this->getRevisionTimestamp(), 4, 2));
             break;
         case 'revisionyear':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n");
             $value = substr($this->getRevisionTimestamp(), 0, 4);
             break;
         case 'revisiontimestamp':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n");
             $value = $this->getRevisionTimestamp();
             break;
         case 'revisionuser':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n");
             $value = $this->getRevisionUser();
             break;
         case 'revisionsize':
             # Let the edit saving system know we should parse the page
             # *after* a revision ID has been assigned. This is for null edits.
             $this->mOutput->setFlag('vary-revision');
             wfDebug(__METHOD__ . ": {{REVISIONSIZE}} used, setting vary-revision...\n");
             $value = $this->getRevisionSize();
             break;
         case 'namespace':
             $value = str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace()));
             break;
         case 'namespacee':
             $value = wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace()));
             break;
         case 'namespacenumber':
             $value = $this->mTitle->getNamespace();
             break;
         case 'talkspace':
             $value = $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '';
             break;
         case 'talkspacee':
             $value = $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '';
             break;
         case 'subjectspace':
             $value = str_replace('_', ' ', $this->mTitle->getSubjectNsText());
             break;
         case 'subjectspacee':
             $value = wfUrlencode($this->mTitle->getSubjectNsText());
             break;
         case 'currentdayname':
             $value = $pageLang->getWeekdayName((int) MWTimestamp::getInstance($ts)->format('w') + 1);
             break;
         case 'currentyear':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('Y'), true);
             break;
         case 'currenttime':
             $value = $pageLang->time(wfTimestamp(TS_MW, $ts), false, false);
             break;
         case 'currenthour':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('H'), true);
             break;
         case 'currentweek':
             # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             # int to remove the padding
             $value = $pageLang->formatNum((int) MWTimestamp::getInstance($ts)->format('W'));
             break;
         case 'currentdow':
             $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('w'));
             break;
         case 'localdayname':
             $value = $pageLang->getWeekdayName((int) MWTimestamp::getLocalInstance($ts)->format('w') + 1);
             break;
         case 'localyear':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('Y'), true);
             break;
         case 'localtime':
             $value = $pageLang->time(MWTimestamp::getLocalInstance($ts)->format('YmdHis'), false, false);
             break;
         case 'localhour':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('H'), true);
             break;
         case 'localweek':
             # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             # int to remove the padding
             $value = $pageLang->formatNum((int) MWTimestamp::getLocalInstance($ts)->format('W'));
             break;
         case 'localdow':
             $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('w'));
             break;
         case 'numberofarticles':
             $value = $pageLang->formatNum(SiteStats::articles());
             break;
         case 'numberoffiles':
             $value = $pageLang->formatNum(SiteStats::images());
             break;
         case 'numberofusers':
             $value = $pageLang->formatNum(SiteStats::users());
             break;
         case 'numberofactiveusers':
             $value = $pageLang->formatNum(SiteStats::activeUsers());
             break;
         case 'numberofpages':
             $value = $pageLang->formatNum(SiteStats::pages());
             break;
         case 'numberofadmins':
             $value = $pageLang->formatNum(SiteStats::numberingroup('sysop'));
             break;
         case 'numberofedits':
             $value = $pageLang->formatNum(SiteStats::edits());
             break;
         case 'numberofviews':
             global $wgDisableCounters;
             $value = !$wgDisableCounters ? $pageLang->formatNum(SiteStats::views()) : '';
             break;
         case 'currenttimestamp':
             $value = wfTimestamp(TS_MW, $ts);
             break;
         case 'localtimestamp':
             $value = MWTimestamp::getLocalInstance($ts)->format('YmdHis');
             break;
         case 'currentversion':
             $value = SpecialVersion::getVersion();
             break;
         case 'articlepath':
             return $wgArticlePath;
         case 'sitename':
             return $wgSitename;
         case 'server':
             return $wgServer;
         case 'servername':
             $serverParts = wfParseUrl($wgServer);
             return $serverParts && isset($serverParts['host']) ? $serverParts['host'] : $wgServer;
         case 'scriptpath':
             return $wgScriptPath;
         case 'stylepath':
             return $wgStylePath;
         case 'directionmark':
             return $pageLang->getDirMark();
         case 'contentlanguage':
             global $wgLanguageCode;
             return $wgLanguageCode;
         case 'cascadingsources':
             $value = CoreParserFunctions::cascadingsources($this);
             break;
         default:
             $ret = null;
             wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$this->mVarCache, &$index, &$ret, &$frame));
             return $ret;
     }
     if ($index) {
         $this->mVarCache[$index] = $value;
     }
     return $value;
 }
Esempio n. 23
0
 public function prepareVariables()
 {
     global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
     global $wgContLanguageCode;
     global $wgTitle;
     $this->mRevisionId = $this->mTitle->getLatestRevID();
     $ts = time();
     # Use the time zone
     global $wgLocaltimezone;
     if (isset($wgLocaltimezone)) {
         $oldtz = getenv('TZ');
         putenv('TZ=' . $wgLocaltimezone);
     }
     wfSuppressWarnings();
     // E_STRICT system time bitching
     $localTimestamp = date('YmdHis', $ts);
     $localMonth = date('m', $ts);
     $localMonthName = date('n', $ts);
     $localDay = date('j', $ts);
     $localDay2 = date('d', $ts);
     $localDayOfWeek = date('w', $ts);
     $localWeek = date('W', $ts);
     $localYear = date('Y', $ts);
     $localHour = date('H', $ts);
     if (isset($wgLocaltimezone)) {
         putenv('TZ=' . $oldtz);
     }
     wfRestoreWarnings();
     // some simpler ones...
     $w2lVars = array('currentmonth' => $wgContLang->formatNum(gmdate('m', $ts)), 'currentmonthname' => $wgContLang->getMonthName(gmdate('n', $ts)), 'currentmonthnamegen' => $wgContLang->getMonthNameGen(gmdate('n', $ts)), 'currentmonthabbrev' => $wgContLang->getMonthAbbreviation(gmdate('n', $ts)), 'currentday' => $wgContLang->formatNum(gmdate('j', $ts)), 'currentday2' => $wgContLang->formatNum(gmdate('d', $ts)), 'localmonth' => $wgContLang->formatNum($localMonth), 'localmonthname' => $wgContLang->getMonthName($localMonthName), 'localmonthnamegen' => $wgContLang->getMonthNameGen($localMonthName), 'localmonthabbrev' => $wgContLang->getMonthAbbreviation($localMonthName), 'localday' => $wgContLang->formatNum($localDay), 'localday2' => $wgContLang->formatNum($localDay2), 'pagename' => wfEscapeWikiText($this->mTitle->getText()), 'pagenamee' => $this->mTitle->getPartialURL(), 'fullpagename' => wfEscapeWikiText($this->mTitle->getPrefixedText()), 'fullpagenamee' => $this->mTitle->getPrefixedURL(), 'subpagename' => wfEscapeWikiText($this->mTitle->getSubpageText()), 'subpagenamee' => $this->mTitle->getSubpageUrlForm(), 'basepagename' => wfEscapeWikiText($this->mTitle->getBaseText()), 'basepagenamee' => wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText())), 'revisionid' => $this->mRevisionId, 'revisionday' => intval(substr($this->getRevisionTimestamp(), 6, 2)), 'revisionday2' => substr($this->getRevisionTimestamp(), 6, 2), 'revisionmonth' => substr($this->getRevisionTimestamp(), 4, 2), 'revisionmonth1' => intval(substr($this->getRevisionTimestamp(), 4, 2)), 'revisionyear' => substr($this->getRevisionTimestamp(), 0, 4), 'revisiontimestamp' => $this->getRevisionTimestamp(), 'namespace' => str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace())), 'namespacee' => wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace())), 'talkspace' => $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : '', 'talkspacee' => $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : '', 'subjectspace' => $this->mTitle->getSubjectNsText(), 'subjectspacee' => wfUrlencode($this->mTitle->getSubjectNsText()), 'currentdayname' => $wgContLang->getWeekdayName(gmdate('w', $ts) + 1), 'currentyear' => $wgContLang->formatNum(gmdate('Y', $ts), true), 'currenttime' => $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false), 'currenthour' => $wgContLang->formatNum(gmdate('H', $ts), true), 'currentweek' => $wgContLang->formatNum((int) gmdate('W', $ts)), 'currentdow' => $wgContLang->formatNum(gmdate('w', $ts)), 'localdayname' => $wgContLang->getWeekdayName($localDayOfWeek + 1), 'localyear' => $wgContLang->formatNum($localYear, true), 'localtime' => $wgContLang->time($localTimestamp, false, false), 'localhour' => $wgContLang->formatNum($localHour, true), 'localweek' => $wgContLang->formatNum((int) $localWeek), 'localdow' => $wgContLang->formatNum($localDayOfWeek), 'numberofarticles' => $wgContLang->formatNum(SiteStats::articles()), 'numberoffiles' => $wgContLang->formatNum(SiteStats::images()), 'numberofusers' => $wgContLang->formatNum(SiteStats::users()), 'numberofpages' => $wgContLang->formatNum(SiteStats::pages()), 'numberofadmins' => $wgContLang->formatNum(SiteStats::numberingroup('sysop')), 'numberofedits' => $wgContLang->formatNum(SiteStats::edits()), 'currenttimestamp' => wfTimestampNow(), 'localtimestamp' => $localTimestamp, 'currentversion' => SpecialVersion::getVersion(), 'sitename' => $wgSitename, 'server' => $wgServer, 'servername' => $wgServerName, 'scriptpath' => $wgScriptPath, 'directionmark' => $wgContLang->getDirMark(), 'contentlanguage' => $wgContLanguageCode, 'pageid' => $this->mTitle->getArticleID(), 'namespacenumber' => $this->mTitle->getNamespace(), 'numberofactiveusers' => $wgContLang->formatNum(SiteStats::activeUsers()), 'revisionuser' => $this->mRevision->getUserText(), 'stylepath' => $wgStylePath);
     // These are a bit more complicated...
     //case 'talkpagename':
     if ($this->mTitle->canTalk()) {
         $talkPage = $this->mTitle->getTalkPage();
         $talkpagename = wfEscapeWikiText($talkPage->getPrefixedText());
     } else {
         $talkpagename = '';
     }
     $w2lVars['talkpagename'] = $talkpagename;
     //case 'talkpagenamee':
     if ($this->mTitle->canTalk()) {
         $talkPage = $this->mTitle->getTalkPage();
         $talkpagenamee = $talkPage->getPrefixedUrl();
     } else {
         $talkpagenamee = '';
     }
     $w2lVars['talkpagenamee'] = $talkpagenamee;
     //case 'subjectpagename':
     $subjPage = $this->mTitle->getSubjectPage();
     $w2lVars['subjectpagename'] = wfEscapeWikiText($subjPage->getPrefixedText());
     $w2lVars['subjectpagenamee'] = $subjPage->getPrefixedUrl();
     wfRunHooks('w2lTemplateVars', array(&$this, &$w2lVars));
     $w2lVars = array_change_key_case($w2lVars, CASE_UPPER);
     return $w2lVars;
 }