public function updateRevision(DatabaseBase $dbw, $continue = null)
 {
     $rows = $dbw->select('flow_revision', array('rev_id', 'rev_user_id', 'rev_user_text', 'rev_mod_user_id', 'rev_mod_user_text', 'rev_edit_user_id', 'rev_edit_user_text'), array('rev_id > ' . $dbw->addQuotes($continue), $dbw->makeList(array('rev_user_id' => 0, 'rev_mod_user_id' => 0, 'rev_edit_user_id' => 0), LIST_OR)), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => 'rev_id'));
     $continue = null;
     foreach ($rows as $row) {
         $continue = $row->rev_id;
         $updates = array();
         if ($row->rev_user_id == 0) {
             $updates['rev_user_ip'] = $row->rev_user_text;
         }
         if ($row->rev_mod_user_id == 0) {
             $updates['rev_mod_user_ip'] = $row->rev_mod_user_text;
         }
         if ($row->rev_edit_user_id == 0) {
             $updates['rev_edit_user_ip'] = $row->rev_edit_user_text;
         }
         if ($updates) {
             $dbw->update('flow_revision', $updates, array('rev_id' => $row->rev_id), __METHOD__);
         }
     }
     return $continue;
 }
示例#2
0
 /**
  * @param Array $options
  * @param DatabaseBase $db
  * @return array
  */
 protected function getWamIndexConditions($options, $db)
 {
     $conds = array('fw1.time_id = FROM_UNIXTIME(' . $options['currentTimestamp'] . ')');
     if ($options['wikiId']) {
         $conds['fw1.wiki_id'] = $options['wikiId'];
     }
     if (!is_null($options['wikiWord'])) {
         $conds[] = "dw.url like '%" . $db->strencode($options['wikiWord']) . "%' " . "OR dw.title like '%" . $db->strencode($options['wikiWord']) . "%'";
     }
     if ($options['verticalId']) {
         $verticals = $options['verticalId'];
     } else {
         $verticals = $this->verticalIds;
     }
     $conds['fw1.vertical_id'] = $verticals;
     if (!is_null($options['wikiLang'])) {
         $conds['dw.lang'] = $db->strencode($options['wikiLang']);
     }
     if (!empty($options['excludeBlacklist']) || !empty($options['excludeNonCommercial'])) {
         $bannedIds = !empty($options['excludeBlacklist']) ? $this->getIdsBlacklistedWikis() : [];
         $nonCommercialIds = !empty($options['excludeNonCommercial']) ? $this->getNonCommercialWikis() : [];
         $blacklistIds = array_merge($bannedIds, $nonCommercialIds);
         if (!empty($blacklistIds)) {
             $conds[] = 'fw1.wiki_id NOT IN (' . $db->makeList($blacklistIds) . ')';
         }
     }
     return $conds;
 }
 /**
  * Update one property table by inserting or deleting rows, and compute
  * the changes that this entails for the property usage counts. The
  * given rows are inserted into the table if $insert is true; otherwise
  * they are deleted. The property usage counts are recorded in the
  * call-by-ref parameter $propertyUseIncrements.
  *
  * The method assumes that all of the given rows are about the same
  * subject. This is ensured by callers.
  *
  * @since 1.8
  * @param array $propertyUseIncrements
  * @param SMWSQLStore3Table $propertyTable
  * @param array $rows array of rows to insert/delete
  * @param boolean $insert
  * @param DatabaseBase $dbw used for writing
  */
 protected function writePropertyTableRowUpdates(array &$propertyUseIncrements, SMWSQLStore3Table $propertyTable, array $rows, $insert, DatabaseBase $dbw)
 {
     if (empty($rows)) {
         //print "Nothing to " . ( $insert ? 'insert' : 'delete' ) . " for table {$propertyTable->getName()}.\n"; //DEBUG
         return;
     }
     //print ( $insert ? 'Inserting ' : 'Deleting ' ) . count( $rows ) . " row(s) in table {$propertyTable->getName()}.\n"; //DEBUG
     //print var_export( $rows, true ) . "\n"; //DEBUG
     if (!$propertyTable->usesIdSubject()) {
         // does not occur, but let's be strict
         throw new InvalidArgumentException('Operation not supported for tables without subject IDs.');
     }
     if ($insert) {
         $dbw->insert($propertyTable->getName(), array_values($rows), "SMW::writePropertyTableRowUpdates-insert-{$propertyTable->getName()}");
     } else {
         $condition = '';
         // We build a condition that mentions s_id only once,
         // since it must be the same for all rows. This should
         // help the DBMS in selecting the rows (it would not be
         // easy for to detect that all tuples share one s_id).
         $sid = false;
         foreach ($rows as $row) {
             if ($sid === false) {
                 $sid = $row['s_id'];
                 // 's_id' exists for all tables with $propertyTable->usesIdSubject()
             }
             unset($row['s_id']);
             if ($condition != '') {
                 $condition .= ' OR ';
             }
             $condition .= '(' . $dbw->makeList($row, LIST_AND) . ')';
         }
         $condition = "s_id=" . $dbw->addQuotes($sid) . " AND ({$condition})";
         $dbw->delete($propertyTable->getName(), array($condition), "SMW::writePropertyTableRowUpdates-delete-{$propertyTable->getName()}");
     }
     if ($propertyTable->isFixedPropertyTable()) {
         $property = new SMWDIProperty($propertyTable->getFixedProperty());
         $pid = $this->store->smwIds->makeSMWPropertyID($property);
     }
     foreach ($rows as $row) {
         if (!$propertyTable->isFixedPropertyTable()) {
             $pid = $row['p_id'];
         }
         if (!array_key_exists($pid, $propertyUseIncrements)) {
             $propertyUseIncrements[$pid] = 0;
         }
         $propertyUseIncrements[$pid] += $insert ? 1 : -1;
     }
 }
 /**
  * Makes an encoded list of strings from an array
  * $mode:
  *   LIST_COMMA         - comma separated, no field names
  *   LIST_AND           - ANDed WHERE clause (without the WHERE)
  *   LIST_OR            - ORed WHERE clause (without the WHERE)
  *   LIST_SET           - comma separated with field names, like a SET clause
  *   LIST_NAMES         - comma separated field names
  *   LIST_SET_PREPARED  - like LIST_SET, except with ? tokens as values
  * @param array $a
  * @param int $mode
  * @throws DBUnexpectedError
  * @return string
  */
 function makeList($a, $mode = LIST_COMMA)
 {
     if (!is_array($a)) {
         throw new DBUnexpectedError($this, 'DatabaseIbm_db2::makeList called with incorrect parameters');
     }
     // if this is for a prepared UPDATE statement
     // (this should be promoted to the parent class
     //  once other databases use prepared statements)
     if ($mode == LIST_SET_PREPARED) {
         $first = true;
         $list = '';
         foreach ($a as $field => $value) {
             if (!$first) {
                 $list .= ", {$field} = ?";
             } else {
                 $list .= "{$field} = ?";
                 $first = false;
             }
         }
         $list .= '';
         return $list;
     }
     // otherwise, call the usual function
     return parent::makeList($a, $mode);
 }
示例#5
0
 /**
  * SQL clause to skip forbidden log types for this user
  *
  * @param DatabaseBase $db
  * @param string $audience Public/user
  * @param User $user User to check, or null to use $wgUser
  * @return string|bool String on success, false on failure.
  */
 public static function getExcludeClause($db, $audience = 'public', User $user = null)
 {
     global $wgLogRestrictions;
     if ($audience != 'public' && $user === null) {
         global $wgUser;
         $user = $wgUser;
     }
     // Reset the array, clears extra "where" clauses when $par is used
     $hiddenLogs = array();
     // Don't show private logs to unprivileged users
     foreach ($wgLogRestrictions as $logType => $right) {
         if ($audience == 'public' || !$user->isAllowed($right)) {
             $hiddenLogs[] = $logType;
         }
     }
     if (count($hiddenLogs) == 1) {
         return 'log_type != ' . $db->addQuotes($hiddenLogs[0]);
     } elseif ($hiddenLogs) {
         return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
     }
     return false;
 }
 /**
  * Of the current set of keys, construct database query conditions.
  * @since 2011-12-28
  * @param DatabaseBase $db
  * @return string
  */
 protected function getTitleConds($db)
 {
     // Array of array( namespace, pagename )
     $byNamespace = array();
     foreach ($this->getTitles() as $title) {
         $namespace = $title->getNamespace();
         $pagename = $title->getDBKey();
         $byNamespace[$namespace][] = $pagename;
     }
     $conds = array();
     foreach ($byNamespace as $namespaces => $pagenames) {
         $cond = array('page_namespace' => $namespaces, 'page_title' => $pagenames);
         $conds[] = $db->makeList($cond, LIST_AND);
     }
     return $db->makeList($conds, LIST_OR);
 }
 /**
  * Makes an encoded list of strings from an array
  * @param array $a Containing the data
  * @param int $mode Constant
  *      - LIST_COMMA:          comma separated, no field names
  *      - LIST_AND:            ANDed WHERE clause (without the WHERE). See
  *        the documentation for $conds in DatabaseBase::select().
  *      - LIST_OR:             ORed WHERE clause (without the WHERE)
  *      - LIST_SET:            comma separated with field names, like a SET clause
  *      - LIST_NAMES:          comma separated field names
  * @param array $binaryColumns Contains a list of column names that are binary types
  *      This is a custom parameter only present for MS SQL.
  *
  * @throws MWException|DBUnexpectedError
  * @return string
  */
 public function makeList($a, $mode = LIST_COMMA, $binaryColumns = array())
 {
     if (!is_array($a)) {
         throw new DBUnexpectedError($this, 'DatabaseBase::makeList called with incorrect parameters');
     }
     if ($mode != LIST_NAMES) {
         // In MS SQL, values need to be specially encoded when they are
         // inserted into binary fields. Perform this necessary encoding
         // for the specified set of columns.
         foreach (array_keys($a) as $field) {
             if (!isset($binaryColumns[$field])) {
                 continue;
             }
             if (is_array($a[$field])) {
                 foreach ($a[$field] as &$v) {
                     $v = new MssqlBlob($v);
                 }
                 unset($v);
             } else {
                 $a[$field] = new MssqlBlob($a[$field]);
             }
         }
     }
     return parent::makeList($a, $mode);
 }
 /**
  * Get the where clause to query rows by either old or new name
  *
  * @param DatabaseBase $db
  *
  * @return string
  */
 private function getNameWhereClause(DatabaseBase $db)
 {
     return $db->makeList(array('ru_oldname' => $this->name, 'ru_newname' => $this->name), LIST_OR);
 }
示例#9
0
 private static function __parse($aInput, $aParams, &$parser, $returnPlainData = false)
 {
     global $wgLang, $wgUser, $wgCityId, $wgParser, $wgTitle;
     global $wgExtensionsPath, $wgStylePath, $wgRequest;
     wfProfileIn(__METHOD__);
     /**
      * because this parser tag contains elements of interface we need to
      * inform parser to vary parser cache key by user lang option
      **/
     /* @var $parser Parser */
     if ($parser instanceof Parser && $parser->mOutput instanceof ParserOutput) {
         $parser->mOutput->recordOption('userlang');
     }
     $result = "";
     self::$aTables = self::$aWhere = self::$aOptions = array();
     self::$dbr = null;
     /* default settings for query */
     self::__setDefault();
     $showOnlyPage = 0;
     try {
         /* database connect */
         self::$dbr = wfGetDB(DB_SLAVE, 'dpl');
         /* parse parameters as XML tags */
         wfDebugLog(__METHOD__, "parse " . count($aInput) . " parameters (XML tags)\n");
         $relationArray = array();
         foreach ($aInput as $sParamName => $aParamValues) {
             /* ignore empty lines */
             if (empty($aParamValues)) {
                 wfDebugLog(__METHOD__, "ignore empty param: " . $sParamName . " \n");
                 continue;
             }
             /* invalid name of parameter or empty name */
             if (!in_array($sParamName, array_keys(self::$aBlogParams))) {
                 throw new Exception(wfMsg('blog-invalidparam', $sParamName, implode(", ", array_keys(self::$aBlogParams))));
             } elseif (trim($sParamName) == '') {
                 throw new Exception(wfMsg('blog-emptyparam'));
             }
             /* ignore comment lines */
             if ($sParamName[0] == '#') {
                 wfDebugLog(__METHOD__, "ignore comment line: " . $sParamName . " \n");
                 continue;
             }
             /* parse value of parameter */
             switch ($sParamName) {
                 case 'category':
                     if (!empty($aParamValues)) {
                         $aParamValues = array_slice($aParamValues, 0, self::$aBlogParams[$sParamName]['count']);
                         $aParamValues = str_replace(" ", "_", $aParamValues);
                         if (!empty($aParamValues) && is_array($aParamValues)) {
                             $relationArray[$sParamName] = $aParamValues;
                         }
                         $aPages = self::__getCategories($aParamValues, $parser);
                         if (!empty($aPages)) {
                             self::$aWhere[] = "page_id in (" . implode(",", $aPages) . ")";
                         } else {
                             self::$aWhere[] = "page_id = 0";
                         }
                     }
                     break;
                 case 'pages':
                     if (!empty($aParamValues)) {
                         $showOnlyPage = $aParamValues;
                     }
                     break;
                 case 'author':
                     if (!empty($aParamValues)) {
                         $aParamValues = array_slice($aParamValues, 0, self::$aBlogParams[$sParamName]['count']);
                         if (!empty($aParamValues) && is_array($aParamValues)) {
                             $relationArray[$sParamName] = $aParamValues;
                             $aTmpWhere = array();
                             foreach ($aParamValues as $id => $sParamValue) {
                                 $sParamValue = str_replace(" ", "\\_", $sParamValue);
                                 $aTmpWhere[] = "page_title like '" . addslashes($sParamValue) . "/%'";
                             }
                             if (!empty($aTmpWhere)) {
                                 self::$aWhere[] = implode(" OR ", $aTmpWhere);
                             }
                         }
                     }
                     break;
                 case 'order':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeOrder($sParamName, $sParamValue);
                     }
                     break;
                 case 'ordertype':
                 case 'type':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeListOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'count':
                 case 'displaycount':
                 case 'offset':
                 case 'summarylength':
                 case 'create_timestamp':
                 case 'timestamp':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeIntOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'summary':
                 case 'paging':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeBoolOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'seemore':
                 case 'title':
                 case 'class':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeStringOption($sParamName, $sParamValue);
                     }
                     break;
             }
         }
         wfRunHooks('BlogListAfterParse', array(self::$oTitle, $relationArray));
         /* */
         if (!empty($showOnlyPage)) {
             self::$aWhere = array("page_id in (" . self::$dbr->makeList($showOnlyPage) . ")");
         }
         // style attribute is deprecated but we cannot afford braking existing bloglist just because
         // they have style attribute - bugID: 68203 https://wikia.fogbugz.com/default.asp?68203
         unset($aParams['style']);
         /* parse parameters */
         foreach ($aParams as $sParamName => $sParamValue) {
             /* ignore empty lines */
             if (!isset($sParamValue)) {
                 wfDebugLog(__METHOD__, "ignore empty param: " . $sParamName . " \n");
                 continue;
             }
             /* invalid name of parameter or empty name */
             if (!in_array($sParamName, array_keys(self::$aBlogParams))) {
                 throw new Exception(wfMsg('blog-invalidparam', $sParamName, implode(", ", array_keys(self::$aBlogParams))));
             }
             /* parse value of parameter */
             switch ($sParamName) {
                 case 'order':
                     self::__makeOrder($sParamName, $sParamValue);
                     break;
                 case 'ordertype':
                 case 'type':
                     self::__makeListOption($sParamName, $sParamValue);
                     break;
                 case 'count':
                 case 'displaycount':
                 case 'offset':
                 case 'create_timestamp':
                 case 'timestamp':
                 case 'summarylength':
                     self::__makeIntOption($sParamName, $sParamValue);
                     break;
                 case 'summary':
                 case 'paging':
                     self::__makeBoolOption($sParamName, $sParamValue);
                     break;
                 case 'seemore':
                 case 'title':
                 case 'class':
                     self::__makeStringOption($sParamName, $sParamValue);
                     break;
             }
         }
         // Allows caller to turn off paging of results
         if (self::$aOptions['paging'] == true) {
             $__pageVal = $wgRequest->getVal('page');
             if (isset($__pageVal) && !empty($__pageVal)) {
                 $count = intval(self::$aOptions['count']);
                 self::__makeIntOption('offset', $count * $__pageVal);
             }
         }
         # use revision table to get results
         self::__addRevisionTable();
         /* build query */
         if ($returnPlainData) {
             $res = self::__getResults();
             wfProfileOut(__METHOD__);
             return $res;
         } else {
             if (!empty($parser->mOutput) && $parser->mOutput instanceof ParserOutput) {
                 $parser->mOutput->setProperty("blogPostCount", self::getResultsCount());
             }
             if (self::$aOptions['type'] == 'count') {
                 /* get results count */
                 $result = self::getResultsCount();
             } else {
                 $aResult = self::__getResults();
                 /* set output */
                 if (!empty($aResult)) {
                     if (self::$aOptions['type'] != 'array') {
                         $sPager = "";
                         if (self::$aOptions['type'] == 'plain') {
                             $iCount = self::getResultsCount();
                             $sPager = self::__getPager($iCount, intval(self::$aOptions['offset']));
                         }
                         if (F::app()->checkSkin('oasis')) {
                             wfRunHooks('BlogsRenderBlogArticlePage', array(&$result, $aResult, self::$aOptions, $sPager));
                         } else {
                             /* run template */
                             $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
                             $oTmpl->set_vars(array("wgUser" => $wgUser, "cityId" => $wgCityId, "wgLang" => $wgLang, "aRows" => $aResult, "aOptions" => self::$aOptions, "wgParser" => $wgParser, "skin" => RequestContext::getMain()->getSkin(), "wgExtensionsPath" => $wgExtensionsPath, "wgStylePath" => $wgStylePath, "sPager" => $sPager, "wgTitle" => self::$oTitle));
                             # ---
                             if (self::$aOptions['type'] == 'box') {
                                 $result = $oTmpl->render("blog-page");
                             } else {
                                 $page = $oTmpl->render("blog-post-page");
                                 $oTmpl->set_vars(array("page" => $page));
                                 $result = $oTmpl->render("blog-article-page");
                             }
                         }
                     } else {
                         unset($result);
                         $result = self::__makeRssOutput($aResult);
                     }
                 } else {
                     if (!empty(self::$oTitle) && self::$oTitle->getNamespace() == NS_BLOG_ARTICLE) {
                         $result = wfMsgExt('blog-empty-user-blog', array('parse'));
                     } else {
                         if (self::$aOptions['type'] != 'array') {
                             // $sk = RequestContext::getMain()->getSkin();
                             $result = "";
                             // RT #69906
                             // $result = wfMsg('blog-nopostfound') . " " . $sk->makeLinkObj(Title::newFromText('CreateBlogPage', NS_SPECIAL), wfMsg('blog-writeone' ) );
                         } else {
                             $result = "";
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         wfDebugLog(__METHOD__, "parse error: " . $e->getMessage() . "\n");
         wfProfileOut(__METHOD__);
         return $e->getMessage();
     }
     wfProfileOut(__METHOD__);
     return $result;
 }