/** * Generates a notification that can be easily interpreted by a machine. * @see RCFeedFormatter::getLine */ public function getLine(array $feed, RecentChange $rc, $actionComment) { global $wgCanonicalServer, $wgServerName, $wgScriptPath; $packet = array('id' => $rc->getAttribute('rc_id'), 'type' => RecentChange::parseFromRCType($rc->getAttribute('rc_type')), 'namespace' => $rc->getTitle()->getNamespace(), 'title' => $rc->getTitle()->getPrefixedText(), 'comment' => $rc->getAttribute('rc_comment'), 'timestamp' => (int) wfTimestamp(TS_UNIX, $rc->getAttribute('rc_timestamp')), 'user' => $rc->getAttribute('rc_user_text'), 'bot' => (bool) $rc->getAttribute('rc_bot')); if (isset($feed['channel'])) { $packet['channel'] = $feed['channel']; } $type = $rc->getAttribute('rc_type'); if ($type == RC_EDIT || $type == RC_NEW) { global $wgUseRCPatrol, $wgUseNPPatrol; $packet['minor'] = (bool) $rc->getAttribute('rc_minor'); if ($wgUseRCPatrol || $type == RC_NEW && $wgUseNPPatrol) { $packet['patrolled'] = (bool) $rc->getAttribute('rc_patrolled'); } } switch ($type) { case RC_EDIT: $packet['length'] = array('old' => $rc->getAttribute('rc_old_len'), 'new' => $rc->getAttribute('rc_new_len')); $packet['revision'] = array('old' => $rc->getAttribute('rc_last_oldid'), 'new' => $rc->getAttribute('rc_this_oldid')); break; case RC_NEW: $packet['length'] = array('old' => null, 'new' => $rc->getAttribute('rc_new_len')); $packet['revision'] = array('old' => null, 'new' => $rc->getAttribute('rc_this_oldid')); break; case RC_LOG: $packet['log_id'] = $rc->getAttribute('rc_logid'); $packet['log_type'] = $rc->getAttribute('rc_log_type'); $packet['log_action'] = $rc->getAttribute('rc_log_action'); if ($rc->getAttribute('rc_params')) { wfSuppressWarnings(); $params = unserialize($rc->getAttribute('rc_params')); wfRestoreWarnings(); if ($rc->getAttribute('rc_params') == serialize(false) || $params !== false) { // From ApiQueryLogEvents::addLogParams $logParams = array(); // Keys like "4::paramname" can't be used for output so we change them to "paramname" foreach ($params as $key => $value) { if (strpos($key, ':') === false) { $logParams[$key] = $value; continue; } $logParam = explode(':', $key, 3); $logParams[$logParam[2]] = $value; } $packet['log_params'] = $logParams; } else { $packet['log_params'] = explode("\n", $rc->getAttribute('rc_params')); } } $packet['log_action_comment'] = $actionComment; break; } $packet['server_url'] = $wgCanonicalServer; $packet['server_name'] = $wgServerName; $packet['server_script_path'] = $wgScriptPath ?: '/'; $packet['wiki'] = wfWikiID(); return $this->formatArray($packet); }
/** * @param RecentChange $rc * @param string[] &$classes * @param bool $watched * * @return string */ private function formatChangeLine(RecentChange $rc, array &$classes, $watched) { $html = ''; if ($rc->mAttribs['rc_log_type']) { $logtitle = SpecialPage::getTitleFor('Log', $rc->mAttribs['rc_log_type']); $this->insertLog($html, $logtitle, $rc->mAttribs['rc_log_type']); // Log entries (old format) or log targets, and special pages } elseif ($rc->mAttribs['rc_namespace'] == NS_SPECIAL) { list($name, $htmlubpage) = SpecialPageFactory::resolveAlias($rc->mAttribs['rc_title']); if ($name == 'Log') { $this->insertLog($html, $rc->getTitle(), $htmlubpage); } // Regular entries } else { $unpatrolled = $this->showAsUnpatrolled($rc); $this->insertDiffHist($html, $rc, $unpatrolled); # M, N, b and ! (minor, new, bot and unpatrolled) $html .= $this->recentChangesFlags(array('newpage' => $rc->mAttribs['rc_type'] == RC_NEW, 'minor' => $rc->mAttribs['rc_minor'], 'unpatrolled' => $unpatrolled, 'bot' => $rc->mAttribs['rc_bot']), ''); $this->insertArticleLink($html, $rc, $unpatrolled, $watched); } # Edit/log timestamp $this->insertTimestamp($html, $rc); # Bytes added or removed if ($this->getConfig()->get('RCShowChangedSize')) { $cd = $this->formatCharacterDifference($rc); if ($cd !== '') { $html .= $cd . ' <span class="mw-changeslist-separator">. .</span> '; } } if ($rc->mAttribs['rc_type'] == RC_LOG) { $html .= $this->insertLogEntry($rc); } elseif ($this->isCategorizationWithoutRevision($rc)) { $html .= $this->insertComment($rc); } else { # User tool links $this->insertUserRelatedLinks($html, $rc); # LTR/RTL direction mark $html .= $this->getLanguage()->getDirMark(); $html .= $this->insertComment($rc); } # Tags $this->insertTags($html, $rc, $classes); # Rollback $this->insertRollback($html, $rc); # For subclasses $this->insertExtra($html, $rc, $classes); # How many users watch this page if ($rc->numberofWatchingusers > 0) { $html .= ' ' . $this->numberofWatchingusers($rc->numberofWatchingusers); } return $html; }
/** * @see RCFeedFormatter::getLine */ public function getLine(array $feed, RecentChange $rc, $actionComment) { global $wgWWRCFeedHideLogs, $wgWWRCFeedHideNamespaces; $attribs = $rc->getAttributes(); if ($attribs['rc_type'] == RC_LOG) { $title = Title::newFromText('Log/' . $attribs['rc_log_type'], NS_SPECIAL); } else { $title =& $rc->getTitle(); } if ($attribs['rc_type'] == RC_LOG && in_array($attribs['rc_log_type'], $wgWWRCFeedHideLogs)) { return null; } elseif (in_array($title->getNamespace(), $wgWWRCFeedHideNamespaces)) { return null; } // if we aren't hiding it, let the core class do all the heavy lifting return parent::getLine($feed, $rc, $actionComment); }
/** * @see RCFeedFormatter::getLine */ public function getLine(array $feed, RecentChange $rc, $actionComment) { global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwikis, $wgCanonicalServer, $wgScript, $wgDBname; $attribs = $rc->getAttributes(); if ($attribs['rc_type'] == RC_LOG) { // Don't use SpecialPage::getTitleFor, backwards compatibility with // IRC API which expects "Log". $titleObj = Title::newFromText('Log/' . $attribs['rc_log_type'], NS_SPECIAL); } else { $titleObj =& $rc->getTitle(); } $title = $titleObj->getPrefixedText(); $title = self::cleanupForIRC($title); if ($attribs['rc_type'] == RC_LOG) { $url = ''; } else { $url = $wgCanonicalServer . $wgScript; if ($attribs['rc_type'] == RC_NEW) { $query = '?oldid=' . $attribs['rc_this_oldid']; } else { $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid']; } if ($wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol) { $query .= '&rcid=' . $attribs['rc_id']; } // HACK: We need this hook for WMF's secure server setup Hooks::run('IRCLineURL', array(&$url, &$query, $rc)); $url .= $query; } if ($attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null) { $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len']; if ($szdiff < -500) { $szdiff = "{$szdiff}"; } elseif ($szdiff >= 0) { $szdiff = '+' . $szdiff; } // @todo i18n with parentheses in content language? $szdiff = '(' . $szdiff . ')'; } else { $szdiff = ''; } $user = self::cleanupForIRC($attribs['rc_user_text']); if ($attribs['rc_type'] == RC_LOG) { $targetText = $rc->getTitle()->getPrefixedText(); $comment = self::cleanupForIRC(str_replace("[[{$targetText}]]", "[[02{$targetText}10]]", $actionComment)); $flag = $attribs['rc_log_action']; } else { $comment = self::cleanupForIRC($attribs['rc_comment']); $flag = ''; if (!$attribs['rc_patrolled'] && ($wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol)) { $flag .= '!'; } $flag .= ($attribs['rc_type'] == RC_NEW ? "N" : "") . ($attribs['rc_minor'] ? "M" : "") . ($attribs['rc_bot'] ? "B" : ""); } if ($feed['add_interwiki_prefix'] === true && $wgLocalInterwikis) { // we use the first entry in $wgLocalInterwikis in recent changes feeds $prefix = $wgLocalInterwikis[0]; } elseif ($feed['add_interwiki_prefix']) { $prefix = $feed['add_interwiki_prefix']; } else { $prefix = false; } if ($prefix !== false) { $titleString = "14[[03{$prefix}:07{$title}14]]"; } else { $titleString = "14[[07{$title}14]]"; } # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003, # no colour (\003) switches back to the term default $fullString = "{$wgDBname} 5* {$titleString}4 {$flag}10 " . "02{$url} 5* 03{$user} 5* {$szdiff} 10{$comment}\n"; return $fullString; }
/** Inserts a rollback link * * @param string $s * @param RecentChange $rc */ public function insertRollback(&$s, &$rc) { if ($rc->mAttribs['rc_type'] == RC_EDIT && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id']) { $page = $rc->getTitle(); /** Check for rollback and edit permissions, disallow special pages, and only * show a link on the top-most revision */ if ($this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']) { $rev = new Revision(array('title' => $page, 'id' => $rc->mAttribs['rc_this_oldid'], 'user' => $rc->mAttribs['rc_user'], 'user_text' => $rc->mAttribs['rc_user_text'], 'deleted' => $rc->mAttribs['rc_deleted'])); $s .= ' ' . Linker::generateRollback($rev, $this->getContext()); } } }
/** * @brief Adjusting blocks on Enhanced Recent Changes page * * @desc Changes $secureName which is an array key in RC cache by which blocks on enchance RC page are displayed * * @param ChangesList $changesList * @param string $secureName * @param RecentChange $rc * * @author Andrzej 'nAndy' Łukaszewski */ public function onChangesListMakeSecureName($changesList, &$secureName, $rc) { if (intval($rc->getAttribute('rc_namespace')) === NS_USER_WALL_MESSAGE) { $oTitle = $rc->getTitle(); if ($oTitle instanceof Title) { $wm = F::build('WallMessage', array($oTitle)); $parent = $wm->getTopParentObj(); $isMain = is_null($parent); if (!$isMain) { $wm = $parent; unset($parent); } $secureName = self::RC_WALL_SECURENAME_PREFIX . $wm->getArticleId(); } } return true; }
/** * @brief Adjusting blocks on Enhanced Recent Changes page * * Changes $secureName which is an array key in RC cache by which blocks on enchance RC page are displayed * * @param ChangesList $changesList * @param string $secureName * @param RecentChange $rc * * @return bool * @author Andrzej 'nAndy' Łukaszewski */ public static function onChangesListMakeSecureName($changesList, &$secureName, $rc) { if (WallHelper::isWallNamespace(intval($rc->getAttribute('rc_namespace')))) { $oTitle = $rc->getTitle(); if ($oTitle instanceof Title) { $wm = new WallMessage($oTitle); $parent = $wm->getTopParentObj(); $isMain = is_null($parent); if (!$isMain) { $wm = $parent; unset($parent); } $secureName = self::RC_WALL_SECURENAME_PREFIX . $wm->getArticleId(); } } return true; }
/** * @param RecentChange $cacheEntry * @param bool $showDiffLinks * * @return string */ private function buildLastLink(RecentChange $cacheEntry, $showDiffLinks) { $lastOldid = $cacheEntry->mAttribs['rc_last_oldid']; $lastMessage = $this->getMessage('last'); $type = $cacheEntry->mAttribs['rc_type']; $logTypes = array(RC_LOG); // Make "last" link if (!$showDiffLinks || !$lastOldid || in_array($type, $logTypes)) { $lastLink = $lastMessage; } else { $lastLink = Linker::linkKnown($cacheEntry->getTitle(), $lastMessage, array(), $this->buildDiffQueryParams($cacheEntry)); } return $lastLink; }
/** * Generates a notification that can be easily interpreted by a machine. * @see RCFeedFormatter::getLine */ public function getLine( array $feed, RecentChange $rc, $actionComment ) { global $wgCanonicalServer, $wgScriptPath, $wgDBname; $attrib = $rc->getAttributes(); $packet = array( // Usually, RC ID is exposed only for patrolling purposes, // but there is no real reason not to expose it in other cases, // and I can see how this may be potentially useful for clients. 'id' => $attrib['rc_id'], 'type' => $attrib['rc_type'], 'namespace' => $rc->getTitle()->getNamespace(), 'title' => $rc->getTitle()->getPrefixedText(), 'comment' => $attrib['rc_comment'], 'timestamp' => (int)wfTimestamp( TS_UNIX, $attrib['rc_timestamp'] ), 'user' => $attrib['rc_user_text'], 'bot' => (bool)$attrib['rc_bot'], ); if ( isset( $feed['channel'] ) ) { $packet['channel'] = $feed['channel']; } $type = $attrib['rc_type']; if ( $type == RC_EDIT || $type == RC_NEW ) { global $wgUseRCPatrol, $wgUseNPPatrol; $packet['minor'] = $attrib['rc_minor']; if ( $wgUseRCPatrol || ( $type == RC_NEW && $wgUseNPPatrol ) ) { $packet['patrolled'] = $attrib['rc_patrolled']; } } switch ( $type ) { case RC_EDIT: $packet['length'] = array( 'old' => $attrib['rc_old_len'], 'new' => $attrib['rc_new_len'] ); $packet['revision'] = array( 'old' => $attrib['rc_last_oldid'], 'new' => $attrib['rc_this_oldid'] ); break; case RC_NEW: $packet['length'] = array( 'old' => NULL, 'new' => $attrib['rc_new_len'] ); $packet['revision'] = array( 'old' => NULL, 'new' => $attrib['rc_this_oldid'] ); break; case RC_LOG: $packet['log_type'] = $attrib['rc_log_type']; $packet['log_action'] = $attrib['rc_log_action']; if ( $attrib['rc_params'] ) { wfSuppressWarnings(); $params = unserialize( $attrib['rc_params'] ); wfRestoreWarnings(); if ( // If it's an actual serialised false... $attrib['rc_params'] == serialize( false ) || // Or if we did not get false back when trying to unserialise $params !== false ) { // From ApiQueryLogEvents::addLogParams $logParams = array(); // Keys like "4::paramname" can't be used for output so we change them to "paramname" foreach ( $params as $key => $value ) { if ( strpos( $key, ':' ) === false ) { $logParams[$key] = $value; continue; } $logParam = explode( ':', $key, 3 ); $logParams[$logParam[2]] = $value; } $packet['log_params'] = $logParams; } else { $packet['log_params'] = explode( "\n", $attrib['rc_params'] ); } } $packet['log_action_comment'] = $actionComment; break; } $packet['server_url'] = $wgCanonicalServer; $packet['server_script_path'] = $wgScriptPath ?: '/'; $packet['wiki'] = $wgDBname; return FormatJson::encode( $packet ); }
/** * Mark auto-reviewed edits as patrolled */ public static function autoMarkPatrolled(RecentChange &$rc) { if (empty($rc->mAttribs['rc_this_oldid'])) { return true; } $fa = FlaggableWikiPage::getTitleInstance($rc->getTitle()); $fa->loadPageData('fromdbmaster'); // Is the page reviewable? if ($fa->isReviewable()) { $revId = $rc->mAttribs['rc_this_oldid']; // If the edit we just made was reviewed, then it's the stable rev $frev = FlaggedRevision::newFromTitle($rc->getTitle(), $revId, FR_MASTER); // Reviewed => patrolled if ($frev) { RevisionReviewForm::updateRecentChanges($rc, 'patrol', $frev); $rc->mAttribs['rc_patrolled'] = 1; // make sure irc/email notifs know status } return true; } return true; }
public static function addToChangeListLine(&$list, &$articlelink, &$s, RecentChange &$rc) { global $wgUser; $title = $rc->getTitle(); // convenience if (!FlaggedRevs::inReviewNamespace($title) || empty($rc->mAttribs['rc_this_oldid']) || !array_key_exists('fp_stable', $rc->mAttribs)) { return true; // confirm that page is in reviewable namespace } $rlink = $css = ''; // page is not reviewed if ($rc->mAttribs['fp_stable'] == null) { // Is this a config were pages start off reviewable? // Hide notice from non-reviewers due to vandalism concerns (bug 24002). if (!FlaggedRevs::useOnlyIfProtected() && $wgUser->isAllowed('review')) { $rlink = wfMsgHtml('revreview-unreviewedpage'); $css = 'flaggedrevs-unreviewed'; } // page is reviewed and has pending edits (use timestamps; bug 15515) } elseif (isset($rc->mAttribs['fp_pending_since']) && $rc->mAttribs['rc_timestamp'] >= $rc->mAttribs['fp_pending_since']) { $rlink = $list->skin->link($title, wfMsgHtml('revreview-reviewlink'), array('title' => wfMsg('revreview-reviewlink-title')), array('oldid' => $rc->mAttribs['fp_stable'], 'diff' => 'cur') + FlaggedRevs::diffOnlyCGI()); $css = 'flaggedrevs-pending'; } if ($rlink != '') { $articlelink .= " <span class=\"mw-fr-reviewlink {$css}\">[{$rlink}]</span>"; } return true; }
/** * When an edit is made to a page: * (a) If the page is reviewable, silently mark the edit patrolled if it was auto-reviewed * (b) If the page can be patrolled, auto-patrol the edit patrolled as normal * (c) If the page is new and $wgUseNPPatrol is on, auto-patrol the edit patrolled as normal * (d) If the edit is neither reviewable nor patrolleable, silently mark it patrolled */ public static function autoMarkPatrolled(RecentChange &$rc) { if (empty($rc->mAttribs['rc_this_oldid'])) { return true; } $fa = FlaggableWikiPage::getTitleInstance($rc->getTitle()); $fa->loadPageData('fromdbmaster'); // Is the page reviewable? if ($fa->isReviewable()) { $revId = $rc->mAttribs['rc_this_oldid']; $quality = FlaggedRevision::getRevQuality($revId, FR_MASTER); // Reviewed => patrolled if ($quality !== false && $quality >= FR_CHECKED) { RevisionReviewForm::updateRecentChanges($rc, 'patrol', $fa->getStableRev()); $rc->mAttribs['rc_patrolled'] = 1; // make sure irc/email notifs know status } return true; } return true; }
/** * @param RecentChange $cacheEntry * @param bool $showDiffLinks * * @return string */ private function buildLastLink(RecentChange $cacheEntry, $showDiffLinks) { $lastOldid = $cacheEntry->mAttribs['rc_last_oldid']; $lastMessage = $this->getMessage('last'); $type = $cacheEntry->mAttribs['rc_type']; $logTypes = [RC_LOG]; // Make "last" link if (!$showDiffLinks || !$lastOldid || in_array($type, $logTypes)) { $lastLink = $lastMessage; } else { $lastLink = $this->linkRenderer->makeKnownLink($cacheEntry->getTitle(), new HtmlArmor($lastMessage), [], $this->buildDiffQueryParams($cacheEntry)); } return $lastLink; }