Index: trunk/extensions/PageTriage/SpecialPageTriage.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | $triageInterface .= $this->getTriageHeader(); |
57 | 57 | |
58 | 58 | // Get the list of articles |
59 | | - $triageInterface .= $this->getTriageList(); |
| 59 | + $triageInterface .= $this->getFormattedTriageList(); |
60 | 60 | |
61 | 61 | // Get triage footer |
62 | 62 | $triageInterface .= $this->getTriageFooter(); |
— | — | @@ -85,185 +85,39 @@ |
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Builds the list of articles to triage. |
89 | | - * This is a paginated list of articles and associated metadata. |
| 89 | + * This is a list of articles and associated metadata. |
90 | 90 | * @return string HTML for the list |
91 | 91 | */ |
92 | | - public function getTriageList() { |
93 | | - global $wgOut; |
| 92 | + public function getFormattedTriageList() { |
94 | 93 | |
95 | | - $pager = new TriagePager( $this, $this->opts ); |
| 94 | + // Retrieve the IDs of all the pages that match our filtering options |
| 95 | + $pageList = ApiPageTriageList::getPageIds( $this->opts->getAllValues() ); |
96 | 96 | |
97 | | - if( $pager->getNumRows() ) { |
98 | | - $navigation = $pager->getNavigationBar(); |
99 | | - $htmlOut = $navigation . $pager->getBody() . $navigation; |
| 97 | + $htmlOut = ''; |
| 98 | + |
| 99 | + if ( $pageList ) { |
| 100 | + foreach ( $pageList as $pageId ) { |
| 101 | + $formattedRow = $this->buildRow( $pageId ); |
| 102 | + $htmlOut .= $formattedRow; |
| 103 | + } |
100 | 104 | } else { |
101 | | - $htmlOut = wfMessage( 'specialpage-empty' ); |
| 105 | + $htmlOut .= wfMessage( 'specialpage-empty' ); |
102 | 106 | } |
103 | 107 | |
104 | 108 | return $htmlOut; |
105 | 109 | } |
106 | 110 | |
107 | | -} |
108 | | - |
109 | | -class TriagePager extends ReverseChronologicalPager { |
110 | | - |
111 | | - // Holds the various options for viewing the list |
112 | | - protected $opts; |
113 | | - |
114 | | - public function __construct( $special, FormOptions $opts ) { |
115 | | - parent::__construct( $special->getContext() ); |
116 | | - $this->mLimit = $opts->getValue( 'limit' ); |
117 | | - $this->mOffset = $opts->getValue( 'offset' ); |
118 | | - $this->opts = $opts; |
119 | | - } |
120 | | - |
121 | 111 | /** |
122 | | - * Sort the list by rc_timestamp |
123 | | - * @return string |
| 112 | + * Builds a single row for the article list. |
| 113 | + * @param $pageId integer ID for a single page |
| 114 | + * @return string HTML for the row |
124 | 115 | */ |
125 | | - public function getIndexField() { |
126 | | - return 'rc_timestamp'; |
127 | | - } |
128 | | - |
129 | | - /** |
130 | | - * Set the database query to retrieve all the pages that need triaging |
131 | | - * @return array of query settings |
132 | | - */ |
133 | | - public function getQueryInfo() { |
134 | | - |
135 | | - $conds = array(); |
136 | | - $conds['rc_new'] = 1; |
| 116 | + protected function buildRow( $pageId ) { |
137 | 117 | |
138 | | - $namespace = $this->opts->getValue( 'namespace' ); |
139 | | - if ( $namespace === 'all' ) { |
140 | | - $namespace = false; |
141 | | - } else { |
142 | | - $namespace = intval( $namespace ); |
143 | | - } |
| 118 | + // TODO: get all the metadata for the page |
144 | 119 | |
145 | | - if( $namespace !== false ) { |
146 | | - $conds['rc_namespace'] = $namespace; |
147 | | - $rcIndexes = array( 'new_name_timestamp' ); |
148 | | - } else { |
149 | | - $rcIndexes = array( 'rc_timestamp' ); |
150 | | - } |
| 120 | + return '<div>'.$pageId.'</div>'; |
151 | 121 | |
152 | | - if( !$this->opts->getValue( 'showbots' ) ) { |
153 | | - $conds['rc_bot'] = 0; |
154 | | - } |
155 | | - |
156 | | - if ( !$this->opts->getValue( 'showredirs' ) ) { |
157 | | - $conds['page_is_redirect'] = 0; |
158 | | - } |
159 | | - |
160 | | - $tables = array( 'recentchanges', 'page' ); |
161 | | - |
162 | | - $fields = array( |
163 | | - 'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text', |
164 | | - 'rc_comment', 'rc_timestamp', 'rc_patrolled','rc_id', 'rc_deleted', |
165 | | - 'page_len AS length', 'page_latest AS rev_id', 'rc_this_oldid', |
166 | | - 'page_namespace', 'page_title' |
167 | | - ); |
168 | | - $join_conds = array( 'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ) ); |
169 | | - |
170 | | - $info = array( |
171 | | - 'tables' => $tables, |
172 | | - 'fields' => $fields, |
173 | | - 'conds' => $conds, |
174 | | - 'join_conds' => $join_conds |
175 | | - ); |
176 | | - |
177 | | - return $info; |
178 | 122 | } |
179 | 123 | |
180 | | - public function formatRow( $result ) { |
181 | | - |
182 | | - // Create a revision object to work with |
183 | | - $row = array( |
184 | | - 'comment' => $result->rc_comment, |
185 | | - 'deleted' => $result->rc_deleted, |
186 | | - 'user_text' => $result->rc_user_text, |
187 | | - 'user' => $result->rc_user, |
188 | | - ); |
189 | | - $rev = new Revision( $row ); |
190 | | - |
191 | | - $lang = $this->getLanguage(); |
192 | | - |
193 | | - $title = Title::newFromRow( $result ); |
194 | | - $spanTime = Html::element( 'span', array( 'class' => 'mw-pagetriage-time' ), |
195 | | - $lang->timeanddate( $result->rc_timestamp, true ) |
196 | | - ); |
197 | | - $time = Linker::linkKnown( |
198 | | - $title, |
199 | | - $spanTime, |
200 | | - array(), |
201 | | - array( 'oldid' => $result->rc_this_oldid ), |
202 | | - array() |
203 | | - ); |
204 | | - |
205 | | - $query = array( 'redirect' => 'no' ); |
206 | | - |
207 | | - // If the user is allowed to triage and the page hasn't been triaged yet, add an rcid param |
208 | | - // to the article link. |
209 | | - if( $this->getUser()->useNPPatrol() && !$result->rc_patrolled ) { |
210 | | - $query['rcid'] = $result->rc_id; |
211 | | - } |
212 | | - |
213 | | - $pageLink = Linker::linkKnown( |
214 | | - $title, |
215 | | - null, |
216 | | - array( 'class' => 'mw-pagetriage-pagename' ), |
217 | | - $query |
218 | | - ); |
219 | | - $histLink = Linker::linkKnown( |
220 | | - $title, |
221 | | - wfMsgHtml( 'hist' ), |
222 | | - array(), |
223 | | - array( 'action' => 'history' ) |
224 | | - ); |
225 | | - $history = Html::rawElement( 'span', array( 'class' => 'mw-pagetriage-history' ), wfMsg( 'parentheses', $histLink ) ); |
226 | | - |
227 | | - $length = Html::element( 'span', array( 'class' => 'mw-pagetriage-length' ), |
228 | | - $this->msg( 'nbytes' )->numParams( $result->length )->text() |
229 | | - ); |
230 | | - |
231 | | - $userLink = Linker::revUserTools( $rev ); |
232 | | - $comment = Linker::revComment( $rev ); |
233 | | - |
234 | | - if ( $result->rc_patrolled ) { |
235 | | - $class = 'mw-pagetriage-triaged'; |
236 | | - } else { |
237 | | - $class = 'mw-pagetriage-not-triaged'; |
238 | | - } |
239 | | - |
240 | | - $htmlOut = ''; |
241 | | - $htmlOut .= Xml::openElement( 'div', array( |
242 | | - 'style' => 'border: 1px solid #CCCCCC; border-top: none;', |
243 | | - 'class' => $class, |
244 | | - ) ); |
245 | | - $htmlOut .= "$pageLink $history · $length<br/>"; |
246 | | - $htmlOut .= "    By $userLink"; |
247 | | - $htmlOut .= Xml::closeElement( 'div' ); |
248 | | - |
249 | | - return $htmlOut; |
250 | | - } |
251 | | - |
252 | | - /** |
253 | | - * Begin div at the start of the list |
254 | | - * @return string HTML |
255 | | - */ |
256 | | - public function getStartBody() { |
257 | | - $htmlOut = Xml::openElement( 'div', array( 'style' => 'border-top: 1px solid #CCCCCC' ) ); |
258 | | - return $htmlOut; |
259 | | - } |
260 | | - |
261 | | - /** |
262 | | - * Close div at the end of the list |
263 | | - * @return string HTML |
264 | | - */ |
265 | | - public function getEndBody() { |
266 | | - $htmlOut = Xml::closeElement( 'div' ); |
267 | | - return $htmlOut; |
268 | | - } |
269 | | - |
270 | 124 | } |
Index: trunk/extensions/PageTriage/api/ApiPageTriageList.php |
— | — | @@ -7,16 +7,13 @@ |
8 | 8 | */ |
9 | 9 | class ApiPageTriageList extends ApiBase { |
10 | 10 | |
11 | | - // Holds the various options for filtering the list |
12 | | - protected $opts; |
13 | | - |
14 | 11 | public function execute() { |
15 | 12 | |
16 | 13 | // Get the API parameters and store them |
17 | | - $this->opts = $this->extractRequestParams(); |
| 14 | + $opts = $this->extractRequestParams(); |
18 | 15 | |
19 | 16 | // Retrieve the list of page IDs |
20 | | - $pages = $this->getPageIds(); |
| 17 | + $pages = $this->getPageIds( $opts ); |
21 | 18 | $pages = implode( ', ', $pages ); |
22 | 19 | |
23 | 20 | // Output the results |
— | — | @@ -26,9 +23,10 @@ |
27 | 24 | |
28 | 25 | /** |
29 | 26 | * Return all the page ids in PageTraige matching the specified filters |
| 27 | + * @param $opts array of filtering options |
30 | 28 | * @return an array of ids |
31 | 29 | */ |
32 | | - protected function getPageIds() { |
| 30 | + public static function getPageIds( $opts = array() ) { |
33 | 31 | |
34 | 32 | // Initialize required variables |
35 | 33 | $pages = array(); |
— | — | @@ -39,8 +37,8 @@ |
40 | 38 | $dbr = wfGetDB( DB_SLAVE ); |
41 | 39 | |
42 | 40 | // If a limit was specified, limit the results to that number |
43 | | - if ( $this->opts['limit'] ) { |
44 | | - $options = array( 'LIMIT' => $this->opts['limit'] ); |
| 41 | + if ( isset( $opts['limit'] ) && is_numeric( $opts['limit'] ) && $opts['limit'] > 0 ) { |
| 42 | + $options = array( 'LIMIT' => $opts['limit'] ); |
45 | 43 | } |
46 | 44 | |
47 | 45 | // TODO: Handle filtering options |