Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Memento/Memento.body.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,26 @@ public function onBeforeParserFetchTemplateAndtitle(
// $mementoResource is only set if we are on an actual page
// as opposed to diff pages, edit pages, etc.
if ( $this->mementoResource ) {
$this->mementoResource->fixTemplate( $title, $parser, $id );
$this->mementoResource->fixTemplate( $title, $parser, $skip, $id );
}

return true;
}

/**
* The GetLinkColours hook, used here to verify the colour of the
* links at the Memento date
*
* @param array $linkcolour_ids Titles (DB keys) of all links to be checked
* @param array $colours Corresponding colours of the links ('', 'new', 'mw-redirect', 'stub')
*
* @return boolean indicating success to the caller
*/
public function onGetLinkColours(
$linkcolour_ids, &$colours ) {

if ( $this->mementoResource ) {
$this->mementoResource->fixLinkColours( $linkcolour_ids, $colours /*, $parser*/ );
}

return true;
Expand Down
1 change: 1 addition & 0 deletions Memento/Memento.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@
$wgHooks['ArticleViewHeader'][] = $wgMemento;
$wgHooks['BeforeParserFetchTemplateAndtitle'][] = $wgMemento;
$wgHooks['ImageBeforeProduceHTML'][] = $wgMemento;
$wgHooks['GetLinkColours'][] = $wgMemento;
44 changes: 42 additions & 2 deletions Memento/MementoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public static function mementoPageResourceFactory( DatabaseBase $db, $article, $
*
* @return array containing the text, finalTitle, and deps
*/
public function fixTemplate( Title $title, Parser $parser, &$id ) {
public function fixTemplate( Title $title, Parser $parser, &$skip, &$id ) {

$parser->disableCache();

Expand Down Expand Up @@ -534,11 +534,51 @@ public function fixTemplate( Title $title, Parser $parser, &$id ) {
} else {
// if we get something prior to the first memento, just
// go with the first one
$id = $firstRev->getId();
$skip = true;
}
}
}

/**
* fixLinkColour
*
* This code ensures that the links have the colour they had at the
* Memento time.
*
* @fixme make this compatible with parser cache
* @fixme manage the case where an article was created then deleted, and the datetime is after the deletion
* @fixme check if the link is a redirect or a stub (small article lesser than a threshold)
* @param array $titles
* @param array $colours
*
* @return array containing the text, finalTitle, and deps
*/
public function fixLinkColours( $titles, &$colours /*, Parser $parser*/ ) {

//$parser->disableCache();

$request = $this->article->getContext()->getRequest();

if ( $request->getHeader( 'ACCEPT-DATETIME' ) ) {

$requestDatetime = $request->getHeader( 'ACCEPT-DATETIME' );

$mwMementoTimestamp = $this->parseRequestDateTime(
$requestDatetime );

foreach ( $titles as $id => $s ) {

$title = Title::newFromID( $id );
$pdbk = $title->getPrefixedDBkey();
$firstRev = $title->getFirstRevision();
if ( is_null($firstRev) || $firstRev->getTimestamp() > $mwMementoTimestamp ) {
$colours[$pdbk] = 'new';
} else {
$colours[$pdbk] = '';
}
}
}
}

/**
* alterHeaders
Expand Down