コード例 #1
0
 /**
  * Updates Phalanx rules cache after one changing one rule (add, modify or delete)
  *
  * @param $oldData mixed Old rule data or null if adding a rule
  * @param $newData mixed New rule data or null if removing a rule
  */
 public static function updateCache($oldData, $newData)
 {
     global $wgMemc, $wgPhalanxSupportedLanguages;
     $allLanguages = array_keys($wgPhalanxSupportedLanguages);
     if (array_search('all', $allLanguages)) {
         array_unshift($allLanguages, 'all');
     }
     $list = array();
     // Find where the rule was removed from?
     if ($oldData) {
         $lang = $oldData['lang'] ? $oldData['lang'] : null;
         $langs = $lang ? array($lang) : $allLanguages;
         $type = $oldData['type'];
         for ($i = 1; $type > 0; $i <<= 1, $type >>= 1) {
             if ($type & 1) {
                 foreach ($langs as $l) {
                     $list[$i][$l]['remove'] = true;
                 }
             }
         }
     }
     // Find where the rule will be added to?
     if ($newData) {
         $lang = $newData['lang'] ? $newData['lang'] : null;
         $langs = $lang ? array($lang) : $allLanguages;
         $type = $newData['type'];
         for ($i = 1; $type > 0; $i <<= 1, $type >>= 1) {
             if ($type & 1) {
                 foreach ($langs as $l) {
                     $list[$i][$l]['save'] = true;
                 }
             }
         }
     }
     $id = intval($oldData ? $oldData['id'] : $newData['id']);
     // Iterate through each affected cache case and update
     foreach ($list as $moduleId => $list2) {
         foreach ($list2 as $lang => $props) {
             if (empty($lang) || $lang == 'all') {
                 $lang = null;
             }
             $remove = !empty($props['remove']);
             $save = !empty($props['save']);
             $sLang = $lang ? $lang : 'all';
             $key = 'phalanx:' . $moduleId . ':' . $sLang;
             Phalanx::clearCache($moduleId, $sLang);
             // clear local cache
             $blocksData = $wgMemc->get($key);
             if (empty($blocksData)) {
                 Phalanx::getFromFilter($moduleId, $lang, true);
             } else {
                 if ($remove && !$save) {
                     unset($blocksData['blocks'][$id]);
                     // remove block
                 } else {
                     if ($save) {
                         $blocksData['blocks'][$id] = $newData;
                         // add or overwrite block
                     }
                 }
                 $wgMemc->set($key, $blocksData);
             }
             unset($wgMemc->_dupe_cache[$key]);
         }
     }
     Phalanx::setLastUpdate();
 }
コード例 #2
0
<?php

/**
 * A maintenance script to rebuild Phalanx's cache. Rebuilding the cache
 * during regular HTTP requests has become too resource-consuming.
 * 
 * @file extensions/wikia/Phalanx/maintenance/rebuildPhalanxCache.php
 * @author Michał Roszka (Mix) <*****@*****.**>
 */
// MediaWiki
include __DIR__ . '/../../../../maintenance/commandLine.inc';
// Phalanx caches its blocks by the type and by the language. Let's
// get supported types and languages.
$aTypes = array_keys(Phalanx::$typeNames);
$aLanguages = array_keys($wgPhalanxSupportedLanguages);
// Walk through all types...
foreach ($aTypes as $iType) {
    // ... and languages.
    foreach ($aLanguages as $sLanguage) {
        // Fill the cache with the current data from DB_MASTER.
        Phalanx::getFromFilter($iType, $sLanguage, true, true);
        if ($iType == Phalanx::TYPE_USER) {
            Phalanx::getFromFilterShort($iType, $sLanguage, true, true);
        }
        echo "iType = {$iType}, {$sLanguage}, {$time} sec \n";
    }
    // Touch.
    Phalanx::setLastUpdate();
}
exit(0);
コード例 #3
0
 /**
  * Updates Phalanx rules cache after one changing one rule (add, modify or delete)
  *
  * @param $oldData mixed Old rule data or null if adding a rule
  * @param $newData mixed New rule data or null if removing a rule
  */
 public static function updateCache($oldData, $newData)
 {
     global $wgMemc, $wgPhalanxSupportedLanguages;
     $allLanguages = array_keys($wgPhalanxSupportedLanguages);
     if (array_search('all', $allLanguages)) {
         array_unshift($allLanguages, 'all');
     }
     $list = array();
     // Find where the rule was removed from?
     if ($oldData) {
         $lang = $oldData['lang'] ? $oldData['lang'] : null;
         $langs = $lang ? array($lang) : $allLanguages;
         $type = $oldData['type'];
         for ($i = 1; $type > 0; $i <<= 1, $type >>= 1) {
             if ($type & 1) {
                 foreach ($langs as $l) {
                     $list[$i][$l]['remove'] = true;
                 }
             }
         }
     }
     // Find where the rule will be added to?
     if ($newData) {
         $lang = $newData['lang'] ? $newData['lang'] : null;
         $langs = $lang ? array($lang) : $allLanguages;
         $type = $newData['type'];
         for ($i = 1; $type > 0; $i <<= 1, $type >>= 1) {
             if ($type & 1) {
                 foreach ($langs as $l) {
                     $list[$i][$l]['save'] = true;
                 }
             }
         }
     }
     $newDataShort = false;
     if ($newData) {
         $newDataShort = array($newData['id'], $newData['text'], ($newData['exact'] ? Phalanx::FLAG_EXACT : 0) + ($newData['regex'] ? Phalanx::FLAG_REGEX : 0) + ($newData['case'] ? Phalanx::FLAG_CASE : 0));
     }
     $id = intval($oldData ? $oldData['id'] : $newData['id']);
     $memcClient = is_callable(array($wgMemc, 'getClient')) ? $wgMemc->getClient() : false;
     // Iterate through each affected cache case and update
     foreach ($list as $moduleId => $list2) {
         foreach ($list2 as $lang => $props) {
             if (empty($lang) || $lang == 'all') {
                 $lang = null;
             }
             $remove = !empty($props['remove']);
             $save = !empty($props['save']);
             $sLang = $lang ? $lang : 'all';
             // update full format
             $key = 'phalanx:' . $moduleId . ':' . $sLang;
             Phalanx::clearCache($moduleId, $sLang);
             // clear local cache
             $blocksData = $wgMemc->get($key);
             if (empty($blocksData)) {
                 Phalanx::getFromFilter($moduleId, $lang, true);
             } else {
                 if ($remove && !$save) {
                     unset($blocksData['blocks'][$id]);
                     // remove block
                 } else {
                     if ($save) {
                         $blocksData['blocks'][$id] = $newData;
                         // add or overwrite block
                     }
                 }
                 $wgMemc->set($key, $blocksData);
             }
             if ($memcClient) {
                 unset($memcClient->_dupe_cache[$key]);
             }
             // update short format (only for user)
             if ($moduleId == Phalanx::TYPE_USER) {
                 $key = 'phalanx:' . $moduleId . ':' . $sLang . ':short';
                 $blocksData = $wgMemc->get($key);
                 if (empty($blocksData)) {
                     Phalanx::getFromFilterShort($moduleId, $lang, true);
                 } else {
                     if ($remove && !$save) {
                         unset($blocksData['blocks'][$id]);
                         // remove block
                     } else {
                         if ($save) {
                             $blocksData['blocks'][$id] = $newDataShort;
                             // add or overwrite block
                         }
                     }
                     $wgMemc->set($key, $blocksData);
                 }
                 if ($memcClient) {
                     unset($memcClient->_dupe_cache[$key]);
                 }
             }
         }
     }
     Phalanx::setLastUpdate();
 }