r34942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34941‎ | r34942 | r34943 >
Date:21:34, 16 May 2008
Author:aaron
Status:old
Tags:
Comment:
* Respect feed limits
* Decrappify WLH enough that it at least looks kind of tolerable
Modified paths:
  • /trunk/phase3/includes/PageHistory.php (modified) (history)
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialRecentchangeslinked.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFeedWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialRecentchangeslinked.php
@@ -15,7 +15,6 @@
1616 */
1717 function wfSpecialRecentchangeslinked( $par = NULL ) {
1818 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgTitle, $wgScript;
19 - $fname = 'wfSpecialRecentchangeslinked';
2019
2120 $days = $wgRequest->getInt( 'days' );
2221 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
@@ -57,7 +56,7 @@
5857 $wgOut->setSyndicated();
5958 $wgOut->setFeedAppendQuery( "target=" . urlencode( $target ) );
6059
61 - if ( ! $days ) {
 60+ if ( !$days ) {
6261 $days = (int)$wgUser->getOption( 'rcdays', 7 );
6362 }
6463 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
@@ -83,49 +82,39 @@
8483 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
8584
8685 $uid = $wgUser->getID();
87 -
88 - $GROUPBY = "
89 - GROUP BY rc_cur_id,rc_namespace,rc_title,
 86+ // The fields we are selecting
 87+ $fields = "rc_cur_id,rc_namespace,rc_title,
9088 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_log_type,rc_log_action,rc_params,rc_deleted,
91 - rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
92 -" . ($uid ? ",wl_user" : "") . "
93 - ORDER BY rc_timestamp DESC
94 - LIMIT {$limit}";
 89+ rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len";
 90+ $fields .= $uid ? ",wl_user" : "";
9591
 92+ // Check if this should be a feed
 93+ $feed = false;
 94+ global $wgSitename, $wgFeedClasses, $wgContLanguageCode, $wgFeedLimit;
 95+ $feedFormat = $wgRequest->getVal( 'feed' );
 96+ if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
 97+ $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) .
 98+ ' [' . $wgContLanguageCode . ']';
 99+ $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
 100+ htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
 101+ # Sanity check
 102+ if( $limit > $wgFeedLimit ) {
 103+ $limit = $wgFeedLimit;
 104+ }
 105+ }
 106+
96107 // If target is a Category, use categorylinks and invert from and to
97108 if( $nt->getNamespace() == NS_CATEGORY ) {
98109 $catkey = $dbr->addQuotes( $nt->getDBkey() );
99 - $sql = "SELECT /* wfSpecialRecentchangeslinked */
100 - rc_id,
101 - rc_cur_id,
102 - rc_namespace,
103 - rc_title,
104 - rc_this_oldid,
105 - rc_last_oldid,
106 - rc_user,
107 - rc_comment,
108 - rc_user_text,
109 - rc_timestamp,
110 - rc_minor,
111 - rc_bot,
112 - rc_new,
113 - rc_patrolled,
114 - rc_type,
115 - rc_old_len,
116 - rc_new_len,
117 - rc_log_type,
118 - rc_log_action,
119 - rc_params,
120 - rc_deleted
121 -" . ($uid ? ",wl_user" : "") . "
122 - FROM $categorylinks, $recentchanges
123 -" . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
124 - WHERE rc_timestamp > '{$cutoff}'
125 - {$cmq}
126 - AND cl_from=rc_cur_id
127 - AND cl_to=$catkey
128 -$GROUPBY
129 - ";
 110+ # The table clauses
 111+ $tables = "$categorylinks, $recentchanges";
 112+ $tables .= $uid ? "LEFT JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "";
 113+
 114+ $sql = "SELECT /* wfSpecialRecentchangeslinked */ $fields FROM $tables
 115+ WHERE rc_timestamp > '{$cutoff}' {$cmq}
 116+ AND cl_from=rc_cur_id
 117+ AND cl_to=$catkey
 118+ GROUP BY $fields ORDER BY rc_timestamp DESC LIMIT {$limit}"; // Shitty-ass GROUP BY by for postgres apparently
130119 } else {
131120 if( $showlinkedto ) {
132121 $ns = $dbr->addQuotes( $nt->getNamespace() );
@@ -134,41 +123,40 @@
135124 } else {
136125 $joinConds = "AND pl_namespace=rc_namespace AND pl_title=rc_title AND pl_from=$id";
137126 }
 127+ # The table clauses
 128+ $tables = "$pagelinks, $recentchanges";
 129+ $tables .= $uid ? "LEFT JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "";
138130
139 - $sql =
140 -"SELECT /* wfSpecialRecentchangeslinked */
141 - rc_id,
142 - rc_cur_id,
143 - rc_namespace,
144 - rc_title,
145 - rc_user,
146 - rc_comment,
147 - rc_user_text,
148 - rc_this_oldid,
149 - rc_last_oldid,
150 - rc_timestamp,
151 - rc_minor,
152 - rc_bot,
153 - rc_new,
154 - rc_patrolled,
155 - rc_type,
156 - rc_old_len,
157 - rc_new_len,
158 - rc_log_type,
159 - rc_log_action,
160 - rc_params,
161 - rc_deleted
162 -" . ($uid ? ",wl_user" : "") . "
163 - FROM $pagelinks, $recentchanges
164 -" . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
165 - WHERE rc_timestamp > '{$cutoff}'
166 - {$cmq}
167 - {$joinConds}
168 -$GROUPBY
169 -";
 131+ $sql = "SELECT /* wfSpecialRecentchangeslinked */ $fields FROM $tables
 132+ WHERE rc_timestamp > '{$cutoff}' {$cmq}
 133+ {$joinConds}
 134+ GROUP BY $fields ORDER BY rc_timestamp DESC LIMIT {$limit}"; // Shitty-ass GROUP BY by for postgres apparently
170135 }
171 - $res = $dbr->query( $sql, $fname );
172 -
 136+ # Actually do the query
 137+ $res = $dbr->query( $sql, __METHOD__ );
 138+ $count = $dbr->numRows( $res );
 139+ $rchanges = array();
 140+ # Output feeds now and be done with it!
 141+ if( $feed ) {
 142+ if( $count ) {
 143+ $counter = 1;
 144+ while ( $limit ) {
 145+ if ( 0 == $count ) { break; }
 146+ $obj = $dbr->fetchObject( $res );
 147+ --$count;
 148+ $rc = RecentChange::newFromRow( $obj );
 149+ $rc->counter = $counter++;
 150+ --$limit;
 151+ $rchanges[] = $obj;
 152+ }
 153+ }
 154+ require_once( "SpecialRecentchanges.php" );
 155+ $wgOut->disable();
 156+ rcDoOutputFeed( $rchanges, $feed );
 157+ return;
 158+ }
 159+
 160+ # Otherwise, carry on with regular output...
173161 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
174162 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
175163 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
@@ -181,9 +169,7 @@
182170
183171 $list = ChangesList::newFromUser( $wgUser );
184172 $s = $list->beginRecentChangesList();
185 - $count = $dbr->numRows( $res );
186173
187 - $rchanges = array();
188174 if ( $count ) {
189175 $counter = 1;
190176 while ( $limit ) {
@@ -194,7 +180,6 @@
195181 $rc->counter = $counter++;
196182 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
197183 --$limit;
198 - $rchanges[] = $obj;
199184 }
200185 } else {
201186 $wgOut->addWikiMsg('recentchangeslinked-noresult');
@@ -203,16 +188,4 @@
204189
205190 $dbr->freeResult( $res );
206191 $wgOut->addHTML( $s );
207 -
208 - global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
209 - $feedFormat = $wgRequest->getVal( 'feed' );
210 - if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
211 - $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) . ' [' . $wgContLanguageCode . ']';
212 - $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
213 - htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
214 -
215 - require_once( "SpecialRecentchanges.php" );
216 - $wgOut->disable();
217 - rcDoOutputFeed( $rchanges, $feed );
218 - }
219192 }
Index: trunk/phase3/includes/api/ApiFeedWatchlist.php
@@ -54,7 +54,7 @@
5555 */
5656 public function execute() {
5757
58 - global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
 58+ global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgContLanguageCode;
5959
6060 try {
6161 $params = $this->extractRequestParams();
@@ -72,7 +72,7 @@
7373 'wlprop' => 'title|user|comment|timestamp',
7474 'wldir' => 'older', // reverse order - from newest to oldest
7575 'wlend' => $dbr->timestamp($endTime), // stop at this time
76 - 'wllimit' => 50
 76+ 'wllimit' => (50 > $wgFeedLimit) ? $wgFeedLimit : 50
7777 );
7878
7979 // Check for 'allrev' parameter, and if found, show all revisions to each page on wl.
Index: trunk/phase3/includes/SpecialNewpages.php
@@ -289,6 +289,12 @@
290290 $this->title->getFullUrl() );
291291
292292 $pager = new NewPagesPager( $this, $this->opts );
 293+ $limit = $this->opts->getValue( 'limit' );
 294+ global $wgFeedLimit;
 295+ if( $limit > $wgFeedLimit ) {
 296+ $limit = $wgFeedLimit;
 297+ }
 298+ $pager->mLimit = $limit;
293299
294300 $feed->outHeader();
295301 if( $pager->getNumRows() > 0 ) {
Index: trunk/phase3/includes/PageHistory.php
@@ -108,6 +108,10 @@
109109 */
110110 if ( $wgRequest->getText("go") == 'first' ) {
111111 $limit = $wgRequest->getInt( 'limit', 50 );
 112+ global $wgFeedLimit;
 113+ if( $limit > $wgFeedLimit ) {
 114+ $limit = $wgFeedLimit;
 115+ }
112116 $wgOut->redirect( $wgTitle->getLocalURL( "action=history&limit={$limit}&dir=prev" ) );
113117 return;
114118 }
Index: trunk/phase3/includes/QueryPage.php
@@ -454,6 +454,11 @@
455455 $wgOut->addWikiMsg( 'feed-unavailable' );
456456 return;
457457 }
 458+
 459+ global $wgFeedLimit;
 460+ if( $limit > $wgFeedLimit ) {
 461+ $limit = $wgFeedLimit;
 462+ }
458463
459464 if( isset($wgFeedClasses[$class]) ) {
460465 $feed = new $wgFeedClasses[$class](

Status & tagging log