/** * Perform one of the "standard" actions * * @param Page $page * @param Title $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!Hooks::run('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { return; } $act = $this->getAction(); $action = Action::factory($act, $page, $this->context); if ($action instanceof Action) { # Let CDN cache things if we can purge them. if ($this->config->get('UseSquid') && in_array(wfExpandUrl($request->getRequestURL(), PROTO_INTERNAL), $requestTitle->getCdnUrls())) { $output->setCdnMaxage($this->config->get('SquidMaxage')); } $action->show(); return; } if (Hooks::run('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->setStatusCode(404); $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } }
/** * Perform one of the "standard" actions * * @param Page $page * @param Title $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!Hooks::run('MediaWikiPerformAction', [$output, $page, $title, $user, $request, $this])) { return; } $act = $this->getAction(); $action = Action::factory($act, $page, $this->context); if ($action instanceof Action) { // Narrow DB query expectations for this HTTP request $trxLimits = $this->config->get('TrxProfilerLimits'); $trxProfiler = Profiler::instance()->getTransactionProfiler(); if ($request->wasPosted() && !$action->doesWrites()) { $trxProfiler->setExpectations($trxLimits['POST-nonwrite'], __METHOD__); $request->markAsSafeRequest(); } # Let CDN cache things if we can purge them. if ($this->config->get('UseSquid') && in_array(wfExpandUrl($request->getRequestURL(), PROTO_INTERNAL), $requestTitle->getCdnUrls())) { $output->setCdnMaxage($this->config->get('SquidMaxage')); } $action->show(); return; } if (Hooks::run('UnknownAction', [$request->getVal('action', 'view'), $page])) { $output->setStatusCode(404); $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } }
public function testDisabledAction_factoryReturnsFalse() { $page = $this->getPage(); $action = Action::factory('disabled', $page); $this->assertFalse($action); }
/** * initialize various variables and generate the template * * @param $out OutputPage */ function outputPage(OutputPage $out = null) { global $wgContLang; global $wgScript, $wgStylePath; global $wgMimeType, $wgJsMimeType; global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version; global $wgDisableCounters, $wgSitename, $wgLogo, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgDebugComments; global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn(__METHOD__); Profiler::instance()->setTemplated(true); $oldContext = null; if ($out !== null) { // @todo Add wfDeprecated in 1.20 $oldContext = $this->getContext(); $this->setContext($out->getContext()); } $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); $title = $this->getTitle(); wfProfileIn(__METHOD__ . '-init'); $this->initPage($out); $tpl = $this->setupTemplate($this->template, 'skins'); wfProfileOut(__METHOD__ . '-init'); wfProfileIn(__METHOD__ . '-stuff'); $this->thispage = $title->getPrefixedDBkey(); $this->titletxt = $title->getPrefixedText(); $this->userpage = $user->getUserPage()->getPrefixedText(); $query = array(); if (!$request->wasPosted()) { $query = $request->getValues(); unset($query['title']); unset($query['returnto']); unset($query['returntoquery']); } $this->thisquery = wfArrayToCGI($query); $this->loggedin = $user->isLoggedIn(); $this->username = $user->getName(); if ($this->loggedin || $this->showIPinHeader()) { $this->userpageUrlDetails = self::makeUrlDetails($this->userpage); } else { # This won't be used in the standard skins, but we define it to preserve the interface # To save time, we check for existence $this->userpageUrlDetails = self::makeKnownUrlDetails($this->userpage); } wfProfileOut(__METHOD__ . '-stuff'); wfProfileIn(__METHOD__ . '-stuff-head'); if (!$this->useHeadElement) { $tpl->set('pagecss', false); $tpl->set('usercss', false); $tpl->set('userjs', false); $tpl->set('userjsprev', false); $tpl->set('jsvarurl', false); $tpl->setRef('xhtmldefaultnamespace', $wgXhtmlDefaultNamespace); $tpl->set('xhtmlnamespaces', $wgXhtmlNamespaces); $tpl->set('html5version', $wgHtml5Version); $tpl->set('headlinks', $out->getHeadLinks()); $tpl->set('csslinks', $out->buildCssLinks()); $tpl->set('pageclass', $this->getPageClasses($title)); $tpl->set('skinnameclass', 'skin-' . Sanitizer::escapeClass($this->getSkinName())); } wfProfileOut(__METHOD__ . '-stuff-head'); wfProfileIn(__METHOD__ . '-stuff2'); $tpl->set('title', $out->getPageTitle()); $tpl->set('pagetitle', $out->getHTMLTitle()); $tpl->set('displaytitle', $out->mPageLinkTitle); $tpl->setRef('thispage', $this->thispage); $tpl->setRef('titleprefixeddbkey', $this->thispage); $tpl->set('titletext', $title->getText()); $tpl->set('articleid', $title->getArticleId()); $tpl->set('isarticle', $out->isArticle()); $subpagestr = $this->subPageSubtitle(); if ($subpagestr !== '') { $subpagestr = '<span class="subpages">' . $subpagestr . '</span>'; } $tpl->set('subtitle', $subpagestr . $out->getSubtitle()); $undelete = $this->getUndeleteLink(); if ($undelete === '') { $tpl->set('undelete', ''); } else { $tpl->set('undelete', '<span class="subpages">' . $undelete . '</span>'); } $tpl->set('catlinks', $this->getCategories()); if ($out->isSyndicated()) { $feeds = array(); foreach ($out->getSyndicationLinks() as $format => $link) { $feeds[$format] = array('text' => $this->msg("feed-{$format}")->text(), 'href' => $link); } $tpl->setRef('feeds', $feeds); } else { $tpl->set('feeds', false); } $tpl->setRef('mimetype', $wgMimeType); $tpl->setRef('jsmimetype', $wgJsMimeType); $tpl->set('charset', 'UTF-8'); $tpl->setRef('wgScript', $wgScript); $tpl->setRef('skinname', $this->skinname); $tpl->set('skinclass', get_class($this)); $tpl->setRef('skin', $this); $tpl->setRef('stylename', $this->stylename); $tpl->set('printable', $out->isPrintable()); $tpl->set('handheld', $request->getBool('handheld')); $tpl->setRef('loggedin', $this->loggedin); $tpl->set('notspecialpage', !$title->isSpecialPage()); /* XXX currently unused, might get useful later $tpl->set( 'editable', ( !$title->isSpecialPage() ) ); $tpl->set( 'exists', $title->getArticleID() != 0 ); $tpl->set( 'watch', $title->userIsWatching() ? 'unwatch' : 'watch' ); $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' ); $tpl->set( 'helppage', $this->msg( 'helppage' )->text() ); */ $tpl->set('searchaction', $this->escapeSearchLink()); $tpl->set('searchtitle', SpecialPage::getTitleFor('Search')->getPrefixedDBKey()); $tpl->set('search', trim($request->getVal('search'))); $tpl->setRef('stylepath', $wgStylePath); $tpl->setRef('articlepath', $wgArticlePath); $tpl->setRef('scriptpath', $wgScriptPath); $tpl->setRef('serverurl', $wgServer); $tpl->setRef('logopath', $wgLogo); $tpl->setRef('sitename', $wgSitename); $lang = $this->getLanguage(); $userlang = $lang->getHtmlCode(); $userdir = $lang->getDir(); $tpl->set('lang', $userlang); $tpl->set('dir', $userdir); $tpl->set('rtl', $lang->isRTL()); $tpl->set('capitalizeallnouns', $lang->capitalizeAllNouns() ? ' capitalize-all-nouns' : ''); $tpl->set('showjumplinks', $user->getOption('showjumplinks')); $tpl->set('username', $this->loggedin ? $this->username : null); $tpl->setRef('userpage', $this->userpage); $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']); $tpl->set('userlang', $userlang); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser // that interface elements are in a different language. $tpl->set('userlangattributes', ''); $tpl->set('specialpageattributes', ''); # obsolete if ($userlang !== $wgContLang->getHtmlCode() || $userdir !== $wgContLang->getDir()) { $escUserlang = htmlspecialchars($userlang); $escUserdir = htmlspecialchars($userdir); // Attributes must be in double quotes because htmlspecialchars() doesn't // escape single quotes $attrs = " lang=\"{$escUserlang}\" dir=\"{$escUserdir}\""; $tpl->set('userlangattributes', $attrs); } wfProfileOut(__METHOD__ . '-stuff2'); wfProfileIn(__METHOD__ . '-stuff3'); $tpl->set('newtalk', $this->getNewtalks()); $tpl->set('logo', $this->logoText()); $tpl->set('copyright', false); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); if ($out->isArticle() && $title->exists()) { if ($this->isRevisionCurrent()) { if (!$wgDisableCounters) { $viewcount = $this->getWikiPage()->getCount(); if ($viewcount) { $tpl->set('viewcount', $this->msg('viewcount')->numParams($viewcount)->parse()); } } if ($wgPageShowWatchingUsers) { $dbr = wfGetDB(DB_SLAVE); $num = $dbr->selectField('watchlist', 'COUNT(*)', array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace()), __METHOD__); if ($num > 0) { $tpl->set('numberofwatchingusers', $this->msg('number_of_watching_users_pageview')->numParams($num)->parse()); } } if ($wgMaxCredits != 0) { $tpl->set('credits', Action::factory('credits', $this->getWikiPage(), $this->getContext())->getCredits($wgMaxCredits, $wgShowCreditsIfMax)); } else { $tpl->set('lastmod', $this->lastModified()); } } $tpl->set('copyright', $this->getCopyright()); } wfProfileOut(__METHOD__ . '-stuff3'); wfProfileIn(__METHOD__ . '-stuff4'); $tpl->set('copyrightico', $this->getCopyrightIcon()); $tpl->set('poweredbyico', $this->getPoweredBy()); $tpl->set('disclaimer', $this->disclaimerLink()); $tpl->set('privacy', $this->privacyLink()); $tpl->set('about', $this->aboutLink()); $tpl->set('footerlinks', array('info' => array('lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright'), 'places' => array('privacy', 'about', 'disclaimer'))); global $wgFooterIcons; $tpl->set('footericons', $wgFooterIcons); foreach ($tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock) { if (count($footerIconsBlock) > 0) { foreach ($footerIconsBlock as &$footerIcon) { if (isset($footerIcon['src'])) { if (!isset($footerIcon['width'])) { $footerIcon['width'] = 88; } if (!isset($footerIcon['height'])) { $footerIcon['height'] = 31; } } } } else { unset($tpl->data['footericons'][$footerIconsKey]); } } if ($wgDebugComments) { $tpl->setRef('debug', $out->mDebugtext); } else { $tpl->set('debug', ''); } $tpl->set('sitenotice', $this->getSiteNotice()); $tpl->set('bottomscripts', $this->bottomScripts()); $tpl->set('printfooter', $this->printSource()); # An ID that includes the actual body text; without categories, contentSub, ... $realBodyAttribs = array('id' => 'mw-content-text'); # Add a mw-content-ltr/rtl class to be able to style based on text direction # when the content is different from the UI language, i.e.: # not for special pages or file pages AND only when viewing AND if the page exists # (or is in MW namespace, because that has default content) if (!in_array($title->getNamespace(), array(NS_SPECIAL, NS_FILE)) && in_array($request->getVal('action', 'view'), array('view', 'historysubmit')) && ($title->exists() || $title->getNamespace() == NS_MEDIAWIKI)) { $pageLang = $title->getPageLanguage(); $realBodyAttribs['lang'] = $pageLang->getHtmlCode(); $realBodyAttribs['dir'] = $pageLang->getDir(); $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir(); } $out->mBodytext = Html::rawElement('div', $realBodyAttribs, $out->mBodytext); $tpl->setRef('bodytext', $out->mBodytext); # Language links $language_urls = array(); if (!$wgHideInterlanguageLinks) { foreach ($out->getLanguageLinks() as $l) { $tmp = explode(':', $l, 2); $class = 'interwiki-' . $tmp[0]; unset($tmp); $nt = Title::newFromText($l); if ($nt) { $language_urls[] = array('href' => $nt->getFullURL(), 'text' => $wgContLang->getLanguageName($nt->getInterwiki()) != '' ? $wgContLang->getLanguageName($nt->getInterwiki()) : $l, 'title' => $nt->getText(), 'class' => $class, 'lang' => $nt->getInterwiki(), 'hreflang' => $nt->getInterwiki()); } } } if (count($language_urls)) { $tpl->setRef('language_urls', $language_urls); } else { $tpl->set('language_urls', false); } wfProfileOut(__METHOD__ . '-stuff4'); wfProfileIn(__METHOD__ . '-stuff5'); # Personal toolbar $tpl->set('personal_urls', $this->buildPersonalUrls()); $content_navigation = $this->buildContentNavigationUrls(); $content_actions = $this->buildContentActionUrls($content_navigation); $tpl->setRef('content_navigation', $content_navigation); $tpl->setRef('content_actions', $content_actions); $tpl->set('sidebar', $this->buildSidebar()); $tpl->set('nav_urls', $this->buildNavUrls()); // Set the head scripts near the end, in case the above actions resulted in added scripts if ($this->useHeadElement) { $tpl->set('headelement', $out->headElement($this)); } else { $tpl->set('headscripts', $out->getHeadScripts() . $out->getHeadItems()); } $tpl->set('debughtml', $this->generateDebugHTML()); $tpl->set('reporttime', wfReportTime()); // original version by hansm if (!wfRunHooks('SkinTemplateOutputPageBeforeExec', array(&$this, &$tpl))) { wfDebug(__METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n"); } // Set the bodytext to another key so that skins can just output it on it's own // and output printfooter and debughtml separately $tpl->set('bodycontent', $tpl->data['bodytext']); // Append printfooter and debughtml onto bodytext so that skins that were already // using bodytext before they were split out don't suddenly start not outputting information $tpl->data['bodytext'] .= Html::rawElement('div', array('class' => 'printfooter'), "\n{$tpl->data['printfooter']}") . "\n"; $tpl->data['bodytext'] .= $tpl->data['debughtml']; // allow extensions adding stuff after the page content. // See Skin::afterContentHook() for further documentation. $tpl->set('dataAfterContent', $this->afterContentHook()); wfProfileOut(__METHOD__ . '-stuff5'); // execute template wfProfileIn(__METHOD__ . '-execute'); $res = $tpl->execute(); wfProfileOut(__METHOD__ . '-execute'); // result may be an error $this->printOrError($res); if ($oldContext) { $this->setContext($oldContext); } wfProfileOut(__METHOD__); }
/** * Run a replaceText job * @return boolean success */ function run() { wfProfileIn(__METHOD__); if (is_null($this->title)) { $this->error = "replaceText: Invalid title"; wfProfileOut(__METHOD__); return false; } if (array_key_exists('move_page', $this->params)) { global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId($this->params['user_id']); $cur_page_name = $this->title->getText(); if ($this->params['use_regex']) { $new_page_name = preg_replace("/" . $this->params['target_str'] . "/U", $this->params['replacement_str'], $cur_page_name); } else { $new_page_name = str_replace($this->params['target_str'], $this->params['replacement_str'], $cur_page_name); } $new_title = Title::newFromText($new_page_name, $this->title->getNamespace()); $reason = $this->params['edit_summary']; $create_redirect = $this->params['create_redirect']; $this->title->moveTo($new_title, true, $reason, $create_redirect); if ($this->params['watch_page']) { if (class_exists('WatchAction')) { // Class was added in MW 1.19 WatchAction::doWatch($new_title, $wgUser); } else { Action::factory('watch', new WikiPage($new_title))->execute(); } } $wgUser = $actual_user; } else { // WikiPage::getContent() replaced // Article::fetchContent() starting in MW 1.21. if (method_exists('WikiPage', 'getContent')) { if ($this->title->getContentModel() !== CONTENT_MODEL_WIKITEXT) { $this->error = 'replaceText: Wiki page "' . $this->title->getPrefixedDBkey() . '" does not hold regular wikitext.'; wfProfileOut(__METHOD__); return false; } $wikiPage = new WikiPage($this->title); // Is this check necessary? if (!$wikiPage) { $this->error = 'replaceText: Wiki page not found for "' . $this->title->getPrefixedDBkey() . '."'; wfProfileOut(__METHOD__); return false; } $article_text = $wikiPage->getContent()->getNativeData(); } else { $article = new Article($this->title, 0); if (!$article) { $this->error = 'replaceText: Article not found for "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut(__METHOD__); return false; } $article_text = $article->fetchContent(); } wfProfileIn(__METHOD__ . '-replace'); $target_str = $this->params['target_str']; $replacement_str = $this->params['replacement_str']; // @todo FIXME eh? $num_matches; if ($this->params['use_regex']) { $new_text = preg_replace('/' . $target_str . '/U', $replacement_str, $article_text, -1, $num_matches); } else { $new_text = str_replace($target_str, $replacement_str, $article_text, $num_matches); } // If there's at least one replacement, modify the page, // using the passed-in edit summary. if ($num_matches > 0) { // Change global $wgUser variable to the one // specified by the job only for the extent of // this replacement. global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId($this->params['user_id']); $edit_summary = $this->params['edit_summary']; $flags = EDIT_MINOR; if ($wgUser->isAllowed('bot')) { $flags |= EDIT_FORCE_BOT; } if (method_exists('WikiPage', 'getContent')) { $new_content = new WikitextContent($new_text); $wikiPage->doEditContent($new_content, $edit_summary, $flags); } else { $article->doEdit($new_text, $edit_summary, $flags); } $wgUser = $actual_user; } wfProfileOut(__METHOD__ . '-replace'); } wfProfileOut(__METHOD__); return true; }
/** * Handle action=rollback * @deprecated since 1.19 */ public function rollback() { wfDeprecated(__METHOD__, '1.19'); Action::factory('rollback', $this)->show(); }
/** * Perform one of the "standard" actions * * @param $page Page */ private function performAction(Page $page) { wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $page); if ($action instanceof Action) { $action->show(); wfProfileOut(__METHOD__); return; } if (wfRunHooks('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } wfProfileOut(__METHOD__); }
/** * initialize various variables and generate the template * * @since 1.23 * @return QuickTemplate The template to be executed by outputPage */ protected function prepareQuickTemplate() { global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType, $wgSitename, $wgLogo, $wgMaxCredits, $wgShowCreditsIfMax, $wgArticlePath, $wgScriptPath, $wgServer; $title = $this->getTitle(); $request = $this->getRequest(); $out = $this->getOutput(); $tpl = $this->setupTemplateForOutput(); $tpl->set('title', $out->getPageTitle()); $tpl->set('pagetitle', $out->getHTMLTitle()); $tpl->set('displaytitle', $out->mPageLinkTitle); $tpl->setRef('thispage', $this->thispage); $tpl->setRef('titleprefixeddbkey', $this->thispage); $tpl->set('titletext', $title->getText()); $tpl->set('articleid', $title->getArticleID()); $tpl->set('isarticle', $out->isArticle()); $subpagestr = $this->subPageSubtitle(); if ($subpagestr !== '') { $subpagestr = '<span class="subpages">' . $subpagestr . '</span>'; } $tpl->set('subtitle', $subpagestr . $out->getSubtitle()); $undelete = $this->getUndeleteLink(); if ($undelete === '') { $tpl->set('undelete', ''); } else { $tpl->set('undelete', '<span class="subpages">' . $undelete . '</span>'); } $tpl->set('catlinks', $this->getCategories()); if ($out->isSyndicated()) { $feeds = array(); foreach ($out->getSyndicationLinks() as $format => $link) { $feeds[$format] = array('text' => $this->msg("feed-{$format}")->text(), 'href' => $link); } $tpl->setRef('feeds', $feeds); } else { $tpl->set('feeds', false); } $tpl->setRef('mimetype', $wgMimeType); $tpl->setRef('jsmimetype', $wgJsMimeType); $tpl->set('charset', 'UTF-8'); $tpl->setRef('wgScript', $wgScript); $tpl->setRef('skinname', $this->skinname); $tpl->set('skinclass', get_class($this)); $tpl->setRef('skin', $this); $tpl->setRef('stylename', $this->stylename); $tpl->set('printable', $out->isPrintable()); $tpl->set('handheld', $request->getBool('handheld')); $tpl->setRef('loggedin', $this->loggedin); $tpl->set('notspecialpage', !$title->isSpecialPage()); $tpl->set('searchaction', $this->escapeSearchLink()); $tpl->set('searchtitle', SpecialPage::getTitleFor('Search')->getPrefixedDBkey()); $tpl->set('search', trim($request->getVal('search'))); $tpl->setRef('stylepath', $wgStylePath); $tpl->setRef('articlepath', $wgArticlePath); $tpl->setRef('scriptpath', $wgScriptPath); $tpl->setRef('serverurl', $wgServer); $tpl->setRef('logopath', $wgLogo); $tpl->setRef('sitename', $wgSitename); $userLang = $this->getLanguage(); $userLangCode = $userLang->getHtmlCode(); $userLangDir = $userLang->getDir(); $tpl->set('lang', $userLangCode); $tpl->set('dir', $userLangDir); $tpl->set('rtl', $userLang->isRTL()); $tpl->set('capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : ''); $tpl->set('showjumplinks', true); // showjumplinks preference has been removed $tpl->set('username', $this->loggedin ? $this->username : null); $tpl->setRef('userpage', $this->userpage); $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']); $tpl->set('userlang', $userLangCode); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser // that interface elements are in a different language. $tpl->set('userlangattributes', ''); $tpl->set('specialpageattributes', ''); # obsolete // Used by VectorBeta to insert HTML before content but after the // heading for the page title. Defaults to empty string. $tpl->set('prebodyhtml', ''); if ($userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir()) { $escUserlang = htmlspecialchars($userLangCode); $escUserdir = htmlspecialchars($userLangDir); // Attributes must be in double quotes because htmlspecialchars() doesn't // escape single quotes $attrs = " lang=\"{$escUserlang}\" dir=\"{$escUserdir}\""; $tpl->set('userlangattributes', $attrs); } $tpl->set('newtalk', $this->getNewtalks()); $tpl->set('logo', $this->logoText()); $tpl->set('copyright', false); // No longer used $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); if ($out->isArticle() && $title->exists()) { if ($this->isRevisionCurrent()) { if ($wgMaxCredits != 0) { $tpl->set('credits', Action::factory('credits', $this->getWikiPage(), $this->getContext())->getCredits($wgMaxCredits, $wgShowCreditsIfMax)); } else { $tpl->set('lastmod', $this->lastModified()); } } $tpl->set('copyright', $this->getCopyright()); } $tpl->set('copyrightico', $this->getCopyrightIcon()); $tpl->set('poweredbyico', $this->getPoweredBy()); $tpl->set('disclaimer', $this->disclaimerLink()); $tpl->set('privacy', $this->privacyLink()); $tpl->set('about', $this->aboutLink()); $tpl->set('footerlinks', array('info' => array('lastmod', 'numberofwatchingusers', 'credits', 'copyright'), 'places' => array('privacy', 'about', 'disclaimer'))); global $wgFooterIcons; $tpl->set('footericons', $wgFooterIcons); foreach ($tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock) { if (count($footerIconsBlock) > 0) { foreach ($footerIconsBlock as &$footerIcon) { if (isset($footerIcon['src'])) { if (!isset($footerIcon['width'])) { $footerIcon['width'] = 88; } if (!isset($footerIcon['height'])) { $footerIcon['height'] = 31; } } } } else { unset($tpl->data['footericons'][$footerIconsKey]); } } $tpl->set('indicators', $out->getIndicators()); $tpl->set('sitenotice', $this->getSiteNotice()); $tpl->set('bottomscripts', $this->bottomScripts()); $tpl->set('printfooter', $this->printSource()); # An ID that includes the actual body text; without categories, contentSub, ... $realBodyAttribs = array('id' => 'mw-content-text'); # Add a mw-content-ltr/rtl class to be able to style based on text direction # when the content is different from the UI language, i.e.: # not for special pages or file pages AND only when viewing AND if the page exists # (or is in MW namespace, because that has default content) if (!in_array($title->getNamespace(), array(NS_SPECIAL, NS_FILE)) && Action::getActionName($this) === 'view' && ($title->exists() || $title->getNamespace() == NS_MEDIAWIKI)) { $pageLang = $title->getPageViewLanguage(); $realBodyAttribs['lang'] = $pageLang->getHtmlCode(); $realBodyAttribs['dir'] = $pageLang->getDir(); $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir(); } $out->mBodytext = Html::rawElement('div', $realBodyAttribs, $out->mBodytext); $tpl->setRef('bodytext', $out->mBodytext); $language_urls = $this->getLanguages(); if (count($language_urls)) { $tpl->setRef('language_urls', $language_urls); } else { $tpl->set('language_urls', false); } # Personal toolbar $tpl->set('personal_urls', $this->buildPersonalUrls()); $content_navigation = $this->buildContentNavigationUrls(); $content_actions = $this->buildContentActionUrls($content_navigation); $tpl->setRef('content_navigation', $content_navigation); $tpl->setRef('content_actions', $content_actions); $tpl->set('sidebar', $this->buildSidebar()); $tpl->set('nav_urls', $this->buildNavUrls()); // Set the head scripts near the end, in case the above actions resulted in added scripts $tpl->set('headelement', $out->headElement($this)); $tpl->set('debug', ''); $tpl->set('debughtml', $this->generateDebugHTML()); $tpl->set('reporttime', wfReportTime()); // original version by hansm if (!Hooks::run('SkinTemplateOutputPageBeforeExec', array(&$this, &$tpl))) { wfDebug(__METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n"); } // Set the bodytext to another key so that skins can just output it on its own // and output printfooter and debughtml separately $tpl->set('bodycontent', $tpl->data['bodytext']); // Append printfooter and debughtml onto bodytext so that skins that // were already using bodytext before they were split out don't suddenly // start not outputting information. $tpl->data['bodytext'] .= Html::rawElement('div', array('class' => 'printfooter'), "\n{$tpl->data['printfooter']}") . "\n"; $tpl->data['bodytext'] .= $tpl->data['debughtml']; // allow extensions adding stuff after the page content. // See Skin::afterContentHook() for further documentation. $tpl->set('dataAfterContent', $this->afterContentHook()); return $tpl; }
/** * Perform one of the "standard" actions * * @param $article Article */ private function performAction(Page $article) { global $wgSquidMaxage, $wgUseExternalEditor; wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $article, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $article); if ($action instanceof Action) { $action->show(); wfProfileOut(__METHOD__); return; } switch ($act) { case 'view': $output->setSquidMaxage($wgSquidMaxage); $article->view(); break; case 'raw': // includes JS/CSS wfProfileIn(__METHOD__ . '-raw'); $raw = new RawPage($article); $raw->view(); wfProfileOut(__METHOD__ . '-raw'); break; case 'delete': case 'protect': case 'unprotect': case 'render': $article->{$act}(); break; case 'submit': if (session_id() == '') { // Send a cookie so anons get talk message notifications wfSetupSession(); } // Continue... // Continue... case 'edit': if (wfRunHooks('CustomEditor', array($article, $user))) { $internal = $request->getVal('internaledit'); $external = $request->getVal('externaledit'); $section = $request->getVal('section'); $oldid = $request->getVal('oldid'); if (!$wgUseExternalEditor || $act == 'submit' || $internal || $section || $oldid || !$user->getOption('externaleditor') && !$external) { $editor = new EditPage($article); $editor->submit(); } elseif ($wgUseExternalEditor && ($external || $user->getOption('externaleditor'))) { $mode = $request->getVal('mode'); $extedit = new ExternalEdit($article->getTitle(), $mode); $extedit->edit(); } } break; case 'history': if ($request->getFullRequestURL() == $title->getInternalURL('action=history')) { $output->setSquidMaxage($wgSquidMaxage); } $history = new HistoryPage($article); $history->history(); break; default: if (wfRunHooks('UnknownAction', array($act, $article))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } } wfProfileOut(__METHOD__); }
function execute($par) { global $wgUser, $wgOut, $wgRequest, $wgTitle; if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } if (!($wgUser->isSysop() || in_array('newarticlepatrol', $wgUser->getRights()))) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } wfLoadExtensionMessages("NFDGuardian"); if ($wgRequest->getVal('fetchInnards')) { //get next article to vote on $wgOut->disable(); $result = self::getNextInnards($wgRequest->getVal('nfd_type')); print_r(json_encode($result)); return; } else { if ($wgRequest->getVal('getVoteBlock')) { //get all the votes for the right rail module $wgOut->setArticleBodyOnly(true); $wgOut->addHTML(self::getVoteBlock($wgRequest->getVal('nfd_id'))); return; } else { if ($wgRequest->getVal('edit')) { //get the html that goes into the page when a user clicks the edit tab $wgOut->setArticleBodyOnly(true); $t = Title::newFromID($wgRequest->getVal('articleId')); if ($t) { $a = new Article($t); $editor = new EditPage($a); $editor->edit(); //Old code for when we wanted to remove //the nfd template from the edit window /*$content = $wgOut->getHTML(); $wgOut->clearHTML(); //grab the edit form $data = array(); $data['form'] = $content; //then take out the template $c = new NFDProcessor(); $template = $c->getFullTemplate($wgRequest->getVal('nfd_id')); $articleContent = $a->getContent(); $articleContent = str_replace($template, "", $articleContent); $data['newContent'] = $articleContent; print_r(json_encode($data));*/ } return; } else { if ($wgRequest->getVal('discussion')) { //get the html that goes into the page when a user clicks the discussion tab $wgOut->setArticleBodyOnly(true); $t = Title::newFromID($wgRequest->getVal('articleId')); if ($t) { $tDiscussion = $t->getTalkPage(); if ($tDiscussion) { $a = new Article($tDiscussion); $content = $a->getContent(); $wgOldTitle = $wgTitle; $wgTitle = $tDiscussion; $wgOut->addHTML($wgOut->parse($content)); $wgOut->addHTML(PostComment::getForm(true, $tDiscussion, true)); $wgTitle = $wgOldTitle; } } return; } else { if ($wgRequest->getVal('confirmation')) { //get confirmation dialog after user has edited the article $wgOut->setArticleBodyOnly(true); echo $this->confirmationModal($wgRequest->getVal('articleId')); return; } else { if ($wgRequest->getVal('history')) { //get the html that goes into the page when a user clicks the history tab $wgOut->setArticleBodyOnly(true); $t = Title::newFromID($wgRequest->getVal('articleId')); if ($t) { $historyContext = clone $this->getContext(); $historyContext->setTitle($t); $historyContext->setWikiPage(WikiPage::factory($t)); $pageHistory = Action::factory("history", WikiPage::factory($t), $historyContext); $pageHistory->onView(); return; } } else { if ($wgRequest->getVal('diff')) { //get the html that goes into the page when a user asks for a diffs $wgOut->setArticleBodyOnly(true); $t = Title::newFromID($wgRequest->getVal('articleId')); if ($t) { $a = new Article($t); $wgOut->addHtml('<div class="article_inner">'); $a->view(); $wgOut->addHtml('</div>'); } return; } else { if ($wgRequest->getVal('article')) { //get the html that goes into the page when a user clicks the article tab $wgOut->setArticleBodyOnly(true); $t = Title::newFromId($wgRequest->getVal('articleId')); if ($t) { $r = Revision::newFromTitle($t); if ($r) { $popts = $wgOut->parserOptions(); $popts->setTidy(true); echo WikihowArticleHTML::processArticleHTML($wgOut->parse($r->getText(), $t, $popts), array('no-ads' => true, 'ns' => $t->getNamespace())); } } return; } else { if ($wgRequest->wasPosted()) { $wgOut->setArticleBodyOnly(true); if ($wgRequest->getVal('submitEditForm')) { //user has edited the article from within the NFD Guardian tool $wgOut->disable(); $this->submitEdit(); $result = self::getNextInnards($wgRequest->getVal('nfd_type')); print_r(json_encode($result)); return; } else { //user has voted if ($wgRequest->getVal('nfd_skip', 0) == 1) { NFDProcessor::skip($wgRequest->getVal('nfd_id')); } else { NFDProcessor::vote($wgRequest->getVal('nfd_id'), $wgRequest->getVal('nfd_vote')); } $wgOut->disable(); $result = self::getNextInnards($wgRequest->getVal('nfd_type')); print_r(json_encode($result)); return; } } } } } } } } } } /** * This is the shell of the page, has the buttons, etc. */ $wgOut->addJScode('nfdgj'); $wgOut->addJScode('csjs'); $wgOut->addCSScode('nfdgc'); $wgOut->addCSScode('diffc'); //add delete confirmation to bottom of page $wgOut->addHtml("<div class='waiting'><img src='" . wfGetPad('/extensions/wikihow/rotate.gif') . "' alt='' /></div>"); $tmpl = new EasyTemplate(dirname(__FILE__)); $wgOut->addHTML($tmpl->execute('NFDdelete.tmpl.php')); $wgOut->setHTMLTitle(wfMsg('nfd')); $wgOut->setPageTitle(wfMsg('nfd')); // add standings widget $group = new NFDStandingsGroup(); $indi = new NFDStandingsIndividual(); $indi->addStatsWidget(); $group->addStandingsWidget(); }
function pageStats() { global $wgOut, $wgLang, $wgRequest, $wgUser; global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers; if (!is_null($wgRequest->getVal('oldid')) || !is_null($wgRequest->getVal('diff'))) { return ''; } if (!$wgOut->isArticle() || !$this->getSkin()->getTitle()->exists()) { return ''; } $article = new Article($this->getSkin()->getTitle(), 0); $s = ''; if (!$wgDisableCounters) { $count = $wgLang->formatNum($article->getCount()); if ($count) { $s = wfMsgExt('viewcount', array('parseinline'), $count); } } if ($wgMaxCredits != 0) { $s .= ' ' . Action::factory('credits', $article)->getCredits($wgMaxCredits, $wgShowCreditsIfMax); } else { $s .= $this->data['lastmod']; } if ($wgPageShowWatchingUsers && $wgUser->getOption('shownumberswatching')) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('watchlist', array('COUNT(*) AS n'), array('wl_title' => $dbr->strencode($this->getSkin()->getTitle()->getDBkey()), 'wl_namespace' => $this->getSkin()->getTitle()->getNamespace()), __METHOD__); $x = $dbr->fetchObject($res); $s .= ' ' . wfMsgExt('number_of_watching_users_pageview', array('parseinline'), $wgLang->formatNum($x->n)); } return $s . ' ' . $this->getSkin()->getCopyright(); }
public function execute() { global $wgRequestTime; if (!$this->enabled) { $this->error("Nothing to do -- \$wgUseFileCache is disabled.", true); } $start = $this->getOption('start', "0"); if (!ctype_digit($start)) { $this->error("Invalid value for start parameter.", true); } $start = intval($start); $end = $this->getOption('end', "0"); if (!ctype_digit($end)) { $this->error("Invalid value for end parameter.", true); } $end = intval($end); $this->output("Building content page file cache from page {$start}!\n"); $dbr = $this->getDB(DB_REPLICA); $overwrite = $this->getOption('overwrite', false); $start = $start > 0 ? $start : $dbr->selectField('page', 'MIN(page_id)', false, __METHOD__); $end = $end > 0 ? $end : $dbr->selectField('page', 'MAX(page_id)', false, __METHOD__); if (!$start) { $this->error("Nothing to do.", true); } $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client # Do remaining chunk $end += $this->mBatchSize - 1; $blockStart = $start; $blockEnd = $start + $this->mBatchSize - 1; $dbw = $this->getDB(DB_MASTER); // Go through each page and save the output while ($blockEnd <= $end) { // Get the pages $res = $dbr->select('page', ['page_namespace', 'page_title', 'page_id'], ['page_namespace' => MWNamespace::getContentNamespaces(), "page_id BETWEEN {$blockStart} AND {$blockEnd}"], __METHOD__, ['ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY']); $this->beginTransaction($dbw, __METHOD__); // for any changes foreach ($res as $row) { $rebuilt = false; $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); if (null == $title) { $this->output("Page {$row->page_id} has bad title\n"); continue; // broken title? } $context = new RequestContext(); $context->setTitle($title); $article = Article::newFromTitle($title, $context); $context->setWikiPage($article->getPage()); // If the article is cacheable, then load it if ($article->isFileCacheable(HTMLFileCache::MODE_REBUILD)) { $viewCache = new HTMLFileCache($title, 'view'); $historyCache = new HTMLFileCache($title, 'history'); if ($viewCache->isCacheGood() && $historyCache->isCacheGood()) { if ($overwrite) { $rebuilt = true; } else { $this->output("Page '{$title}' (id {$row->page_id}) already cached\n"); continue; // done already! } } MediaWiki\suppressWarnings(); // header notices // Cache ?action=view $wgRequestTime = microtime(true); # bug 22852 ob_start(); $article->view(); $context->getOutput()->output(); $context->getOutput()->clearHTML(); $viewHtml = ob_get_clean(); $viewCache->saveToFileCache($viewHtml); // Cache ?action=history $wgRequestTime = microtime(true); # bug 22852 ob_start(); Action::factory('history', $article, $context)->show(); $context->getOutput()->output(); $context->getOutput()->clearHTML(); $historyHtml = ob_get_clean(); $historyCache->saveToFileCache($historyHtml); MediaWiki\restoreWarnings(); if ($rebuilt) { $this->output("Re-cached page '{$title}' (id {$row->page_id})..."); } else { $this->output("Cached page '{$title}' (id {$row->page_id})..."); } $this->output("[view: " . strlen($viewHtml) . " bytes; " . "history: " . strlen($historyHtml) . " bytes]\n"); } else { $this->output("Page '{$title}' (id {$row->page_id}) not cacheable\n"); } } $this->commitTransaction($dbw, __METHOD__); // commit any changes (just for sanity) $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; } $this->output("Done!\n"); }
public function setAttributes($attributes) { foreach ($this->methodActions as $method => &$actions) { foreach ($actions as &$action) { $action = Action::factory($action, $attributes); } } return $this; }
/** * Get the action that will be executed, not necessarily the one passed * passed through the "action" request parameter. Actions disabled in * $wgActions will be replaced by "nosuchaction". * * @since 1.19 * @param $context IContextSource * @return string: action name */ final public static function getActionName( IContextSource $context ) { global $wgActions; $request = $context->getRequest(); $actionName = $request->getVal( 'action', 'view' ); // Check for disabled actions if ( isset( $wgActions[$actionName] ) && $wgActions[$actionName] === false ) { $actionName = 'nosuchaction'; } // Workaround for bug #20966: inability of IE to provide an action dependent // on which submit button is clicked. if ( $actionName === 'historysubmit' ) { if ( $request->getBool( 'revisiondelete' ) ) { $actionName = 'revisiondelete'; } else { $actionName = 'view'; } } elseif ( $actionName == 'editredlink' ) { $actionName = 'edit'; } // Trying to get a WikiPage for NS_SPECIAL etc. will result // in WikiPage::factory throwing "Invalid or virtual namespace -1 given." // For SpecialPages et al, default to action=view. if ( !$context->canUseWikiPage() ) { return 'view'; } $action = Action::factory( $actionName, $context->getWikiPage(), $context ); if ( $action instanceof Action ) { return $action->getName(); } return 'nosuchaction'; }
/** * Run a replaceText job * @return boolean success */ function run() { wfProfileIn( __METHOD__ ); if ( is_null( $this->title ) ) { $this->error = "replaceText: Invalid title"; wfProfileOut( __METHOD__ ); return false; } if ( array_key_exists( 'move_page', $this->params ) ) { global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId( $this->params['user_id'] ); $cur_page_name = $this->title->getText(); if ( $this->params['use_regex'] ) { $new_page_name = preg_replace( "/".$this->params['target_str']."/U", $this->params['replacement_str'], $cur_page_name ); } else { $new_page_name = str_replace( $this->params['target_str'], $this->params['replacement_str'], $cur_page_name ); } $new_title = Title::newFromText( $new_page_name, $this->title->getNamespace() ); $reason = $this->params['edit_summary']; $create_redirect = $this->params['create_redirect']; $this->title->moveTo( $new_title, true, $reason, $create_redirect ); if ( $this->params['watch_page'] ) { if ( class_exists( 'WatchAction' ) ) { // Class was added in MW 1.19 WatchAction::doWatch( $new_title, $wgUser ); } elseif ( class_exists( 'Action' ) ) { // Class was added in MW 1.18 Action::factory( 'watch', new Article( $new_title, 0 ) )->execute(); } else { $article = new Article( $new_title, 0 ); $article->doWatch(); } } $wgUser = $actual_user; } else { $article = new Article( $this->title, 0 ); if ( !$article ) { $this->error = 'replaceText: Article not found "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut( __METHOD__ ); return false; } wfProfileIn( __METHOD__ . '-replace' ); $article_text = $article->fetchContent(); $target_str = $this->params['target_str']; $replacement_str = $this->params['replacement_str']; $num_matches; if ( $this->params['use_regex'] ) { $new_text = preg_replace( '/'.$target_str.'/U', $replacement_str, $article_text, -1, $num_matches ); } else { $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches ); } // if there's at least one replacement, modify the page, // using the passed-in edit summary if ( $num_matches > 0 ) { // change global $wgUser variable to the one // specified by the job only for the extent of // this replacement global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId( $this->params['user_id'] ); $edit_summary = $this->params['edit_summary']; $flags = EDIT_MINOR; if ( $wgUser->isAllowed( 'bot' ) ) $flags |= EDIT_FORCE_BOT; $article->doEdit( $new_text, $edit_summary, $flags ); $wgUser = $actual_user; } wfProfileOut( __METHOD__ . '-replace' ); } wfProfileOut( __METHOD__ ); return true; }
/** * User interface handler for the "unwatch" action. * Requires Request to pass a token as of 1.18. * @deprecated since 1.18 */ public function unwatch() { wfDeprecated(__METHOD__, '1.18'); Action::factory('unwatch', $this)->show(); }
/** * initialize various variables and generate the template * * @param $out OutputPage */ function outputPage(OutputPage $out) { global $wgUser, $wgLang, $wgContLang; global $wgScript, $wgStylePath; global $wgMimeType, $wgJsMimeType, $wgRequest; global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version; global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments; global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn(__METHOD__); Profiler::instance()->setTemplated(true); $oldid = $wgRequest->getVal('oldid'); $diff = $wgRequest->getVal('diff'); $action = $wgRequest->getVal('action', 'view'); wfProfileIn(__METHOD__ . '-init'); $this->initPage($out); $tpl = $this->setupTemplate($this->template, 'skins'); wfProfileOut(__METHOD__ . '-init'); wfProfileIn(__METHOD__ . '-stuff'); $this->thispage = $this->getTitle()->getPrefixedDBkey(); $this->userpage = $wgUser->getUserPage()->getPrefixedText(); $query = array(); if (!$wgRequest->wasPosted()) { $query = $wgRequest->getValues(); unset($query['title']); unset($query['returnto']); unset($query['returntoquery']); } $this->thisquery = wfArrayToCGI($query); $this->loggedin = $wgUser->isLoggedIn(); $this->iscontent = $this->getTitle()->getNamespace() != NS_SPECIAL; $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit')); $this->username = $wgUser->getName(); if ($wgUser->isLoggedIn() || $this->showIPinHeader()) { $this->userpageUrlDetails = self::makeUrlDetails($this->userpage); } else { # This won't be used in the standard skins, but we define it to preserve the interface # To save time, we check for existence $this->userpageUrlDetails = self::makeKnownUrlDetails($this->userpage); } $this->titletxt = $this->getTitle()->getPrefixedText(); wfProfileOut(__METHOD__ . '-stuff'); wfProfileIn(__METHOD__ . '-stuff-head'); if ($this->useHeadElement) { $pagecss = $this->setupPageCss(); if ($pagecss) { $out->addInlineStyle($pagecss); } } else { $this->setupUserCss($out); $tpl->set('pagecss', $this->setupPageCss()); $tpl->set('usercss', false); $this->userjs = $this->userjsprev = false; # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we # get rid of it? For that matter, why is any of this here at all? $this->setupUserJs($out->isUserJsAllowed()); $tpl->setRef('userjs', $this->userjs); $tpl->setRef('userjsprev', $this->userjsprev); if ($wgUseSiteJs) { $jsCache = $this->loggedin ? '&smaxage=0' : ''; $tpl->set('jsvarurl', self::makeUrl('-', "action=raw{$jsCache}&gen=js&useskin=" . urlencode($this->getSkinName()))); } else { $tpl->set('jsvarurl', false); } $tpl->setRef('xhtmldefaultnamespace', $wgXhtmlDefaultNamespace); $tpl->set('xhtmlnamespaces', $wgXhtmlNamespaces); $tpl->set('html5version', $wgHtml5Version); $tpl->set('headlinks', $out->getHeadLinks($this)); $tpl->set('csslinks', $out->buildCssLinks($this)); if ($wgUseTrackbacks && $out->isArticleRelated()) { $tpl->set('trackbackhtml', $out->getTitle()->trackbackRDF()); } else { $tpl->set('trackbackhtml', null); } } wfProfileOut(__METHOD__ . '-stuff-head'); wfProfileIn(__METHOD__ . '-stuff2'); $tpl->set('title', $out->getPageTitle()); $tpl->set('pagetitle', $out->getHTMLTitle()); $tpl->set('displaytitle', $out->mPageLinkTitle); $tpl->set('pageclass', $this->getPageClasses($this->getTitle())); $tpl->set('skinnameclass', 'skin-' . Sanitizer::escapeClass($this->getSkinName())); $nsname = MWNamespace::exists($this->getTitle()->getNamespace()) ? MWNamespace::getCanonicalName($this->getTitle()->getNamespace()) : $this->getTitle()->getNsText(); $tpl->set('nscanonical', $nsname); $tpl->set('nsnumber', $this->getTitle()->getNamespace()); $tpl->set('titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey()); $tpl->set('titletext', $this->getTitle()->getText()); $tpl->set('articleid', $this->getTitle()->getArticleId()); $tpl->set('currevisionid', $this->getTitle()->getLatestRevID()); $tpl->set('isarticle', $out->isArticle()); $tpl->setRef('thispage', $this->thispage); $subpagestr = $this->subPageSubtitle(); $tpl->set('subtitle', !empty($subpagestr) ? '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() : $out->getSubtitle()); $undelete = $this->getUndeleteLink(); $tpl->set('undelete', !empty($undelete) ? '<span class="subpages">' . $undelete . '</span>' : ''); $tpl->set('catlinks', $this->getCategories()); if ($out->isSyndicated()) { $feeds = array(); foreach ($out->getSyndicationLinks() as $format => $link) { $feeds[$format] = array('text' => wfMsg("feed-{$format}"), 'href' => $link); } $tpl->setRef('feeds', $feeds); } else { $tpl->set('feeds', false); } $tpl->setRef('mimetype', $wgMimeType); $tpl->setRef('jsmimetype', $wgJsMimeType); $tpl->set('charset', 'UTF-8'); $tpl->setRef('wgScript', $wgScript); $tpl->setRef('skinname', $this->skinname); $tpl->set('skinclass', get_class($this)); $tpl->setRef('stylename', $this->stylename); $tpl->set('printable', $out->isPrintable()); $tpl->set('handheld', $wgRequest->getBool('handheld')); $tpl->setRef('loggedin', $this->loggedin); $tpl->set('notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL); /* XXX currently unused, might get useful later $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) ); $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 ); $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' ); $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' ); $tpl->set( 'helppage', wfMsg( 'helppage' ) ); */ $tpl->set('searchaction', $this->escapeSearchLink()); $tpl->set('searchtitle', SpecialPage::getTitleFor('Search')->getPrefixedDBKey()); $tpl->set('search', trim($wgRequest->getVal('search'))); $tpl->setRef('stylepath', $wgStylePath); $tpl->setRef('articlepath', $wgArticlePath); $tpl->setRef('scriptpath', $wgScriptPath); $tpl->setRef('serverurl', $wgServer); $tpl->setRef('logopath', $wgLogo); $contentlang = $wgContLang->getCode(); $contentdir = $wgContLang->getDir(); $userlang = $wgLang->getCode(); $userdir = $wgLang->getDir(); $tpl->set('lang', $userlang); $tpl->set('dir', $userdir); $tpl->set('rtl', $wgLang->isRTL()); $tpl->set('capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : ''); $tpl->set('showjumplinks', $wgUser->getOption('showjumplinks')); $tpl->set('username', $wgUser->isAnon() ? null : $this->username); $tpl->setRef('userpage', $this->userpage); $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']); $tpl->set('userlang', $userlang); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser // that interface elements are in a different language. $tpl->set('userlangattributes', ''); $tpl->set('specialpageattributes', ''); # obsolete if ($userlang !== $contentlang || $userdir !== $contentdir) { $attrs = " lang='{$userlang}' dir='{$userdir}'"; $tpl->set('userlangattributes', $attrs); } $newtalks = $this->getNewtalks($out); wfProfileOut(__METHOD__ . '-stuff2'); wfProfileIn(__METHOD__ . '-stuff3'); $tpl->setRef('newtalk', $newtalks); $tpl->setRef('skin', $this); $tpl->set('logo', $this->logoText()); if ($out->isArticle() && (!isset($oldid) || isset($diff)) && $this->getTitle()->exists()) { $article = new Article($this->getTitle(), 0); if (!$wgDisableCounters) { $viewcount = $wgLang->formatNum($article->getCount()); if ($viewcount) { $tpl->set('viewcount', wfMsgExt('viewcount', array('parseinline'), $viewcount)); } else { $tpl->set('viewcount', false); } } else { $tpl->set('viewcount', false); } if ($wgPageShowWatchingUsers) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('watchlist', array('COUNT(*) AS n'), array('wl_title' => $dbr->strencode($this->getTitle()->getDBkey()), 'wl_namespace' => $this->getTitle()->getNamespace()), __METHOD__); $x = $dbr->fetchObject($res); $numberofwatchingusers = $x->n; if ($numberofwatchingusers > 0) { $tpl->set('numberofwatchingusers', wfMsgExt('number_of_watching_users_pageview', array('parseinline'), $wgLang->formatNum($numberofwatchingusers))); } else { $tpl->set('numberofwatchingusers', false); } } else { $tpl->set('numberofwatchingusers', false); } $tpl->set('copyright', $this->getCopyright()); $this->credits = false; if ($wgMaxCredits != 0) { $this->credits = Action::factory('credits', $article)->getCredits($wgMaxCredits, $wgShowCreditsIfMax); } else { $tpl->set('lastmod', $this->lastModified($article)); } $tpl->setRef('credits', $this->credits); } elseif (isset($oldid) && !isset($diff)) { $tpl->set('copyright', $this->getCopyright()); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } else { $tpl->set('copyright', false); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } wfProfileOut(__METHOD__ . '-stuff3'); wfProfileIn(__METHOD__ . '-stuff4'); $tpl->set('copyrightico', $this->getCopyrightIcon()); $tpl->set('poweredbyico', $this->getPoweredBy()); $tpl->set('disclaimer', $this->disclaimerLink()); $tpl->set('privacy', $this->privacyLink()); $tpl->set('about', $this->aboutLink()); $tpl->set('footerlinks', array('info' => array('lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright'), 'places' => array('privacy', 'about', 'disclaimer'))); global $wgFooterIcons; $tpl->set('footericons', $wgFooterIcons); foreach ($tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock) { if (count($footerIconsBlock) > 0) { foreach ($footerIconsBlock as &$footerIcon) { if (isset($footerIcon['src'])) { if (!isset($footerIcon['width'])) { $footerIcon['width'] = 88; } if (!isset($footerIcon['height'])) { $footerIcon['height'] = 31; } } } } else { unset($tpl->data['footericons'][$footerIconsKey]); } } if ($wgDebugComments) { $tpl->setRef('debug', $out->mDebugtext); } else { $tpl->set('debug', ''); } $tpl->set('reporttime', wfReportTime()); $tpl->set('sitenotice', $this->getSiteNotice()); $tpl->set('bottomscripts', $this->bottomScripts($out)); $tpl->set('printfooter', $this->printSource()); # Add a <div class="mw-content-ltr/rtl"> around the body text # not for special pages or file pages AND only when viewing AND if the page exists # (or is in MW namespace, because that has default content) if (!in_array($this->getTitle()->getNamespace(), array(NS_SPECIAL, NS_FILE)) && in_array($action, array('view', 'historysubmit')) && ($this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI)) { $pageLang = $this->getTitle()->getPageLanguage(); $realBodyAttribs = array('lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir()); $out->mBodytext = Html::rawElement('div', $realBodyAttribs, $out->mBodytext); } $tpl->setRef('bodytext', $out->mBodytext); # Language links $language_urls = array(); if (!$wgHideInterlanguageLinks) { foreach ($out->getLanguageLinks() as $l) { $tmp = explode(':', $l, 2); $class = 'interwiki-' . $tmp[0]; unset($tmp); $nt = Title::newFromText($l); if ($nt) { $language_urls[] = array('href' => $nt->getFullURL(), 'text' => $wgContLang->getLanguageName($nt->getInterwiki()) != '' ? $wgContLang->getLanguageName($nt->getInterwiki()) : $l, 'title' => $nt->getText(), 'class' => $class, 'lang' => $nt->getInterwiki(), 'hreflang' => $nt->getInterwiki()); } } } if (count($language_urls)) { $tpl->setRef('language_urls', $language_urls); } else { $tpl->set('language_urls', false); } wfProfileOut(__METHOD__ . '-stuff4'); wfProfileIn(__METHOD__ . '-stuff5'); # Personal toolbar $tpl->set('personal_urls', $this->buildPersonalUrls($out)); $content_navigation = $this->buildContentNavigationUrls($out); $content_actions = $this->buildContentActionUrls($content_navigation); $tpl->setRef('content_navigation', $content_navigation); $tpl->setRef('content_actions', $content_actions); $tpl->set('sidebar', $this->buildSidebar()); $tpl->set('nav_urls', $this->buildNavUrls($out)); // Set the head scripts near the end, in case the above actions resulted in added scripts if ($this->useHeadElement) { $tpl->set('headelement', $out->headElement($this)); } else { $tpl->set('headscripts', $out->getScript()); } $tpl->set('debughtml', $this->generateDebugHTML()); // original version by hansm if (!wfRunHooks('SkinTemplateOutputPageBeforeExec', array(&$this, &$tpl))) { wfDebug(__METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n"); } // Set the bodytext to another key so that skins can just output it on it's own // and output printfooter and debughtml separately $tpl->set('bodycontent', $tpl->data['bodytext']); // Append printfooter and debughtml onto bodytext so that skins that were already // using bodytext before they were split out don't suddenly start not outputting information $tpl->data['bodytext'] .= Html::rawElement('div', array('class' => 'printfooter'), "\n{$tpl->data['printfooter']}") . "\n"; $tpl->data['bodytext'] .= $tpl->data['debughtml']; // allow extensions adding stuff after the page content. // See Skin::afterContentHook() for further documentation. $tpl->set('dataAfterContent', $this->afterContentHook()); wfProfileOut(__METHOD__ . '-stuff5'); // execute template wfProfileIn(__METHOD__ . '-execute'); $res = $tpl->execute(); wfProfileOut(__METHOD__ . '-execute'); // result may be an error $this->printOrError($res); wfProfileOut(__METHOD__); }
/** * Perform one of the "standard" actions * * @param $page Page * @param $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { global $wgUseSquid, $wgSquidMaxage; wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $page); if ($action instanceof Action) { # Let Squid cache things if we can purge them. if ($wgUseSquid && in_array($request->getFullRequestURL(), $requestTitle->getSquidURLs())) { $output->setSquidMaxage($wgSquidMaxage); } $action->show(); wfProfileOut(__METHOD__); return; } if (wfRunHooks('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } wfProfileOut(__METHOD__); }
/** * User interface for rollback operations */ public function rollback() { Action::factory('rollback', $this)->show(); }