-
Notifications
You must be signed in to change notification settings - Fork 0
/
News.php
126 lines (94 loc) · 3.97 KB
/
News.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* News extension - shows recent changes on a wiki page.
*
* @file
* @ingroup Extensions
* @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler
* @licence GNU General Public Licence 2.0 or later
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'News',
'author' => 'Daniel Kinzler, brightbyte.de',
'url' => 'https://mediawiki.org/wiki/Extension:News',
'descriptionmsg' => 'newsextension-desc',
);
$wgMessagesDirs['NewsExtension'] = __DIR__ . '/i18n';
$wgNewsFeedURLPattern = false; // pattern for feed-URLs; useful when using rewrites for canonical feed URLs
$wgNewsFeedUserPattern = false; // pattern to use for the author-field in feed items.
$wgAutoloadClasses['NewsRenderer'] = dirname( __FILE__ ) . '/NewsRenderer.php';
$wgAutoloadClasses['NewsFeedPage'] = dirname( __FILE__ ) . '/NewsRenderer.php';
$wgHooks['ArticleFromTitle'][] = 'wfNewsArticleFromTitle';
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'wfNewsSkinTemplateOutputPageBeforeExec';
$wgHooks['ParserFirstCallInit'][] = 'wfNewsSetHooks';
//FIXME: find a way to override the feed URLs generated by OutputPage::getHeadLinks
function wfNewsSetHooks( $parser ) {
$parser->setHook( 'news', 'wfNewsTag' );
$parser->setHook( 'newsfeed', 'wfNewsFeedTag' );
$parser->setHook( 'newsfeedlink', 'wfNewsFeedLinkTag' );
return true;
}
function wfNewsTag( $templatetext, $argv, $parser ) {
$context = RequestContext::getMain();
$parser->getOutput()->updateCacheExpiry( 0 ); //TODO: use smart cache & purge...?
$renderer = new NewsRenderer($context, $templatetext, $argv, $parser);
return $renderer->renderNews();
}
function wfNewsFeedTag( $templatetext, $argv, $parser ) {
$out = $parser->getOutput();
$out->updateCacheExpiry( 0 ); //TODO: use smart cache & purge...?
$out->setSyndicated( true );
$silent = @$argv['silent'];
if ( $silent === 'false' || $silent === 'no' || $silent === '0' )
$silent = false;
if ( $silent ) return "";
$context = RequestContext::getMain();
$renderer = new NewsRenderer($context, $templatetext, $argv, $parser);
$html = $renderer->renderFeedPreview();
return $html;
}
function wfNewsFeedLinkTag( $linktext, $argv, $parser ) {
return NewsRenderer::renderFeedLink($linktext, $argv, $parser);
}
function wfNewsArticleFromTitle( $title, &$article, IContextSource $context ) {
global $wgFeedClasses;
$fname = 'extension/News: wfNewsArticleFromTitle';
$request = $context->getRequest();
$ns = $title->getNamespace();
if ($ns < 0 || $ns == NS_SPECIAL || $ns == NS_MEDIAWIKI) return true;
$format = $request->getVal( 'feed' );
if (!$format) return true;
$format = strtolower( trim($format) );
$action = strtolower( trim( $request->getVal( 'action', 'view' ) ) );
if ($action != 'view' && $action != 'purge') return true;
if ( !isset($wgFeedClasses[$format] ) ) {
wfDebug( "$fname: unknown feed format: $format \n" );
wfHttpError(400, "Bad Request", "unknown feed format: " . $format); //TODO: better code & text
return false;
}
if (!$title->exists()) {
wfDebug( "$fname: feed page not found: " . $title->getPrefixedDBKey() . "\n" );
wfHttpError(404, "Not Found", "feed page not found: " . $title->getPrefixedText()); //TODO: better text
return false;
}
wfDebug( "$fname: handling feed request for " . $title->getPrefixedDBKey() . "\n" );
$article = new NewsFeedPage( $title, $format );
return false;
}
function wfNewsSkinTemplateOutputPageBeforeExec( $skin, $tpl ) {
$feeds = $tpl->data['feeds'];
if (!$feeds) return true;
$title = $skin->getTitle(); //hack...
foreach ($feeds as $format => $e) {
$e['href'] = NewsRenderer::getFeedURL( $title, $format );
$feeds[$format] = $e;
}
$tpl->set( 'feeds', $feeds );
return true;
}