function wfNotifyTwitterOnSave(&$article, &$user, $text, $summary) { // ignore rollbacks if (preg_match("@Reverted @", $summary)) { return true; } if (MyTwitter::hasBadTemplate($text)) { return true; } // is it in nab? is it patrolled? If unpatrolled, skip this. $dbr = wfGetDB(DB_MASTER); $row = $dbr->selectRow('newarticlepatrol', array('*'), array('nap_page' => $article->getID())); if ($row && $row->nap_patrolled == 0) { return true; } // old categories $oldtext = $article->mPreparedEdit->oldText; preg_match_all("@\\[\\[Category:[^\\]]*\\]\\]@", $oldtext, $matches); $oldcats = array(); if (sizeof($matches[0]) > 0) { $oldcats = $matches[0]; } // find new cats - like kittens! $newcats = array(); preg_match_all("@\\[\\[Category:[^\\]]*\\]\\]@", $text, $matches); $newcats = array(); if (sizeof($matches[0]) > 0) { $newcats = $matches[0]; } // find out what we need to check // what's changed? $tocheck = array(); foreach ($newcats as $n) { if (!in_array($n, $oldcats)) { $n = str_replace("[[Category:", "", $n); $n = str_replace("]]", "", $n); $cat = Title::makeTitle(NS_CATEGORY, $n); $tocheck[] = $cat; $tree = $cat->getParentCategoryTree(); $flat = wfFlattenArrayCategoryKeys($tree); foreach ($flat as $f) { $f = str_replace("Category:", "", $f); $c = Title::makeTitle(NS_CATEGORY, $f); $tocheck[] = $c; } } } $t = $article->getTitle(); foreach ($tocheck as $cat) { wfNotifyTwitter($cat, $t); } return true; }
public function getTopLevelCategories() { global $wgCategoryNames, $wgContLang; $mine = array_unique(wfFlattenArrayCategoryKeys($this->getParentCategoryTree())); $topcats = $wgCategoryNames; $results = array(); foreach ($mine as $m) { #echo"\tchecking $m\n"; $y = Title::makeTitle(NS_CATEGORY, str_replace($wgContLang->getNsText(NS_CATEGORY) . ":", "", $m)); if (in_array($y->getText(), $topcats)) { $results[] = $y; } } return $results; }
function wfFlattenArrayCategoryKeys($arg, &$results = array()) { if (is_array($arg)) { foreach ($arg as $a => $p) { $results[] = $a; if (is_array($p)) { wfFlattenArrayCategoryKeys($p, $results); } } } return $results; }