fetchObject() protected method

protected fetchObject ( $res )
Example #1
0
 /**
  * Populates the search index with content from all pages
  */
 protected function populateSearchIndex()
 {
     $res = $this->db->select('page', 'MAX(page_id) AS count');
     $s = $this->db->fetchObject($res);
     $count = $s->count;
     $this->output("Rebuilding index fields for {$count} pages...\n");
     $n = 0;
     $fields = array_merge(Revision::selectPageFields(), Revision::selectFields(), Revision::selectTextFields());
     while ($n < $count) {
         if ($n) {
             $this->output($n . "\n");
         }
         $end = $n + self::RTI_CHUNK_SIZE - 1;
         $res = $this->db->select(['page', 'revision', 'text'], $fields, ["page_id BETWEEN {$n} AND {$end}", 'page_latest = rev_id', 'rev_text_id = old_id'], __METHOD__);
         foreach ($res as $s) {
             try {
                 $title = Title::makeTitle($s->page_namespace, $s->page_title);
                 $rev = new Revision($s);
                 $content = $rev->getContent();
                 $u = new SearchUpdate($s->page_id, $title, $content);
                 $u->doUpdate();
             } catch (MWContentSerializationException $ex) {
                 $this->output("Failed to deserialize content of revision {$s->rev_id} of page " . "`" . $title->getPrefixedDBkey() . "`!\n");
             }
         }
         $n += self::RTI_CHUNK_SIZE;
     }
 }
 /**
  * Pre-cache page existence to speed up link generation
  *
  * @param Database $dbr Database connection
  * @param int $res Result pointer
  */
 public function preprocessResults($dbr, $res)
 {
     $batch = new LinkBatch();
     while ($row = $dbr->fetchObject($res)) {
         $title = Title::makeTitleSafe($row->namespace, $row->title);
         $batch->addObj($title);
     }
     $batch->execute();
     if ($dbr->numRows($res) > 0) {
         $dbr->dataSeek($res, 0);
     }
 }
Example #3
0
 public function load()
 {
     $statement = new Database(SQL::select('data,lastTime,ip,user', 'sessions', 'id=:id'), array(':id' => $this->id));
     if ($fetch = $statement->fetchObject()) {
         $this->lastTime = $fetch->lastTime;
         $this->ip = $fetch->ip;
         $this->data = (array) json_decode($fetch->data);
         if (isset($this->user)) {
             $this->user->load($fetch->user);
         }
     }
 }
Example #4
0
 /**
  * Format and output report results using the given information plus
  * OutputPage
  *
  * @param OutputPage $out OutputPage to print to
  * @param Skin $skin User skin to use
  * @param Database $dbr Database (read) connection to use
  * @param int $res Result pointer
  * @param int $num Number of available result rows
  * @param int $offset Paging offset
  */
 protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
 {
     if ($num > 0) {
         $gallery = new ImageGallery();
         $gallery->useSkin($skin);
         # $res might contain the whole 1,000 rows, so we read up to
         # $num [should update this to use a Pager]
         for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) {
             $image = $this->prepareImage($row);
             if ($image) {
                 $gallery->add($image->getTitle(), $this->getCellHtml($row));
             }
         }
         $out->addHTML($gallery->toHtml());
     }
 }
 /**
  * Format and output report results using the given information plus
  * OutputPage
  *
  * @param OutputPage $out OutputPage to print to
  * @param Skin $skin User skin to use
  * @param Database $dbr Database (read) connection to use
  * @param int $res Result pointer
  * @param int $num Number of available result rows
  * @param int $offset Paging offset
  */
 protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
 {
     global $wgContLang, $wgUser, $wgLanguageCode;
     if ($num > 0) {
         $html = array();
         if (!$this->listoutput) {
             $html[] = $this->openList($offset);
         }
         # $res might contain the whole 1,000 rows, so we read up to
         # $num [should update this to use a Pager]
         for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) {
             $line = $this->formatResult($skin, $row);
             $title = preg_replace('/-/', ' ', $row->title);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 if ($wgUser->getID() > 0 && ($wgLanguageCode != 'zh' && $wgLanguageCode != 'ru' && $wgLanguageCode != 'hi')) {
                     $html[] = $this->listoutput ? $line : "<li{$attr}><div id=\"" . htmlentities($title, ENT_QUOTES) . "\">{$line}   <input type=\"button\" value=\"" . wfMsg('up_add_category') . "\" onclick=\"frames['dlogBody'].supAC('" . urlencode($title) . "');\"></div> </li>\n";
                 } else {
                     $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
                 }
             }
         }
         # Flush the final result
         if ($this->tryLastResult()) {
             $row = null;
             $line = $this->formatResult($skin, $row);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $html[] = $this->closeList();
         }
         $html = $this->listoutput ? $wgContLang->listToText($html) : implode('', $html);
         $out->addHtml($html);
         if ($wgUser->getID() > 0 && ($wgLanguageCode != 'zh' && $wgLanguageCode != 'ru' && $wgLanguageCode != 'hi')) {
             $out->addHtml($this->getCategoryPopup());
         }
     }
 }
<?php

require_once 'commandLine.inc';
$db = new Database($wgVanillaDB['host'], $wgVanillaDB['user'], $wgVanillaDB['password'], $wgVanillaDB['dbname']);
$oldignore = $db->ignoreErrors(true);
$res = $db->select('GDN_UserAuthentication', array('UserID', 'ForeignUserKey'));
$updates = array();
while ($row = $db->fetchObject($res)) {
    $u = User::newFromID($row->ForeignUserKey);
    $url = Avatar::getAvatarURL($u->getName());
    $updates[$row->UserID] = $url;
}
foreach ($updates as $userid => $url) {
    echo "Updating {$userid} with avatar {$url}\n";
    $db->update("GDN_User", array("Photo" => $url), array("UserID" => $userid));
}
Example #7
0
 public function getPreferenceValue(Database $db, $key)
 {
     $res = $db->query("\n\t\t\t\tSELECT *\n\t\t\t\tFROM " . TABLE_PLUGINS_SETTINGS . "\n\t\t\t\tWHERE package = ? AND `key` = ?\n\t\t\t", array($this->package, $key));
     $row = $db->fetchObject($res);
     if ($row) {
         return $row->value;
     }
     return null;
 }
Example #8
0
 /**
  * Format and output report results using the given information plus
  * OutputPage
  *
  * @param OutputPage $out OutputPage to print to
  * @param Skin $skin User skin to use
  * @param Database $dbr Database (read) connection to use
  * @param int $res Result pointer
  * @param int $num Number of available result rows
  * @param int $offset Paging offset
  */
 protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
 {
     global $wgContLang;
     if ($num > 0) {
         $html = array();
         if (!$this->listoutput) {
             $html[] = $this->openList($offset);
         }
         # $res might contain the whole 1,000 rows, so we read up to
         # $num [should update this to use a Pager]
         for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) {
             $line = $this->formatResult($skin, $row);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
             }
         }
         # Flush the final result
         if ($this->tryLastResult()) {
             $row = null;
             $line = $this->formatResult($skin, $row);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $html[] = $this->closeList();
         }
         $html = $this->listoutput ? $wgContLang->listToText($html) : implode('', $html);
         $out->addHTML($html);
     }
 }