mediawiki-extensions-CiteTh.../includes/CiteThisPageHooks.php
Sohom Datta ca97c3fb06 Add setFormIdentifier to prevent validation errors
Used the setFormIdentifier to add a additional
parameter to the url, allowing prefilled requests
to be distinguished and thus preventing validation
errors. Also, updated the url parameters at
CiteThisPageHooks.php.

Bug: T238467
Change-Id: Ic1d0612bb4d4a40bc1ce0588c65782e33c09c3ca
2019-11-18 18:24:46 +05:30

64 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class CiteThisPageHooks {
/**
* @param SkinTemplate &$skintemplate
* @param array &$nav_urls
* @param int &$oldid
* @param int &$revid
* @return bool
*/
public static function onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink(
&$skintemplate, &$nav_urls, &$oldid, &$revid
) {
// check whether were in the right namespace, the $revid has the correct type and is not empty
// (which would mean that the current page doesnt exist)
$title = $skintemplate->getTitle();
if ( self::shouldAddLink( $title ) && $revid !== 0 && !empty( $revid ) ) {
$nav_urls['citethispage'] = [
'text' => $skintemplate->msg( 'citethispage-link' )->text(),
'href' => SpecialPage::getTitleFor( 'CiteThisPage' )
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid,
'wpFormIdentifier' => 'titleform' ] ),
'id' => 't-cite',
# Used message keys: 'tooltip-citethispage', 'accesskey-citethispage'
'single-id' => 'citethispage',
];
}
return true;
}
/**
* 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 $wgCiteThisPageAddiotionalNamespaces.
*
* @param Title $title
* @return bool
*/
private static function shouldAddLink( Title $title ) {
global $wgCiteThisPageAdditionalNamespaces;
return $title->isContentPage() ||
(
isset( $wgCiteThisPageAdditionalNamespaces[$title->getNamespace()] ) &&
$wgCiteThisPageAdditionalNamespaces[$title->getNamespace()]
);
}
/**
* @param BaseTemplate $baseTemplate
* @param array &$toolbox
* @return bool
*/
public static function onBaseTemplateToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
if ( isset( $baseTemplate->data['nav_urls']['citethispage'] ) ) {
$toolbox['citethispage'] = $baseTemplate->data['nav_urls']['citethispage'];
}
return true;
}
}