~ubuntu-branches/ubuntu/maverick/mediawiki/maverick

« back to all changes in this revision

Viewing changes to includes/api/ApiQueryRandom.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-06-19 01:38:50 UTC
  • mfrom: (16.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090619013850-dsn4lrxvs90ab4rx
Tags: 1:1.15.0-1
* New upstream release. 
* Upstream added support for OASIS documents.
Closes: #530328
* Refreshed quilt patches
* Bumped standards versions to 3.8.2
* Bumped compat to 7
* Pointed to GPL-2 in debian/copyright
* Added php5-sqlite to possible DB backend dependencies.
Closes: #501569
* Proofread README.Debian, upgrade is documented there.
Closes: #520121

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
                        $this->addFields($resultPageSet->getPageTableFields());
63
63
        }
64
64
 
65
 
        protected function runQuery(&$data, &$resultPageSet) {
 
65
        protected function runQuery(&$resultPageSet) {
66
66
                $db = $this->getDB();
67
67
                $res = $this->select(__METHOD__);
68
68
                $count = 0;
73
73
                                // Prevent duplicates
74
74
                                if(!in_array($row->page_id, $this->pageIDs))
75
75
                                {
76
 
                                        $data[] = $this->extractRowInfo($row);
 
76
                                        $fit = $this->getResult()->addValue(
 
77
                                                        array('query', $this->getModuleName()),
 
78
                                                        null, $this->extractRowInfo($row));
 
79
                                        if(!$fit)
 
80
                                                # We can't really query-continue a random list.
 
81
                                                # Return an insanely high value so
 
82
                                                # $count < $limit is false
 
83
                                                return 1E9;
77
84
                                        $this->pageIDs[] = $row->page_id;
78
85
                                }
79
86
                        }
87
94
        public function run($resultPageSet = null) {
88
95
                $params = $this->extractRequestParams();
89
96
                $result = $this->getResult();
90
 
                $data = array();
91
97
                $this->pageIDs = array();
92
98
                
93
99
                $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']);
94
 
                $count = $this->runQuery($data, $resultPageSet);
 
100
                $count = $this->runQuery($resultPageSet);
95
101
                if($count < $params['limit'])
96
102
                {
97
103
                        /* We got too few pages, we probably picked a high value
99
105
                         * also the comment in Title::getRandomTitle()
100
106
                         */
101
107
                         $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']);
102
 
                         $this->runQuery($data, $resultPageSet);
 
108
                         $this->runQuery($resultPageSet);
103
109
                }
104
110
 
105
111
                if(is_null($resultPageSet)) {
106
 
                        $result->setIndexedTagName($data, 'page');
107
 
                        $result->addValue('query', $this->getModuleName(), $data);
 
112
                        $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'page');
108
113
                }
109
114
        }
110
115
 
111
116
        private function extractRowInfo($row) {
112
117
                $title = Title::makeTitle($row->page_namespace, $row->page_title);
113
118
                $vals = array();
114
 
                $vals['title'] = $title->getPrefixedText();
115
 
                $vals['ns'] = $row->page_namespace;
116
 
                $vals['id'] = $row->page_id;
 
119
                $vals['id'] = intval($row->page_id);
 
120
                ApiQueryBase::addTitleInfo($vals, $title);
117
121
                return $vals;
118
122
        }
119
123
 
157
161
        public function getVersion() {
158
162
                return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$';
159
163
        }
160
 
}
 
164
}
 
 
b'\\ No newline at end of file'