public function testFilterTextBetweenTags() { $testCases = array(array('in' => '<div>foo</div><noscript>test</noscript>', 'out' => '<div>foo</div>'), array('in' => '<figcaption class="thumbcaption"><span itemprop="geo" itemscope itemtype="http://data-vocabulary.org/Geo">52° 24.479\' N 16° 56.164\' E<meta itemprop="latitude" content="52.407991"><meta itemprop="longitude" content="16.936064"></span></figcaption>', 'out' => ''), array('in' => '<figcaption class="thumbcaption">Powódź w 1888.</figcaption><div class="picture-attribution"><img src="http://images.wikia.com/common/avatars/thumb/a/af/2240397.png/16px-2240397.png?cb=1320183718" width="16" height="16" class="avatar" alt="Shareif" />Dodane przez <a href="/wiki/U%C5%BCytkownik:Shareif">Shareif</a></div>', 'out' => '')); foreach ($testCases as $testCase) { $this->assertEquals($testCase['out'], ActivityFeedHelper::filterTextBetweenTags($testCase['in'])); } }
/** * 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(' ' => ' ', '&' => '&')); 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; }