X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPageHistory.php;h=4202debf2e4eef81815d9f3b721a0712159df579;hb=f059e0952407f368a6fbcccefe57982c4d63ba2a;hp=05f0b9d3003f36a30a46a8d25e07849397782d59;hpb=83f95c241fff133abb2d67c6b8bc638f390cdd5a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 05f0b9d300..4202debf2e 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -1,299 +1,373 @@ history() to print the + * history. + * */ - -include_once ( "SpecialValidate.php" ) ; - class PageHistory { + const DIR_PREV = 0; + const DIR_NEXT = 1; + var $mArticle, $mTitle, $mSkin; var $lastdate; var $linesonpage; - function PageHistory( $article ) { + var $mNotificationTimestamp; + var $mLatestId = null; + + /** + * Construct a new PageHistory. + * + * @param Article $article + * @returns nothing + */ + function __construct($article) { + global $wgUser; + $this->mArticle =& $article; $this->mTitle =& $article->mTitle; + $this->mNotificationTimestamp = NULL; + $this->mSkin = $wgUser->getSkin(); } - # This shares a lot of issues (and code) with Recent Changes - + /** + * Print the history page for an article. + * + * @returns nothing + */ function history() { - global $wgUser, $wgOut, $wgLang, $wgShowUpdatedMarker, $wgRequest, - $wgTitle, $wgUseValidation ; + global $wgOut, $wgRequest, $wgTitle; - # If page hasn't changed, client can cache this + /* + * Allow client caching. + */ - if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){ - # Client cache fresh and headers sent, nothing more to do. + if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ) + /* Client cache fresh and headers sent, nothing more to do. */ return; - } + $fname = 'PageHistory::history'; wfProfileIn( $fname ); - $wgOut->setPageTitle( $this->mTitle->getPRefixedText() ); - $wgOut->setSubtitle( wfMsg( 'revhistory' ) ); + /* + * Setup page variables. + */ + $wgOut->setPageTitle( wfMsg( 'history-title', $this->mTitle->getPrefixedText() ) ); + $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) ); $wgOut->setArticleFlag( false ); $wgOut->setArticleRelated( true ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->setSyndicated( true ); + $wgOut->setFeedAppendQuery( 'action=history' ); - $id = $this->mTitle->getArticleID(); - if( $id == 0 ) { - $wgOut->addHTML( wfMsg( 'nohistory' ) ); + $logPage = SpecialPage::getTitleFor( 'Log' ); + $logLink = $this->mSkin->makeKnownLinkObj( $logPage, wfMsgHtml( 'viewpagelogs' ), 'page=' . $this->mTitle->getPrefixedUrl() ); + $wgOut->setSubtitle( $logLink ); + + $feedType = $wgRequest->getVal( 'feed' ); + if( $feedType ) { wfProfileOut( $fname ); - return; + return $this->feed( $feedType ); } - $limit = $wgRequest->getInt('limit'); - if (!$limit) $limit = 50; - $offset = $wgRequest->getText('offset'); - if (!isset($offset) || !preg_match("/^[0-9]+$/", $offset)) $offset = 0; - - /* Check one extra row to see whether we need to show 'next' and diff links */ - $limitplus = $limit + 1; - - $namespace = $this->mTitle->getNamespace(); - $title = $this->mTitle->getText(); - $uid = $wgUser->getID(); - $db =& wfGetDB( DB_SLAVE ); - if ($uid && $wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) - $notificationtimestamp = $db->selectField( 'watchlist', - 'wl_notificationtimestamp', - array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle->getDBkey(), 'wl_user' => $uid ), - $fname ); - else $notificationtimestamp = false; - - $use_index = $db->useIndexClause( 'page_timestamp' ); - $revision = $db->tableName( 'revision' ); - - $limits = $offsets = ""; - $dir = 0; - if ($wgRequest->getText("dir") == "prev") - $dir = 1; - - list($dirs, $oper) = array("DESC", "<"); - if ($dir) { - list($dirs, $oper) = array("ASC", ">"); + /* + * Fail if article doesn't exist. + */ + if( !$this->mTitle->exists() ) { + $wgOut->addWikiText( wfMsg( 'nohistory' ) ); + wfProfileOut( $fname ); + return; } - if ($offset) - $offsets .= " AND rev_timestamp $oper '$offset' "; - if ($limit) - $limits .= " LIMIT $limitplus "; - - $sql = "SELECT rev_id,rev_user," . - "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,rev_deleted ". - "FROM $revision $use_index " . - "WHERE rev_page=$id " . - $offsets . - "ORDER BY rev_timestamp $dirs " . - $limits; - $res = $db->query( $sql, $fname ); - - $revs = $db->numRows( $res ); - - if( $revs < $limitplus ) // the sql above tries to fetch one extra - $this->linesonpage = $revs; - else - $this->linesonpage = $revs - 1; - - $atend = ($revs < $limitplus); - - $this->mSkin = $wgUser->getSkin(); - - $pages = array(); - $lowts = 0; - while ($line = $db->fetchObject($res)) { - $pages[] = $line; + /* + * "go=first" means to jump to the last (earliest) history page. + * This is deprecated, it no longer appears in the user interface + */ + if ( $wgRequest->getText("go") == 'first' ) { + $limit = $wgRequest->getInt( 'limit', 50 ); + $wgOut->redirect( $wgTitle->getLocalURL( "action=history&limit={$limit}&dir=prev" ) ); + return; } - if ($dir) $pages = array_reverse($pages); - if (count($pages) > 1) - $lowts = $pages[count($pages) - 2]->rev_timestamp; - else - $lowts = $pages[count($pages) - 1]->rev_timestamp; - - $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset={$offset}&limit={$limit}"); - $nexturl = $wgTitle->escapeLocalURL("action=history&offset={$lowts}&limit={$limit}"); - $urls = array(); - foreach (array(20, 50, 100, 250, 500) as $num) { - $urls[] = "escapeLocalURL( - "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num).""; - } - $bits = implode($urls, ' | '); - $numbar = wfMsg("viewprevnext", - "".wfMsg("prevn", $limit)."", - "".wfMsg("nextn", $limit)."", - $bits); - - $s = $numbar; - $s .= $this->beginHistoryList(); - $counter = 1; - foreach($pages as $i => $line) { - $first = ($counter == 1 && $offset == 0); - $next = isset( $pages[$i + 1] ) ? $pages[$i + 1 ] : null; - $s .= $this->historyLine( $line, $next, $counter, $notificationtimestamp, $first ); - $counter++; - } - $s .= $this->endHistoryList( !$atend ); - $s .= $numbar; - - # Validation line - if ( isset ( $wgUseValidation ) && $wgUseValidation ) { - $s .= "

" . Validation::link2statistics ( $this->mArticle ) . "

" ; - } - - $wgOut->addHTML( $s ); + wfRunHooks( 'PageHistoryBeforeList', array( &$this->mArticle ) ); + + /** + * Do the list + */ + $pager = new PageHistoryPager( $this ); + $this->linesonpage = $pager->getNumRows(); + $wgOut->addHTML( + $pager->getNavigationBar() . + $this->beginHistoryList() . + $pager->getBody() . + $this->endHistoryList() . + $pager->getNavigationBar() + ); wfProfileOut( $fname ); } + /** + * Creates begin of history list with a submit button + * + * @return string HTML output + */ function beginHistoryList() { global $wgTitle; $this->lastdate = ''; - $s = '

' . wfMsg( 'histlegend' ) . '

'; + $s = wfMsgExt( 'histlegend', array( 'parse') ); $s .= '
'; $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey()); + + // The following line is SUPPOSED to have double-quotes around the + // $prefixedkey variable, because htmlspecialchars() doesn't escape + // single-quotes. + // + // On at least two occasions people have changed it to single-quotes, + // which creates invalid HTML and incorrect display of the resulting + // link. + // + // Please do not break this a third time. Thank you for your kind + // consideration and cooperation. + // $s .= "\n"; + $s .= $this->submitButton(); - $s .= '