Example #1
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;
             }
     }
 }
Example #2
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;
             }
     }
 }