|
23 | 23 | */ |
24 | 24 |
|
25 | 25 | /** |
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. |
27 | 32 | * |
28 | | -
|
29 | 33 | */ |
30 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
| 34 | +if ( ! defined( 'MEDIAWIKI' ) ) { |
31 | 35 | echo "Not a valid entry point"; |
32 | 36 | exit( 1 ); |
33 | 37 | } |
34 | 38 |
|
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 { |
48 | 40 |
|
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() ) { |
52 | 62 |
|
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(); |
56 | 64 |
|
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 ) ) { |
60 | 68 |
|
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(); |
64 | 72 |
|
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 ); |
74 | 74 |
|
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 | + } |
81 | 78 |
|
82 | | -// default settings values |
83 | | -$wgMementoIncludeNamespaces = [ 0 ]; |
84 | | -$wgMementoTimemapNumberOfMementos = 500; |
85 | | -$wgMementoTimeNegotiationForThumbnails = false; |
| 79 | + return true; |
| 80 | + } |
86 | 81 |
|
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 | +} |
0 commit comments