/** * Get the last author with the last modification time * @param Page $page * @return string HTML */ protected function getAuthor(Page $page) { $user = User::newFromName($page->getUserText(), false); $timestamp = $page->getTimestamp(); if ($timestamp) { $lang = $this->getLanguage(); $d = $lang->date($page->getTimestamp(), true); $t = $lang->time($page->getTimestamp(), true); } else { $d = ''; $t = ''; } return $this->msg('lastmodifiedatby', $d, $t)->rawParams($this->userLink($user))->params($user->getName())->escaped(); }
/** * Get the last author with the last modification time * @param $article Article object * @return String HTML */ protected static function getAuthor(Page $article) { global $wgLang; $user = User::newFromId($article->getUser()); $timestamp = $article->getTimestamp(); if ($timestamp) { $d = $wgLang->date($article->getTimestamp(), true); $t = $wgLang->time($article->getTimestamp(), true); } else { $d = ''; $t = ''; } return wfMessage('lastmodifiedatby', $d, $t)->rawParams(self::userLink($user))->params($user->getName())->escaped(); }
/** * Returns page counts that would be too "expensive" to retrieve by normal means. * * @param WikiPage|Article|Page $page * @return array */ protected function pageCounts(Page $page) { $fname = __METHOD__; $config = $this->context->getConfig(); return ObjectCache::getMainWANInstance()->getWithSetCallback(self::getCacheKey($page->getTitle(), $page->getLatest()), WANObjectCache::TTL_WEEK, function ($oldValue, &$ttl, &$setOpts) use($page, $config, $fname) { $title = $page->getTitle(); $id = $title->getArticleID(); $dbr = wfGetDB(DB_REPLICA); $dbrWatchlist = wfGetDB(DB_REPLICA, 'watchlist'); $setOpts += Database::getCacheSetOptions($dbr, $dbrWatchlist); $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore(); $result = []; $result['watchers'] = $watchedItemStore->countWatchers($title); if ($config->get('ShowUpdatedMarker')) { $updated = wfTimestamp(TS_UNIX, $page->getTimestamp()); $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers($title, $updated - $config->get('WatchersMaxAge')); } // Total number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(*)', ['rev_page' => $id], $fname); $result['edits'] = $edits; // Total number of distinct authors if ($config->get('MiserMode')) { $result['authors'] = 0; } else { $result['authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', ['rev_page' => $id], $fname); } // "Recent" threshold defined by RCMaxAge setting $threshold = $dbr->timestamp(time() - $config->get('RCMaxAge')); // Recent number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(rev_page)', ['rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)], $fname); $result['recent_edits'] = $edits; // Recent number of distinct authors $result['recent_authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', ['rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)], $fname); // Subpages (if enabled) if (MWNamespace::hasSubpages($title->getNamespace())) { $conds = ['page_namespace' => $title->getNamespace()]; $conds[] = 'page_title ' . $dbr->buildLike($title->getDBkey() . '/', $dbr->anyString()); // Subpages of this page (redirects) $conds['page_is_redirect'] = 1; $result['subpages']['redirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (non-redirects) $conds['page_is_redirect'] = 0; $result['subpages']['nonredirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (total) $result['subpages']['total'] = $result['subpages']['redirects'] + $result['subpages']['nonredirects']; } // Counts for the number of transclusion links (to/from) if ($config->get('MiserMode')) { $result['transclusion']['to'] = 0; } else { $result['transclusion']['to'] = (int) $dbr->selectField('templatelinks', 'COUNT(tl_from)', ['tl_namespace' => $title->getNamespace(), 'tl_title' => $title->getDBkey()], $fname); } $result['transclusion']['from'] = (int) $dbr->selectField('templatelinks', 'COUNT(*)', ['tl_from' => $title->getArticleID()], $fname); return $result; }); }
/** * Returns page counts that would be too "expensive" to retrieve by normal means. * * @param WikiPage|Article|Page $page * @return array */ protected function pageCounts(Page $page) { $fname = __METHOD__; $config = $this->context->getConfig(); return ObjectCache::getMainWANInstance()->getWithSetCallback(self::getCacheKey($page->getTitle(), $page->getLatest()), 86400 * 7, function ($oldValue, &$ttl, &$setOpts) use($page, $config, $fname) { $title = $page->getTitle(); $id = $title->getArticleID(); $dbr = wfGetDB(DB_SLAVE); $dbrWatchlist = wfGetDB(DB_SLAVE, 'watchlist'); $setOpts += Database::getCacheSetOptions($dbr, $dbrWatchlist); $result = array(); // Number of page watchers $watchers = (int) $dbrWatchlist->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $title->getNamespace(), 'wl_title' => $title->getDBkey()), $fname); $result['watchers'] = $watchers; if ($config->get('ShowUpdatedMarker')) { // Threshold: last visited about 26 weeks before latest edit $updated = wfTimestamp(TS_UNIX, $page->getTimestamp()); $age = $config->get('WatchersMaxAge'); $threshold = $dbrWatchlist->timestamp($updated - $age); // Number of page watchers who also visited a "recent" edit $visitingWatchers = (int) $dbrWatchlist->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $title->getNamespace(), 'wl_title' => $title->getDBkey(), 'wl_notificationtimestamp >= ' . $dbrWatchlist->addQuotes($threshold) . ' OR wl_notificationtimestamp IS NULL'), $fname); $result['visitingWatchers'] = $visitingWatchers; } // Total number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(*)', array('rev_page' => $id), $fname); $result['edits'] = $edits; // Total number of distinct authors if ($config->get('MiserMode')) { $result['authors'] = 0; } else { $result['authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', array('rev_page' => $id), $fname); } // "Recent" threshold defined by RCMaxAge setting $threshold = $dbr->timestamp(time() - $config->get('RCMaxAge')); // Recent number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(rev_page)', array('rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)), $fname); $result['recent_edits'] = $edits; // Recent number of distinct authors $result['recent_authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', array('rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)), $fname); // Subpages (if enabled) if (MWNamespace::hasSubpages($title->getNamespace())) { $conds = array('page_namespace' => $title->getNamespace()); $conds[] = 'page_title ' . $dbr->buildLike($title->getDBkey() . '/', $dbr->anyString()); // Subpages of this page (redirects) $conds['page_is_redirect'] = 1; $result['subpages']['redirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (non-redirects) $conds['page_is_redirect'] = 0; $result['subpages']['nonredirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (total) $result['subpages']['total'] = $result['subpages']['redirects'] + $result['subpages']['nonredirects']; } // Counts for the number of transclusion links (to/from) if ($config->get('MiserMode')) { $result['transclusion']['to'] = 0; } else { $result['transclusion']['to'] = (int) $dbr->selectField('templatelinks', 'COUNT(tl_from)', array('tl_namespace' => $title->getNamespace(), 'tl_title' => $title->getDBkey()), $fname); } $result['transclusion']['from'] = (int) $dbr->selectField('templatelinks', 'COUNT(*)', array('tl_from' => $title->getArticleID()), $fname); return $result; }); }