示例#1
0
 /**
  * Extract inexpensive information from a Title object for return to Lua
  *
  * @param $title Title Title to return
  * @return array Lua data
  */
 private function getInexpensiveTitleData(Title $title)
 {
     $ns = $title->getNamespace();
     $ret = array('isLocal' => (bool) $title->isLocal(), 'interwiki' => $title->getInterwiki(), 'namespace' => $ns, 'nsText' => $title->getNsText(), 'text' => $title->getText(), 'fragment' => $title->getFragment(), 'thePartialUrl' => $title->getPartialURL());
     if ($ns === NS_SPECIAL) {
         // Core doesn't currently record special page links, but it may in the future.
         if ($this->getParser() && !$title->equals($this->getTitle())) {
             $this->getParser()->getOutput()->addLink($title);
         }
         $ret['exists'] = (bool) SpecialPageFactory::exists($title->getDBkey());
     }
     if ($ns !== NS_FILE && $ns !== NS_MEDIA) {
         $ret['file'] = false;
     }
     return $ret;
 }
示例#2
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;
 }
示例#3
0
文件: Linker.php 项目: paladox/2
 /**
  * Get the URL to upload a certain file
  *
  * @param Title $destFile Title object of the file to upload
  * @param string $query Urlencoded query string to prepend
  * @return string Urlencoded URL
  */
 protected static function getUploadUrl($destFile, $query = '')
 {
     global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
     $q = 'wpDestFile=' . $destFile->getPartialURL();
     if ($query != '') {
         $q .= '&' . $query;
     }
     if ($wgUploadMissingFileUrl) {
         return wfAppendQuery($wgUploadMissingFileUrl, $q);
     } elseif ($wgUploadNavigationUrl) {
         return wfAppendQuery($wgUploadNavigationUrl, $q);
     } else {
         $upload = SpecialPage::getTitleFor('Upload');
         return $upload->getLocalURL($q);
     }
 }
示例#4
0
 /**
  * Return value of a magic variable (like PAGENAME)
  *
  * @private
  *
  * @param $index integer
  * @param $frame PPFrame
  */
 function getVariableValue($index, $frame = false)
 {
     global $wgContLang, $wgSitename, $wgServer;
     global $wgArticlePath, $wgScriptPath, $wgStylePath;
     /**
      * 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);
     }
     switch ($index) {
         case 'currentmonth':
             $value = $wgContLang->formatNum(gmdate('m', $ts));
             break;
         case 'currentmonth1':
             $value = $wgContLang->formatNum(gmdate('n', $ts));
             break;
         case 'currentmonthname':
             $value = $wgContLang->getMonthName(gmdate('n', $ts));
             break;
         case 'currentmonthnamegen':
             $value = $wgContLang->getMonthNameGen(gmdate('n', $ts));
             break;
         case 'currentmonthabbrev':
             $value = $wgContLang->getMonthAbbreviation(gmdate('n', $ts));
             break;
         case 'currentday':
             $value = $wgContLang->formatNum(gmdate('j', $ts));
             break;
         case 'currentday2':
             $value = $wgContLang->formatNum(gmdate('d', $ts));
             break;
         case 'localmonth':
             $value = $wgContLang->formatNum($localMonth);
             break;
         case 'localmonth1':
             $value = $wgContLang->formatNum($localMonth1);
             break;
         case 'localmonthname':
             $value = $wgContLang->getMonthName($localMonthName);
             break;
         case 'localmonthnamegen':
             $value = $wgContLang->getMonthNameGen($localMonthName);
             break;
         case 'localmonthabbrev':
             $value = $wgContLang->getMonthAbbreviation($localMonthName);
             break;
         case 'localday':
             $value = $wgContLang->formatNum($localDay);
             break;
         case 'localday2':
             $value = $wgContLang->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 = $wgContLang->getWeekdayName(gmdate('w', $ts) + 1);
             break;
         case 'currentyear':
             $value = $wgContLang->formatNum(gmdate('Y', $ts), true);
             break;
         case 'currenttime':
             $value = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false);
             break;
         case 'currenthour':
             $value = $wgContLang->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 = $wgContLang->formatNum((int) gmdate('W', $ts));
             break;
         case 'currentdow':
             $value = $wgContLang->formatNum(gmdate('w', $ts));
             break;
         case 'localdayname':
             $value = $wgContLang->getWeekdayName($localDayOfWeek + 1);
             break;
         case 'localyear':
             $value = $wgContLang->formatNum($localYear, true);
             break;
         case 'localtime':
             $value = $wgContLang->time($localTimestamp, false, false);
             break;
         case 'localhour':
             $value = $wgContLang->formatNum($localHour, true);
             break;
         case 'localweek':
             # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
             # int to remove the padding
             $value = $wgContLang->formatNum((int) $localWeek);
             break;
         case 'localdow':
             $value = $wgContLang->formatNum($localDayOfWeek);
             break;
         case 'numberofarticles':
             $value = $wgContLang->formatNum(SiteStats::articles());
             break;
         case 'numberoffiles':
             $value = $wgContLang->formatNum(SiteStats::images());
             break;
         case 'numberofusers':
             $value = $wgContLang->formatNum(SiteStats::users());
             break;
         case 'numberofactiveusers':
             $value = $wgContLang->formatNum(SiteStats::activeUsers());
             break;
         case 'numberofpages':
             $value = $wgContLang->formatNum(SiteStats::pages());
             break;
         case 'numberofadmins':
             $value = $wgContLang->formatNum(SiteStats::numberingroup('sysop'));
             break;
         case 'numberofedits':
             $value = $wgContLang->formatNum(SiteStats::edits());
             break;
         case 'numberofviews':
             $value = $wgContLang->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 $wgContLang->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;
 }
示例#5
0
 /**
  * @param Title $title
  * @param Title $newtitle
  * @param User $user
  * @param $oldid
  * @param $newid
  * @return bool
  */
 public static function onTitleMoveComplete(Title &$title, Title &$newtitle, User &$user, $oldid, $newid)
 {
     ArticlesApiController::purgeCache($newtitle->getArticleID());
     ArticlesApiController::purgeMethods([['getAsJson', ['id' => $title->getArticleID()]], ['getAsJson', ['title' => $title->getPartialURL()]]]);
     return true;
 }
 /**
  * ArticleFromTitle
  *
  * hook handler for redirecting pages from old central to new community wiki
  *
  * @author Marooned
  */
 static function ArticleFromTitle(Title &$title, &$article)
 {
     global $wgRequest, $wgCorporatePageRedirectWiki;
     //do not redirect for action different than view (allow creating, deleting, etc)
     if ($wgRequest->getVal('action', 'view') != 'view') {
         return true;
     }
     wfProfileIn(__METHOD__);
     switch ($title->getNamespace()) {
         case NS_USER:
         case NS_USER_TALK:
         case NS_FILE_TALK:
         case NS_HELP:
         case NS_HELP_TALK:
         case NS_CATEGORY_TALK:
         case NS_FORUM:
         case NS_FORUM_TALK:
         case 150:
             //NS_HUB
         //NS_HUB
         case 151:
             //NS_HUB_TALK
         //NS_HUB_TALK
         case 400:
             //NS_VIDEO
         //NS_VIDEO
         case 401:
             //NS_VIDEO_TALK
         //NS_VIDEO_TALK
         case 500:
             //NS_BLOG_ARTICLE
         //NS_BLOG_ARTICLE
         case 501:
             //NS_BLOG_ARTICLE_TALK
         //NS_BLOG_ARTICLE_TALK
         case 502:
             //NS_BLOG_LISTING
         //NS_BLOG_LISTING
         case 503:
             //NS_BLOG_LISTING_TALK
         //NS_BLOG_LISTING_TALK
         case 1200:
             // NS_WALL
             if (!$title->exists() && !empty($wgCorporatePageRedirectWiki)) {
                 $redirect = $wgCorporatePageRedirectWiki . self::getPrefixedText($title->getPartialURL(), array($title->getInterwiki(), $title->getNsText()));
             }
             break;
         case NS_FILE:
             $file = wfFindFile($title);
             if (empty($file) && !empty($wgCorporatePageRedirectWiki)) {
                 $redirect = $wgCorporatePageRedirectWiki . self::getPrefixedText($title->getPartialURL(), array($title->getInterwiki(), $title->getNsText()));
             }
             break;
         case NS_PROJECT:
         case NS_PROJECT_TALK:
             if (!$title->exists()) {
                 //"Project" namespace hardcoded because MW will rename it to name of redirecting page - not the destination wiki
                 $redirect = 'http://community.wikia.com/wiki/Project:' . $title->getPartialURL();
             }
             break;
         case NS_TALK:
             $t = $title->getSubjectPage();
             if ($t->exists()) {
                 $redirect = 'http://www.wikia.com/' . $t->getPartialURL();
             }
             break;
     }
     if (!wfRunHooks('CorporateBeforeRedirect', array(&$title))) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if (!empty($redirect)) {
         header("Location: {$redirect}");
         wfProfileOut(__METHOD__);
         exit;
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * @desc Add Mercury Article API urls to the purge urls list
  *
  * @param Title $title
  * @param array $urls
  * @return bool
  */
 public static function onTitleGetSquidURLs(Title $title, array &$urls)
 {
     global $wgServer;
     if ($title->inNamespaces(NS_MAIN)) {
         // Mercury API call from Ember.js to Hapi.js e.g.
         // http://elderscrolls.wikia.com/api/v1/article/Morrowind
         // To access it, you have to set your client to be directed to the Mercury machines.
         $urls[] = $wgServer . self::SERVICE_API_BASE . self::SERVICE_API_ARTICLE . $title->getPartialURL();
         // Mercury API call from Hapi.js to MediaWiki e.g.
         // http://elderscrolls.wikia.com/wikia.php?controller=MercuryApi&method=getArticle&title=Morrowind
         $urls[] = MercuryApiController::getUrl('getArticle', ['title' => $title->getPartialURL()]);
     }
     return true;
 }