-
Notifications
You must be signed in to change notification settings - Fork 0
/
PageCreator.php
120 lines (94 loc) · 3.66 KB
/
PageCreator.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
<?php
define( 'PPP_PAGECREATOR', 'PAGECREATOR' );
define( 'PPP_CREATIONTIMESTAMP', 'CREATIONTIMESTAMP' );
$GLOBALS['wgHooks']['LanguageGetMagic'][] = 'wfPppWikiWords';
$GLOBALS['wgHooks']['MagicWordwgVariableIDs'][] = 'wfPppDeclareVarIds';
$GLOBALS['wgHooks']['ParserGetVariableValueSwitch'][] = 'wfPppAssignAValue';
$GLOBALS['wgExtensionCredits']['variable'][] = array(
'name' => 'PageCreator',
'author' => 'Pierro78 (sql query from PLX)',
'version' => '0.3',
'description' => 'Get Page Creator in variable PAGECREATOR, Creation TimeStamp in CREATIONTIMESTAMP',
'url' => 'http://www.mediawiki.org/wiki/Extension:PageCreator',
);
function wfPppWikiWords( &$magicWords, $langCode ) {
// tell MediaWiki that all {{NiftyVar}}, {{NIFTYVAR}}, {{CoolVar}},
// {{COOLVAR}} and all case variants found in wiki text should be mapped to
// magic ID 'mycustomvar1' (0 means case-insensitive)
$magicWords[PPP_PAGECREATOR] = array( 0, PPP_PAGECREATOR);
$magicWords[PPP_CREATIONTIMESTAMP] = array( 0, PPP_CREATIONTIMESTAMP);
// must do this or you will silence every LanguageGetMagic hook after this!
return true;
}
function wfPppAssignAValue( &$parser, &$cache, &$magicWordId, &$ret ) {
if ( PPP_PAGECREATOR == $magicWordId ) {
global $wgUser;
$revuser = $wgUser->getName();
$ret = $revuser;
global $wgArticle;
if (isset($wgArticle)){
$myArticle=$wgArticle;
}
else{
$myTitle=$parser->getTitle();
$myArticle=new Article($myTitle);
}
$dbr = wfGetDB( DB_SLAVE );
$revTable = $dbr->tableName( 'revision' );
$pageId = $myArticle->getId();
$q0 = "select rev_user_text from ".$revTable." where rev_page=".$pageId." order by rev_timestamp asc limit 1";
if(($res0 = mysql_query($q0)) && ($row0 = mysql_fetch_object($res0))) {
$ret=$row0->rev_user_text;
}
else{
$myTitle=$parser->getTitle();
$articleId=$myTitle->getArticleID();
}
}
if ( PPP_CREATIONTIMESTAMP == $magicWordId ) {
global $wgUser;
$revuser = $wgUser->getName();
$ret = $revuser;
global $wgArticle;
if (isset($wgArticle)) {
$myArticle=$wgArticle;
}
else {
$myTitle=$parser->getTitle();
$myArticle=new Article($myTitle);
}
$dbr = wfGetDB( DB_SLAVE );
$revTable = $dbr->tableName( 'revision' );
$pageId = $myArticle->getId();
$q0 = "select rev_timestamp from ".$revTable." where rev_page=".$pageId." order by rev_timestamp asc limit 1";
if(($res0 = mysql_query($q0)) && ($row0 = mysql_fetch_object($res0))) {
$ret=$row0->rev_timestamp;
}
else {
$myTitle=$parser->getTitle();
$articleId=$myTitle->getArticleID();
}
}
// We must return true for two separate reasons:
// 1. To permit further callbacks to run for this hook.
// They might override our value but that's life.
// Returning false would prevent these future callbacks from running.
// 2. At the same time, "true" indicates we found a value.
// Returning false would the set variable value to null.
//
// In other words, true means "we found a value AND other
// callbacks will run," and false means "we didn't find a value
// AND abort future callbacks." It's a shame these two meanings
// are mixed in the same return value. So as a rule, return
// true whether we found a value or not.
return true;
}
function wfPppDeclareVarIds( &$customVariableIds ) {
// $customVariableIds is where MediaWiki wants to store its list of custom
// variable IDs. We oblige by adding ours:
$customVariableIds[] = PPP_PAGECREATOR;
$customVariableIds[] = PPP_CREATIONTIMESTAMP;
// must do this or you will silence every MagicWordwgVariableIds hook
// registered after this!
return true;
}