r10459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10458‎ | r10459 | r10460 >
Date:16:14, 12 August 2005
Author:nikerabbit
Status:old
Tags:
Comment:
Cleanup, html-safety and output
bug 2323 Remove "last" tabindex from history page
hopefully no new bugs
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -18,6 +18,7 @@
1919 if running prior to 4.2.0 as it causes the call to fail
2020 * (bug 3117) Fix display of upload size and type with tidy on
2121 * (bug 3076) Support MacBinary-encoded uploads from IE/Mac
 22+* (bug 2323) Remove "last" tabindex from history page
2223
2324
2425 === Caveats ===
Index: trunk/phase3/includes/PageHistory.php
@@ -42,6 +42,8 @@
4343 $this->mTitle =& $article->mTitle;
4444 $this->mNotificationTimestamp = NULL;
4545 $this->mSkin = $wgUser->getSkin();
 46+
 47+ $this->defaultLimit = 50;
4648 }
4749
4850 /**
@@ -64,8 +66,6 @@
6567 $fname = 'PageHistory::history';
6668 wfProfileIn( $fname );
6769
68 - $dbr = wfGetDB(DB_SLAVE);
69 -
7070 /*
7171 * Setup page variables.
7272 */
@@ -78,33 +78,34 @@
7979 /*
8080 * Fail if article doesn't exist.
8181 */
82 - $id = $this->mTitle->getArticleID();
83 - if( $id == 0 ) {
 82+ if( !$this->mTitle->exists() ) {
8483 $wgOut->addWikiText( wfMsg( 'nohistory' ) );
8584 wfProfileOut( $fname );
8685 return;
8786 }
8887
 88+ $dbr =& wfGetDB(DB_SLAVE);
 89+
8990 /*
9091 * Extract limit, the number of revisions to show, and
9192 * offset, the timestamp to begin at, from the URL.
9293 */
93 - $limit = $wgRequest->getInt('limit', 50);
 94+ $limit = $wgRequest->getInt('limit', $this->defaultLimit);
9495 $offset = $wgRequest->getText('offset');
9596
9697 /* Offset must be an integral. */
9798 if (!strlen($offset) || !preg_match("/^[0-9]+$/", $offset))
9899 $offset = 0;
99100 # $offset = $dbr->timestamp($offset);
100 - $dboffset = $dbr->timestamp($offset);
101 -wfdebug("offset=[$offset] dboffset=[$dboffset]\n");
 101+ $dboffset = $offset === 0 ? 0 : $dbr->timestamp($offset);
 102+ wfdebug("offset=[$offset] dboffset=[$dboffset]\n");
102103 /*
103104 * "go=last" means to jump to the last history page.
104105 */
105106 if (($gowhere = $wgRequest->getText("go")) !== NULL) {
106107 switch ($gowhere) {
107108 case "first":
108 - if (($lastid = $this->getLastOffsetForPaging($id, $limit)) === NULL)
 109+ if (($lastid = $this->getLastOffsetForPaging($this->mTitle->getArticleID(), $limit)) === NULL)
109110 break;
110111 $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset=".
111112 wfTimestamp(TS_MW, $lastid));
@@ -156,9 +157,10 @@
157158 * Print each revision, excluding the one-past-the-end, if any.
158159 */
159160 foreach (array_slice($revisions, 0, $limit) as $i => $line) {
160 - $first = !$i && $offset == 0;
 161+ $latest = !$i && $offset == 0;
 162+ $firstInList = !$i;
161163 $next = isset( $revisions[$i + 1] ) ? $revisions[$i + 1 ] : null;
162 - $s .= $this->historyLine($line, $next, $counter, $this->getNotificationTimestamp(), $first);
 164+ $s .= $this->historyLine($line, $next, $counter, $this->getNotificationTimestamp(), $latest, $firstInList);
163165 $counter++;
164166 }
165167
@@ -182,12 +184,12 @@
183185 function beginHistoryList() {
184186 global $wgTitle;
185187 $this->lastdate = '';
186 - $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
 188+ $s = wfMsgWikiHtml( 'histlegend' );
187189 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
188190 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
189 - $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
 191+ $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
190192 $s .= $this->submitButton();
191 - $s .= '<ul id="pagehistory">';
 193+ $s .= '<ul id="pagehistory">' . "\n";
192194 return $s;
193195 }
194196
@@ -208,26 +210,17 @@
209211 array(
210212 'class' => 'historysubmit',
211213 'type' => 'submit',
212 - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
213 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
214 - 'value' => wfMsg( 'compareselectedversions' ),
 214+ 'accesskey' => wfMsgHtml( 'accesskey-compareselectedversions' ),
 215+ 'title' => wfMsgHtml( 'tooltip-compareselectedversions' ),
 216+ 'value' => wfMsgHtml( 'compareselectedversions' ),
215217 ) ) )
216218 : '';
217219 }
218220
219221 /** @todo document */
220 - function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false ) {
 222+ function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false, $firstInList = false ) {
221223 global $wgLang, $wgContLang;
222224
223 - static $message;
224 - if( !isset( $message ) ) {
225 - foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
226 - $message[$msg] = wfMsg( $msg );
227 - }
228 - }
229 -
230 - $link = $this->revLink( $row );
231 -
232225 if ( 0 == $row->rev_user ) {
233226 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
234227 $ul = $this->mSkin->makeKnownLinkObj( $contribsPage,
@@ -239,26 +232,29 @@
240233 }
241234
242235 $s = '<li>';
 236+ /* This feature is not yet used according to schema */
243237 if( $row->rev_deleted ) {
244 - $s .= '<span class="deleted">';
 238+ $s .= '<span class="history-deleted">';
245239 }
246240 $curlink = $this->curLink( $row, $latest );
247241 $lastlink = $this->lastLink( $row, $next, $counter );
248 - $arbitrary = $this->diffButtons( $row, $latest, $counter );
249 - $s .= "({$curlink}) ({$lastlink}) $arbitrary {$link} <span class='user'>{$ul}</span>";
 242+ $arbitrary = $this->diffButtons( $row, $firstInList, $counter );
 243+ $link = $this->revLink( $row );
250244
 245+ $s .= "($curlink) ($lastlink) $arbitrary $link <span class='history-user'>$ul</span>";
 246+
251247 if( $row->rev_minor_edit ) {
252 - $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), $message['minoreditletter'] );
 248+ $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), wfMsgHtml( 'minoreditletter') );
253249 }
254250
255251 $s .= $this->mSkin->commentBlock( $row->rev_comment, $this->mTitle );
256 - if ($this->getNotificationTimestamp() && ($row->rev_timestamp >= $this->getNotificationTimestamp())) {
257 - $s .= wfMsg( 'updatedmarker' );
 252+ if ($notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp)) {
 253+ $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
258254 }
259255 if( $row->rev_deleted ) {
260 - $s .= "</span> " . htmlspecialchars( wfMsg( 'deletedrev' ) );
 256+ $s .= '</span> ' . wfMsgHtml( 'deletedrev' );
261257 }
262 - $s .= '</li>';
 258+ $s .= "</li>\n";
263259
264260 return $s;
265261 }
@@ -271,25 +267,22 @@
272268 return $date;
273269 } else {
274270 return $this->mSkin->makeKnownLinkObj(
275 - $this->mTitle,
276 - $date,
277 - 'oldid='.$row->rev_id );
 271+ $this->mTitle, $date, "oldid={$row->rev_id}" );
278272 }
279273 }
280274
281275 /** @todo document */
282276 function curLink( $row, $latest ) {
283277 global $wgUser;
284 - $cur = htmlspecialchars( wfMsg( 'cur' ) );
 278+ $cur = wfMsgHtml( 'cur' );
285279 if( $latest
286280 || ( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) ) {
287281 return $cur;
288282 } else {
289283 return $this->mSkin->makeKnownLinkObj(
290 - $this->mTitle,
291 - $cur,
292 - 'diff=' . $this->getLatestID($this->mTitle->getArticleID())
293 - . '&oldid=' . $row->rev_id );
 284+ $this->mTitle, $cur,
 285+ 'diff=' . $this->getLatestID() .
 286+ "&oldid={$row->rev_id}" );
294287 }
295288 }
296289
@@ -302,30 +295,33 @@
303296 return $last;
304297 } else {
305298 return $this->mSkin->makeKnownLinkObj(
306 - $this->mTitle,
307 - $last,
308 - "diff={$row->rev_id}&oldid={$next->rev_id}",
309 - '',
310 - '',
311 - ' tabindex="'.$counter.'"' );
 299+ $this->mTitle,
 300+ $last,
 301+ "diff={$row->rev_id}&oldid={$next->rev_id}"
 302+ /*,
 303+ '',
 304+ '',
 305+ "tabindex={$counter}"*/ );
312306 }
313307 }
314308
315309 /** @todo document */
316 - function diffButtons( $row, $latest, $counter ) {
 310+ function diffButtons( $row, $firstInList, $counter ) {
317311 global $wgUser;
318312 if( $this->linesonpage > 1) {
319313 $radio = array(
320314 'type' => 'radio',
321315 'value' => $row->rev_id,
322 - 'title' => wfMsg( 'selectolderversionfordiff' )
 316+# do we really need to flood this on every item?
 317+# 'title' => wfMsgHtml( 'selectolderversionfordiff' )
323318 );
 319+
324320 if( $row->rev_deleted && !$wgUser->isAllowed( 'undelete' ) ) {
325321 $radio['disabled'] = 'disabled';
326322 }
327323
328 - # XXX: move title texts to javascript
329 - if ( $latest ) {
 324+ /** @todo: move title texts to javascript */
 325+ if ( $firstInList ) {
330326 $first = wfElement( 'input', array_merge(
331327 $radio,
332328 array(
@@ -355,12 +351,14 @@
356352 }
357353
358354 /** @todo document */
359 - function getLatestOffset($id) {
 355+ function getLatestOffset( $id = null ) {
 356+ if ( $id === null) $id = $this->mTitle->getArticleID();
360357 return $this->getExtremeOffset( $id, 'max' );
361358 }
362359
363360 /** @todo document */
364 - function getEarliestOffset($id) {
 361+ function getEarliestOffset( $id = null ) {
 362+ if ( $id === null) $id = $this->mTitle->getArticleID();
365363 return $this->getExtremeOffset( $id, 'min' );
366364 }
367365
@@ -374,7 +372,8 @@
375373 }
376374
377375 /** @todo document */
378 - function getLatestID( $id ) {
 376+ function getLatestID( $id = null ) {
 377+ if ( $id === null) $id = $this->mTitle->getArticleID();
379378 $db =& wfGetDB(DB_SLAVE);
380379 return $db->selectField( 'revision',
381380 "max(rev_id)",
@@ -383,15 +382,18 @@
384383 }
385384
386385 /** @todo document */
387 - function getLastOffsetForPaging( $id, $step = 50 ) {
388 - $db =& wfGetDB(DB_SLAVE);
389 - $revision = $db->tableName( 'revision' );
390 - $sql = "SELECT rev_timestamp FROM $revision WHERE rev_page = $id " .
391 - "ORDER BY rev_timestamp ASC";
392 - $sql = $db->limitResult($sql, $step, 0);
393 - $res = $db->query( $sql, "PageHistory::getLastOffsetForPaging" );
394 - $n = $db->numRows( $res );
 386+ function getLastOffsetForPaging( $id, $step ) {
 387+ $fname = 'PageHistory::getLastOffsetForPaging';
395388
 389+ $dbr =& wfGetDB(DB_SLAVE);
 390+ $res = $dbr->select(
 391+ 'revision',
 392+ 'rev_timestamp',
 393+ "rev_page=$id",
 394+ $fname,
 395+ array('ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => $step));
 396+
 397+ $n = $dbr->numRows( $res );
396398 $last = null;
397399 while( $obj = $db->fetchObject( $res ) ) {
398400 $last = $obj->rev_timestamp;
@@ -400,10 +402,11 @@
401403 return $last;
402404 }
403405
404 - /** @todo document */
 406+ /**
 407+ * @return returns the direction of browsing watchlist
 408+ */
405409 function getDirection() {
406410 global $wgRequest;
407 -
408411 if ($wgRequest->getText("dir") == "prev")
409412 return DIR_PREV;
410413 else
@@ -413,42 +416,34 @@
414417 /** @todo document */
415418 function fetchRevisions($limit, $offset, $direction) {
416419 global $wgUser, $wgShowUpdatedMarker;
 420+ $fname = 'PageHistory::fetchRevisions';
417421
418 - /* Check one extra row to see whether we need to show 'next' and diff links */
419 - $limitplus = $limit + 1;
 422+ $dbr =& wfGetDB( DB_SLAVE );
420423
421 - $namespace = $this->mTitle->getNamespace();
422 - $title = $this->mTitle->getText();
423 - $uid = $wgUser->getID();
424 - $db =& wfGetDB( DB_SLAVE );
425 -
426 - $use_index = $db->useIndexClause( 'page_timestamp' );
427 - $revision = $db->tableName( 'revision' );
428 -
429 - $limits = $offsets = "";
430 -
431424 if ($direction == DIR_PREV)
432425 list($dirs, $oper) = array("ASC", ">=");
433 - else /* $direction = DIR_NEXT */
 426+ else /* $direction == DIR_NEXT */
434427 list($dirs, $oper) = array("DESC", "<=");
435428
436429 if ($offset)
437 - $offsets .= " AND rev_timestamp $oper '$offset' ";
 430+ $offsets = array("rev_timestamp $oper '$offset'");
 431+ else
 432+ $offsets = array();
438433
439434 $page_id = $this->mTitle->getArticleID();
440435
441 - $sql = "SELECT rev_id,rev_user," .
442 - "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,rev_deleted ".
443 - "FROM $revision $use_index " .
444 - "WHERE rev_page=$page_id " .
445 - $offsets .
446 - "ORDER BY rev_timestamp $dirs ";
447 - if ($limit)
448 - $sql = $db->limitResult($sql, $limitplus, 0);
449 - $res = $db->query($sql, "PageHistory::fetchRevisions");
 436+ $res = $dbr->select(
 437+ 'revision',
 438+ array('rev_id', 'rev_user', 'rev_comment', 'rev_user_text',
 439+ 'rev_timestamp', 'rev_minor_edit', 'rev_deleted'),
 440+ array_merge(array("rev_page=$page_id"), $offsets),
 441+ $fname,
 442+ array('ORDER BY' => "rev_timestamp $dirs",
 443+ 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
 444+ );
450445
451446 $result = array();
452 - while (($obj = $db->fetchObject($res)) != NULL)
 447+ while (($obj = $dbr->fetchObject($res)) != NULL)
453448 $result[] = $obj;
454449
455450 return $result;
@@ -457,23 +452,24 @@
458453 /** @todo document */
459454 function getNotificationTimestamp() {
460455 global $wgUser, $wgShowUpdatedMarker;
 456+ $fname = 'PageHistory::getNotficationTimestamp';
461457
462458 if ($this->mNotificationTimestamp !== NULL)
463459 return $this->mNotificationTimestamp;
464460
465 - if ($wgUser->getID() == 0 || !$wgShowUpdatedMarker)
 461+ if ($wgUser->isAnon() || !$wgShowUpdatedMarker)
466462 return $this->mNotificationTimestamp = false;
467463
468 - $db =& wfGetDB(DB_SLAVE);
 464+ $dbr =& wfGetDB(DB_SLAVE);
469465
470 - $this->mNotificationTimestamp = $db->selectField(
 466+ $this->mNotificationTimestamp = $dbr->selectField(
471467 'watchlist',
472468 'wl_notificationtimestamp',
473469 array( 'wl_namespace' => $this->mTitle->getNamespace(),
474470 'wl_title' => $this->mTitle->getDBkey(),
475471 'wl_user' => $wgUser->getID()
476472 ),
477 - "PageHistory::getNotficationTimestamp");
 473+ $fname);
478474
479475 return $this->mNotificationTimestamp;
480476 }
@@ -484,9 +480,8 @@
485481
486482 $revisions = array_slice($revisions, 0, $limit);
487483
488 - $pageid = $this->mTitle->getArticleID();
489 - $latestTimestamp = wfTimestamp(TS_MW, $this->getLatestOffset( $pageid ));
490 - $earliestTimestamp = wfTimestamp(TS_MW, $this->getEarliestOffset( $pageid ));
 484+ $latestTimestamp = wfTimestamp(TS_MW, $this->getLatestOffset());
 485+ $earliestTimestamp = wfTimestamp(TS_MW, $this->getEarliestOffset());
491486
492487 /*
493488 * When we're displaying previous revisions, we need to reverse
@@ -507,43 +502,52 @@
508503 $earliestShown = wfTimestamp(TS_MW, $revisions[count($revisions) - 1]->rev_timestamp);
509504 }
510505
511 - $firsturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}&go=first");
512 - $lasturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}");
513 - $firsttext = wfMsgHtml('histfirst');
514 - $lasttext = wfMsgHtml('histlast');
 506+ /* Don't announce the limit everywhere if it's the default */
 507+ $usefulLimit = $limit == $this->defaultLimit ? '' : $limit;
515508
516 - $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset=$latestShown&limit={$limit}");
517 - $nexturl = $wgTitle->escapeLocalURL("action=history&offset=$earliestShown&limit={$limit}");
518 -
519509 $urls = array();
520510 foreach (array(20, 50, 100, 250, 500) as $num) {
521 - $urls[] = "<a href=\"".$wgTitle->escapeLocalURL(
522 - "action=history&offset=" . wfTimestamp(TS_MW, $offset) .
523 - "&limit={$num}")."\">".$wgLang->formatNum($num)."</a>";
 511+ $urls[] = $this->MakeLink( $wgLang->formatNum($num),
 512+ array('offset' => $offset == 0 ? '' : wfTimestamp(TS_MW, $offset), 'limit' => $num, ) );
524513 }
525514
526515 $bits = implode($urls, ' | ');
527516
528517 wfDebug("latestShown=$latestShown latestTimestamp=$latestTimestamp\n");
529518 if( $latestShown < $latestTimestamp ) {
530 - $prevtext = "<a href=\"$prevurl\">".wfMsgHtml("prevn", $limit)."</a>";
531 - $lasttext = "<a href=\"$lasturl\">$lasttext</a>";
 519+ $prevtext = $this->MakeLink( wfMsgHtml("prevn", $limit),
 520+ array( 'dir' => 'prev', 'offset' => $latestShown, 'limit' => $usefulLimit ) );
 521+ $lasttext = $this->MakeLink( wfMsgHtml('histlast'),
 522+ array( 'limit' => $usefulLimit ) );
532523 } else {
533524 $prevtext = wfMsgHtml("prevn", $limit);
 525+ $lasttext = wfMsgHtml('histlast');
534526 }
535527
536528 wfDebug("earliestShown=$earliestShown earliestTimestamp=$earliestTimestamp\n");
537529 if( $earliestShown > $earliestTimestamp ) {
538 - $nexttext = "<a href=\"$nexturl\">".wfMsgHtml("nextn", $limit)."</a>";
539 - $firsttext = "<a href=\"$firsturl\">$firsttext</a>";
 530+ $nexttext = $this->MakeLink( wfMsgHtml("nextn", $limit),
 531+ array( 'offset' => $earliestShown, 'limit' => $usefulLimit ) );
 532+ $firsttext = $this->MakeLink( wfMsgHtml('histfirst'),
 533+ array( 'go' => 'first', 'limit' => $usefulLimit ) );
540534 } else {
541535 $nexttext = wfMsgHtml("nextn", $limit);
 536+ $firsttext = wfMsgHtml('histfirst');
542537 }
543538
544539 $firstlast = "($lasttext | $firsttext)";
545540
546541 return "$firstlast " . wfMsgHtml("viewprevnext", $prevtext, $nexttext, $bits);
547542 }
 543+
 544+ function MakeLink($text, $query = NULL) {
 545+ if ( $query === null ) return $text;
 546+ return $this->mSkin->makeKnownLinkObj(
 547+ $this->mTitle, $text,
 548+ wfArrayToCGI( $query, array( 'action' => 'history' )));
 549+ }
 550+
 551+
548552 }
549553
550554 ?>
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -388,6 +388,24 @@
389389 }
390390
391391 /**
 392+ * Return an HTML version of message
 393+ * Parameter replacements, if any, are done *after* parsing the wiki-text message,
 394+ * so parameters may contain HTML (eg links or form controls). Be sure
 395+ * to pre-escape them if you really do want plaintext, or just wrap
 396+ * the whole thing in htmlspecialchars().
 397+ *
 398+ * @param string $key
 399+ * @param string ... parameters
 400+ * @return string
 401+ */
 402+function wfMsgWikiHtml( $key ) {
 403+ global $wgOut;
 404+ $args = func_get_args();
 405+ array_shift( $args );
 406+ return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args );
 407+}
 408+
 409+/**
392410 * Just like exit() but makes a note of it.
393411 * Commits open transactions except if the error parameter is set
394412 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r28139* PageHistory::diffButtons...raymond12:22, 4 December 2007

Status & tagging log