require_once '../commandLine.inc'; if (isset($options['help'])) { die("Update field `city_description` in table `city_list` base on media wiki msg "); } function deleteScript($document) { $search = array('@<script[^>]*?>.*?</script>@si'); $text = preg_replace($search, '', $document); return trim(strip_tags($text)); } $sql = 'SELECT cv_id, city_url, city_description FROM `city_list`'; $db = WikiFactory::db(DB_MASTER); $res = $db->query($sql); $countAll = $countNoEmpty = 0; $sql = ''; $countNoEmpty = 0; while ($row = $db->fetchRow($res)) { $countAll++; $url = $row['city_url'] . "index.php?title=MediaWiki:Description&action=render"; $out = HTTP::get($url); $out = deleteScript($out); if ($out != $row['city_description']) { echo $row['city_id'] . ":" . $row[' city_sitename'] . ":" . $countNoEmpty . "\n"; $sql = " UPDATE city_list SET city_description =" . $db->addQuotes($out) . " where city_id=" . $row['city_id'] . ";\n"; $db->query($sql); $countNoEmpty++; } else { echo "is up to date\n"; } } echo "Found {$countAll} rows, {$countNoEmpty} with the wiki description updated.\n";
function authenticated_via_ldap($username, $password, &$ldap_displayname) { global $LDAP_options, $debug_mode; $LDAP_defaults = array('group_attr' => 'memberof', 'group_filter' => '/^[Cc][Nn]=([^,]+)/', 'cache_refresh' => 300, 'cache_retry' => 15, 'cache_expiry' => 600); foreach ($LDAP_defaults as $option_name => $option_value) { if (!array_key_exists($option_name, $LDAP_options)) { $LDAP_options[$option_name] = $option_value; } } try { // Destroy the cache each time config changes. if ($LDAP_options['cache_expiry'] != 0 && sha1(serialize($LDAP_options)) != loadScript('LDAPConfigHash')) { discardLDAPCache(); saveScript('LDAPConfigHash', sha1(serialize($LDAP_options))); deleteScript('LDAPLastSuccessfulServer'); } if ($LDAP_options['cache_retry'] > $LDAP_options['cache_refresh'] or $LDAP_options['cache_refresh'] > $LDAP_options['cache_expiry']) { throw new RackTablesError('LDAP misconfiguration: refresh/retry/expiry mismatch', RackTablesError::MISCONFIGURED); } if ($LDAP_options['cache_expiry'] == 0) { // immediate expiry set means disabled cache return authenticated_via_ldap_nocache($username, $password, $ldap_displayname); } // authenticated_via_ldap_cache()'s way of locking can sometimes result in // a PDO error condition that convertPDOException() was not able to dispatch. // To avoid reaching printPDOException() (which prints backtrace with password // argument in cleartext), any remaining PDO condition is converted locally. return authenticated_via_ldap_cache($username, $password, $ldap_displayname); } catch (PDOException $e) { if (isset($debug_mode) && $debug_mode) { // in debug mode re-throw DB exception as-is throw $e; } else { // re-create exception to hide private data from its backtrace throw new RackTablesError('LDAP caching error', RackTablesError::DB_WRITE_FAILED); } } }