From 94132b791394af7c6ebcc2fab93b464250a75577 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Fri, 12 Aug 2005 16:14:20 +0000 Subject: [PATCH] Cleanup, html-safety and output bug 2323 Remove "last" tabindex from history page hopefully no new bugs --- RELEASE-NOTES | 1 + includes/GlobalFunctions.php | 18 +++ includes/PageHistory.php | 226 ++++++++++++++++++----------------- 3 files changed, 134 insertions(+), 111 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 69f2c971ab..e3efc8af1a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -18,6 +18,7 @@ Misc work going on..... if running prior to 4.2.0 as it causes the call to fail * (bug 3117) Fix display of upload size and type with tidy on * (bug 3076) Support MacBinary-encoded uploads from IE/Mac +* (bug 2323) Remove "last" tabindex from history page === Caveats === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index d3c07c88e0..a95f5f3d55 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -387,6 +387,24 @@ function wfMsgHtml( $key ) { return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key, true ) ), $args ); } +/** + * Return an HTML version of message + * Parameter replacements, if any, are done *after* parsing the wiki-text message, + * so parameters may contain HTML (eg links or form controls). Be sure + * to pre-escape them if you really do want plaintext, or just wrap + * the whole thing in htmlspecialchars(). + * + * @param string $key + * @param string ... parameters + * @return string + */ +function wfMsgWikiHtml( $key ) { + global $wgOut; + $args = func_get_args(); + array_shift( $args ); + return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args ); +} + /** * Just like exit() but makes a note of it. * Commits open transactions except if the error parameter is set diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 5079a3b9d9..f06bf62699 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -42,6 +42,8 @@ class PageHistory { $this->mTitle =& $article->mTitle; $this->mNotificationTimestamp = NULL; $this->mSkin = $wgUser->getSkin(); + + $this->defaultLimit = 50; } /** @@ -64,8 +66,6 @@ class PageHistory { $fname = 'PageHistory::history'; wfProfileIn( $fname ); - $dbr = wfGetDB(DB_SLAVE); - /* * Setup page variables. */ @@ -78,33 +78,34 @@ class PageHistory { /* * Fail if article doesn't exist. */ - $id = $this->mTitle->getArticleID(); - if( $id == 0 ) { + if( !$this->mTitle->exists() ) { $wgOut->addWikiText( wfMsg( 'nohistory' ) ); wfProfileOut( $fname ); return; } + $dbr =& wfGetDB(DB_SLAVE); + /* * Extract limit, the number of revisions to show, and * offset, the timestamp to begin at, from the URL. */ - $limit = $wgRequest->getInt('limit', 50); + $limit = $wgRequest->getInt('limit', $this->defaultLimit); $offset = $wgRequest->getText('offset'); /* Offset must be an integral. */ if (!strlen($offset) || !preg_match("/^[0-9]+$/", $offset)) $offset = 0; # $offset = $dbr->timestamp($offset); - $dboffset = $dbr->timestamp($offset); -wfdebug("offset=[$offset] dboffset=[$dboffset]\n"); + $dboffset = $offset === 0 ? 0 : $dbr->timestamp($offset); + wfdebug("offset=[$offset] dboffset=[$dboffset]\n"); /* * "go=last" means to jump to the last history page. */ if (($gowhere = $wgRequest->getText("go")) !== NULL) { switch ($gowhere) { case "first": - if (($lastid = $this->getLastOffsetForPaging($id, $limit)) === NULL) + if (($lastid = $this->getLastOffsetForPaging($this->mTitle->getArticleID(), $limit)) === NULL) break; $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset=". wfTimestamp(TS_MW, $lastid)); @@ -156,9 +157,10 @@ wfdebug("offset=[$offset] dboffset=[$dboffset]\n"); * Print each revision, excluding the one-past-the-end, if any. */ foreach (array_slice($revisions, 0, $limit) as $i => $line) { - $first = !$i && $offset == 0; + $latest = !$i && $offset == 0; + $firstInList = !$i; $next = isset( $revisions[$i + 1] ) ? $revisions[$i + 1 ] : null; - $s .= $this->historyLine($line, $next, $counter, $this->getNotificationTimestamp(), $first); + $s .= $this->historyLine($line, $next, $counter, $this->getNotificationTimestamp(), $latest, $firstInList); $counter++; } @@ -182,12 +184,12 @@ wfdebug("offset=[$offset] dboffset=[$dboffset]\n"); function beginHistoryList() { global $wgTitle; $this->lastdate = ''; - $s = '

' . wfMsg( 'histlegend' ) . '

'; + $s = wfMsgWikiHtml( 'histlegend' ); $s .= '
'; $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey()); - $s .= "\n"; + $s .= "\n"; $s .= $this->submitButton(); - $s .= '