Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4102000
Hooks.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
Hooks.php
View Options
<?php
namespace
MediaWiki\Extension\CiteThisPage
;
use
MediaWiki\Config\Config
;
use
MediaWiki\SpecialPage\SpecialPage
;
use
MediaWiki\Title\Title
;
class
Hooks
implements
\MediaWiki\Hook\SidebarBeforeOutputHook
{
/**
* Checks, if the "cite this page" link should be added. By default the link is added to all
* pages in the main namespace, and additionally to pages, which are in one of the namespaces
* named in $wgCiteThisPageAdditionalNamespaces.
*
* @param Title|null $title
* @param Config|null $config
* @return bool
*/
private
static
function
shouldAddLink
(
?
Title
$title
,
?
Config
$config
)
{
if
(
!
$title
||
!
$config
)
{
return
false
;
}
$additionalNamespaces
=
$config
->
get
(
'CiteThisPageAdditionalNamespaces'
);
return
$title
->
isContentPage
()
||
(
isset
(
$additionalNamespaces
[
$title
->
getNamespace
()]
)
&&
$additionalNamespaces
[
$title
->
getNamespace
()]
);
}
/** @inheritDoc */
public
function
onSidebarBeforeOutput
(
$skin
,
&
$sidebar
):
void
{
$out
=
$skin
->
getOutput
();
$title
=
$out
->
getTitle
();
if
(
!
self
::
shouldAddLink
(
$title
,
$out
->
getConfig
()
)
)
{
return
;
}
$revid
=
$out
->
getRevisionId
();
if
(
$revid
===
0
||
$revid
===
null
)
{
return
;
}
$specialPage
=
SpecialPage
::
getTitleFor
(
'CiteThisPage'
);
$citeURL
=
$specialPage
->
getLocalURL
(
[
'page'
=>
$title
->
getPrefixedDBkey
(),
'id'
=>
$revid
,
'wpFormIdentifier'
=>
'titleform'
]
);
$citeThisPageLink
=
[
'id'
=>
't-cite'
,
'href'
=>
$citeURL
,
'icon'
=>
'quotes'
,
'text'
=>
$skin
->
msg
(
'citethispage-link'
)->
text
(),
// Message keys: 'tooltip-citethispage', 'accesskey-citethispage'
'single-id'
=>
'citethispage'
,
];
// Append link
$sidebar
[
'TOOLBOX'
][
'citethispage'
]
=
$citeThisPageLink
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 17:13 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6e/ff/25876451b5d75400a0b1c8171e4e
Default Alt Text
Hooks.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment