/** * Initialize the object to be known as $wgArticle for "standard" actions * Create an Article object for the page, following redirects if needed. * @param Title $title * @param Request $request * @param string $action * @return mixed an Article, or a string to redirect to another URL */ function initializeArticle($title, $request) { global $wgTitle; wfProfileIn('MediaWiki::initializeArticle'); $action = $this->getVal('Action'); $article = $this->articleFromTitle($title); // Namespace might change when using redirects if (($action == 'view' || $action == 'render') && !$request->getVal('oldid') && $request->getVal('redirect') != 'no' && !($wgTitle->getNamespace() == NS_IMAGE && wfFindFile($wgTitle->getText()))) { $dbr = wfGetDB(DB_SLAVE); $article->loadPageData($article->pageDataFromTitle($dbr, $title)); /* Follow redirects only for... redirects */ if ($article->mIsRedirect) { $target = $article->followRedirect(); if (is_string($target)) { global $wgDisableHardRedirects; if (!$wgDisableHardRedirects) { // we'll need to redirect return $target; } } if (is_object($target)) { /* Rewrite environment to redirected article */ //XXCHANGED USE 301 redirects for redirected articles global $wgOut, $wgRequest; // XXCHANGED - pass platform param through the redirect $platform = @$wgRequest ? @$wgRequest->getVal('platform') : ''; $platformStr = $platform ? '?platform=' . $platform : ''; $wgOut->redirect($target->getFullURL() . $platformStr, 301); $rarticle = $this->articleFromTitle($target); $rarticle->loadPageData($rarticle->pageDataFromTitle($dbr, $target)); if ($rarticle->mTitle->mArticleID) { $article = $rarticle; $wgTitle = $target; $article->setRedirectedFrom($title); } else { $wgTitle = $title; } } } else { $wgTitle = $article->mTitle; } } wfProfileOut('MediaWiki::initializeArticle'); return $article; }
/** * Initialize the object to be known as $wgArticle for "standard" actions * Create an Article object for the page, following redirects if needed. * @param Title $title * @param Request $request * @param string $action * @return mixed an Article, or a string to redirect to another URL */ function initializeArticle($title, $request) { global $wgTitle; wfProfileIn('MediaWiki::initializeArticle'); $action = $this->getVal('Action'); $article = $this->articleFromTitle($title); // Namespace might change when using redirects if ($action == 'view' && !$request->getVal('oldid') && $request->getVal('redirect') != 'no') { $dbr =& wfGetDB(DB_SLAVE); $article->loadPageData($article->pageDataFromTitle($dbr, $title)); /* Follow redirects only for... redirects */ if ($article->mIsRedirect) { $target = $article->followRedirect(); if (is_string($target)) { global $wgDisableHardRedirects; if (!$wgDisableHardRedirects) { // we'll need to redirect return $target; } } if (is_object($target)) { /* Rewrite environment to redirected article */ $rarticle = $this->articleFromTitle($target); $rarticle->loadPageData($rarticle->pageDataFromTitle($dbr, $target)); if ($rarticle->mTitle->mArticleID) { $article = $rarticle; $wgTitle = $target; $article->setRedirectedFrom($title); } else { $wgTitle = $title; } } } else { $wgTitle = $article->mTitle; } } wfProfileOut('MediaWiki::initializeArticle'); return $article; }
/** * Inserts a trace of the user action into the database * @global string $wgDBtype * @param Title $oTitle * @param User $oUser * @param Request $oRequest * @return boolean */ public function insertTrace($oTitle, $oUser, $oRequest) { if (wfReadOnly()) { return true; } if ($oUser->getId() == 0) { return true; } // Anonymous user $sPageTitle = $oTitle->getText(); if ($sPageTitle == '-') { return true; } // otherwise strange '-' with page_id 0 are logged $iPageId = $oTitle->getArticleId(); $iPageNamespaceId = $oTitle->getNamespace(); $iCurrentTimestamp = time(); $vLastLoggedPageHash = $oRequest->getSessionData($this->mExtensionKey . '::lastLoggedPageHash'); $vLastLoggedTime = $oRequest->getSessionData($this->mExtensionKey . '::lastLoggedTime'); $sCurrentPageHash = md5($iPageId . $iPageNamespaceId . $sPageTitle); //this combination should be pretty unique, even with specialpages. $iMaxIdleTime = BsConfig::get('MW::WhoIsOnline::MaxIdleTime'); $iInterval = BsConfig::get('MW::WhoIsOnline::Interval'); if ($vLastLoggedPageHash == $sCurrentPageHash && $vLastLoggedTime + $iMaxIdleTime + $iInterval + $iMaxIdleTime * 0.1 > $iCurrentTimestamp) { return true; } //log action wfProfileIn('BS::' . __METHOD__); $oRequest->setSessionData($this->mExtensionKey . '::lastLoggedPageHash', $sCurrentPageHash); $oRequest->setSessionData($this->mExtensionKey . '::lastLoggedTime', $iCurrentTimestamp); $iRemoveEntriesAfter = 2592000; $dbw = wfGetDB(DB_MASTER); $dbw->delete('bs_whoisonline', array('wo_timestamp < ' . ($iCurrentTimestamp - $iRemoveEntriesAfter))); $aNewRow = array(); $aNewRow['wo_page_id'] = $oTitle->getArticleId(); $aNewRow['wo_page_namespace'] = $oTitle->getNamespace(); $aNewRow['wo_page_title'] = $sPageTitle; $aNewRow['wo_user_id'] = $oUser->getId(); $aNewRow['wo_user_name'] = $oUser->getName(); $aNewRow['wo_user_real_name'] = $oUser->getRealName(); $aNewRow['wo_timestamp'] = $iCurrentTimestamp; $aNewRow['wo_action'] = $oRequest->getVal('action', 'view'); global $wgDBtype; if ($wgDBtype == 'oracle') { $aNewRow['wo_id'] = 0; } $dbw->insert('bs_whoisonline', $aNewRow); wfProfileOut('BS::' . __METHOD__); return true; }