diff --git a/Memento/Memento.body.php b/Memento/Memento.body.php index ff54219..30a0b17 100644 --- a/Memento/Memento.body.php +++ b/Memento/Memento.body.php @@ -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; diff --git a/Memento/Memento.php b/Memento/Memento.php index 6ee1f2d..4de9147 100644 --- a/Memento/Memento.php +++ b/Memento/Memento.php @@ -95,3 +95,4 @@ $wgHooks['ArticleViewHeader'][] = $wgMemento; $wgHooks['BeforeParserFetchTemplateAndtitle'][] = $wgMemento; $wgHooks['ImageBeforeProduceHTML'][] = $wgMemento; +$wgHooks['GetLinkColours'][] = $wgMemento; diff --git a/Memento/MementoResource.php b/Memento/MementoResource.php index 85bb2ab..d0984b0 100644 --- a/Memento/MementoResource.php +++ b/Memento/MementoResource.php @@ -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(); @@ -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