/** * @param Title $title Title object that this entry is for. * @param String $pubDate Publish date formattable by wfTimestamp. * @param Array $keywords list of (String) keywords * @param Mixed Boolean or Integer. Namespace containing comments page for entry. * True for the corresponding talk page of $title * False for none * An integer for the page name of $title in the specific namespace denoted by that integer. */ public function __construct($title, $pubDate, $keywords = '', $comment = true) { if (!$title || !$title instanceof Title) { // Paranoia throw new MWException('Invalid title object passed to FeedSMItem'); } $commentsURL = ''; if ($comment === true) { // The comment ns is this article's talk namespace. $commentsURL = $title->getTalkPage()->getFullUrl(); } elseif (is_int($comment)) { // There's a specific comments namespace. $commentsTitle = Title::makeTitle($comment, $title->getDBkey()); if ($commentsTitle) { $commentsURL = $commentsTitle->getFullUrl(); } } $this->keywords = $keywords; $this->titleObj = $title; parent::__construct($title->getText(), '', $title->getFullURL(), $pubDate, '', $commentsURL); }
/** * Move this page's subpages to be subpages of $nt * * @param Title $nt Move target * @param bool $auth Whether $wgUser's permissions should be checked * @param string $reason The reason for the move * @param bool $createRedirect Whether to create redirects from the old subpages to * the new ones Ignored if the user doesn't have the 'suppressredirect' right * @return array Array with old page titles as keys, and strings (new page titles) or * arrays (errors) as values, or an error array with numeric indices if no pages * were moved */ public function moveSubpages($nt, $auth = true, $reason = '', $createRedirect = true) { global $wgMaximumMovedPages; // Check permissions if (!$this->userCan('move-subpages')) { return array('cant-move-subpages'); } // Do the source and target namespaces support subpages? if (!MWNamespace::hasSubpages($this->getNamespace())) { return array('namespace-nosubpages', MWNamespace::getCanonicalName($this->getNamespace())); } if (!MWNamespace::hasSubpages($nt->getNamespace())) { return array('namespace-nosubpages', MWNamespace::getCanonicalName($nt->getNamespace())); } $subpages = $this->getSubpages($wgMaximumMovedPages + 1); $retval = array(); $count = 0; foreach ($subpages as $oldSubpage) { $count++; if ($count > $wgMaximumMovedPages) { $retval[$oldSubpage->getPrefixedText()] = array('movepage-max-pages', $wgMaximumMovedPages); break; } // We don't know whether this function was called before // or after moving the root page, so check both // $this and $nt if ($oldSubpage->getArticleID() == $this->getArticleID() || $oldSubpage->getArticleID() == $nt->getArticleID()) { // When moving a page to a subpage of itself, // don't move it twice continue; } $newPageName = preg_replace('#^' . preg_quote($this->getDBkey(), '#') . '#', StringUtils::escapeRegexReplacement($nt->getDBkey()), $oldSubpage->getDBkey()); if ($oldSubpage->isTalkPage()) { $newNs = $nt->getTalkPage()->getNamespace(); } else { $newNs = $nt->getSubjectPage()->getNamespace(); } # Bug 14385: we need makeTitleSafe because the new page names may # be longer than 255 characters. $newSubpage = Title::makeTitleSafe($newNs, $newPageName); $success = $oldSubpage->moveTo($newSubpage, $auth, $reason, $createRedirect); if ($success === true) { $retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText(); } else { $retval[$oldSubpage->getPrefixedText()] = $success; } } return $retval; }
/** * 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; }
/** * 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; }
/** * Show subpages of the page being moved. Section is not shown if both current * namespace does not support subpages and no talk subpages were found. * * @param Title $title Page being moved. */ function showSubpages($title) { $nsHasSubpages = MWNamespace::hasSubpages($title->getNamespace()); $subpages = $title->getSubpages(); $count = $subpages instanceof TitleArray ? $subpages->count() : 0; $titleIsTalk = $title->isTalkPage(); $subpagesTalk = $title->getTalkPage()->getSubpages(); $countTalk = $subpagesTalk instanceof TitleArray ? $subpagesTalk->count() : 0; $totalCount = $count + $countTalk; if (!$nsHasSubpages && $countTalk == 0) { return; } $this->getOutput()->wrapWikiMsg('== $1 ==', ['movesubpage', $titleIsTalk ? $count : $totalCount]); if ($nsHasSubpages) { $this->showSubpagesList($subpages, $count, 'movesubpagetext', true); } if (!$titleIsTalk && $countTalk > 0) { $this->showSubpagesList($subpagesTalk, $countTalk, 'movesubpagetalktext'); } }
/** * Show the form * * @param array $err Error messages. Each item is an error message. * It may either be a string message name or array message name and * parameters, like the second argument to OutputPage::wrapWikiMsg(). */ function showForm($err) { global $wgContLang; $this->getSkin()->setRelevantTitle($this->oldTitle); $oldTitleLink = Linker::link($this->oldTitle); $out = $this->getOutput(); $out->setPageTitle($this->msg('move-page', $this->oldTitle->getPrefixedText())); $out->addModules('mediawiki.special.movePage'); $out->addModuleStyles('mediawiki.special.movePage.styles'); $this->addHelpLink('Help:Moving a page'); $newTitle = $this->newTitle; if (!$newTitle) { # Show the current title as a default # when the form is first opened. $newTitle = $this->oldTitle; } elseif (!count($err)) { # If a title was supplied, probably from the move log revert # link, check for validity. We can then show some diagnostic # information and save a click. $newerr = $this->oldTitle->isValidMoveOperation($newTitle); if (is_array($newerr)) { $err = $newerr; } } $user = $this->getUser(); if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'articleexists' && $newTitle->quickUserCan('delete', $user)) { $out->addWikiMsg('delete_and_move_text', $newTitle->getPrefixedText()); $movepagebtn = $this->msg('delete_and_move')->text(); $submitVar = 'wpDeleteAndMove'; $confirm = true; $err = array(); } else { if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage()) { $out->wrapWikiMsg("<div class=\"error mw-moveuserpage-warning\">\n\$1\n</div>", 'moveuserpage-warning'); } elseif ($this->oldTitle->getNamespace() == NS_CATEGORY) { $out->wrapWikiMsg("<div class=\"error mw-movecategorypage-warning\">\n\$1\n</div>", 'movecategorypage-warning'); } $out->addWikiMsg($this->getConfig()->get('FixDoubleRedirects') ? 'movepagetext' : 'movepagetext-noredirectfixer'); $movepagebtn = $this->msg('movepagebtn')->text(); $submitVar = 'wpMove'; $confirm = false; } if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'file-exists-sharedrepo' && $user->isAllowed('reupload-shared')) { $out->addWikiMsg('move-over-sharedrepo', $newTitle->getPrefixedText()); $submitVar = 'wpMoveOverSharedFile'; $err = array(); } $oldTalk = $this->oldTitle->getTalkPage(); $oldTitleSubpages = $this->oldTitle->hasSubpages(); $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages(); $canMoveSubpage = ($oldTitleSubpages || $oldTitleTalkSubpages) && !count($this->oldTitle->getUserPermissionsErrors('move-subpages', $user)); # We also want to be able to move assoc. subpage talk-pages even if base page # has no associated talk page, so || with $oldTitleTalkSubpages. $considerTalk = !$this->oldTitle->isTalkPage() && ($oldTalk->exists() || $oldTitleTalkSubpages && $canMoveSubpage); $dbr = wfGetDB(DB_SLAVE); if ($this->getConfig()->get('FixDoubleRedirects')) { $hasRedirects = $dbr->selectField('redirect', '1', array('rd_namespace' => $this->oldTitle->getNamespace(), 'rd_title' => $this->oldTitle->getDBkey()), __METHOD__); } else { $hasRedirects = false; } if ($considerTalk) { $out->addWikiMsg('movepagetalktext'); } if (count($err)) { $out->addHTML("<div class='error'>\n"); $action_desc = $this->msg('action-move')->plain(); $out->addWikiMsg('permissionserrorstext-withaction', count($err), $action_desc); if (count($err) == 1) { $errMsg = $err[0]; $errMsgName = array_shift($errMsg); if ($errMsgName == 'hookaborted') { $out->addHTML("<p>{$errMsg[0]}</p>\n"); } else { $out->addWikiMsgArray($errMsgName, $errMsg); } } else { $errStr = array(); foreach ($err as $errMsg) { if ($errMsg[0] == 'hookaborted') { $errStr[] = $errMsg[1]; } else { $errMsgName = array_shift($errMsg); $errStr[] = $this->msg($errMsgName, $errMsg)->parse(); } } $out->addHTML('<ul><li>' . implode("</li>\n<li>", $errStr) . "</li></ul>\n"); } $out->addHTML("</div>\n"); } if ($this->oldTitle->isProtected('move')) { # Is the title semi-protected? if ($this->oldTitle->isSemiProtected('move')) { $noticeMsg = 'semiprotectedpagemovewarning'; $classes[] = 'mw-textarea-sprotected'; } else { # Then it must be protected based on static groups (regular) $noticeMsg = 'protectedpagemovewarning'; $classes[] = 'mw-textarea-protected'; } $out->addHTML("<div class='mw-warning-with-logexcerpt'>\n"); $out->addWikiMsg($noticeMsg); LogEventsList::showLogExtract($out, 'protect', $this->oldTitle, '', array('lim' => 1)); $out->addHTML("</div>\n"); } // Byte limit (not string length limit) for wpReason and wpNewTitleMain // is enforced in the mediawiki.special.movePage module $immovableNamespaces = array(); foreach (array_keys($this->getLanguage()->getNamespaces()) as $nsId) { if (!MWNamespace::isMovable($nsId)) { $immovableNamespaces[] = $nsId; } } $handler = ContentHandler::getForTitle($this->oldTitle); $out->enableOOUI(); $fields = array(); $fields[] = new OOUI\FieldLayout(new OOUI\LabelWidget(array('label' => new OOUI\HtmlSnippet("<strong>{$oldTitleLink}</strong>"))), array('label' => $this->msg('movearticle')->text(), 'align' => 'top')); $fields[] = new OOUI\FieldLayout(new MediaWiki\Widget\ComplexTitleInputWidget(array('id' => 'wpNewTitle', 'namespace' => array('id' => 'wpNewTitleNs', 'name' => 'wpNewTitleNs', 'value' => $newTitle->getNamespace(), 'exclude' => $immovableNamespaces), 'title' => array('id' => 'wpNewTitleMain', 'name' => 'wpNewTitleMain', 'value' => $wgContLang->recodeForEdit($newTitle->getText()), 'suggestions' => false), 'infusable' => true)), array('label' => $this->msg('newtitle')->text(), 'align' => 'top')); $fields[] = new OOUI\FieldLayout(new OOUI\TextInputWidget(array('name' => 'wpReason', 'id' => 'wpReason', 'maxLength' => 200, 'infusable' => true, 'value' => $this->reason)), array('label' => $this->msg('movereason')->text(), 'align' => 'top')); if ($considerTalk) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovetalk', 'id' => 'wpMovetalk', 'value' => '1', 'selected' => $this->moveTalk)), array('label' => $this->msg('movetalk')->text(), 'align' => 'inline')); } if ($user->isAllowed('suppressredirect')) { if ($handler->supportsRedirects()) { $isChecked = $this->leaveRedirect; $isDisabled = false; } else { $isChecked = false; $isDisabled = true; } $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpLeaveRedirect', 'id' => 'wpLeaveRedirect', 'value' => '1', 'selected' => $isChecked, 'disabled' => $isDisabled)), array('label' => $this->msg('move-leave-redirect')->text(), 'align' => 'inline')); } if ($hasRedirects) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpFixRedirects', 'id' => 'wpFixRedirects', 'value' => '1', 'selected' => $this->fixRedirects)), array('label' => $this->msg('fix-double-redirects')->text(), 'align' => 'inline')); } if ($canMoveSubpage) { $maximumMovedPages = $this->getConfig()->get('MaximumMovedPages'); $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovesubpages', 'id' => 'wpMovesubpages', 'value' => '1', 'selected' => $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk))), array('label' => new OOUI\HtmlSnippet($this->msg($this->oldTitle->hasSubpages() ? 'move-subpages' : 'move-talk-subpages')->numParams($maximumMovedPages)->params($maximumMovedPages)->parse()), 'align' => 'inline')); } # Don't allow watching if user is not logged in if ($user->isLoggedIn()) { $watchChecked = $user->isLoggedIn() && ($this->watch || $user->getBoolOption('watchmoves') || $user->isWatched($this->oldTitle)); $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpWatch', 'id' => 'watch', 'value' => '1', 'selected' => $watchChecked)), array('label' => $this->msg('move-watch')->text(), 'align' => 'inline')); } if ($confirm) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpConfirm', 'id' => 'wpConfirm', 'value' => '1')), array('label' => $this->msg('delete_and_move_confirm')->text(), 'align' => 'inline')); } $fields[] = new OOUI\FieldLayout(new OOUI\ButtonInputWidget(array('name' => $submitVar, 'value' => $movepagebtn, 'label' => $movepagebtn, 'flags' => array('constructive', 'primary'), 'type' => 'submit')), array('align' => 'top')); $fieldset = new OOUI\FieldsetLayout(array('label' => $this->msg('move-page-legend')->text(), 'id' => 'mw-movepage-table', 'items' => $fields)); $form = new OOUI\FormLayout(array('method' => 'post', 'action' => $this->getPageTitle()->getLocalURL('action=submit'), 'id' => 'movepage')); $form->appendContent($fieldset, new OOUI\HtmlSnippet(Html::hidden('wpOldTitle', $this->oldTitle->getPrefixedText()) . Html::hidden('wpEditToken', $user->getEditToken()))); $out->addHTML(new OOUI\PanelLayout(array('classes' => array('movepage-wrapper'), 'expanded' => false, 'padded' => true, 'framed' => true, 'content' => $form))); $this->showLogFragment($this->oldTitle); $this->showSubpages($this->oldTitle); }
/** * Check if the given title already is watched by the user, and if so * add watches on a new title. To be used for page renames and such. * * @param Title $ot Page title to duplicate entries from, if present * @param Title $nt Page title to add watches on */ public static function duplicateEntries($ot, $nt) { WatchedItem::doDuplicateEntries($ot->getSubjectPage(), $nt->getSubjectPage()); WatchedItem::doDuplicateEntries($ot->getTalkPage(), $nt->getTalkPage()); }
/** * Clears caches when article is deleted * * @param Title $title */ public static function onArticleDelete($title) { // Update existence markers on article/talk tabs... if ($title->isTalkPage()) { $other = $title->getSubjectPage(); } else { $other = $title->getTalkPage(); } $other->invalidateCache(); $other->purgeSquid(); $title->touchLinks(); $title->purgeSquid(); // File cache HTMLFileCache::clearFileCache($title); InfoAction::invalidateCache($title); // Messages if ($title->getNamespace() == NS_MEDIAWIKI) { MessageCache::singleton()->replace($title->getDBkey(), false); } // Images if ($title->getNamespace() == NS_FILE) { $update = new HTMLCacheUpdate($title, 'imagelinks'); $update->doUpdate(); } // User talk pages if ($title->getNamespace() == NS_USER_TALK) { $user = User::newFromName($title->getText(), false); if ($user) { $user->setNewtalk(false); } } // Image redirects RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title); }
/** * Check if the given title already is watched by the user, and if so * add watches on a new title. To be used for page renames and such. * * @param Title $ot Page title to duplicate entries from, if present * @param Title $nt Page title to add watches on * @static */ function duplicateEntries($ot, $nt, $summary = null) { //WERELATE - add optional $summary parameter WatchedItem::doDuplicateEntries($ot->getSubjectPage(), $nt->getSubjectPage(), $summary); WatchedItem::doDuplicateEntries($ot->getTalkPage(), $nt->getTalkPage()); }
/** * * @param Title $related_title The title the talk is related to * @param User $user * @param string $content * @return Title */ public static function createTalk($related_title, $user, $content = '-') { if (!$related_title instanceof Title || !$user instanceof User) { throw new MWException('Cannot create talk page (wrong argument)'); } if (!$related_title->canTalk()) { return array('sz-internal-error'); } $talk = $related_title->getTalkPage(); if (!$talk instanceof Title) { return array('sz-internal-error'); } if ($talk->isKnown()) { return array('wp-title-already-exists'); } // as seen in EditPage->getEditPermissionErrors() ( called by EditPage->edit() ) $permErrors = $talk->getUserPermissionsErrors('edit', $user); $permErrors = array_merge($permErrors, wfArrayDiff2($talk->getUserPermissionsErrors('create', $user), $permErrors)); if ($permErrors) { // creation impossible return $permErrors[0]; // strange, but only key 0 seems to be used by MW when reading errors } // now store the new page in mediawiki, this will trigger the WikiplaceHook, wich will // allow the page saving $article = new Article($talk); $status = $article->doEdit($content, '', EDIT_NEW, false, $user); if (!$status->isgood()) { return array('sz-internal-error'); } return $talk; }
/** * Stop watching an article. * @since 1.22 $checkRights parameter added * @param Title $title Title of the article to look at * @param bool $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights. * Pass User::CHECK_USER_RIGHTS or User::IGNORE_USER_RIGHTS. */ public function removeWatch($title, $checkRights = self::CHECK_USER_RIGHTS) { if (!$checkRights || $this->isAllowed('editmywatchlist')) { $store = MediaWikiServices::getInstance()->getWatchedItemStore(); $store->removeWatch($this, $title->getSubjectPage()); $store->removeWatch($this, $title->getTalkPage()); } $this->invalidateCache(); }