Esempio n. 1
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;
 }