/**
  * @deprecated since 1.24
  * @param int $pageid
  * @param Title $title
  * @param RecentChange|null $rc
  * @return bool|string
  */
 public static function getPatrolToken($pageid, $title, $rc = null)
 {
     global $wgUser;
     $validTokenUser = false;
     if ($rc) {
         if ($wgUser->useRCPatrol() && $rc->getAttribute('rc_type') == RC_EDIT || $wgUser->useNPPatrol() && $rc->getAttribute('rc_type') == RC_NEW) {
             $validTokenUser = true;
         }
     } elseif ($wgUser->useRCPatrol() || $wgUser->useNPPatrol()) {
         $validTokenUser = true;
     }
     if ($validTokenUser) {
         // The patrol token is always the same, let's exploit that
         static $cachedPatrolToken = null;
         if (is_null($cachedPatrolToken)) {
             $cachedPatrolToken = $wgUser->getEditToken('patrol');
         }
         return $cachedPatrolToken;
     }
     return false;
 }
示例#2
0
 /**
  * Determines whether a revision is linked to this change; this may not be the case
  * when the categorization wasn't done by an edit but a conditional parser function
  *
  * @since 1.27
  *
  * @param RecentChange|RCCacheEntry $rcObj
  * @return bool
  */
 protected function isCategorizationWithoutRevision($rcObj)
 {
     return intval($rcObj->getAttribute('rc_type')) === RC_CATEGORIZE && intval($rcObj->getAttribute('rc_this_oldid')) === 0;
 }
 /**
  * RecentChange_save hook handler that tags mobile changes
  * @see https://www.mediawiki.org/wiki/Manual:Hooks/RecentChange_save
  *
  * @param RecentChange $rc
  * @return bool
  */
 public static function onRecentChange_save(RecentChange $rc)
 {
     $context = MobileContext::singleton();
     $userAgent = $context->getRequest()->getHeader("User-agent");
     $logType = $rc->getAttribute('rc_log_type');
     // Only log edits and uploads
     if ($context->shouldDisplayMobileView() && ($logType === 'upload' || is_null($logType))) {
         $rcId = $rc->getAttribute('rc_id');
         $revId = $rc->getAttribute('rc_this_oldid');
         $logId = $rc->getAttribute('rc_logid');
         ChangeTags::addTags('mobile edit', $rcId, $revId, $logId);
         // Tag as mobile web edit specifically, if it isn't coming from the apps
         if (strpos($userAgent, 'WikipediaApp/') !== 0) {
             ChangeTags::addTags('mobile web edit', $rcId, $revId, $logId);
         }
     }
     return true;
 }
 /**
  * Hook
  *
  * @param RecentChange $oRC -- instance of RecentChange class
  *
  * @static
  * @access public
  *
  * @return Bool true -- because it's a hook
  */
 public static function watchlistNotify(RecentChange &$oRC)
 {
     global $wgEnableGroupedArticleCommentsRC;
     wfProfileIn(__METHOD__);
     wfRunHooks('AC_RecentChange_Save', array(&$oRC));
     if (!empty($wgEnableGroupedArticleCommentsRC) && $oRC instanceof RecentChange) {
         $title = $oRC->getAttribute('rc_title');
         $namespace = $oRC->getAttribute('rc_namespace');
         $article_id = $oRC->getAttribute('rc_cur_id');
         $title = Title::newFromText($title, $namespace);
         //TODO: review
         if (MWNamespace::isTalk($namespace) && ArticleComment::isTitleComment($title) && !empty($article_id)) {
             $comment = ArticleComment::newFromId($article_id);
             if ($comment instanceof ArticleComment) {
                 $oArticlePage = $comment->getArticleTitle();
                 $mAttribs = $oRC->mAttribs;
                 $mAttribs['rc_title'] = $oArticlePage->getDBkey();
                 $mAttribs['rc_namespace'] = $oArticlePage->getNamespace();
                 $mAttribs['rc_log_action'] = 'article_comment';
                 $oRC->setAttribs($mAttribs);
             }
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
示例#5
0
 /**
  * Prepare log parameters for a patrolled change
  *
  * @param RecentChange $change RecentChange to represent
  * @param bool $auto Whether the patrol event was automatic
  * @return array
  */
 private static function buildParams($change, $auto)
 {
     return array('4::curid' => $change->getAttribute('rc_this_oldid'), '5::previd' => $change->getAttribute('rc_last_oldid'), '6::auto' => (int) $auto);
 }
 /**
  * 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')) {
                 $params = $rc->parseParams();
                 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);
 }
 /**
  * @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;
 }
 /**
  * Generates and returns data for edit event to be processed
  *
  * @param User $editor
  * @param RecentChange $oRecentChange
  * @param boolean $isRegisteredUser
  * @param boolean $isRegisteredUserFirstEdit
  * @return array
  */
 public static function getEventData($editor, $oRecentChange, $isRegisteredUser, $isRegisteredUserFirstEdit)
 {
     $oTitle = Title::makeTitle($oRecentChange->getAttribute('rc_namespace'), $oRecentChange->getAttribute('rc_title'));
     $eventData = ['titleText' => $oTitle->getText(), 'titleNs' => $oRecentChange->getAttribute('rc_namespace'), 'titleUrl' => $oTitle->getFullUrl(), 'currentRevId' => $oRecentChange->getAttribute('rc_this_oldid'), 'previousRevId' => $oRecentChange->getAttribute('rc_last_oldid'), 'editorName' => $editor->getName(), 'editorPageUrl' => $editor->getUserPage()->getFullUrl(), 'editorTalkPageUrl' => $editor->getTalkPage()->getFullUrl(), 'registeredUser' => $isRegisteredUser, 'registeredUserFirstEdit' => $isRegisteredUserFirstEdit, 'myHomeUrl' => Title::newFromText('WikiActivity', NS_SPECIAL)->getFullUrl()];
     return $eventData;
 }
示例#10
0
 /**
  * Prepare log parameters for a patrolled change
  *
  * @param RecentChange $change RecentChange to represent
  * @param bool $auto Whether the patrol event was automatic
  * @return array
  */
 private static function buildParams($change, $auto)
 {
     return array($change->getAttribute('rc_this_oldid'), $change->getAttribute('rc_last_oldid'), (int) $auto);
 }
 public static function onIRCLineURL(&$url, &$query, RecentChange $rc)
 {
     if ($rc->getAttribute('rc_source') !== Flow\Data\Listener\RecentChangesListener::SRC_FLOW) {
         return true;
     }
     set_error_handler(new Flow\RecoverableErrorHandler(), -1);
     $result = null;
     try {
         /** @var Flow\Formatter\IRCLineUrlFormatter $formatter */
         $formatter = Container::get('formatter.irclineurl');
         $result = $formatter->format($rc);
     } catch (Exception $e) {
         $result = null;
         wfDebugLog('Flow', __METHOD__ . ': Failed formatting rc ' . $rc->getAttribute('rc_id') . ': ' . $e->getMessage());
         MWExceptionHandler::logException($e);
     }
     restore_error_handler();
     if ($result !== null) {
         $url = $result;
         $query = '';
     }
     return true;
 }
示例#12
0
 /**
  * Store custom data in rc_params field as JSON encoded table prefixed with extra string.
  * To pass in extra key-value pairs, pass in 'data' as an associative array.
  *
  * @see http://www.mediawiki.org/wiki/Logging_table#log_params
  *
  * @author Maciej Brencz <*****@*****.**>
  */
 public static function storeInRecentChanges(RecentChange $rc, $data = array())
 {
     wfProfileIn(__METHOD__);
     /* @var $wgParser Parser */
     global $wgParser;
     // If we have existing data packed into rc_params, make sure it is preserved.
     if (isset($rc->mAttribs['rc_params'])) {
         $unpackedData = self::unpackData($rc->mAttribs['rc_params']);
         if (is_array($unpackedData)) {
             foreach ($unpackedData as $key => $val) {
                 // Give preference to the data array that was passed into the function.
                 if (!isset($data[$key])) {
                     $data[$key] = $val;
                 }
             }
         }
     }
     // summary generated by MW: store auto-summary type
     if (Wikia::isVarSet('AutoSummaryType')) {
         $data['autosummaryType'] = Wikia::getVar('AutoSummaryType');
     }
     switch ($rc->getAttribute('rc_type')) {
         // existing article
         case RC_EDIT:
             // rollback: store ID of the revision rollback is made to
             if (Wikia::isVarSet('RollbackedRevId')) {
                 $data['rollback'] = true;
                 $data['revId'] = Wikia::getVar('RollbackedRevId');
             }
             // edit from view mode
             if (Wikia::isVarSet('EditFromViewMode')) {
                 $data['viewMode'] = 1;
                 if (Wikia::isVarSet('EditFromViewMode') == 'CategorySelect') {
                     $data['CategorySelect'] = 1;
                 }
             }
             // section edit: store section name and modified summary
             if (self::$editedSectionName !== false) {
                 // store section name
                 $data['sectionName'] = self::$editedSectionName;
                 // edit summary
                 $comment = trim($rc->getAttribute('rc_comment'));
                 // summary has changed - store modified summary
                 if (!preg_match('#^/\\*(.*)\\*/$#', $comment)) {
                     // remove /* Section title */
                     $comment = preg_replace('#/\\*(.*)\\*/#', '', $comment);
                     // remove all wikitext
                     $comment = trim($wgParser->stripSectionName($comment));
                     if ($comment != '') {
                         $data['summary'] = $comment;
                     }
                 }
             }
             break;
             // new article
         // new article
         case RC_NEW:
             $content = $wgParser->getOutput()->getText();
             // remove [edit] section links
             $content = preg_replace('#<span class="editsection">(.*)</a>]</span>#', '', $content);
             // remove <script> tags (RT #46350)
             $content = preg_replace('#<script[^>]+>(.*)<\\/script>#', '', $content);
             // remove text between tags (RT #141394) and get rid of photo attribution (BugId:23871)
             $content = ActivityFeedHelper::filterTextBetweenTags($content);
             // remove HTML tags
             $content = trim(strip_tags($content));
             // store first 150 characters of parsed content
             $data['intro'] = mb_substr($content, 0, 150);
             $data['intro'] = strtr($data['intro'], array('&nbsp;' => ' ', '&amp;' => '&'));
             break;
     }
     //allow to alter $data by other extensions (eg. Article Comments)
     wfRunHooks('MyHome:BeforeStoreInRC', array(&$rc, &$data));
     // encode data to be stored in rc_params
     if (!empty($data)) {
         $rc->mAttribs['rc_params'] = self::packData($data);
     }
     Wikia::setVar('rc', $rc);
     Wikia::setVar('rc_data', $data);
     wfProfileOut(__METHOD__);
     return true;
 }