public function modifyQuery(DpleQuery &$query)
 {
     switch ($this->redirects_) {
         case 'only':
             $query->addConds(array('page_is_redirect' => 1));
             break;
         case 'exclude':
             $query->addConds(array('page_is_redirect' => 0));
             break;
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     $dbr = $query->getDbr();
     switch ($this->subpages_) {
         case 'only':
             $query->addConds('page_title' . $dbr->buildLike($dbr->anyString(), '/', $dbr->anyString()));
             break;
         case 'exclude':
             $query->addConds('page_title NOT' . $dbr->buildLike($dbr->anyString(), '/', $dbr->anyString()));
             break;
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     switch (count($this->namespaces_)) {
         case 0:
             break;
         case 1:
             $query->addConds("page_namespace = {$this->namespaces_[0]}");
             break;
         default:
             $query->addConds('page_namespace IN (' . implode(',', $this->namespaces_) . ')');
     }
     switch (count($this->notNamespaces_)) {
         case 0:
             break;
         case 1:
             $query->addConds("page_namespace != {$this->notNamespaces_[0]}");
             break;
         default:
             $query->addConds('page_namespace NOT IN (' . implode(',', $this->notNamespaces_) . ')');
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     global $wgDpleMaxCost;
     /** Throw an exception if there is no WHERE clause. */
     if (!$query->getConds()) {
         throw new Scribunto_LuaError(wfMessage('dple-error-no-criteria')->text());
     }
     /** Sum up the total cost. */
     $this->totalCost_ = 0;
     foreach ($this->getFeatures() as $feature) {
         $this->totalCost_ += $feature->getCost();
     }
     /** Throw an exception if @ref $totalCost_ exceeds @ref
      *	$wgDpleMaxCost#. */
     if ($this->totalCost_ > $wgDpleMaxCost) {
         throw new Scribunto_LuaError(wfMessage('dple-error-too-expensive', $this->totalCost_, $wgDpleMaxCost)->text());
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     $categoryFeature = $this->getFeature('DpleFeatureCategory');
     /** Do nothing if no category was defined. */
     if (!isset($categoryFeature) || !$categoryFeature->getLinkedCount()) {
         return;
     }
     $dbr = $query->getDbr();
     /** Otherwise, also fetch the sort key for the first
      *	category. */
     $query->addVars(array('sortkey' => 'cl1.cl_sortkey_prefix'));
     if ($this->extras_) {
         $extraConds = array();
         /** Add conditions based on @ref $extras_. */
         foreach ($this->extras_ as $extra) {
             $extraConds[] = 'cl1.cl_sortkey_prefix' . $dbr->buildLike($dbr->anyString(), "|{$extra}");
         }
         $query->addConds('(' . implode(' OR ', $extraConds) . ')');
     }
     /** Add conditions based on @ref $notExtras_. */
     foreach ((array) $this->notExtras_ as $extra) {
         $query->addConds('cl1.cl_sortkey_prefix NOT ' . $dbr->buildLike($dbr->anyString(), "|{$extra}"));
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     $dbr = $query->getDbr();
     $tableName = $dbr->tableName('revision');
     /** Add condition based on @ref $createdby_. */
     if ($this->createdby_) {
         $table = "{$tableName} AS rev_c";
         $query->addTables($table);
         $cond = $this->buildIn($this->createdby_);
         $query->addJoinCond($table, 'INNER JOIN', array('page_id = rev_c.rev_page', 'rev_c.rev_parent_id = 0'));
         $query->addConds("rev_c.rev_user {$cond}");
     }
     /** Add condition based on @ref $notCreatedby_. */
     if ($this->notCreatedby_) {
         $table = "{$tableName} AS rev_nc";
         $query->addTables($table);
         $cond = 'NOT' . $this->buildIn($this->notCreatedby_);
         $query->addJoinCond($table, 'INNER JOIN', array('page_id = rev_nc.rev_page', 'rev_nc.rev_parent_id = 0'));
         $query->addConds("rev_nc.rev_user {$cond}");
     }
     /** Add condition based on @ref $lastmodifiedby_. */
     if ($this->lastmodifiedby_) {
         $table = "{$tableName} AS rev_l";
         $query->addTables($table);
         $cond = $this->buildIn($this->lastmodifiedby_);
         $query->addJoinCond($table, 'INNER JOIN', array('page_latest = rev_l.rev_id'));
         $query->addConds("rev_l.rev_user {$cond}");
     }
     /** Add condition based on @ref $notLastmodifiedby_. */
     if ($this->notLastmodifiedby_) {
         $table = "{$tableName} AS rev_nl";
         $query->addTables($table);
         $cond = 'NOT' . $this->buildIn($this->notLastmodifiedby_);
         $query->addJoinCond($table, 'INNER JOIN', array('page_latest = rev_nl.rev_id'));
         $query->addConds("rev_nl.rev_user {$cond}");
     }
     /** Add condition based on @ref $modifiedby_. */
     if ($this->modifiedby_) {
         $table = "{$tableName} AS rev_m";
         $query->addTables($table);
         $cond = $this->buildIn($this->modifiedby_);
         $query->addJoinCond($table, 'INNER JOIN', array('page_id = rev_m.rev_page'));
         $query->addConds("rev_m.rev_user {$cond}");
         $query->setOption('DISTINCT');
     }
     /** Add condition based on @ref $notModifiedby_. */
     if ($this->notModifiedby_) {
         $table = "{$tableName} AS rev_nm";
         $query->addTables($table);
         $cond = $this->buildIn($this->notModifiedby_);
         $query->addJoinCond($table, 'LEFT OUTER JOIN', array('page_id = rev_nm.rev_page', "rev_nm.rev_user {$cond}"));
         $query->addConds(array('rev_nm.rev_page' => null));
         $query->setOption('DISTINCT');
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     $dbr = $query->getDbr();
     if ($this->titleprefixes_) {
         $prefixConds = array();
         foreach ($this->titleprefixes_ as $prefix) {
             $prefixConds[] = 'page_title' . $dbr->buildLike($prefix, $dbr->anyString());
         }
         $query->addConds('(' . implode(' OR ', $prefixConds) . ')');
     }
     foreach ((array) $this->notTitleprefixes_ as $prefix) {
         $query->addConds('page_title NOT' . $dbr->buildLike($prefix, $dbr->anyString()));
     }
     if ($this->titlesuffixes_) {
         $suffixConds = array();
         foreach ($this->titlesuffixes_ as $suffix) {
             $suffixConds[] = 'page_title' . $dbr->buildLike($dbr->anyString(), $suffix);
         }
         $query->addConds('(' . implode(' OR ', $suffixConds) . ')');
     }
     foreach ((array) $this->notTitlesuffixes_ as $suffix) {
         $query->addConds('page_title NOT' . $dbr->buildLike($dbr->anyString(), $suffix));
     }
     if ($this->titlecontains_) {
         $containsConds = array();
         foreach ($this->titlecontains_ as $contains) {
             $containsConds[] = 'page_title' . $dbr->buildLike($dbr->anyString(), $contains, $dbr->anyString());
         }
         $query->addConds('(' . implode(' OR ', $containsConds) . ')');
     }
     foreach ((array) $this->notTitlecontains_ as $contains) {
         $query->addConds('page_title NOT' . $dbr->buildLike($dbr->anyString(), $contains, $dbr->anyString()));
     }
 }
 public function modifyQuery(DpleQuery &$query)
 {
     /** Set the LIMIT clause. */
     $query->setOption('LIMIT', $this->count_);
 }
 public function modifyQuery(DpleQuery &$query)
 {
     /** Call parseOrdermethod(). */
     $this->ordermethod_ = $this->parseOrdermethod($this->ordermethod_);
     /** Set the ORDER BY clause based on $ordermethod_. */
     switch ($this->ordermethod_) {
         case 'lastedit':
             $sqlSort = 'page_touched';
             break;
         case 'length':
             $sqlSort = 'page_len';
             break;
         case 'created':
             $sqlSort = 'page_id';
             // Since they're never reused
             // and increasing
             break;
         case 'categorysortkey':
             $sqlSort = "cl1.cl_type {$this->sqlOrder_}, cl1.cl_sortkey";
             break;
         case 'categorysortkeyx':
             $sqlSort = "clx1.cl_type {$this->sqlOrder_}, clx1.cl_sortkey";
             break;
         case 'popularity':
             $sqlSort = 'page_counter';
             break;
         case 'title':
             $sqlSort = $query->getDbr()->strreplace('page_title', "'_'", "' '");
             break;
         case 'categoryadd':
             $sqlSort = 'cl1.cl_timestamp';
             break;
         case 'categoryaddx':
             $sqlSort = 'clx1.cl_timestamp';
             break;
     }
     $query->setOption('ORDER BY', "{$sqlSort} {$this->sqlOrder_}");
 }
 /**
  * @brief Modify a given query.
  *
  * Add table aliases `{$tableAlias_}1, {$tableAlias_}2, ...` to
  * DpleQuery::$tables_.
  *
  * @param DpleQuery $query Query object.
  */
 public function modifyQuery(DpleQuery &$query)
 {
     $dbr = $query->getDbr();
     $tableName = $dbr->tableName($this->tableName_);
     $n = 1;
     /** Add conditions based on @ref $linkedTitles_. */
     for ($i = 0; $i < $this->linkedCount_; $i++) {
         $table = "{$tableName} AS {$this->tableAlias_}{$n}";
         $query->addTables($table);
         $query->addJoinCond($table, 'INNER JOIN', $this->transformJoinConds_($dbr, $n, $this->linkedTitles_[$i]));
         $n++;
     }
     /** Add conditions based on @ref $notLinkedTitles_. */
     for ($i = 0; $i < $this->notLinkedCount_; $i++) {
         $table = "{$tableName} AS {$this->tableAlias_}{$n}";
         $query->addTables($table);
         $query->addJoinCond($table, 'LEFT OUTER JOIN', $this->transformJoinConds_($dbr, $n, $this->notLinkedTitles_[$i]));
         $query->addConds(array("{$this->tableAlias_}{$n}.{$this->tableColumn_}" => null));
         $n++;
     }
 }