/** * Find pages in mainspace that have a prefix of the new namespace * so we know titles that will need migrating * @param $ns int Namespace id (id for new namespace?) * @param $name String Prefix that is being made a namespace */ private function getConflicts( $ns, $name ) { $page = 'page'; $table = $this->db->tableName( $page ); $prefix = $this->db->strencode( $name ); $encNamespace = $this->db->addQuotes( $ns ); $titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)"; if( $ns == 0 ) { // An interwiki; try an alternate encoding with '-' for ':' $titleSql = $this->db->buildConcat( array( "'$prefix-'", $titleSql ) ); } $sql = "SELECT {$page}_id AS id, {$page}_title AS oldtitle, $encNamespace + {$page}_namespace AS namespace, $titleSql AS title, {$page}_namespace AS oldnamespace FROM {$table} WHERE ( {$page}_namespace=0 OR {$page}_namespace=1 ) AND {$page}_title " . $this->db->buildLike( $name . ':', $this->db->anyString() ); $result = $this->db->query( $sql, __METHOD__ ); $set = array(); foreach( $result as $row ) { $set[] = $row; } return $set; }
/** * Find pages in main and talk namespaces that have a prefix of the new * namespace so we know titles that will need migrating * * @param int $ns Destination namespace id * @param string $name Prefix that is being made a namespace * @param array $options Associative array of validated command-line options * * @return ResultWrapper */ private function getTargetList($ns, $name, $options) { if ($options['move-talk'] && MWNamespace::isSubject($ns)) { $checkNamespaces = array(NS_MAIN, NS_TALK); } else { $checkNamespaces = NS_MAIN; } return $this->db->select('page', array('page_id', 'page_title', 'page_namespace'), array('page_namespace' => $checkNamespaces, 'page_title' . $this->db->buildLike("{$name}:", $this->db->anyString())), __METHOD__); }
/** * Find pages in mainspace that have a prefix of the new namespace * so we know titles that will need migrating * * @param int $ns Namespace id (id for new namespace?) * @param string $name Prefix that is being made a namespace * * @return array */ private function getConflicts($ns, $name) { $titleSql = "TRIM(LEADING {$this->db->addQuotes("{$name}:")} FROM page_title)"; if ($ns == 0) { // An interwiki; try an alternate encoding with '-' for ':' $titleSql = $this->db->buildConcat(array($this->db->addQuotes("{$name}-"), $titleSql)); } return iterator_to_array($this->db->select('page', array('id' => 'page_id', 'oldtitle' => 'page_title', 'namespace' => $this->db->addQuotes($ns) . ' + page_namespace', 'title' => $titleSql, 'oldnamespace' => 'page_namespace'), array('page_namespace' => array(0, 1), 'page_title' . $this->db->buildLike("{$name}:", $this->db->anyString())), __METHOD__)); }
/** * Get temp user accounts * * - check if these accounts are really temp ones * - do not remove accounts with password set (122 of them) * * @param DatabaseBase $db * @return int[] */ protected function getAccountsToRemove(DatabaseBase $db) { $res = $db->select(self::USER_TABLE, ['user_id', 'user_name'], ['user_name ' . $db->buildLike(self::TEMPUSER_PREFIX, $db->anyString()), 'user_password' => ''], __METHOD__); $users = []; while ($user = $res->fetchObject()) { // check if this is really a temp user: "******" + <user ID> if ($user->user_name === self::TEMPUSER_PREFIX . $user->user_id) { $users[] = intval($user->user_id); } else { $this->output(sprintf(" > skipped %s (#%d)\n", $user->user_name, $user->user_id)); } } return $users; }
/** * @return string */ function buildLike() { $params = func_get_args(); if (count($params) > 0 && is_array($params[0])) { $params = $params[0]; } return parent::buildLike($params) . "ESCAPE '\\' "; }
/** * RenameUser process marks fake user accounts in user_properties table: * * select up_user, up_value from user_properties where up_property = 'renameData' and up_value LIKE 'renamed_to=W-%' limit 15; * * @see https://github.com/Wikia/app/commit/14238c4bdace691da929b46a55012f152ac815fa * * @param DatabaseBase $db * @return int[] */ protected function getAccountsToRemove(DatabaseBase $db) { $users = $db->selectFieldValues(self::USER_PROPERTIES_TABLE, 'up_user', ['up_property' => 'renameData', 'up_value ' . $db->buildLike(self::RENAMEDUSER_PROPERTY_PREFIX, $db->anyString())], __METHOD__); return $users; }
/** * @param DatabaseBase $dbw * @return array */ function getConditions($dbw) { $conds = []; $end = $this->getOption('end', false); $mime = $this->getOption('mime', false); $mediatype = $this->getOption('mediatype', false); $like = $this->getOption('metadata-contains', false); if ($end !== false) { $conds[] = 'img_name <= ' . $dbw->addQuotes($end); } if ($mime !== false) { list($major, $minor) = File::splitMime($mime); $conds['img_major_mime'] = $major; if ($minor !== '*') { $conds['img_minor_mime'] = $minor; } } if ($mediatype !== false) { $conds['img_media_type'] = $mediatype; } if ($like) { $conds[] = 'img_metadata ' . $dbw->buildLike($dbw->anyString(), $like, $dbw->anyString()); } return $conds; }