Пример #1
0
 /**
  * @param string $s
  * @return string
  */
 function checkTitleEncoding($s)
 {
     if (is_array($s)) {
         throw new MWException('Given array to checkTitleEncoding.');
     }
     if (StringUtils::isUtf8($s)) {
         return $s;
     }
     return $this->iconv($this->fallback8bitEncoding(), 'utf-8', $s);
 }
Пример #2
0
 /**
  * @param $s string
  * @return string
  */
 function checkTitleEncoding($s)
 {
     if (is_array($s)) {
         wfDebugDieBacktrace('Given array to checkTitleEncoding.');
     }
     if (StringUtils::isUtf8($s)) {
         return $s;
     }
     return $this->iconv($this->fallback8bitEncoding(), 'utf-8', $s);
 }
Пример #3
0
 protected function doQuery($sql)
 {
     wfDebug("SQL: [{$sql}]\n");
     if (!StringUtils::isUtf8($sql)) {
         throw new MWException("SQL encoding is invalid\n{$sql}");
     }
     // handle some oracle specifics
     // remove AS column/table/subquery namings
     if (!$this->getFlag(DBO_DDLMODE)) {
         $sql = preg_replace('/ as /i', ' ', $sql);
     }
     // Oracle has issues with UNION clause if the statement includes LOB fields
     // So we do a UNION ALL and then filter the results array with array_unique
     $union_unique = preg_match('/\\/\\* UNION_UNIQUE \\*\\/ /', $sql) != 0;
     // EXPLAIN syntax in Oracle is EXPLAIN PLAN FOR and it return nothing
     // you have to select data from plan table after explain
     $explain_id = MWTimestamp::getLocalInstance()->format('dmYHis');
     $sql = preg_replace('/^EXPLAIN /', 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR', $sql, 1, $explain_count);
     MediaWiki\suppressWarnings();
     $this->mLastResult = $stmt = oci_parse($this->mConn, $sql);
     if ($stmt === false) {
         $e = oci_error($this->mConn);
         $this->reportQueryError($e['message'], $e['code'], $sql, __METHOD__);
         return false;
     }
     if (!oci_execute($stmt, $this->execFlags())) {
         $e = oci_error($stmt);
         if (!$this->ignoreDupValOnIndex || $e['code'] != '1') {
             $this->reportQueryError($e['message'], $e['code'], $sql, __METHOD__);
             return false;
         }
     }
     MediaWiki\restoreWarnings();
     if ($explain_count > 0) {
         return $this->doQuery('SELECT id, cardinality "ROWS" FROM plan_table ' . 'WHERE statement_id = \'' . $explain_id . '\'');
     } elseif (oci_statement_type($stmt) == 'SELECT') {
         return new ORAResult($this, $stmt, $union_unique);
     } else {
         $this->mAffectedRows = oci_num_rows($stmt);
         return true;
     }
 }
 /**
  * Reads messages from the file in a given language and returns an array
  * of AUTHORS, MESSAGES and possibly other properties.
  *
  * @param string $code Language code.
  * @return array|bool False if the file does not exist
  * @throws MWException if the file is not readable or has bad encoding
  */
 public function read($code)
 {
     if (!$this->exists($code)) {
         return false;
     }
     $filename = $this->group->getSourceFilePath($code);
     $input = file_get_contents($filename);
     if ($input === false) {
         throw new MWException("Unable to read file {$filename}.");
     }
     if (!StringUtils::isUtf8($input)) {
         throw new MWException("Contents of {$filename} are not valid utf-8.");
     }
     $input = UtfNormal::cleanUp($input);
     try {
         return $this->readFromVariable($input);
     } catch (Exception $e) {
         throw new MWException("Parsing {$filename} failed: " . $e->getMessage());
     }
 }