r114421 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114420‎ | r114421 | r114422 >
Date:01:28, 22 March 2012
Author:kaldari
Status:deferred
Tags:
Comment:
beginning to switch over to our own data for the triage list, making getPageIds static so that SpecialPageTriage can access it directly without having to go through the API
Modified paths:
  • /trunk/extensions/PageTriage/SpecialPageTriage.php (modified) (history)
  • /trunk/extensions/PageTriage/api/ApiPageTriageList.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageTriage/SpecialPageTriage.php
@@ -55,7 +55,7 @@
5656 $triageInterface .= $this->getTriageHeader();
5757
5858 // Get the list of articles
59 - $triageInterface .= $this->getTriageList();
 59+ $triageInterface .= $this->getFormattedTriageList();
6060
6161 // Get triage footer
6262 $triageInterface .= $this->getTriageFooter();
@@ -85,185 +85,39 @@
8686
8787 /**
8888 * 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.
9090 * @return string HTML for the list
9191 */
92 - public function getTriageList() {
93 - global $wgOut;
 92+ public function getFormattedTriageList() {
9493
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() );
9696
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+ }
100104 } else {
101 - $htmlOut = wfMessage( 'specialpage-empty' );
 105+ $htmlOut .= wfMessage( 'specialpage-empty' );
102106 }
103107
104108 return $htmlOut;
105109 }
106110
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 -
121111 /**
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
124115 */
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 ) {
137117
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
144119
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>';
151121
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;
178122 }
179123
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 &#183; $length<br/>";
246 - $htmlOut .= "&#160;&#160;&#160;&#160;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 -
270124 }
Index: trunk/extensions/PageTriage/api/ApiPageTriageList.php
@@ -7,16 +7,13 @@
88 */
99 class ApiPageTriageList extends ApiBase {
1010
11 - // Holds the various options for filtering the list
12 - protected $opts;
13 -
1411 public function execute() {
1512
1613 // Get the API parameters and store them
17 - $this->opts = $this->extractRequestParams();
 14+ $opts = $this->extractRequestParams();
1815
1916 // Retrieve the list of page IDs
20 - $pages = $this->getPageIds();
 17+ $pages = $this->getPageIds( $opts );
2118 $pages = implode( ', ', $pages );
2219
2320 // Output the results
@@ -26,9 +23,10 @@
2724
2825 /**
2926 * Return all the page ids in PageTraige matching the specified filters
 27+ * @param $opts array of filtering options
3028 * @return an array of ids
3129 */
32 - protected function getPageIds() {
 30+ public static function getPageIds( $opts = array() ) {
3331
3432 // Initialize required variables
3533 $pages = array();
@@ -39,8 +37,8 @@
4038 $dbr = wfGetDB( DB_SLAVE );
4139
4240 // 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'] );
4543 }
4644
4745 // TODO: Handle filtering options

Status & tagging log