Skip to content

Commit 8b2ece4

Browse files
committed
merging in 'fixing-integration-tests' branch
2 parents 27c2678 + 2c08a37 commit 8b2ece4

40 files changed

+6359
-236
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/node_modules
33
/vendor
44
/composer.lock
5+
build

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ endif
150150
# Pre-requisites: export TESTHOST=<hostname of the host under test>
151151
#
152152

153-
defaults-integration-test: standard-integration-test 302-style-time-negotiation-recommended-headers-integration-test friendly-error-integration-test
153+
defaults-integration-test: standard-integration-test 302-style-time-negotiation-recommended-headers-integration-test friendly-error-integration-test timemap-integration-test
154154

155155
# run tests on all non-configurable items
156156
standard-integration-test: check-integration-env ${TESTOUTPUTDIR}
@@ -174,6 +174,18 @@ standard-integration-test: check-integration-env ${TESTOUTPUTDIR}
174174
@echo "#########################"
175175
@echo ""
176176

177+
# run all of the tests on timemaps
178+
timemap-integration-test: check-integration-env ${TESTOUTPUTDIR}
179+
@echo "timemap-integration-test"
180+
@echo ""
181+
@echo "#########################"
182+
@echo "Running timemap integration tests"
183+
cd ${TESTOUTPUTDIR}; phpunit --include-path "${STARTINGDIR}/../../Memento:${STARTINGDIR}/../../tests/lib:${TESTDATADIR}" --group timemap ${STARTINGDIR}/../../tests/integration
184+
@echo "Done with integration tests"
185+
@echo "#########################"
186+
@echo ""
187+
188+
177189
# run all of the friendly error integration tests
178190
friendly-error-integration-test: check-integration-env ${TESTOUTPUTDIR}
179191
@echo "friendly-error-integration-test"

Memento.php

Lines changed: 0 additions & 1 deletion
This file was deleted.

Memento/Memento.body.php

Lines changed: 0 additions & 152 deletions
This file was deleted.

Memento/Memento.php

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,60 @@
2323
*/
2424

2525
/**
26-
* Ensure that this file is only executed in the right context.
26+
* Main Memento class, used by hooks.
27+
*
28+
* This class handles the entry point from Mediawiki and performs
29+
* the mediation over the real work. The goal is to separate
30+
* the Mediawiki setup code from the Memento code as much as possible
31+
* for clarity, testing, maintainability, etc.
2732
*
28-
2933
*/
30-
if ( !defined( 'MEDIAWIKI' ) ) {
34+
if ( ! defined( 'MEDIAWIKI' ) ) {
3135
echo "Not a valid entry point";
3236
exit( 1 );
3337
}
3438

35-
// Set up the extension
36-
$wgExtensionCredits['specialpage'][] = [
37-
'name' => 'Memento',
38-
'descriptionmsg' => 'memento-desc',
39-
'url' => 'https://www.mediawiki.org/wiki/Extension:Memento',
40-
'author' => [
41-
'Harihar Shankar',
42-
'Herbert Van de Sompel',
43-
'Robert Sanderson',
44-
'Shawn M. Jones'
45-
],
46-
'version' => '2.1.4'
47-
];
39+
class Memento {
4840

49-
// Set up the messages file
50-
$wgMessagesDirs['Memento'] = __DIR__ . '/i18n';
51-
$wgExtensionMessagesFiles['MementoAlias'] = __DIR__ . '/Memento.alias.php';
41+
/**
42+
* The ArticleViewHeader hook, used to alter the headers before the rest
43+
* of the data is loaded.
44+
*
45+
* Note: this is not called when the Edit, Diff or History pages are loaded.
46+
*
47+
* @param Article &$article pointer to the Article Object from the hook
48+
* @param bool &$outputDone pointer to variable that indicates that
49+
* the output should be terminated
50+
* @param bool &$pcache pointer to variable that indicates whether the parser
51+
* cache should try retrieving the cached results
52+
*
53+
* @return bool indicating success to the caller
54+
*/
55+
public static function onArticleViewHeader(
56+
&$article, &$outputDone, &$pcache
57+
) {
58+
// avoid processing Mementos for nonexistent pages
59+
// if we're an article, do memento processing, otherwise don't worry
60+
// if we're a diff page, Memento doesn't make sense
61+
if ( $article->getTitle()->isKnown() ) {
5262

53-
// Set up the core classes used by Memento
54-
$wgAutoloadClasses['Memento'] = __DIR__ . '/Memento.body.php';
55-
$wgAutoloadClasses['MementoResource'] = __DIR__ . '/MementoResource.php';
63+
$revision = $article->getRevisionFetched();
5664

57-
// Set up the Memento (URI-M) Classes
58-
$wgAutoloadClasses['MementoResourceDirectlyAccessed'] =
59-
__DIR__ . '/MementoResourceDirectlyAccessed.php';
65+
// avoid processing Mementos for bad revisions,
66+
// let MediaWiki handle that case instead
67+
if ( is_object( $revision ) ) {
6068

61-
// Set up the Original page (URI-R) Classes
62-
$wgAutoloadClasses['OriginalResourceDirectlyAccessed'] =
63-
__DIR__ . '/OriginalResourceDirectlyAccessed.php';
69+
$db = wfGetDB( DB_REPLICA );
70+
$oldID = $article->getOldID();
71+
$request = $article->getContext()->getRequest();
6472

65-
// set up the Time Map (URI-T) classes
66-
$wgAutoloadClasses['TimeMapResource'] = __DIR__ . '/TimeMapResource.php';
67-
$wgAutoloadClasses['TimeMapFullResource'] = __DIR__ . '/TimeMapFullResource.php';
68-
$wgAutoloadClasses['TimeMapPivotAscendingResource'] =
69-
__DIR__ . '/TimeMapPivotAscendingResource.php';
70-
$wgAutoloadClasses['TimeMapPivotDescendingResource'] =
71-
__DIR__ . '/TimeMapPivotDescendingResource.php';
72-
$wgAutoloadClasses['TimeMap'] = __DIR__ . '/TimeMap.php';
73-
$wgSpecialPages['TimeMap'] = 'TimeMap';
73+
$mementoResource = MementoResource::mementoPageResourceFactory( $db, $article, $oldID );
7474

75-
// set up the Time Gate (URI-G) classes
76-
$wgAutoloadClasses['TimeGateResourceFrom302TimeNegotiation'] =
77-
__DIR__ . '/TimeGateResourceFrom302TimeNegotiation.php';
78-
$wgAutoloadClasses['TimeNegotiator'] = __DIR__ . '/TimeNegotiator.php';
79-
$wgAutoloadClasses['TimeGate'] = __DIR__ . '/TimeGate.php';
80-
$wgSpecialPages['TimeGate'] = 'TimeGate';
75+
$mementoResource->alterHeaders();
76+
}
77+
}
8178

82-
// default settings values
83-
$wgMementoIncludeNamespaces = [ 0 ];
84-
$wgMementoTimemapNumberOfMementos = 500;
85-
$wgMementoTimeNegotiationForThumbnails = false;
79+
return true;
80+
}
8681

87-
// instantiate entry point
88-
$wgMemento = new Memento();
89-
90-
// Set up the hooks for this class
91-
$wgHooks['ArticleViewHeader'][] = $wgMemento;
92-
$wgHooks['BeforeParserFetchTemplateAndtitle'][] = $wgMemento;
93-
$wgHooks['ImageBeforeProduceHTML'][] = $wgMemento;
82+
}

Memento/extension.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "Memento",
3+
"version": "2.2a",
4+
"author": [
5+
"Harihar Shankar",
6+
"Herbert Van de Sompel",
7+
"Robert Sanderson",
8+
"Shawn M. Jones"
9+
],
10+
"url": "https://www.mediawiki.org/wiki/Extension:Memento",
11+
"descriptionmsg": "memento-desc",
12+
"type": "specialpage",
13+
"requires": {
14+
"MediaWiki": ">= 1.31.1"
15+
},
16+
"SpecialPages": {
17+
"TimeMap": "TimeMap",
18+
"TimeGate": "TimeGate"
19+
},
20+
"MessagesDirs": {
21+
"Memento": [
22+
"i18n"
23+
]
24+
},
25+
"ExtensionMessagesFiles": {
26+
"MementoAlias": "includes/Memento.alias.php"
27+
},
28+
"AutoloadClasses": {
29+
"Memento": "Memento.php",
30+
"MementoResource": "includes/MementoResource.php",
31+
"MementoResourceDirectlyAccessed": "includes/MementoResourceDirectlyAccessed.php",
32+
"OriginalResourceDirectlyAccessed": "includes/OriginalResourceDirectlyAccessed.php",
33+
"TimeMapResource": "includes/TimeMapResource.php",
34+
"TimeMapFullResource": "includes/TimeMapFullResource.php",
35+
"TimeMapPivotAscendingResource": "includes/TimeMapPivotAscendingResource.php",
36+
"TimeMapPivotDescendingResource": "includes/TimeMapPivotDescendingResource.php",
37+
"TimeMap": "includes/TimeMap.php",
38+
"TimeGateResourceFrom302TimeNegotiation": "includes/TimeGateResourceFrom302TimeNegotiation.php",
39+
"TimeNegotiator": "includes/TimeNegotiator.php",
40+
"TimeGate": "includes/TimeGate.php"
41+
},
42+
"Hooks": {
43+
"ArticleViewHeader": [ "Memento::onArticleViewHeader" ]
44+
},
45+
"config": {
46+
"MementoIncludeNamespaces": {
47+
"value": [
48+
0
49+
]
50+
},
51+
"MementoTimemapNumberOfMementos": {
52+
"value": 500
53+
},
54+
"MementoTimeNegotiationForThumbnails": {
55+
"value": false
56+
},
57+
"Memento": {
58+
"value": {}
59+
}
60+
},
61+
"manifest_version": 2
62+
}

Memento/i18n/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"timemap-title" : "Memento TimeMap",
1111
"timemap-welcome-message" : "This Special Page takes care of creating Memento TimeMaps for your wiki, which are machine-readable versions of the history of the pages they represent.<br />For a specific page, it lists the Mementos archived for that page.<br /><br />To see Memento in action, either follow instructions from the [https://www.mediawiki.org/wiki/Extension:Memento MediaWiki Extension] page or type in the address of the wiki page in this format:<br /><pre>http://yourwikisite/wiki/index.php/Special:TimeMap/YourPage</pre><br />where, the name that follows the TimeMap URL is the title of the article.",
1212
"timemap-404-title" : "Either the resource does not exist or the namespace is not understood by memento for the title: '$1'.",
13-
"timemap-specialpage-listing" : "Memento",
1413
"timegate-400-date" : "Error 400: Requested date '$1' not parseable.<br /><b>First Memento:</b> $2<br /><b>Last Memento:</b> $3<br />",
1514
"timemap-desc" : "The Memento TimeMap retrieves the revision list of an article including the datetime when the revision was created. The revision list is serialized as application/link-format. Please see http://mementoweb.org for more information.",
1615
"timemap-403-inaccessible" : "Error 403: Resource '$1' is not accessible.",

0 commit comments

Comments
 (0)