summaryrefslogtreecommitdiff
path: root/www/wiki/includes/skins
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/includes/skins
first commit
Diffstat (limited to 'www/wiki/includes/skins')
-rw-r--r--www/wiki/includes/skins/BaseTemplate.php767
-rw-r--r--www/wiki/includes/skins/MediaWikiI18N.php60
-rw-r--r--www/wiki/includes/skins/QuickTemplate.php207
-rw-r--r--www/wiki/includes/skins/Skin.php1640
-rw-r--r--www/wiki/includes/skins/SkinApi.php69
-rw-r--r--www/wiki/includes/skins/SkinApiTemplate.php61
-rw-r--r--www/wiki/includes/skins/SkinException.php29
-rw-r--r--www/wiki/includes/skins/SkinFactory.php103
-rw-r--r--www/wiki/includes/skins/SkinFallback.php36
-rw-r--r--www/wiki/includes/skins/SkinFallbackTemplate.php122
-rw-r--r--www/wiki/includes/skins/SkinTemplate.php1404
11 files changed, 4498 insertions, 0 deletions
diff --git a/www/wiki/includes/skins/BaseTemplate.php b/www/wiki/includes/skins/BaseTemplate.php
new file mode 100644
index 00000000..e1f2969a
--- /dev/null
+++ b/www/wiki/includes/skins/BaseTemplate.php
@@ -0,0 +1,767 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * New base template for a skin's template extended from QuickTemplate
+ * this class features helper methods that provide common ways of interacting
+ * with the data stored in the QuickTemplate
+ */
+abstract class BaseTemplate extends QuickTemplate {
+
+ /**
+ * Get a Message object with its context set
+ *
+ * @param string $name Message name
+ * @param mixed $params,... Message params
+ * @return Message
+ */
+ public function getMsg( $name /* ... */ ) {
+ return call_user_func_array( [ $this->getSkin(), 'msg' ], func_get_args() );
+ }
+
+ function msg( $str ) {
+ echo $this->getMsg( $str )->escaped();
+ }
+
+ function msgHtml( $str ) {
+ echo $this->getMsg( $str )->text();
+ }
+
+ function msgWiki( $str ) {
+ echo $this->getMsg( $str )->parseAsBlock();
+ }
+
+ /**
+ * Create an array of common toolbox items from the data in the quicktemplate
+ * stored by SkinTemplate.
+ * The resulting array is built according to a format intended to be passed
+ * through makeListItem to generate the html.
+ * @return array
+ */
+ function getToolbox() {
+ $toolbox = [];
+ if ( isset( $this->data['nav_urls']['whatlinkshere'] )
+ && $this->data['nav_urls']['whatlinkshere']
+ ) {
+ $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
+ $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
+ }
+ if ( isset( $this->data['nav_urls']['recentchangeslinked'] )
+ && $this->data['nav_urls']['recentchangeslinked']
+ ) {
+ $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
+ $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
+ $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
+ $toolbox['recentchangeslinked']['rel'] = 'nofollow';
+ }
+ if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
+ $toolbox['feeds']['id'] = 'feedlinks';
+ $toolbox['feeds']['links'] = [];
+ foreach ( $this->data['feeds'] as $key => $feed ) {
+ $toolbox['feeds']['links'][$key] = $feed;
+ $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
+ $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
+ $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
+ $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
+ }
+ }
+ foreach ( [ 'contributions', 'log', 'blockip', 'emailuser',
+ 'userrights', 'upload', 'specialpages' ] as $special
+ ) {
+ if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
+ $toolbox[$special] = $this->data['nav_urls'][$special];
+ $toolbox[$special]['id'] = "t-$special";
+ }
+ }
+ if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
+ $toolbox['print'] = $this->data['nav_urls']['print'];
+ $toolbox['print']['id'] = 't-print';
+ $toolbox['print']['rel'] = 'alternate';
+ $toolbox['print']['msg'] = 'printableversion';
+ }
+ if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
+ $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
+ $toolbox['permalink']['id'] = 't-permalink';
+ }
+ if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
+ $toolbox['info'] = $this->data['nav_urls']['info'];
+ $toolbox['info']['id'] = 't-info';
+ }
+
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $template = $this;
+ Hooks::run( 'BaseTemplateToolbox', [ &$template, &$toolbox ] );
+ return $toolbox;
+ }
+
+ /**
+ * Create an array of personal tools items from the data in the quicktemplate
+ * stored by SkinTemplate.
+ * The resulting array is built according to a format intended to be passed
+ * through makeListItem to generate the html.
+ * This is in reality the same list as already stored in personal_urls
+ * however it is reformatted so that you can just pass the individual items
+ * to makeListItem instead of hardcoding the element creation boilerplate.
+ * @return array
+ */
+ function getPersonalTools() {
+ $personal_tools = [];
+ foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
+ # The class on a personal_urls item is meant to go on the <a> instead
+ # of the <li> so we have to use a single item "links" array instead
+ # of using most of the personal_url's keys directly.
+ $ptool = [
+ 'links' => [
+ [ 'single-id' => "pt-$key" ],
+ ],
+ 'id' => "pt-$key",
+ ];
+ if ( isset( $plink['active'] ) ) {
+ $ptool['active'] = $plink['active'];
+ }
+ foreach ( [ 'href', 'class', 'text', 'dir', 'data', 'exists' ] as $k ) {
+ if ( isset( $plink[$k] ) ) {
+ $ptool['links'][0][$k] = $plink[$k];
+ }
+ }
+ $personal_tools[$key] = $ptool;
+ }
+ return $personal_tools;
+ }
+
+ function getSidebar( $options = [] ) {
+ // Force the rendering of the following portals
+ $sidebar = $this->data['sidebar'];
+ if ( !isset( $sidebar['SEARCH'] ) ) {
+ $sidebar['SEARCH'] = true;
+ }
+ if ( !isset( $sidebar['TOOLBOX'] ) ) {
+ $sidebar['TOOLBOX'] = true;
+ }
+ if ( !isset( $sidebar['LANGUAGES'] ) ) {
+ $sidebar['LANGUAGES'] = true;
+ }
+
+ if ( !isset( $options['search'] ) || $options['search'] !== true ) {
+ unset( $sidebar['SEARCH'] );
+ }
+ if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
+ unset( $sidebar['TOOLBOX'] );
+ }
+ if ( isset( $options['languages'] ) && $options['languages'] === false ) {
+ unset( $sidebar['LANGUAGES'] );
+ }
+
+ $boxes = [];
+ foreach ( $sidebar as $boxName => $content ) {
+ if ( $content === false ) {
+ continue;
+ }
+ switch ( $boxName ) {
+ case 'SEARCH':
+ // Search is a special case, skins should custom implement this
+ $boxes[$boxName] = [
+ 'id' => 'p-search',
+ 'header' => $this->getMsg( 'search' )->text(),
+ 'generated' => false,
+ 'content' => true,
+ ];
+ break;
+ case 'TOOLBOX':
+ $msgObj = $this->getMsg( 'toolbox' );
+ $boxes[$boxName] = [
+ 'id' => 'p-tb',
+ 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
+ 'generated' => false,
+ 'content' => $this->getToolbox(),
+ ];
+ break;
+ case 'LANGUAGES':
+ if ( $this->data['language_urls'] !== false ) {
+ $msgObj = $this->getMsg( 'otherlanguages' );
+ $boxes[$boxName] = [
+ 'id' => 'p-lang',
+ 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
+ 'generated' => false,
+ 'content' => $this->data['language_urls'] ?: [],
+ ];
+ }
+ break;
+ default:
+ $msgObj = $this->getMsg( $boxName );
+ $boxes[$boxName] = [
+ 'id' => "p-$boxName",
+ 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
+ 'generated' => true,
+ 'content' => $content,
+ ];
+ break;
+ }
+ }
+
+ // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
+ $hookContents = null;
+ if ( isset( $boxes['TOOLBOX'] ) ) {
+ ob_start();
+ // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
+ // can abort and avoid outputting double toolbox links
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $template = $this;
+ Hooks::run( 'SkinTemplateToolboxEnd', [ &$template, true ] );
+ $hookContents = ob_get_contents();
+ ob_end_clean();
+ if ( !trim( $hookContents ) ) {
+ $hookContents = null;
+ }
+ }
+ // END hack
+
+ if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
+ foreach ( $boxes as $boxName => $box ) {
+ if ( is_array( $box['content'] ) ) {
+ $content = '<ul>';
+ foreach ( $box['content'] as $key => $val ) {
+ $content .= "\n " . $this->makeListItem( $key, $val );
+ }
+ // HACK, shove the toolbox end onto the toolbox if we're rendering itself
+ if ( $hookContents ) {
+ $content .= "\n $hookContents";
+ }
+ // END hack
+ $content .= "\n</ul>\n";
+ $boxes[$boxName]['content'] = $content;
+ }
+ }
+ } else {
+ if ( $hookContents ) {
+ $boxes['TOOLBOXEND'] = [
+ 'id' => 'p-toolboxend',
+ 'header' => $boxes['TOOLBOX']['header'],
+ 'generated' => false,
+ 'content' => "<ul>{$hookContents}</ul>",
+ ];
+ // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
+ $boxes2 = [];
+ foreach ( $boxes as $key => $box ) {
+ if ( $key === 'TOOLBOXEND' ) {
+ continue;
+ }
+ $boxes2[$key] = $box;
+ if ( $key === 'TOOLBOX' ) {
+ $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
+ }
+ }
+ $boxes = $boxes2;
+ // END hack
+ }
+ }
+
+ return $boxes;
+ }
+
+ /**
+ * @param string $name
+ */
+ protected function renderAfterPortlet( $name ) {
+ echo $this->getAfterPortlet( $name );
+ }
+
+ /**
+ * Allows extensions to hook into known portlets and add stuff to them
+ *
+ * @param string $name
+ *
+ * @return string html
+ * @since 1.29
+ */
+ protected function getAfterPortlet( $name ) {
+ $html = '';
+ $content = '';
+ Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] );
+
+ if ( $content !== '' ) {
+ $html = Html::rawElement(
+ 'div',
+ [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ],
+ $content
+ );
+ }
+
+ return $html;
+ }
+
+ /**
+ * Makes a link, usually used by makeListItem to generate a link for an item
+ * in a list used in navigation lists, portlets, portals, sidebars, etc...
+ *
+ * @param string $key Usually a key from the list you are generating this
+ * link from.
+ * @param array $item Contains some of a specific set of keys.
+ *
+ * The text of the link will be generated either from the contents of the
+ * "text" key in the $item array, if a "msg" key is present a message by
+ * that name will be used, and if neither of those are set the $key will be
+ * used as a message name.
+ *
+ * If a "href" key is not present makeLink will just output htmlescaped text.
+ * The "href", "id", "class", "rel", and "type" keys are used as attributes
+ * for the link if present.
+ *
+ * If an "id" or "single-id" (if you don't want the actual id to be output
+ * on the link) is present it will be used to generate a tooltip and
+ * accesskey for the link.
+ *
+ * The keys "context" and "primary" are ignored; these keys are used
+ * internally by skins and are not supposed to be included in the HTML
+ * output.
+ *
+ * If you don't want an accesskey, set $item['tooltiponly'] = true;
+ *
+ * If a "data" key is present, it must be an array, where the keys represent
+ * the data-xxx properties with their provided values. For example,
+ * $item['data'] = [
+ * 'foo' => 1,
+ * 'bar' => 'baz',
+ * ];
+ * will render as element properties:
+ * data-foo='1' data-bar='baz'
+ *
+ * @param array $options Can be used to affect the output of a link.
+ * Possible options are:
+ * - 'text-wrapper' key to specify a list of elements to wrap the text of
+ * a link in. This should be an array of arrays containing a 'tag' and
+ * optionally an 'attributes' key. If you only have one element you don't
+ * need to wrap it in another array. eg: To use <a><span>...</span></a>
+ * in all links use [ 'text-wrapper' => [ 'tag' => 'span' ] ]
+ * for your options.
+ * - 'link-class' key can be used to specify additional classes to apply
+ * to all links.
+ * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
+ * if there is no link. eg: If you specify 'link-fallback' => 'span' than
+ * any non-link will output a "<span>" instead of just text.
+ *
+ * @return string
+ */
+ function makeLink( $key, $item, $options = [] ) {
+ if ( isset( $item['text'] ) ) {
+ $text = $item['text'];
+ } else {
+ $text = wfMessage( isset( $item['msg'] ) ? $item['msg'] : $key )->text();
+ }
+
+ $html = htmlspecialchars( $text );
+
+ if ( isset( $options['text-wrapper'] ) ) {
+ $wrapper = $options['text-wrapper'];
+ if ( isset( $wrapper['tag'] ) ) {
+ $wrapper = [ $wrapper ];
+ }
+ while ( count( $wrapper ) > 0 ) {
+ $element = array_pop( $wrapper );
+ $html = Html::rawElement( $element['tag'], isset( $element['attributes'] )
+ ? $element['attributes']
+ : null, $html );
+ }
+ }
+
+ if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
+ $attrs = $item;
+ foreach ( [ 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary',
+ 'tooltip-params', 'exists' ] as $k ) {
+ unset( $attrs[$k] );
+ }
+
+ if ( isset( $attrs['data'] ) ) {
+ foreach ( $attrs['data'] as $key => $value ) {
+ $attrs[ 'data-' . $key ] = $value;
+ }
+ unset( $attrs[ 'data' ] );
+ }
+
+ if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
+ $item['single-id'] = $item['id'];
+ }
+
+ $tooltipParams = [];
+ if ( isset( $item['tooltip-params'] ) ) {
+ $tooltipParams = $item['tooltip-params'];
+ }
+
+ if ( isset( $item['single-id'] ) ) {
+ $tooltipOption = isset( $item['exists'] ) && $item['exists'] === false ? 'nonexisting' : null;
+
+ if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
+ $title = Linker::titleAttrib( $item['single-id'], $tooltipOption, $tooltipParams );
+ if ( $title !== false ) {
+ $attrs['title'] = $title;
+ }
+ } else {
+ $tip = Linker::tooltipAndAccesskeyAttribs(
+ $item['single-id'],
+ $tooltipParams,
+ $tooltipOption
+ );
+ if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
+ $attrs['title'] = $tip['title'];
+ }
+ if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
+ $attrs['accesskey'] = $tip['accesskey'];
+ }
+ }
+ }
+ if ( isset( $options['link-class'] ) ) {
+ if ( isset( $attrs['class'] ) ) {
+ $attrs['class'] .= " {$options['link-class']}";
+ } else {
+ $attrs['class'] = $options['link-class'];
+ }
+ }
+ $html = Html::rawElement( isset( $attrs['href'] )
+ ? 'a'
+ : $options['link-fallback'], $attrs, $html );
+ }
+
+ return $html;
+ }
+
+ /**
+ * Generates a list item for a navigation, portlet, portal, sidebar... list
+ *
+ * @param string $key Usually a key from the list you are generating this link from.
+ * @param array $item Array of list item data containing some of a specific set of keys.
+ * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
+ * if "active" contains a value of true a "active" class will also be appended to class.
+ *
+ * @param array $options
+ *
+ * If you want something other than a "<li>" you can pass a tag name such as
+ * "tag" => "span" in the $options array to change the tag used.
+ * link/content data for the list item may come in one of two forms
+ * A "links" key may be used, in which case it should contain an array with
+ * a list of links to include inside the list item, see makeLink for the
+ * format of individual links array items.
+ *
+ * Otherwise the relevant keys from the list item $item array will be passed
+ * to makeLink instead. Note however that "id" and "class" are used by the
+ * list item directly so they will not be passed to makeLink
+ * (however the link will still support a tooltip and accesskey from it)
+ * If you need an id or class on a single link you should include a "links"
+ * array with just one link item inside of it. You can also set "link-class" in
+ * $item to set a class on the link itself. If you want to add a title
+ * to the list item itself, you can set "itemtitle" to the value.
+ * $options is also passed on to makeLink calls
+ *
+ * @return string
+ */
+ function makeListItem( $key, $item, $options = [] ) {
+ if ( isset( $item['links'] ) ) {
+ $links = [];
+ foreach ( $item['links'] as $linkKey => $link ) {
+ $links[] = $this->makeLink( $linkKey, $link, $options );
+ }
+ $html = implode( ' ', $links );
+ } else {
+ $link = $item;
+ // These keys are used by makeListItem and shouldn't be passed on to the link
+ foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
+ unset( $link[$k] );
+ }
+ if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
+ // The id goes on the <li> not on the <a> for single links
+ // but makeSidebarLink still needs to know what id to use when
+ // generating tooltips and accesskeys.
+ $link['single-id'] = $item['id'];
+ }
+ if ( isset( $link['link-class'] ) ) {
+ // link-class should be set on the <a> itself,
+ // so pass it in as 'class'
+ $link['class'] = $link['link-class'];
+ unset( $link['link-class'] );
+ }
+ $html = $this->makeLink( $key, $link, $options );
+ }
+
+ $attrs = [];
+ foreach ( [ 'id', 'class' ] as $attr ) {
+ if ( isset( $item[$attr] ) ) {
+ $attrs[$attr] = $item[$attr];
+ }
+ }
+ if ( isset( $item['active'] ) && $item['active'] ) {
+ if ( !isset( $attrs['class'] ) ) {
+ $attrs['class'] = '';
+ }
+ $attrs['class'] .= ' active';
+ $attrs['class'] = trim( $attrs['class'] );
+ }
+ if ( isset( $item['itemtitle'] ) ) {
+ $attrs['title'] = $item['itemtitle'];
+ }
+ return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
+ }
+
+ function makeSearchInput( $attrs = [] ) {
+ $realAttrs = [
+ 'type' => 'search',
+ 'name' => 'search',
+ 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
+ ];
+ $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
+ return Html::element( 'input', $realAttrs );
+ }
+
+ function makeSearchButton( $mode, $attrs = [] ) {
+ switch ( $mode ) {
+ case 'go':
+ case 'fulltext':
+ $realAttrs = [
+ 'type' => 'submit',
+ 'name' => $mode,
+ 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
+ ];
+ $realAttrs = array_merge(
+ $realAttrs,
+ Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
+ $attrs
+ );
+ return Html::element( 'input', $realAttrs );
+ case 'image':
+ $buttonAttrs = [
+ 'type' => 'submit',
+ 'name' => 'button',
+ ];
+ $buttonAttrs = array_merge(
+ $buttonAttrs,
+ Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
+ $attrs
+ );
+ unset( $buttonAttrs['src'] );
+ unset( $buttonAttrs['alt'] );
+ unset( $buttonAttrs['width'] );
+ unset( $buttonAttrs['height'] );
+ $imgAttrs = [
+ 'src' => $attrs['src'],
+ 'alt' => isset( $attrs['alt'] )
+ ? $attrs['alt']
+ : wfMessage( 'searchbutton' )->text(),
+ 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
+ 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
+ ];
+ return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
+ default:
+ throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
+ }
+ }
+
+ /**
+ * Returns an array of footerlinks trimmed down to only those footer links that
+ * are valid.
+ * If you pass "flat" as an option then the returned array will be a flat array
+ * of footer icons instead of a key/value array of footerlinks arrays broken
+ * up into categories.
+ * @param string $option
+ * @return array|mixed
+ */
+ function getFooterLinks( $option = null ) {
+ $footerlinks = $this->get( 'footerlinks' );
+
+ // Reduce footer links down to only those which are being used
+ $validFooterLinks = [];
+ foreach ( $footerlinks as $category => $links ) {
+ $validFooterLinks[$category] = [];
+ foreach ( $links as $link ) {
+ if ( isset( $this->data[$link] ) && $this->data[$link] ) {
+ $validFooterLinks[$category][] = $link;
+ }
+ }
+ if ( count( $validFooterLinks[$category] ) <= 0 ) {
+ unset( $validFooterLinks[$category] );
+ }
+ }
+
+ if ( $option == 'flat' ) {
+ // fold footerlinks into a single array using a bit of trickery
+ $validFooterLinks = call_user_func_array(
+ 'array_merge',
+ array_values( $validFooterLinks )
+ );
+ }
+
+ return $validFooterLinks;
+ }
+
+ /**
+ * Returns an array of footer icons filtered down by options relevant to how
+ * the skin wishes to display them.
+ * If you pass "icononly" as the option all footer icons which do not have an
+ * image icon set will be filtered out.
+ * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
+ * in the list of footer icons. This is mostly useful for skins which only
+ * display the text from footericons instead of the images and don't want a
+ * duplicate copyright statement because footerlinks already rendered one.
+ * @param string $option
+ * @return array
+ */
+ function getFooterIcons( $option = null ) {
+ // Generate additional footer icons
+ $footericons = $this->get( 'footericons' );
+
+ if ( $option == 'icononly' ) {
+ // Unset any icons which don't have an image
+ foreach ( $footericons as &$footerIconsBlock ) {
+ foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
+ if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
+ unset( $footerIconsBlock[$footerIconKey] );
+ }
+ }
+ }
+ // Redo removal of any empty blocks
+ foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
+ if ( count( $footerIconsBlock ) <= 0 ) {
+ unset( $footericons[$footerIconsKey] );
+ }
+ }
+ } elseif ( $option == 'nocopyright' ) {
+ unset( $footericons['copyright']['copyright'] );
+ if ( count( $footericons['copyright'] ) <= 0 ) {
+ unset( $footericons['copyright'] );
+ }
+ }
+
+ return $footericons;
+ }
+
+ /**
+ * Renderer for getFooterIcons and getFooterLinks
+ *
+ * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
+ * @param string $linkStyle $option for getFooterLinks: "flat"
+ *
+ * @return string html
+ * @since 1.29
+ */
+ protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
+ $validFooterIcons = $this->getFooterIcons( $iconStyle );
+ $validFooterLinks = $this->getFooterLinks( $linkStyle );
+
+ $html = '';
+
+ if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
+ $html .= Html::openElement( 'div', [
+ 'id' => 'footer-bottom',
+ 'role' => 'contentinfo',
+ 'lang' => $this->get( 'userlang' ),
+ 'dir' => $this->get( 'dir' )
+ ] );
+ $footerEnd = Html::closeElement( 'div' );
+ } else {
+ $footerEnd = '';
+ }
+ foreach ( $validFooterIcons as $blockName => $footerIcons ) {
+ $html .= Html::openElement( 'div', [
+ 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
+ 'class' => 'footer-icons'
+ ] );
+ foreach ( $footerIcons as $icon ) {
+ $html .= $this->getSkin()->makeFooterIcon( $icon );
+ }
+ $html .= Html::closeElement( 'div' );
+ }
+ if ( count( $validFooterLinks ) > 0 ) {
+ $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
+ foreach ( $validFooterLinks as $aLink ) {
+ $html .= Html::rawElement(
+ 'li',
+ [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
+ $this->get( $aLink )
+ );
+ }
+ $html .= Html::closeElement( 'ul' );
+ }
+
+ $html .= $this->getClear() . $footerEnd;
+
+ return $html;
+ }
+
+ /**
+ * Get a div with the core visualClear class, for clearing floats
+ *
+ * @return string html
+ * @since 1.29
+ */
+ protected function getClear() {
+ return Html::element( 'div', [ 'class' => 'visualClear' ] );
+ }
+
+ /**
+ * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
+ * displayed in the top-right corner of the page, outside of the main content.
+ *
+ * Your skin may implement this differently, for example by handling some indicator names
+ * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
+ * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
+ * with extensions and user scripts.
+ *
+ * The raw data is available in `$this->data['indicators']` as an associative array (keys:
+ * identifiers, values: contents) internally ordered by keys.
+ *
+ * @return string HTML
+ * @since 1.25
+ */
+ public function getIndicators() {
+ $out = "<div class=\"mw-indicators mw-body-content\">\n";
+ foreach ( $this->data['indicators'] as $id => $content ) {
+ $out .= Html::rawElement(
+ 'div',
+ [
+ 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
+ 'class' => 'mw-indicator',
+ ],
+ $content
+ ) . "\n";
+ }
+ $out .= "</div>\n";
+ return $out;
+ }
+
+ /**
+ * Output getTrail
+ */
+ function printTrail() {
+ echo $this->getTrail();
+ }
+
+ /**
+ * Get the basic end-page trail including bottomscripts, reporttime, and
+ * debug stuff. This should be called right before outputting the closing
+ * body and html tags.
+ *
+ * @return string
+ * @since 1.29
+ */
+ function getTrail() {
+ $html = MWDebug::getDebugHTML( $this->getSkin()->getContext() );
+ $html .= $this->get( 'bottomscripts' );
+ $html .= $this->get( 'reporttime' );
+
+ return $html;
+ }
+}
diff --git a/www/wiki/includes/skins/MediaWikiI18N.php b/www/wiki/includes/skins/MediaWikiI18N.php
new file mode 100644
index 00000000..731897e4
--- /dev/null
+++ b/www/wiki/includes/skins/MediaWikiI18N.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Wrapper object for MediaWiki's localization functions,
+ * to be passed to the template engine.
+ *
+ * @private
+ * @ingroup Skins
+ */
+class MediaWikiI18N {
+ private $context = [];
+
+ /**
+ * @deprecate since 1.31 Use BaseTemplate::msg() or Skin::msg() instead for setting
+ * message parameters.
+ */
+ function set( $varName, $value ) {
+ wfDeprecated( __METHOD__, '1.31' );
+ $this->context[$varName] = $value;
+ }
+
+ /**
+ * @deprecate since 1.31 Use BaseTemplate::msg(), Skin::msg(), or wfMessage() instead.
+ */
+ function translate( $value ) {
+ wfDeprecated( __METHOD__, '1.31' );
+ // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
+ $value = preg_replace( '/^string:/', '', $value );
+
+ $value = wfMessage( $value )->text();
+ // interpolate variables
+ $m = [];
+ while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
+ list( $src, $var ) = $m;
+ Wikimedia\suppressWarnings();
+ $varValue = $this->context[$var];
+ Wikimedia\restoreWarnings();
+ $value = str_replace( $src, $varValue, $value );
+ }
+ return $value;
+ }
+}
diff --git a/www/wiki/includes/skins/QuickTemplate.php b/www/wiki/includes/skins/QuickTemplate.php
new file mode 100644
index 00000000..18867464
--- /dev/null
+++ b/www/wiki/includes/skins/QuickTemplate.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+use MediaWiki\MediaWikiServices;
+
+/**
+ * Generic wrapper for template functions, with interface
+ * compatible with what we use of PHPTAL 0.7.
+ * @ingroup Skins
+ */
+abstract class QuickTemplate {
+
+ /**
+ * @var array
+ */
+ public $data;
+
+ /**
+ * @var MediaWikiI18N
+ */
+ public $translator;
+
+ /** @var Config $config */
+ protected $config;
+
+ /**
+ * @param Config $config
+ */
+ function __construct( Config $config = null ) {
+ $this->data = [];
+ $this->translator = new MediaWikiI18N();
+ if ( $config === null ) {
+ wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
+ $config = MediaWikiServices::getInstance()->getMainConfig();
+ }
+ $this->config = $config;
+ }
+
+ /**
+ * Sets the value $value to $name
+ * @param string $name
+ * @param mixed $value
+ */
+ public function set( $name, $value ) {
+ $this->data[$name] = $value;
+ }
+
+ /**
+ * extends the value of data with name $name with the value $value
+ * @since 1.25
+ * @param string $name
+ * @param mixed $value
+ */
+ public function extend( $name, $value ) {
+ if ( $this->haveData( $name ) ) {
+ $this->data[$name] = $this->data[$name] . $value;
+ } else {
+ $this->data[$name] = $value;
+ }
+ }
+
+ /**
+ * Gets the template data requested
+ * @since 1.22
+ * @param string $name Key for the data
+ * @param mixed $default Optional default (or null)
+ * @return mixed The value of the data requested or the deafult
+ */
+ public function get( $name, $default = null ) {
+ if ( isset( $this->data[$name] ) ) {
+ return $this->data[$name];
+ } else {
+ return $default;
+ }
+ }
+
+ /**
+ * @deprecated since 1.31 This function is a now-redundant optimisation intended
+ * for very old versions of PHP. The use of references here makes the code
+ * more fragile and is incompatible with plans like T140664. Use set() instead.
+ * @param string $name
+ * @param mixed &$value
+ */
+ public function setRef( $name, &$value ) {
+ wfDeprecated( __METHOD__, '1.31' );
+ $this->data[$name] =& $value;
+ }
+
+ /**
+ * @param MediaWikiI18N &$t
+ * @deprecate since 1.31 Use BaseTemplate::msg() or Skin::msg() instead for setting
+ * message parameters.
+ */
+ public function setTranslator( &$t ) {
+ wfDeprecated( __METHOD__, '1.31' );
+ $this->translator = &$t;
+ }
+
+ /**
+ * Main function, used by classes that subclass QuickTemplate
+ * to show the actual HTML output
+ */
+ abstract public function execute();
+
+ /**
+ * @private
+ * @param string $str
+ */
+ function text( $str ) {
+ echo htmlspecialchars( $this->data[$str] );
+ }
+
+ /**
+ * @private
+ * @param string $str
+ */
+ function html( $str ) {
+ echo $this->data[$str];
+ }
+
+ /**
+ * @private
+ * @param string $msgKey
+ */
+ function msg( $msgKey ) {
+ echo htmlspecialchars( wfMessage( $msgKey )->text() );
+ }
+
+ /**
+ * @private
+ * @param string $msgKey
+ */
+ function msgHtml( $msgKey ) {
+ echo wfMessage( $msgKey )->text();
+ }
+
+ /**
+ * An ugly, ugly hack.
+ * @private
+ * @param string $msgKey
+ */
+ function msgWiki( $msgKey ) {
+ global $wgOut;
+
+ $text = wfMessage( $msgKey )->text();
+ echo $wgOut->parse( $text );
+ }
+
+ /**
+ * @private
+ * @param string $str
+ * @return bool
+ */
+ function haveData( $str ) {
+ return isset( $this->data[$str] );
+ }
+
+ /**
+ * @private
+ *
+ * @param string $msgKey
+ * @return bool
+ */
+ function haveMsg( $msgKey ) {
+ $msg = wfMessage( $msgKey );
+ return $msg->exists() && !$msg->isDisabled();
+ }
+
+ /**
+ * Get the Skin object related to this object
+ *
+ * @return Skin
+ */
+ public function getSkin() {
+ return $this->data['skin'];
+ }
+
+ /**
+ * Fetch the output of a QuickTemplate and return it
+ *
+ * @since 1.23
+ * @return string
+ */
+ public function getHTML() {
+ ob_start();
+ $this->execute();
+ $html = ob_get_contents();
+ ob_end_clean();
+ return $html;
+ }
+}
diff --git a/www/wiki/includes/skins/Skin.php b/www/wiki/includes/skins/Skin.php
new file mode 100644
index 00000000..e2de9ec3
--- /dev/null
+++ b/www/wiki/includes/skins/Skin.php
@@ -0,0 +1,1640 @@
+<?php
+/**
+ * Base class for all skins.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+use MediaWiki\MediaWikiServices;
+
+/**
+ * @defgroup Skins Skins
+ */
+
+/**
+ * The main skin class which provides methods and properties for all other skins.
+ *
+ * See docs/skin.txt for more information.
+ *
+ * @ingroup Skins
+ */
+abstract class Skin extends ContextSource {
+ /**
+ * @var string|null
+ */
+ protected $skinname = null;
+
+ protected $mRelevantTitle = null;
+ protected $mRelevantUser = null;
+
+ /**
+ * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
+ * located. Only needs to be set if you intend to use the getSkinStylePath() method.
+ */
+ public $stylename = null;
+
+ /**
+ * Fetch the set of available skins.
+ * @return array Associative array of strings
+ */
+ static function getSkinNames() {
+ return SkinFactory::getDefaultInstance()->getSkinNames();
+ }
+
+ /**
+ * Fetch the skinname messages for available skins.
+ * @return string[]
+ */
+ static function getSkinNameMessages() {
+ $messages = [];
+ foreach ( self::getSkinNames() as $skinKey => $skinName ) {
+ $messages[] = "skinname-$skinKey";
+ }
+ return $messages;
+ }
+
+ /**
+ * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
+ * Useful for Special:Preferences and other places where you
+ * only want to show skins users _can_ use.
+ * @return string[]
+ * @since 1.23
+ */
+ public static function getAllowedSkins() {
+ global $wgSkipSkins;
+
+ $allowedSkins = self::getSkinNames();
+
+ foreach ( $wgSkipSkins as $skip ) {
+ unset( $allowedSkins[$skip] );
+ }
+
+ return $allowedSkins;
+ }
+
+ /**
+ * Normalize a skin preference value to a form that can be loaded.
+ *
+ * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
+ * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
+ *
+ * @param string $key 'monobook', 'vector', etc.
+ * @return string
+ */
+ static function normalizeKey( $key ) {
+ global $wgDefaultSkin, $wgFallbackSkin;
+
+ $skinNames = self::getSkinNames();
+
+ // Make keys lowercase for case-insensitive matching.
+ $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
+ $key = strtolower( $key );
+ $defaultSkin = strtolower( $wgDefaultSkin );
+ $fallbackSkin = strtolower( $wgFallbackSkin );
+
+ if ( $key == '' || $key == 'default' ) {
+ // Don't return the default immediately;
+ // in a misconfiguration we need to fall back.
+ $key = $defaultSkin;
+ }
+
+ if ( isset( $skinNames[$key] ) ) {
+ return $key;
+ }
+
+ // Older versions of the software used a numeric setting
+ // in the user preferences.
+ $fallback = [
+ 0 => $defaultSkin,
+ 2 => 'cologneblue'
+ ];
+
+ if ( isset( $fallback[$key] ) ) {
+ $key = $fallback[$key];
+ }
+
+ if ( isset( $skinNames[$key] ) ) {
+ return $key;
+ } elseif ( isset( $skinNames[$defaultSkin] ) ) {
+ return $defaultSkin;
+ } else {
+ return $fallbackSkin;
+ }
+ }
+
+ /**
+ * @since 1.31
+ * @param string|null $skinname
+ */
+ public function __construct( $skinname = null ) {
+ if ( is_string( $skinname ) ) {
+ $this->skinname = $skinname;
+ }
+ }
+
+ /**
+ * @return string|null Skin name
+ */
+ public function getSkinName() {
+ return $this->skinname;
+ }
+
+ /**
+ * @param OutputPage $out
+ */
+ public function initPage( OutputPage $out ) {
+ $this->preloadExistence();
+ }
+
+ /**
+ * Defines the ResourceLoader modules that should be added to the skin
+ * It is recommended that skins wishing to override call parent::getDefaultModules()
+ * and substitute out any modules they wish to change by using a key to look them up
+ *
+ * For style modules, use setupSkinUserCss() instead.
+ *
+ * @return array Array of modules with helper keys for easy overriding
+ */
+ public function getDefaultModules() {
+ global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI;
+
+ $out = $this->getOutput();
+ $config = $this->getConfig();
+ $user = $out->getUser();
+ $modules = [
+ // modules not specific to any specific skin or page
+ 'core' => [
+ // Enforce various default modules for all pages and all skins
+ // Keep this list as small as possible
+ 'site',
+ 'mediawiki.page.startup',
+ 'mediawiki.user',
+ ],
+ // modules that enhance the page content in some way
+ 'content' => [
+ 'mediawiki.page.ready',
+ ],
+ // modules relating to search functionality
+ 'search' => [],
+ // modules relating to functionality relating to watching an article
+ 'watch' => [],
+ // modules which relate to the current users preferences
+ 'user' => [],
+ ];
+
+ // Support for high-density display images if enabled
+ if ( $config->get( 'ResponsiveImages' ) ) {
+ $modules['core'][] = 'mediawiki.hidpi';
+ }
+
+ // Preload jquery.tablesorter for mediawiki.page.ready
+ if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
+ $modules['content'][] = 'jquery.tablesorter';
+ }
+
+ // Preload jquery.makeCollapsible for mediawiki.page.ready
+ if ( strpos( $out->getHTML(), 'mw-collapsible' ) !== false ) {
+ $modules['content'][] = 'jquery.makeCollapsible';
+ }
+
+ if ( $out->isTOCEnabled() ) {
+ $modules['content'][] = 'mediawiki.toc';
+ }
+
+ // Add various resources if required
+ if ( $wgUseAjax && $wgEnableAPI ) {
+ if ( $wgEnableWriteAPI && $user->isLoggedIn()
+ && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
+ && $this->getRelevantTitle()->canExist()
+ ) {
+ $modules['watch'][] = 'mediawiki.page.watch.ajax';
+ }
+
+ $modules['search'][] = 'mediawiki.searchSuggest';
+ }
+
+ if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
+ $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
+ }
+
+ // Crazy edit-on-double-click stuff
+ if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
+ $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
+ }
+ return $modules;
+ }
+
+ /**
+ * Preload the existence of three commonly-requested pages in a single query
+ */
+ protected function preloadExistence() {
+ $titles = [];
+
+ // User/talk link
+ $user = $this->getUser();
+ if ( $user->isLoggedIn() ) {
+ $titles[] = $user->getUserPage();
+ $titles[] = $user->getTalkPage();
+ }
+
+ // Check, if the page can hold some kind of content, otherwise do nothing
+ $title = $this->getRelevantTitle();
+ if ( $title->canExist() ) {
+ if ( $title->isTalkPage() ) {
+ $titles[] = $title->getSubjectPage();
+ } else {
+ $titles[] = $title->getTalkPage();
+ }
+ }
+
+ // Footer links (used by SkinTemplate::prepareQuickTemplate)
+ foreach ( [
+ $this->footerLinkTitle( 'privacy', 'privacypage' ),
+ $this->footerLinkTitle( 'aboutsite', 'aboutpage' ),
+ $this->footerLinkTitle( 'disclaimers', 'disclaimerpage' ),
+ ] as $title ) {
+ if ( $title ) {
+ $titles[] = $title;
+ }
+ }
+
+ Hooks::run( 'SkinPreloadExistence', [ &$titles, $this ] );
+
+ if ( $titles ) {
+ $lb = new LinkBatch( $titles );
+ $lb->setCaller( __METHOD__ );
+ $lb->execute();
+ }
+ }
+
+ /**
+ * Get the current revision ID
+ *
+ * @return int
+ */
+ public function getRevisionId() {
+ return $this->getOutput()->getRevisionId();
+ }
+
+ /**
+ * Whether the revision displayed is the latest revision of the page
+ *
+ * @return bool
+ */
+ public function isRevisionCurrent() {
+ $revID = $this->getRevisionId();
+ return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
+ }
+
+ /**
+ * Set the "relevant" title
+ * @see self::getRelevantTitle()
+ * @param Title $t
+ */
+ public function setRelevantTitle( $t ) {
+ $this->mRelevantTitle = $t;
+ }
+
+ /**
+ * Return the "relevant" title.
+ * A "relevant" title is not necessarily the actual title of the page.
+ * Special pages like Special:MovePage use set the page they are acting on
+ * as their "relevant" title, this allows the skin system to display things
+ * such as content tabs which belong to to that page instead of displaying
+ * a basic special page tab which has almost no meaning.
+ *
+ * @return Title
+ */
+ public function getRelevantTitle() {
+ if ( isset( $this->mRelevantTitle ) ) {
+ return $this->mRelevantTitle;
+ }
+ return $this->getTitle();
+ }
+
+ /**
+ * Set the "relevant" user
+ * @see self::getRelevantUser()
+ * @param User $u
+ */
+ public function setRelevantUser( $u ) {
+ $this->mRelevantUser = $u;
+ }
+
+ /**
+ * Return the "relevant" user.
+ * A "relevant" user is similar to a relevant title. Special pages like
+ * Special:Contributions mark the user which they are relevant to so that
+ * things like the toolbox can display the information they usually are only
+ * able to display on a user's userpage and talkpage.
+ * @return User
+ */
+ public function getRelevantUser() {
+ if ( isset( $this->mRelevantUser ) ) {
+ return $this->mRelevantUser;
+ }
+ $title = $this->getRelevantTitle();
+ if ( $title->hasSubjectNamespace( NS_USER ) ) {
+ $rootUser = $title->getRootText();
+ if ( User::isIP( $rootUser ) ) {
+ $this->mRelevantUser = User::newFromName( $rootUser, false );
+ } else {
+ $user = User::newFromName( $rootUser, false );
+
+ if ( $user ) {
+ $user->load( User::READ_NORMAL );
+
+ if ( $user->isLoggedIn() ) {
+ $this->mRelevantUser = $user;
+ }
+ }
+ }
+ return $this->mRelevantUser;
+ }
+ return null;
+ }
+
+ /**
+ * Outputs the HTML generated by other functions.
+ * @param OutputPage $out
+ */
+ abstract function outputPage( OutputPage $out = null );
+
+ /**
+ * @param array $data
+ * @return string
+ */
+ static function makeVariablesScript( $data ) {
+ if ( $data ) {
+ return ResourceLoader::makeInlineScript(
+ ResourceLoader::makeConfigSetScript( $data )
+ );
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * Get the query to generate a dynamic stylesheet
+ *
+ * @return array
+ */
+ public static function getDynamicStylesheetQuery() {
+ global $wgSquidMaxage;
+
+ return [
+ 'action' => 'raw',
+ 'maxage' => $wgSquidMaxage,
+ 'usemsgcache' => 'yes',
+ 'ctype' => 'text/css',
+ 'smaxage' => $wgSquidMaxage,
+ ];
+ }
+
+ /**
+ * Add skin specific stylesheets
+ * Calling this method with an $out of anything but the same OutputPage
+ * inside ->getOutput() is deprecated. The $out arg is kept
+ * for compatibility purposes with skins.
+ * @param OutputPage $out
+ * @todo delete
+ */
+ abstract function setupSkinUserCss( OutputPage $out );
+
+ /**
+ * TODO: document
+ * @param Title $title
+ * @return string
+ */
+ function getPageClasses( $title ) {
+ $numeric = 'ns-' . $title->getNamespace();
+
+ if ( $title->isSpecialPage() ) {
+ $type = 'ns-special';
+ // T25315: provide a class based on the canonical special page name without subpages
+ list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
+ if ( $canonicalName ) {
+ $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
+ } else {
+ $type .= ' mw-invalidspecialpage';
+ }
+ } elseif ( $title->isTalkPage() ) {
+ $type = 'ns-talk';
+ } else {
+ $type = 'ns-subject';
+ }
+
+ $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
+ $root = Sanitizer::escapeClass( 'rootpage-' . $title->getRootTitle()->getPrefixedText() );
+
+ return "$numeric $type $name $root";
+ }
+
+ /**
+ * Return values for <html> element
+ * @return array Array of associative name-to-value elements for <html> element
+ */
+ public function getHtmlElementAttributes() {
+ $lang = $this->getLanguage();
+ return [
+ 'lang' => $lang->getHtmlCode(),
+ 'dir' => $lang->getDir(),
+ 'class' => 'client-nojs',
+ ];
+ }
+
+ /**
+ * This will be called by OutputPage::headElement when it is creating the
+ * "<body>" tag, skins can override it if they have a need to add in any
+ * body attributes or classes of their own.
+ * @param OutputPage $out
+ * @param array &$bodyAttrs
+ */
+ function addToBodyAttributes( $out, &$bodyAttrs ) {
+ // does nothing by default
+ }
+
+ /**
+ * URL to the logo
+ * @return string
+ */
+ function getLogo() {
+ global $wgLogo;
+ return $wgLogo;
+ }
+
+ /**
+ * Whether the logo should be preloaded with an HTTP link header or not
+ * @since 1.29
+ * @return bool
+ */
+ public function shouldPreloadLogo() {
+ return false;
+ }
+
+ /**
+ * @return string HTML
+ */
+ function getCategoryLinks() {
+ global $wgUseCategoryBrowser;
+
+ $out = $this->getOutput();
+ $allCats = $out->getCategoryLinks();
+
+ if ( !count( $allCats ) ) {
+ return '';
+ }
+
+ $embed = "<li>";
+ $pop = "</li>";
+
+ $s = '';
+ $colon = $this->msg( 'colon-separator' )->escaped();
+
+ if ( !empty( $allCats['normal'] ) ) {
+ $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
+
+ $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
+ $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
+ $title = Title::newFromText( $linkPage );
+ $link = $title ? Linker::link( $title, $msg ) : $msg;
+ $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
+ $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
+ }
+
+ # Hidden categories
+ if ( isset( $allCats['hidden'] ) ) {
+ if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
+ $class = ' mw-hidden-cats-user-shown';
+ } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
+ $class = ' mw-hidden-cats-ns-shown';
+ } else {
+ $class = ' mw-hidden-cats-hidden';
+ }
+
+ $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
+ $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
+ $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
+ '</div>';
+ }
+
+ # optional 'dmoz-like' category browser. Will be shown under the list
+ # of categories an article belong to
+ if ( $wgUseCategoryBrowser ) {
+ $s .= '<br /><hr />';
+
+ # get a big array of the parents tree
+ $parenttree = $this->getTitle()->getParentCategoryTree();
+ # Skin object passed by reference cause it can not be
+ # accessed under the method subfunction drawCategoryBrowser
+ $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
+ # Clean out bogus first entry and sort them
+ unset( $tempout[0] );
+ asort( $tempout );
+ # Output one per line
+ $s .= implode( "<br />\n", $tempout );
+ }
+
+ return $s;
+ }
+
+ /**
+ * Render the array as a series of links.
+ * @param array $tree Categories tree returned by Title::getParentCategoryTree
+ * @return string Separated by &gt;, terminate with "\n"
+ */
+ function drawCategoryBrowser( $tree ) {
+ $return = '';
+
+ foreach ( $tree as $element => $parent ) {
+ if ( empty( $parent ) ) {
+ # element start a new list
+ $return .= "\n";
+ } else {
+ # grab the others elements
+ $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
+ }
+
+ # add our current element to the list
+ $eltitle = Title::newFromText( $element );
+ $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
+ }
+
+ return $return;
+ }
+
+ /**
+ * @return string HTML
+ */
+ function getCategories() {
+ $out = $this->getOutput();
+ $catlinks = $this->getCategoryLinks();
+
+ // Check what we're showing
+ $allCats = $out->getCategoryLinks();
+ $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
+ $this->getTitle()->getNamespace() == NS_CATEGORY;
+
+ $classes = [ 'catlinks' ];
+ if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
+ $classes[] = 'catlinks-allhidden';
+ }
+
+ return Html::rawElement(
+ 'div',
+ [ 'id' => 'catlinks', 'class' => $classes, 'data-mw' => 'interface' ],
+ $catlinks
+ );
+ }
+
+ /**
+ * This runs a hook to allow extensions placing their stuff after content
+ * and article metadata (e.g. categories).
+ * Note: This function has nothing to do with afterContent().
+ *
+ * This hook is placed here in order to allow using the same hook for all
+ * skins, both the SkinTemplate based ones and the older ones, which directly
+ * use this class to get their data.
+ *
+ * The output of this function gets processed in SkinTemplate::outputPage() for
+ * the SkinTemplate based skins, all other skins should directly echo it.
+ *
+ * @return string Empty by default, if not changed by any hook function.
+ */
+ protected function afterContentHook() {
+ $data = '';
+
+ if ( Hooks::run( 'SkinAfterContent', [ &$data, $this ] ) ) {
+ // adding just some spaces shouldn't toggle the output
+ // of the whole <div/>, so we use trim() here
+ if ( trim( $data ) != '' ) {
+ // Doing this here instead of in the skins to
+ // ensure that the div has the same ID in all
+ // skins
+ $data = "<div id='mw-data-after-content'>\n" .
+ "\t$data\n" .
+ "</div>\n";
+ }
+ } else {
+ wfDebug( "Hook SkinAfterContent changed output processing.\n" );
+ }
+
+ return $data;
+ }
+
+ /**
+ * Generate debug data HTML for displaying at the bottom of the main content
+ * area.
+ * @return string HTML containing debug data, if enabled (otherwise empty).
+ */
+ protected function generateDebugHTML() {
+ return MWDebug::getHTMLDebugLog();
+ }
+
+ /**
+ * This gets called shortly before the "</body>" tag.
+ *
+ * @return string HTML-wrapped JS code to be put before "</body>"
+ */
+ function bottomScripts() {
+ // TODO and the suckage continues. This function is really just a wrapper around
+ // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
+ // up at some point
+ $bottomScriptText = $this->getOutput()->getBottomScripts();
+ Hooks::run( 'SkinAfterBottomScripts', [ $this, &$bottomScriptText ] );
+
+ return $bottomScriptText;
+ }
+
+ /**
+ * Text with the permalink to the source page,
+ * usually shown on the footer of a printed page
+ *
+ * @return string HTML text with an URL
+ */
+ function printSource() {
+ $oldid = $this->getRevisionId();
+ if ( $oldid ) {
+ $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
+ $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
+ } else {
+ // oldid not available for non existing pages
+ $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
+ }
+
+ return $this->msg( 'retrievedfrom' )
+ ->rawParams( '<a dir="ltr" href="' . $url . '">' . $url . '</a>' )
+ ->parse();
+ }
+
+ /**
+ * @return string HTML
+ */
+ function getUndeleteLink() {
+ $action = $this->getRequest()->getVal( 'action', 'view' );
+
+ if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
+ ( !$this->getTitle()->exists() || $action == 'history' ) ) {
+ $n = $this->getTitle()->isDeleted();
+
+ if ( $n ) {
+ if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
+ $msg = 'thisisdeleted';
+ } else {
+ $msg = 'viewdeleted';
+ }
+
+ return $this->msg( $msg )->rawParams(
+ Linker::linkKnown(
+ SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
+ $this->msg( 'restorelink' )->numParams( $n )->escaped() )
+ )->escaped();
+ }
+ }
+
+ return '';
+ }
+
+ /**
+ * @param OutputPage $out Defaults to $this->getOutput() if left as null
+ * @return string
+ */
+ function subPageSubtitle( $out = null ) {
+ if ( $out === null ) {
+ $out = $this->getOutput();
+ }
+ $title = $out->getTitle();
+ $subpages = '';
+
+ if ( !Hooks::run( 'SkinSubPageSubtitle', [ &$subpages, $this, $out ] ) ) {
+ return $subpages;
+ }
+
+ if ( $out->isArticle() && MWNamespace::hasSubpages( $title->getNamespace() ) ) {
+ $ptext = $title->getPrefixedText();
+ if ( strpos( $ptext, '/' ) !== false ) {
+ $links = explode( '/', $ptext );
+ array_pop( $links );
+ $c = 0;
+ $growinglink = '';
+ $display = '';
+ $lang = $this->getLanguage();
+
+ foreach ( $links as $link ) {
+ $growinglink .= $link;
+ $display .= $link;
+ $linkObj = Title::newFromText( $growinglink );
+
+ if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
+ $getlink = Linker::linkKnown(
+ $linkObj,
+ htmlspecialchars( $display )
+ );
+
+ $c++;
+
+ if ( $c > 1 ) {
+ $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
+ } else {
+ $subpages .= '&lt; ';
+ }
+
+ $subpages .= $getlink;
+ $display = '';
+ } else {
+ $display .= '/';
+ }
+ $growinglink .= '/';
+ }
+ }
+ }
+
+ return $subpages;
+ }
+
+ /**
+ * @return string
+ */
+ function getSearchLink() {
+ $searchPage = SpecialPage::getTitleFor( 'Search' );
+ return $searchPage->getLocalURL();
+ }
+
+ /**
+ * @return string
+ */
+ function escapeSearchLink() {
+ return htmlspecialchars( $this->getSearchLink() );
+ }
+
+ /**
+ * @param string $type
+ * @return string
+ */
+ function getCopyright( $type = 'detect' ) {
+ global $wgRightsPage, $wgRightsUrl, $wgRightsText;
+
+ if ( $type == 'detect' ) {
+ if ( !$this->isRevisionCurrent()
+ && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
+ ) {
+ $type = 'history';
+ } else {
+ $type = 'normal';
+ }
+ }
+
+ if ( $type == 'history' ) {
+ $msg = 'history_copyright';
+ } else {
+ $msg = 'copyright';
+ }
+
+ if ( $wgRightsPage ) {
+ $title = Title::newFromText( $wgRightsPage );
+ $link = Linker::linkKnown( $title, $wgRightsText );
+ } elseif ( $wgRightsUrl ) {
+ $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
+ } elseif ( $wgRightsText ) {
+ $link = $wgRightsText;
+ } else {
+ # Give up now
+ return '';
+ }
+
+ // Allow for site and per-namespace customization of copyright notice.
+ // @todo Remove deprecated $forContent param from hook handlers and then remove here.
+ $forContent = true;
+
+ Hooks::run(
+ 'SkinCopyrightFooter',
+ [ $this->getTitle(), $type, &$msg, &$link, &$forContent ]
+ );
+
+ return $this->msg( $msg )->rawParams( $link )->text();
+ }
+
+ /**
+ * @return null|string
+ */
+ function getCopyrightIcon() {
+ global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgFooterIcons;
+
+ $out = '';
+
+ if ( $wgFooterIcons['copyright']['copyright'] ) {
+ $out = $wgFooterIcons['copyright']['copyright'];
+ } elseif ( $wgRightsIcon ) {
+ $icon = htmlspecialchars( $wgRightsIcon );
+
+ if ( $wgRightsUrl ) {
+ $url = htmlspecialchars( $wgRightsUrl );
+ $out .= '<a href="' . $url . '">';
+ }
+
+ $text = htmlspecialchars( $wgRightsText );
+ $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
+
+ if ( $wgRightsUrl ) {
+ $out .= '</a>';
+ }
+ }
+
+ return $out;
+ }
+
+ /**
+ * Gets the powered by MediaWiki icon.
+ * @return string
+ */
+ function getPoweredBy() {
+ global $wgResourceBasePath;
+
+ $url1 = htmlspecialchars(
+ "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
+ );
+ $url1_5 = htmlspecialchars(
+ "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
+ );
+ $url2 = htmlspecialchars(
+ "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
+ );
+ $text = '<a href="//www.mediawiki.org/"><img src="' . $url1
+ . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
+ . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
+ Hooks::run( 'SkinGetPoweredBy', [ &$text, $this ] );
+ return $text;
+ }
+
+ /**
+ * Get the timestamp of the latest revision, formatted in user language
+ *
+ * @return string
+ */
+ protected function lastModified() {
+ $timestamp = $this->getOutput()->getRevisionTimestamp();
+
+ # No cached timestamp, load it from the database
+ if ( $timestamp === null ) {
+ $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
+ }
+
+ if ( $timestamp ) {
+ $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
+ $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
+ $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse();
+ } else {
+ $s = '';
+ }
+
+ if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) {
+ $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
+ }
+
+ return $s;
+ }
+
+ /**
+ * @param string $align
+ * @return string
+ */
+ function logoText( $align = '' ) {
+ if ( $align != '' ) {
+ $a = " style='float: {$align};'";
+ } else {
+ $a = '';
+ }
+
+ $mp = $this->msg( 'mainpage' )->escaped();
+ $mptitle = Title::newMainPage();
+ $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
+
+ $logourl = $this->getLogo();
+ $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
+
+ return $s;
+ }
+
+ /**
+ * Renders a $wgFooterIcons icon according to the method's arguments
+ * @param array $icon The icon to build the html for, see $wgFooterIcons
+ * for the format of this array.
+ * @param bool|string $withImage Whether to use the icon's image or output
+ * a text-only footericon.
+ * @return string HTML
+ */
+ function makeFooterIcon( $icon, $withImage = 'withImage' ) {
+ if ( is_string( $icon ) ) {
+ $html = $icon;
+ } else { // Assuming array
+ $url = isset( $icon["url"] ) ? $icon["url"] : null;
+ unset( $icon["url"] );
+ if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
+ // do this the lazy way, just pass icon data as an attribute array
+ $html = Html::element( 'img', $icon );
+ } else {
+ $html = htmlspecialchars( $icon["alt"] );
+ }
+ if ( $url ) {
+ global $wgExternalLinkTarget;
+ $html = Html::rawElement( 'a',
+ [ "href" => $url, "target" => $wgExternalLinkTarget ],
+ $html );
+ }
+ }
+ return $html;
+ }
+
+ /**
+ * Gets the link to the wiki's main page.
+ * @return string
+ */
+ function mainPageLink() {
+ $s = Linker::linkKnown(
+ Title::newMainPage(),
+ $this->msg( 'mainpage' )->escaped()
+ );
+
+ return $s;
+ }
+
+ /**
+ * Returns an HTML link for use in the footer
+ * @param string $desc The i18n message key for the link text
+ * @param string $page The i18n message key for the page to link to
+ * @return string HTML anchor
+ */
+ public function footerLink( $desc, $page ) {
+ $title = $this->footerLinkTitle( $desc, $page );
+ if ( !$title ) {
+ return '';
+ }
+
+ return Linker::linkKnown(
+ $title,
+ $this->msg( $desc )->escaped()
+ );
+ }
+
+ /**
+ * @param string $desc
+ * @param string $page
+ * @return Title|null
+ */
+ private function footerLinkTitle( $desc, $page ) {
+ // If the link description has been set to "-" in the default language,
+ if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
+ // then it is disabled, for all languages.
+ return null;
+ }
+ // Otherwise, we display the link for the user, described in their
+ // language (which may or may not be the same as the default language),
+ // but we make the link target be the one site-wide page.
+ $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
+
+ return $title ?: null;
+ }
+
+ /**
+ * Gets the link to the wiki's privacy policy page.
+ * @return string HTML
+ */
+ function privacyLink() {
+ return $this->footerLink( 'privacy', 'privacypage' );
+ }
+
+ /**
+ * Gets the link to the wiki's about page.
+ * @return string HTML
+ */
+ function aboutLink() {
+ return $this->footerLink( 'aboutsite', 'aboutpage' );
+ }
+
+ /**
+ * Gets the link to the wiki's general disclaimers page.
+ * @return string HTML
+ */
+ function disclaimerLink() {
+ return $this->footerLink( 'disclaimers', 'disclaimerpage' );
+ }
+
+ /**
+ * Return URL options for the 'edit page' link.
+ * This may include an 'oldid' specifier, if the current page view is such.
+ *
+ * @return array
+ * @private
+ */
+ function editUrlOptions() {
+ $options = [ 'action' => 'edit' ];
+
+ if ( !$this->isRevisionCurrent() ) {
+ $options['oldid'] = intval( $this->getRevisionId() );
+ }
+
+ return $options;
+ }
+
+ /**
+ * @param User|int $id
+ * @return bool
+ */
+ function showEmailUser( $id ) {
+ if ( $id instanceof User ) {
+ $targetUser = $id;
+ } else {
+ $targetUser = User::newFromId( $id );
+ }
+
+ # The sending user must have a confirmed email address and the receiving
+ # user must accept emails from the sender.
+ return $this->getUser()->canSendEmail()
+ && SpecialEmailUser::validateTarget( $targetUser, $this->getUser() ) === '';
+ }
+
+ /**
+ * Return a fully resolved style path url to images or styles stored in the current skins's folder.
+ * This method returns a url resolved using the configured skin style path
+ * and includes the style version inside of the url.
+ *
+ * Requires $stylename to be set, otherwise throws MWException.
+ *
+ * @param string $name The name or path of a skin resource file
+ * @return string The fully resolved style path url including styleversion
+ * @throws MWException
+ */
+ function getSkinStylePath( $name ) {
+ global $wgStylePath, $wgStyleVersion;
+
+ if ( $this->stylename === null ) {
+ $class = static::class;
+ throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
+ }
+
+ return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
+ }
+
+ /* these are used extensively in SkinTemplate, but also some other places */
+
+ /**
+ * @param string|string[] $urlaction
+ * @return string
+ */
+ static function makeMainPageUrl( $urlaction = '' ) {
+ $title = Title::newMainPage();
+ self::checkTitle( $title, '' );
+
+ return $title->getLinkURL( $urlaction );
+ }
+
+ /**
+ * Make a URL for a Special Page using the given query and protocol.
+ *
+ * If $proto is set to null, make a local URL. Otherwise, make a full
+ * URL with the protocol specified.
+ *
+ * @param string $name Name of the Special page
+ * @param string|string[] $urlaction Query to append
+ * @param string|null $proto Protocol to use or null for a local URL
+ * @return string
+ */
+ static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
+ $title = SpecialPage::getSafeTitleFor( $name );
+ if ( is_null( $proto ) ) {
+ return $title->getLocalURL( $urlaction );
+ } else {
+ return $title->getFullURL( $urlaction, false, $proto );
+ }
+ }
+
+ /**
+ * @param string $name
+ * @param string $subpage
+ * @param string|string[] $urlaction
+ * @return string
+ */
+ static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
+ $title = SpecialPage::getSafeTitleFor( $name, $subpage );
+ return $title->getLocalURL( $urlaction );
+ }
+
+ /**
+ * @param string $name
+ * @param string|string[] $urlaction
+ * @return string
+ */
+ static function makeI18nUrl( $name, $urlaction = '' ) {
+ $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
+ self::checkTitle( $title, $name );
+ return $title->getLocalURL( $urlaction );
+ }
+
+ /**
+ * @param string $name
+ * @param string|string[] $urlaction
+ * @return string
+ */
+ static function makeUrl( $name, $urlaction = '' ) {
+ $title = Title::newFromText( $name );
+ self::checkTitle( $title, $name );
+
+ return $title->getLocalURL( $urlaction );
+ }
+
+ /**
+ * If url string starts with http, consider as external URL, else
+ * internal
+ * @param string $name
+ * @return string URL
+ */
+ static function makeInternalOrExternalUrl( $name ) {
+ if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
+ return $name;
+ } else {
+ return self::makeUrl( $name );
+ }
+ }
+
+ /**
+ * this can be passed the NS number as defined in Language.php
+ * @param string $name
+ * @param string|string[] $urlaction
+ * @param int $namespace
+ * @return string
+ */
+ static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
+ $title = Title::makeTitleSafe( $namespace, $name );
+ self::checkTitle( $title, $name );
+
+ return $title->getLocalURL( $urlaction );
+ }
+
+ /**
+ * these return an array with the 'href' and boolean 'exists'
+ * @param string $name
+ * @param string|string[] $urlaction
+ * @return array
+ */
+ static function makeUrlDetails( $name, $urlaction = '' ) {
+ $title = Title::newFromText( $name );
+ self::checkTitle( $title, $name );
+
+ return [
+ 'href' => $title->getLocalURL( $urlaction ),
+ 'exists' => $title->isKnown(),
+ ];
+ }
+
+ /**
+ * Make URL details where the article exists (or at least it's convenient to think so)
+ * @param string $name Article name
+ * @param string|string[] $urlaction
+ * @return array
+ */
+ static function makeKnownUrlDetails( $name, $urlaction = '' ) {
+ $title = Title::newFromText( $name );
+ self::checkTitle( $title, $name );
+
+ return [
+ 'href' => $title->getLocalURL( $urlaction ),
+ 'exists' => true
+ ];
+ }
+
+ /**
+ * make sure we have some title to operate on
+ *
+ * @param Title &$title
+ * @param string $name
+ */
+ static function checkTitle( &$title, $name ) {
+ if ( !is_object( $title ) ) {
+ $title = Title::newFromText( $name );
+ if ( !is_object( $title ) ) {
+ $title = Title::newFromText( '--error: link target missing--' );
+ }
+ }
+ }
+
+ /**
+ * Build an array that represents the sidebar(s), the navigation bar among them.
+ *
+ * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
+ *
+ * The format of the returned array is [ heading => content, ... ], where:
+ * - heading is the heading of a navigation portlet. It is either:
+ * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
+ * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
+ * - plain text, which should be HTML-escaped by the skin
+ * - content is the contents of the portlet. It is either:
+ * - HTML text (<ul><li>...</li>...</ul>)
+ * - array of link data in a format accepted by BaseTemplate::makeListItem()
+ * - (for a magic string as a key, any value)
+ *
+ * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
+ * and can technically insert anything in here; skin creators are expected to handle
+ * values described above.
+ *
+ * @return array
+ */
+ public function buildSidebar() {
+ global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
+
+ $callback = function ( $old = null, &$ttl = null ) {
+ $bar = [];
+ $this->addToSidebar( $bar, 'sidebar' );
+ Hooks::run( 'SkinBuildSidebar', [ $this, &$bar ] );
+ if ( MessageCache::singleton()->isDisabled() ) {
+ $ttl = WANObjectCache::TTL_UNCACHEABLE; // bug T133069
+ }
+
+ return $bar;
+ };
+
+ $msgCache = MessageCache::singleton();
+ $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+
+ $sidebar = $wgEnableSidebarCache
+ ? $wanCache->getWithSetCallback(
+ $wanCache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
+ $wgSidebarCacheExpiry,
+ $callback,
+ [
+ 'checkKeys' => [
+ // Unless there is both no exact $code override nor an i18n definition
+ // in the the software, the only MediaWiki page to check is for $code.
+ $msgCache->getCheckKey( $this->getLanguage()->getCode() )
+ ],
+ 'lockTSE' => 30
+ ]
+ )
+ : $callback();
+
+ // Apply post-processing to the cached value
+ Hooks::run( 'SidebarBeforeOutput', [ $this, &$sidebar ] );
+
+ return $sidebar;
+ }
+
+ /**
+ * Add content from a sidebar system message
+ * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
+ *
+ * This is just a wrapper around addToSidebarPlain() for backwards compatibility
+ *
+ * @param array &$bar
+ * @param string $message
+ */
+ public function addToSidebar( &$bar, $message ) {
+ $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
+ }
+
+ /**
+ * Add content from plain text
+ * @since 1.17
+ * @param array &$bar
+ * @param string $text
+ * @return array
+ */
+ function addToSidebarPlain( &$bar, $text ) {
+ $lines = explode( "\n", $text );
+
+ $heading = '';
+ $messageTitle = $this->getConfig()->get( 'EnableSidebarCache' )
+ ? Title::newMainPage() : $this->getTitle();
+
+ foreach ( $lines as $line ) {
+ if ( strpos( $line, '*' ) !== 0 ) {
+ continue;
+ }
+ $line = rtrim( $line, "\r" ); // for Windows compat
+
+ if ( strpos( $line, '**' ) !== 0 ) {
+ $heading = trim( $line, '* ' );
+ if ( !array_key_exists( $heading, $bar ) ) {
+ $bar[$heading] = [];
+ }
+ } else {
+ $line = trim( $line, '* ' );
+
+ if ( strpos( $line, '|' ) !== false ) { // sanity check
+ $line = MessageCache::singleton()->transform( $line, false, null, $messageTitle );
+ $line = array_map( 'trim', explode( '|', $line, 2 ) );
+ if ( count( $line ) !== 2 ) {
+ // Second sanity check, could be hit by people doing
+ // funky stuff with parserfuncs... (T35321)
+ continue;
+ }
+
+ $extraAttribs = [];
+
+ $msgLink = $this->msg( $line[0] )->title( $messageTitle )->inContentLanguage();
+ if ( $msgLink->exists() ) {
+ $link = $msgLink->text();
+ if ( $link == '-' ) {
+ continue;
+ }
+ } else {
+ $link = $line[0];
+ }
+ $msgText = $this->msg( $line[1] )->title( $messageTitle );
+ if ( $msgText->exists() ) {
+ $text = $msgText->text();
+ } else {
+ $text = $line[1];
+ }
+
+ if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
+ $href = $link;
+
+ // Parser::getExternalLinkAttribs won't work here because of the Namespace things
+ global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
+ if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
+ $extraAttribs['rel'] = 'nofollow';
+ }
+
+ global $wgExternalLinkTarget;
+ if ( $wgExternalLinkTarget ) {
+ $extraAttribs['target'] = $wgExternalLinkTarget;
+ }
+ } else {
+ $title = Title::newFromText( $link );
+
+ if ( $title ) {
+ $title = $title->fixSpecialName();
+ $href = $title->getLinkURL();
+ } else {
+ $href = 'INVALID-TITLE';
+ }
+ }
+
+ $bar[$heading][] = array_merge( [
+ 'text' => $text,
+ 'href' => $href,
+ 'id' => Sanitizer::escapeIdForAttribute( 'n-' . strtr( $line[1], ' ', '-' ) ),
+ 'active' => false,
+ ], $extraAttribs );
+ } else {
+ continue;
+ }
+ }
+ }
+
+ return $bar;
+ }
+
+ /**
+ * Gets new talk page messages for the current user and returns an
+ * appropriate alert message (or an empty string if there are no messages)
+ * @return string
+ */
+ function getNewtalks() {
+ $newMessagesAlert = '';
+ $user = $this->getUser();
+ $newtalks = $user->getNewMessageLinks();
+ $out = $this->getOutput();
+
+ // Allow extensions to disable or modify the new messages alert
+ if ( !Hooks::run( 'GetNewMessagesAlert', [ &$newMessagesAlert, $newtalks, $user, $out ] ) ) {
+ return '';
+ }
+ if ( $newMessagesAlert ) {
+ return $newMessagesAlert;
+ }
+
+ if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
+ $uTalkTitle = $user->getTalkPage();
+ $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
+ $nofAuthors = 0;
+ if ( $lastSeenRev !== null ) {
+ $plural = true; // Default if we have a last seen revision: if unknown, use plural
+ $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
+ if ( $latestRev !== null ) {
+ // Singular if only 1 unseen revision, plural if several unseen revisions.
+ $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
+ $nofAuthors = $uTalkTitle->countAuthorsBetween(
+ $lastSeenRev, $latestRev, 10, 'include_new' );
+ }
+ } else {
+ // Singular if no revision -> diff link will show latest change only in any case
+ $plural = false;
+ }
+ $plural = $plural ? 999 : 1;
+ // 999 signifies "more than one revision". We don't know how many, and even if we did,
+ // the number of revisions or authors is not necessarily the same as the number of
+ // "messages".
+ $newMessagesLink = Linker::linkKnown(
+ $uTalkTitle,
+ $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
+ [],
+ [ 'redirect' => 'no' ]
+ );
+
+ $newMessagesDiffLink = Linker::linkKnown(
+ $uTalkTitle,
+ $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
+ [],
+ $lastSeenRev !== null
+ ? [ 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' ]
+ : [ 'diff' => 'cur' ]
+ );
+
+ if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
+ $newMessagesAlert = $this->msg(
+ 'youhavenewmessagesfromusers',
+ $newMessagesLink,
+ $newMessagesDiffLink
+ )->numParams( $nofAuthors, $plural );
+ } else {
+ // $nofAuthors === 11 signifies "11 or more" ("more than 10")
+ $newMessagesAlert = $this->msg(
+ $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
+ $newMessagesLink,
+ $newMessagesDiffLink
+ )->numParams( $plural );
+ }
+ $newMessagesAlert = $newMessagesAlert->text();
+ # Disable CDN cache
+ $out->setCdnMaxage( 0 );
+ } elseif ( count( $newtalks ) ) {
+ $sep = $this->msg( 'newtalkseparator' )->escaped();
+ $msgs = [];
+
+ foreach ( $newtalks as $newtalk ) {
+ $msgs[] = Xml::element(
+ 'a',
+ [ 'href' => $newtalk['link'] ], $newtalk['wiki']
+ );
+ }
+ $parts = implode( $sep, $msgs );
+ $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
+ $out->setCdnMaxage( 0 );
+ }
+
+ return $newMessagesAlert;
+ }
+
+ /**
+ * Get a cached notice
+ *
+ * @param string $name Message name, or 'default' for $wgSiteNotice
+ * @return string|bool HTML fragment, or false to indicate that the caller
+ * should fall back to the next notice in its sequence
+ */
+ private function getCachedNotice( $name ) {
+ global $wgRenderHashAppend, $wgContLang;
+
+ $needParse = false;
+
+ if ( $name === 'default' ) {
+ // special case
+ global $wgSiteNotice;
+ $notice = $wgSiteNotice;
+ if ( empty( $notice ) ) {
+ return false;
+ }
+ } else {
+ $msg = $this->msg( $name )->inContentLanguage();
+ if ( $msg->isBlank() ) {
+ return '';
+ } elseif ( $msg->isDisabled() ) {
+ return false;
+ }
+ $notice = $msg->plain();
+ }
+
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $parsed = $cache->getWithSetCallback(
+ // Use the extra hash appender to let eg SSL variants separately cache
+ // Key is verified with md5 hash of unparsed wikitext
+ $cache->makeKey( $name, $wgRenderHashAppend, md5( $notice ) ),
+ // TTL in seconds
+ 600,
+ function () use ( $notice ) {
+ return $this->getOutput()->parse( $notice );
+ }
+ );
+
+ return Html::rawElement(
+ 'div',
+ [
+ 'id' => 'localNotice',
+ 'lang' => $wgContLang->getHtmlCode(),
+ 'dir' => $wgContLang->getDir()
+ ],
+ $parsed
+ );
+ }
+
+ /**
+ * Get the site notice
+ *
+ * @return string HTML fragment
+ */
+ function getSiteNotice() {
+ $siteNotice = '';
+
+ if ( Hooks::run( 'SiteNoticeBefore', [ &$siteNotice, $this ] ) ) {
+ if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
+ $siteNotice = $this->getCachedNotice( 'sitenotice' );
+ } else {
+ $anonNotice = $this->getCachedNotice( 'anonnotice' );
+ if ( $anonNotice === false ) {
+ $siteNotice = $this->getCachedNotice( 'sitenotice' );
+ } else {
+ $siteNotice = $anonNotice;
+ }
+ }
+ if ( $siteNotice === false ) {
+ $siteNotice = $this->getCachedNotice( 'default' );
+ }
+ }
+
+ Hooks::run( 'SiteNoticeAfter', [ &$siteNotice, $this ] );
+ return $siteNotice;
+ }
+
+ /**
+ * Create a section edit link. This supersedes editSectionLink() and
+ * editSectionLinkForOther().
+ *
+ * @param Title $nt The title being linked to (may not be the same as
+ * the current page, if the section is included from a template)
+ * @param string $section The designation of the section being pointed to,
+ * to be included in the link, like "&section=$section"
+ * @param string $tooltip The tooltip to use for the link: will be escaped
+ * and wrapped in the 'editsectionhint' message
+ * @param string $lang Language code
+ * @return string HTML to use for edit link
+ */
+ public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
+ // HTML generated here should probably have userlangattributes
+ // added to it for LTR text on RTL pages
+
+ $lang = wfGetLangObj( $lang );
+
+ $attribs = [];
+ if ( !is_null( $tooltip ) ) {
+ $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
+ ->inLanguage( $lang )->text();
+ }
+
+ $links = [
+ 'editsection' => [
+ 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(),
+ 'targetTitle' => $nt,
+ 'attribs' => $attribs,
+ 'query' => [ 'action' => 'edit', 'section' => $section ],
+ 'options' => [ 'noclasses', 'known' ]
+ ]
+ ];
+
+ Hooks::run( 'SkinEditSectionLinks', [ $this, $nt, $section, $tooltip, &$links, $lang ] );
+
+ $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
+
+ $linksHtml = [];
+ foreach ( $links as $k => $linkDetails ) {
+ $linksHtml[] = Linker::link(
+ $linkDetails['targetTitle'],
+ $linkDetails['text'],
+ $linkDetails['attribs'],
+ $linkDetails['query'],
+ $linkDetails['options']
+ );
+ }
+
+ $result .= implode(
+ '<span class="mw-editsection-divider">'
+ . wfMessage( 'pipe-separator' )->inLanguage( $lang )->escaped()
+ . '</span>',
+ $linksHtml
+ );
+
+ $result .= '<span class="mw-editsection-bracket">]</span></span>';
+ // Deprecated, use SkinEditSectionLinks hook instead
+ Hooks::run(
+ 'DoEditSectionLink',
+ [ $this, $nt, $section, $tooltip, &$result, $lang ],
+ '1.25'
+ );
+ return $result;
+ }
+
+}
diff --git a/www/wiki/includes/skins/SkinApi.php b/www/wiki/includes/skins/SkinApi.php
new file mode 100644
index 00000000..6966ff71
--- /dev/null
+++ b/www/wiki/includes/skins/SkinApi.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Extremely basic "skin" for API output, which needs to output a page without
+ * the usual skin elements but still using CSS, JS, and such via OutputPage and
+ * ResourceLoader.
+ *
+ * Copyright Ā© 2014 Wikimedia Foundation and contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * SkinTemplate class for API output
+ * @since 1.25
+ */
+class SkinApi extends SkinTemplate {
+ public $skinname = 'apioutput';
+ public $template = SkinApiTemplate::class;
+
+ public function setupSkinUserCss( OutputPage $out ) {
+ parent::setupSkinUserCss( $out );
+ $out->addModuleStyles( 'mediawiki.skinning.interface' );
+ }
+
+ // Skip work and hooks for stuff we don't use
+
+ function buildSidebar() {
+ return [];
+ }
+
+ function getNewtalks() {
+ return '';
+ }
+
+ function getSiteNotice() {
+ return '';
+ }
+
+ public function getLanguages() {
+ return [];
+ }
+
+ protected function buildPersonalUrls() {
+ return [];
+ }
+
+ protected function buildContentNavigationUrls() {
+ return [];
+ }
+
+ protected function buildNavUrls() {
+ return [];
+ }
+}
diff --git a/www/wiki/includes/skins/SkinApiTemplate.php b/www/wiki/includes/skins/SkinApiTemplate.php
new file mode 100644
index 00000000..222a7626
--- /dev/null
+++ b/www/wiki/includes/skins/SkinApiTemplate.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Extremely basic "skin" for API output, which needs to output a page without
+ * the usual skin elements but still using CSS, JS, and such via OutputPage and
+ * ResourceLoader.
+ *
+ * Copyright Ā© 2014 Wikimedia Foundation and contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * BaseTemplate class for the 'apioutput' skin
+ * @since 1.25
+ */
+class SkinApiTemplate extends BaseTemplate {
+
+ public function execute() {
+ $this->html( 'headelement' ) ?>
+
+ <div class="mw-body" role="main">
+ <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
+ <div class="mw-body-content">
+ <?php $this->html( 'bodytext' ) ?>
+ </div>
+ </div>
+
+ <?php $this->printTrail() ?>
+ </body></html>
+<?php
+ }
+
+ // Skip work and hooks for stuff we don't use
+
+ function getToolbox() {
+ return [];
+ }
+
+ function getPersonalTools() {
+ return [];
+ }
+
+ function getSidebar( $options = [] ) {
+ return [];
+ }
+}
diff --git a/www/wiki/includes/skins/SkinException.php b/www/wiki/includes/skins/SkinException.php
new file mode 100644
index 00000000..31ff1437
--- /dev/null
+++ b/www/wiki/includes/skins/SkinException.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Exceptions for skin-related failures
+ *
+ * @since 1.24
+ */
+class SkinException extends MWException {
+}
diff --git a/www/wiki/includes/skins/SkinFactory.php b/www/wiki/includes/skins/SkinFactory.php
new file mode 100644
index 00000000..cc993aaf
--- /dev/null
+++ b/www/wiki/includes/skins/SkinFactory.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * Copyright 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+use MediaWiki\MediaWikiServices;
+
+/**
+ * Factory class to create Skin objects
+ *
+ * @since 1.24
+ */
+class SkinFactory {
+
+ /**
+ * Map of name => callback
+ * @var array
+ */
+ private $factoryFunctions = [];
+ /**
+ * Map of name => fallback human-readable name, used when the 'skinname-<skin>' message is not
+ * available
+ *
+ * @var array
+ */
+ private $displayNames = [];
+
+ /**
+ * @deprecated in 1.27
+ * @return SkinFactory
+ */
+ public static function getDefaultInstance() {
+ return MediaWikiServices::getInstance()->getSkinFactory();
+ }
+
+ /**
+ * Register a new Skin factory function.
+ *
+ * Will override if it's already registered.
+ *
+ * @param string $name Internal skin name. Should be all-lowercase (technically doesn't have
+ * to be, but doing so would change the case of i18n message keys).
+ * @param string $displayName For backwards-compatibility with old skin loading system. This is
+ * the text used as skin's human-readable name when the 'skinname-<skin>' message is not
+ * available. It should be the same as the skin name provided in $wgExtensionCredits.
+ * @param callable $callback Callback that takes the skin name as an argument
+ * @throws InvalidArgumentException If an invalid callback is provided
+ */
+ public function register( $name, $displayName, $callback ) {
+ if ( !is_callable( $callback ) ) {
+ throw new InvalidArgumentException( 'Invalid callback provided' );
+ }
+ $this->factoryFunctions[$name] = $callback;
+ $this->displayNames[$name] = $displayName;
+ }
+
+ /**
+ * Returns an associative array of:
+ * skin name => human readable name
+ *
+ * @return array
+ */
+ public function getSkinNames() {
+ return $this->displayNames;
+ }
+
+ /**
+ * Create a given Skin using the registered callback for $name.
+ * @param string $name Name of the skin you want
+ * @throws SkinException If a factory function isn't registered for $name
+ * @throws UnexpectedValueException If the factory function returns a non-Skin object
+ * @return Skin
+ */
+ public function makeSkin( $name ) {
+ if ( !isset( $this->factoryFunctions[$name] ) ) {
+ throw new SkinException( "No registered builder available for $name." );
+ }
+ $skin = call_user_func( $this->factoryFunctions[$name], $name );
+ if ( $skin instanceof Skin ) {
+ return $skin;
+ } else {
+ throw new UnexpectedValueException( "The builder for $name returned a non-Skin object." );
+ }
+ }
+}
diff --git a/www/wiki/includes/skins/SkinFallback.php b/www/wiki/includes/skins/SkinFallback.php
new file mode 100644
index 00000000..d5f764c6
--- /dev/null
+++ b/www/wiki/includes/skins/SkinFallback.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Skin file for the fallback skin.
+ *
+ * The structure is copied from the example skin (mediawiki/skins/Example).
+ *
+ * @since 1.24
+ * @file
+ */
+
+/**
+ * SkinTemplate class for the fallback skin
+ */
+class SkinFallback extends SkinTemplate {
+
+ public $skinname = 'fallback';
+ public $template = SkinFallbackTemplate::class;
+
+ /**
+ * Add CSS via ResourceLoader
+ *
+ * @param OutputPage $out
+ */
+ public function setupSkinUserCss( OutputPage $out ) {
+ parent::setupSkinUserCss( $out );
+ $out->addModuleStyles( 'mediawiki.skinning.interface' );
+ }
+
+ /**
+ * @param OutputPage $out
+ */
+ public function initPage( OutputPage $out ) {
+ parent::initPage( $out );
+ $out->enableClientCache( false );
+ }
+}
diff --git a/www/wiki/includes/skins/SkinFallbackTemplate.php b/www/wiki/includes/skins/SkinFallbackTemplate.php
new file mode 100644
index 00000000..bd02fa32
--- /dev/null
+++ b/www/wiki/includes/skins/SkinFallbackTemplate.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * Skin template for the fallback skin.
+ *
+ * The structure is copied from the example skin (mediawiki/skins/Example).
+ *
+ * @since 1.24
+ * @file
+ */
+
+/**
+ * BaseTemplate class for the fallback skin
+ */
+class SkinFallbackTemplate extends BaseTemplate {
+ /**
+ * @return array
+ */
+ private function findInstalledSkins() {
+ $styleDirectory = $this->config->get( 'StyleDirectory' );
+ // Get all subdirectories which might contains skins
+ $possibleSkins = scandir( $styleDirectory );
+ $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
+ return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
+ } );
+
+ // Filter out skins that aren't installed
+ $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
+ return is_file( "$styleDirectory/$skinDir/skin.json" )
+ || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
+ } );
+
+ return $possibleSkins;
+ }
+
+ /**
+ * Inform the user why they are seeing this skin.
+ *
+ * @return string
+ */
+ private function buildHelpfulInformationMessage() {
+ $defaultSkin = $this->config->get( 'DefaultSkin' );
+ $installedSkins = $this->findInstalledSkins();
+ $enabledSkins = SkinFactory::getDefaultInstance()->getSkinNames();
+ $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
+
+ if ( $installedSkins ) {
+ $skinsInstalledText = [];
+ $skinsInstalledSnippet = [];
+
+ foreach ( $installedSkins as $skin ) {
+ $normalizedKey = strtolower( $skin );
+ $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
+ if ( $isEnabled ) {
+ $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
+ ->params( $normalizedKey, $skin )->plain();
+ } else {
+ $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
+ ->params( $normalizedKey, $skin )->plain();
+ $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skin );
+ }
+ }
+
+ return $this->getMsg( 'default-skin-not-found' )->params(
+ $defaultSkin,
+ implode( "\n", $skinsInstalledText ),
+ implode( "\n", $skinsInstalledSnippet ) )->numParams(
+ count( $skinsInstalledText ),
+ count( $skinsInstalledSnippet )
+ )->parseAsBlock();
+ } else {
+ return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
+ $defaultSkin
+ )->parseAsBlock();
+ }
+ }
+
+ /**
+ * Get the appropriate LocalSettings.php snippet to enable the given skin
+ *
+ * @param string $skin
+ * @return string
+ */
+ private function getSnippetForSkin( $skin ) {
+ global $IP;
+ if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
+ return "wfLoadSkin( '$skin' );";
+ } else {
+ return "require_once \"\$IP/skins/$skin/$skin.php\";";
+ }
+ }
+
+ /**
+ * Outputs the entire contents of the page. No navigation (other than search box), just the big
+ * warning message and page content.
+ */
+ public function execute() {
+ $this->html( 'headelement' );
+ echo Html::warningBox( $this->buildHelpfulInformationMessage() );
+ ?>
+ <form action="<?php $this->text( 'wgScript' ) ?>">
+ <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
+ <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
+ <?php echo $this->makeSearchInput( [ "id" => "searchInput" ] ) ?>
+ <?php echo $this->makeSearchButton( 'go' ) ?>
+ </form>
+
+ <div class="mw-body" role="main">
+ <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
+
+ <div class="mw-body-content">
+ <?php $this->html( 'bodytext' ) ?>
+ <?php $this->html( 'catlinks' ) ?>
+ </div>
+ </div>
+
+ <?php $this->printTrail() ?>
+ </body></html>
+
+ <?php
+ }
+}
diff --git a/www/wiki/includes/skins/SkinTemplate.php b/www/wiki/includes/skins/SkinTemplate.php
new file mode 100644
index 00000000..203326f1
--- /dev/null
+++ b/www/wiki/includes/skins/SkinTemplate.php
@@ -0,0 +1,1404 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+use MediaWiki\Auth\AuthManager;
+use MediaWiki\MediaWikiServices;
+
+/**
+ * Base class for template-based skins.
+ *
+ * Template-filler skin base class
+ * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
+ * Based on Brion's smarty skin
+ * @copyright Copyright Ā© Gabriel Wicke -- http://www.aulinx.de/
+ *
+ * @todo Needs some serious refactoring into functions that correspond
+ * to the computations individual esi snippets need. Most importantly no body
+ * parsing for most of those of course.
+ *
+ * @ingroup Skins
+ */
+class SkinTemplate extends Skin {
+ /**
+ * @var string Name of our skin, it probably needs to be all lower case.
+ * Child classes should override the default.
+ */
+ public $skinname = 'monobook';
+
+ /**
+ * @var string For QuickTemplate, the name of the subclass which will
+ * actually fill the template. Child classes should override the default.
+ */
+ public $template = QuickTemplate::class;
+
+ public $thispage;
+ public $titletxt;
+ public $userpage;
+ public $thisquery;
+ public $loggedin;
+ public $username;
+ public $userpageUrlDetails;
+
+ /**
+ * Add specific styles for this skin
+ *
+ * @param OutputPage $out
+ */
+ public function setupSkinUserCss( OutputPage $out ) {
+ $moduleStyles = [
+ 'mediawiki.legacy.shared',
+ 'mediawiki.legacy.commonPrint',
+ 'mediawiki.sectionAnchor'
+ ];
+ if ( $out->isSyndicated() ) {
+ $moduleStyles[] = 'mediawiki.feedlink';
+ }
+
+ // Deprecated since 1.26: Unconditional loading of mediawiki.ui.button
+ // on every page is deprecated. Express a dependency instead.
+ if ( strpos( $out->getHTML(), 'mw-ui-button' ) !== false ) {
+ $moduleStyles[] = 'mediawiki.ui.button';
+ }
+
+ $out->addModuleStyles( $moduleStyles );
+ }
+
+ /**
+ * Create the template engine object; we feed it a bunch of data
+ * and eventually it spits out some HTML. Should have interface
+ * roughly equivalent to PHPTAL 0.7.
+ *
+ * @param string $classname
+ * @param bool|string $repository Subdirectory where we keep template files
+ * @param bool|string $cache_dir
+ * @return QuickTemplate
+ * @private
+ */
+ function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
+ return new $classname( $this->getConfig() );
+ }
+
+ /**
+ * Generates array of language links for the current page
+ *
+ * @return array
+ */
+ public function getLanguages() {
+ global $wgHideInterlanguageLinks;
+ if ( $wgHideInterlanguageLinks ) {
+ return [];
+ }
+
+ $userLang = $this->getLanguage();
+ $languageLinks = [];
+
+ foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
+ $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
+
+ $languageLinkTitle = Title::newFromText( $languageLinkText );
+ if ( $languageLinkTitle ) {
+ $ilInterwikiCode = $languageLinkTitle->getInterwiki();
+ $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
+
+ if ( strval( $ilLangName ) === '' ) {
+ $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
+ if ( !$ilDisplayTextMsg->isDisabled() ) {
+ // Use custom MW message for the display text
+ $ilLangName = $ilDisplayTextMsg->text();
+ } else {
+ // Last resort: fallback to the language link target
+ $ilLangName = $languageLinkText;
+ }
+ } else {
+ // Use the language autonym as display text
+ $ilLangName = $this->formatLanguageName( $ilLangName );
+ }
+
+ // CLDR extension or similar is required to localize the language name;
+ // otherwise we'll end up with the autonym again.
+ $ilLangLocalName = Language::fetchLanguageName(
+ $ilInterwikiCode,
+ $userLang->getCode()
+ );
+
+ $languageLinkTitleText = $languageLinkTitle->getText();
+ if ( $ilLangLocalName === '' ) {
+ $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
+ if ( !$ilFriendlySiteName->isDisabled() ) {
+ if ( $languageLinkTitleText === '' ) {
+ $ilTitle = wfMessage(
+ 'interlanguage-link-title-nonlangonly',
+ $ilFriendlySiteName->text()
+ )->text();
+ } else {
+ $ilTitle = wfMessage(
+ 'interlanguage-link-title-nonlang',
+ $languageLinkTitleText,
+ $ilFriendlySiteName->text()
+ )->text();
+ }
+ } else {
+ // we have nothing friendly to put in the title, so fall back to
+ // displaying the interlanguage link itself in the title text
+ // (similar to what is done in page content)
+ $ilTitle = $languageLinkTitle->getInterwiki() .
+ ":$languageLinkTitleText";
+ }
+ } elseif ( $languageLinkTitleText === '' ) {
+ $ilTitle = wfMessage(
+ 'interlanguage-link-title-langonly',
+ $ilLangLocalName
+ )->text();
+ } else {
+ $ilTitle = wfMessage(
+ 'interlanguage-link-title',
+ $languageLinkTitleText,
+ $ilLangLocalName
+ )->text();
+ }
+
+ $ilInterwikiCodeBCP47 = LanguageCode::bcp47( $ilInterwikiCode );
+ $languageLink = [
+ 'href' => $languageLinkTitle->getFullURL(),
+ 'text' => $ilLangName,
+ 'title' => $ilTitle,
+ 'class' => $class,
+ 'link-class' => 'interlanguage-link-target',
+ 'lang' => $ilInterwikiCodeBCP47,
+ 'hreflang' => $ilInterwikiCodeBCP47,
+ ];
+ Hooks::run(
+ 'SkinTemplateGetLanguageLink',
+ [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
+ );
+ $languageLinks[] = $languageLink;
+ }
+ }
+
+ return $languageLinks;
+ }
+
+ protected function setupTemplateForOutput() {
+ $request = $this->getRequest();
+ $user = $this->getUser();
+ $title = $this->getTitle();
+
+ $tpl = $this->setupTemplate( $this->template, 'skins' );
+
+ $this->thispage = $title->getPrefixedDBkey();
+ $this->titletxt = $title->getPrefixedText();
+ $this->userpage = $user->getUserPage()->getPrefixedText();
+ $query = [];
+ if ( !$request->wasPosted() ) {
+ $query = $request->getValues();
+ unset( $query['title'] );
+ unset( $query['returnto'] );
+ unset( $query['returntoquery'] );
+ }
+ $this->thisquery = wfArrayToCgi( $query );
+ $this->loggedin = $user->isLoggedIn();
+ $this->username = $user->getName();
+
+ if ( $this->loggedin ) {
+ $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
+ } else {
+ # This won't be used in the standard skins, but we define it to preserve the interface
+ # To save time, we check for existence
+ $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
+ }
+
+ return $tpl;
+ }
+
+ /**
+ * initialize various variables and generate the template
+ *
+ * @param OutputPage $out
+ */
+ function outputPage( OutputPage $out = null ) {
+ Profiler::instance()->setTemplated( true );
+
+ $oldContext = null;
+ if ( $out !== null ) {
+ // Deprecated since 1.20, note added in 1.25
+ wfDeprecated( __METHOD__, '1.25' );
+ $oldContext = $this->getContext();
+ $this->setContext( $out->getContext() );
+ }
+
+ $out = $this->getOutput();
+
+ $this->initPage( $out );
+ $tpl = $this->prepareQuickTemplate();
+ // execute template
+ $res = $tpl->execute();
+
+ // result may be an error
+ $this->printOrError( $res );
+
+ if ( $oldContext ) {
+ $this->setContext( $oldContext );
+ }
+ }
+
+ /**
+ * Wrap the body text with language information and identifiable element
+ *
+ * @param Title $title
+ * @param string $html body text
+ * @return string html
+ */
+ protected function wrapHTML( $title, $html ) {
+ # An ID that includes the actual body text; without categories, contentSub, ...
+ $realBodyAttribs = [ 'id' => 'mw-content-text' ];
+
+ # Add a mw-content-ltr/rtl class to be able to style based on text
+ # direction when the content is different from the UI language (only
+ # when viewing)
+ # Most information on special pages and file pages is in user language,
+ # rather than content language, so those will not get this
+ if ( Action::getActionName( $this ) === 'view' &&
+ ( !$title->inNamespaces( NS_SPECIAL, NS_FILE ) || $title->isRedirect() ) ) {
+ $pageLang = $title->getPageViewLanguage();
+ $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
+ $realBodyAttribs['dir'] = $pageLang->getDir();
+ $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
+ }
+
+ return Html::rawElement( 'div', $realBodyAttribs, $html );
+ }
+
+ /**
+ * initialize various variables and generate the template
+ *
+ * @since 1.23
+ * @return QuickTemplate The template to be executed by outputPage
+ */
+ protected function prepareQuickTemplate() {
+ global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
+ $wgSitename, $wgLogo, $wgMaxCredits,
+ $wgShowCreditsIfMax, $wgArticlePath,
+ $wgScriptPath, $wgServer;
+
+ $title = $this->getTitle();
+ $request = $this->getRequest();
+ $out = $this->getOutput();
+ $tpl = $this->setupTemplateForOutput();
+
+ $tpl->set( 'title', $out->getPageTitle() );
+ $tpl->set( 'pagetitle', $out->getHTMLTitle() );
+ $tpl->set( 'displaytitle', $out->mPageLinkTitle );
+
+ $tpl->set( 'thispage', $this->thispage );
+ $tpl->set( 'titleprefixeddbkey', $this->thispage );
+ $tpl->set( 'titletext', $title->getText() );
+ $tpl->set( 'articleid', $title->getArticleID() );
+
+ $tpl->set( 'isarticle', $out->isArticle() );
+
+ $subpagestr = $this->subPageSubtitle();
+ if ( $subpagestr !== '' ) {
+ $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
+ }
+ $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
+
+ $undelete = $this->getUndeleteLink();
+ if ( $undelete === '' ) {
+ $tpl->set( 'undelete', '' );
+ } else {
+ $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
+ }
+
+ $tpl->set( 'catlinks', $this->getCategories() );
+ if ( $out->isSyndicated() ) {
+ $feeds = [];
+ foreach ( $out->getSyndicationLinks() as $format => $link ) {
+ $feeds[$format] = [
+ // Messages: feed-atom, feed-rss
+ 'text' => $this->msg( "feed-$format" )->text(),
+ 'href' => $link
+ ];
+ }
+ $tpl->set( 'feeds', $feeds );
+ } else {
+ $tpl->set( 'feeds', false );
+ }
+
+ $tpl->set( 'mimetype', $wgMimeType );
+ $tpl->set( 'jsmimetype', $wgJsMimeType );
+ $tpl->set( 'charset', 'UTF-8' );
+ $tpl->set( 'wgScript', $wgScript );
+ $tpl->set( 'skinname', $this->skinname );
+ $tpl->set( 'skinclass', static::class );
+ $tpl->set( 'skin', $this );
+ $tpl->set( 'stylename', $this->stylename );
+ $tpl->set( 'printable', $out->isPrintable() );
+ $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
+ $tpl->set( 'loggedin', $this->loggedin );
+ $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
+ $tpl->set( 'searchaction', $this->escapeSearchLink() );
+ $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
+ $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
+ $tpl->set( 'stylepath', $wgStylePath );
+ $tpl->set( 'articlepath', $wgArticlePath );
+ $tpl->set( 'scriptpath', $wgScriptPath );
+ $tpl->set( 'serverurl', $wgServer );
+ $tpl->set( 'logopath', $wgLogo );
+ $tpl->set( 'sitename', $wgSitename );
+
+ $userLang = $this->getLanguage();
+ $userLangCode = $userLang->getHtmlCode();
+ $userLangDir = $userLang->getDir();
+
+ $tpl->set( 'lang', $userLangCode );
+ $tpl->set( 'dir', $userLangDir );
+ $tpl->set( 'rtl', $userLang->isRTL() );
+
+ $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
+ $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
+ $tpl->set( 'username', $this->loggedin ? $this->username : null );
+ $tpl->set( 'userpage', $this->userpage );
+ $tpl->set( 'userpageurl', $this->userpageUrlDetails['href'] );
+ $tpl->set( 'userlang', $userLangCode );
+
+ // Users can have their language set differently than the
+ // content of the wiki. For these users, tell the web browser
+ // that interface elements are in a different language.
+ $tpl->set( 'userlangattributes', '' );
+ $tpl->set( 'specialpageattributes', '' ); # obsolete
+ // Used by VectorBeta to insert HTML before content but after the
+ // heading for the page title. Defaults to empty string.
+ $tpl->set( 'prebodyhtml', '' );
+
+ if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
+ $escUserlang = htmlspecialchars( $userLangCode );
+ $escUserdir = htmlspecialchars( $userLangDir );
+ // Attributes must be in double quotes because htmlspecialchars() doesn't
+ // escape single quotes
+ $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
+ $tpl->set( 'userlangattributes', $attrs );
+ }
+
+ $tpl->set( 'newtalk', $this->getNewtalks() );
+ $tpl->set( 'logo', $this->logoText() );
+
+ $tpl->set( 'copyright', false );
+ // No longer used
+ $tpl->set( 'viewcount', false );
+ $tpl->set( 'lastmod', false );
+ $tpl->set( 'credits', false );
+ $tpl->set( 'numberofwatchingusers', false );
+ if ( $out->isArticle() && $title->exists() ) {
+ if ( $this->isRevisionCurrent() ) {
+ if ( $wgMaxCredits != 0 ) {
+ $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
+ $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
+ } else {
+ $tpl->set( 'lastmod', $this->lastModified() );
+ }
+ }
+ $tpl->set( 'copyright', $this->getCopyright() );
+ }
+
+ $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
+ $tpl->set( 'poweredbyico', $this->getPoweredBy() );
+ $tpl->set( 'disclaimer', $this->disclaimerLink() );
+ $tpl->set( 'privacy', $this->privacyLink() );
+ $tpl->set( 'about', $this->aboutLink() );
+
+ $tpl->set( 'footerlinks', [
+ 'info' => [
+ 'lastmod',
+ 'numberofwatchingusers',
+ 'credits',
+ 'copyright',
+ ],
+ 'places' => [
+ 'privacy',
+ 'about',
+ 'disclaimer',
+ ],
+ ] );
+
+ global $wgFooterIcons;
+ $tpl->set( 'footericons', $wgFooterIcons );
+ foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
+ if ( count( $footerIconsBlock ) > 0 ) {
+ foreach ( $footerIconsBlock as &$footerIcon ) {
+ if ( isset( $footerIcon['src'] ) ) {
+ if ( !isset( $footerIcon['width'] ) ) {
+ $footerIcon['width'] = 88;
+ }
+ if ( !isset( $footerIcon['height'] ) ) {
+ $footerIcon['height'] = 31;
+ }
+ }
+ }
+ } else {
+ unset( $tpl->data['footericons'][$footerIconsKey] );
+ }
+ }
+
+ $tpl->set( 'indicators', $out->getIndicators() );
+
+ $tpl->set( 'sitenotice', $this->getSiteNotice() );
+ $tpl->set( 'printfooter', $this->printSource() );
+ // Wrap the bodyText with #mw-content-text element
+ $out->mBodytext = $this->wrapHTML( $title, $out->mBodytext );
+ $tpl->set( 'bodytext', $out->mBodytext );
+
+ $language_urls = $this->getLanguages();
+ if ( count( $language_urls ) ) {
+ $tpl->set( 'language_urls', $language_urls );
+ } else {
+ $tpl->set( 'language_urls', false );
+ }
+
+ # Personal toolbar
+ $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
+ $content_navigation = $this->buildContentNavigationUrls();
+ $content_actions = $this->buildContentActionUrls( $content_navigation );
+ $tpl->set( 'content_navigation', $content_navigation );
+ $tpl->set( 'content_actions', $content_actions );
+
+ $tpl->set( 'sidebar', $this->buildSidebar() );
+ $tpl->set( 'nav_urls', $this->buildNavUrls() );
+
+ // Do this last in case hooks above add bottom scripts
+ $tpl->set( 'bottomscripts', $this->bottomScripts() );
+
+ // Set the head scripts near the end, in case the above actions resulted in added scripts
+ $tpl->set( 'headelement', $out->headElement( $this ) );
+
+ $tpl->set( 'debug', '' );
+ $tpl->set( 'debughtml', $this->generateDebugHTML() );
+ $tpl->set( 'reporttime', wfReportTime() );
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ // original version by hansm
+ if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
+ wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
+ }
+
+ // Set the bodytext to another key so that skins can just output it on its own
+ // and output printfooter and debughtml separately
+ $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
+
+ // Append printfooter and debughtml onto bodytext so that skins that
+ // were already using bodytext before they were split out don't suddenly
+ // start not outputting information.
+ $tpl->data['bodytext'] .= Html::rawElement(
+ 'div',
+ [ 'class' => 'printfooter' ],
+ "\n{$tpl->data['printfooter']}"
+ ) . "\n";
+ $tpl->data['bodytext'] .= $tpl->data['debughtml'];
+
+ // allow extensions adding stuff after the page content.
+ // See Skin::afterContentHook() for further documentation.
+ $tpl->set( 'dataAfterContent', $this->afterContentHook() );
+
+ return $tpl;
+ }
+
+ /**
+ * Get the HTML for the p-personal list
+ * @return string
+ */
+ public function getPersonalToolsList() {
+ return $this->makePersonalToolsList();
+ }
+
+ /**
+ * Get the HTML for the personal tools list
+ *
+ * @since 1.31
+ *
+ * @param array $personalTools
+ * @param array $options
+ * @return string
+ */
+ public function makePersonalToolsList( $personalTools = null, $options = [] ) {
+ $tpl = $this->setupTemplateForOutput();
+ $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
+ $html = '';
+
+ if ( $personalTools === null ) {
+ $personalTools = $tpl->getPersonalTools();
+ }
+
+ foreach ( $personalTools as $key => $item ) {
+ $html .= $tpl->makeListItem( $key, $item, $options );
+ }
+
+ return $html;
+ }
+
+ /**
+ * Get personal tools for the user
+ *
+ * @since 1.31
+ *
+ * @return array Array of personal tools
+ */
+ public function getStructuredPersonalTools() {
+ $tpl = $this->setupTemplateForOutput();
+ $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
+
+ return $tpl->getPersonalTools();
+ }
+
+ /**
+ * Format language name for use in sidebar interlanguage links list.
+ * By default it is capitalized.
+ *
+ * @param string $name Language name, e.g. "English" or "espaƱol"
+ * @return string
+ * @private
+ */
+ function formatLanguageName( $name ) {
+ return $this->getLanguage()->ucfirst( $name );
+ }
+
+ /**
+ * Output the string, or print error message if it's
+ * an error object of the appropriate type.
+ * For the base class, assume strings all around.
+ *
+ * @param string $str
+ * @private
+ */
+ function printOrError( $str ) {
+ echo $str;
+ }
+
+ /**
+ * Output a boolean indicating if buildPersonalUrls should output separate
+ * login and create account links or output a combined link
+ * By default we simply return a global config setting that affects most skins
+ * This is setup as a method so that like with $wgLogo and getLogo() a skin
+ * can override this setting and always output one or the other if it has
+ * a reason it can't output one of the two modes.
+ * @return bool
+ */
+ function useCombinedLoginLink() {
+ global $wgUseCombinedLoginLink;
+ return $wgUseCombinedLoginLink;
+ }
+
+ /**
+ * build array of urls for personal toolbar
+ * @return array
+ */
+ protected function buildPersonalUrls() {
+ $title = $this->getTitle();
+ $request = $this->getRequest();
+ $pageurl = $title->getLocalURL();
+ $authManager = AuthManager::singleton();
+
+ /* set up the default links for the personal toolbar */
+ $personal_urls = [];
+
+ # Due to T34276, if a user does not have read permissions,
+ # $this->getTitle() will just give Special:Badtitle, which is
+ # not especially useful as a returnto parameter. Use the title
+ # from the request instead, if there was one.
+ if ( $this->getUser()->isAllowed( 'read' ) ) {
+ $page = $this->getTitle();
+ } else {
+ $page = Title::newFromText( $request->getVal( 'title', '' ) );
+ }
+ $page = $request->getVal( 'returnto', $page );
+ $returnto = [];
+ if ( strval( $page ) !== '' ) {
+ $returnto['returnto'] = $page;
+ $query = $request->getVal( 'returntoquery', $this->thisquery );
+ $paramsArray = wfCgiToArray( $query );
+ unset( $paramsArray['logoutToken'] );
+ $query = wfArrayToCgi( $paramsArray );
+ if ( $query != '' ) {
+ $returnto['returntoquery'] = $query;
+ }
+ }
+
+ if ( $this->loggedin ) {
+ $personal_urls['userpage'] = [
+ 'text' => $this->username,
+ 'href' => &$this->userpageUrlDetails['href'],
+ 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
+ 'exists' => $this->userpageUrlDetails['exists'],
+ 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
+ 'dir' => 'auto'
+ ];
+ $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
+ $personal_urls['mytalk'] = [
+ 'text' => $this->msg( 'mytalk' )->text(),
+ 'href' => &$usertalkUrlDetails['href'],
+ 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
+ 'exists' => $usertalkUrlDetails['exists'],
+ 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
+ ];
+ $href = self::makeSpecialUrl( 'Preferences' );
+ $personal_urls['preferences'] = [
+ 'text' => $this->msg( 'mypreferences' )->text(),
+ 'href' => $href,
+ 'active' => ( $href == $pageurl )
+ ];
+
+ if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
+ $href = self::makeSpecialUrl( 'Watchlist' );
+ $personal_urls['watchlist'] = [
+ 'text' => $this->msg( 'mywatchlist' )->text(),
+ 'href' => $href,
+ 'active' => ( $href == $pageurl )
+ ];
+ }
+
+ # We need to do an explicit check for Special:Contributions, as we
+ # have to match both the title, and the target, which could come
+ # from request values (Special:Contributions?target=Jimbo_Wales)
+ # or be specified in "sub page" form
+ # (Special:Contributions/Jimbo_Wales). The plot
+ # thickens, because the Title object is altered for special pages,
+ # so it doesn't contain the original alias-with-subpage.
+ $origTitle = Title::newFromText( $request->getText( 'title' ) );
+ if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
+ list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
+ $active = $spName == 'Contributions'
+ && ( ( $spPar && $spPar == $this->username )
+ || $request->getText( 'target' ) == $this->username );
+ } else {
+ $active = false;
+ }
+
+ $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
+ $personal_urls['mycontris'] = [
+ 'text' => $this->msg( 'mycontris' )->text(),
+ 'href' => $href,
+ 'active' => $active
+ ];
+
+ // if we can't set the user, we can't unset it either
+ if ( $request->getSession()->canSetUser() ) {
+ $personal_urls['logout'] = [
+ 'text' => $this->msg( 'pt-userlogout' )->text(),
+ 'href' => self::makeSpecialUrl( 'Userlogout',
+ // Note: userlogout link must always contain an & character, otherwise we might not be able
+ // to detect a buggy precaching proxy (T19790)
+ ( $title->isSpecial( 'Preferences' ) ? [] : $returnto )
+ + [ 'logoutToken' => $this->getUser()->getEditToken( 'logoutToken', $this->getRequest() ) ] ),
+ 'active' => false
+ ];
+ }
+ } else {
+ $useCombinedLoginLink = $this->useCombinedLoginLink();
+ if ( !$authManager->canCreateAccounts() || !$authManager->canAuthenticateNow() ) {
+ // don't show combined login/signup link if one of those is actually not available
+ $useCombinedLoginLink = false;
+ }
+
+ $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
+ ? 'nav-login-createaccount'
+ : 'pt-login';
+
+ $login_url = [
+ 'text' => $this->msg( $loginlink )->text(),
+ 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
+ 'active' => $title->isSpecial( 'Userlogin' )
+ || $title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink,
+ ];
+ $createaccount_url = [
+ 'text' => $this->msg( 'pt-createaccount' )->text(),
+ 'href' => self::makeSpecialUrl( 'CreateAccount', $returnto ),
+ 'active' => $title->isSpecial( 'CreateAccount' ),
+ ];
+
+ // No need to show Talk and Contributions to anons if they can't contribute!
+ if ( User::groupHasPermission( '*', 'edit' ) ) {
+ // Because of caching, we can't link directly to the IP talk and
+ // contributions pages. Instead we use the special page shortcuts
+ // (which work correctly regardless of caching). This means we can't
+ // determine whether these links are active or not, but since major
+ // skins (MonoBook, Vector) don't use this information, it's not a
+ // huge loss.
+ $personal_urls['anontalk'] = [
+ 'text' => $this->msg( 'anontalk' )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Mytalk', false ),
+ 'active' => false
+ ];
+ $personal_urls['anoncontribs'] = [
+ 'text' => $this->msg( 'anoncontribs' )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Mycontributions', false ),
+ 'active' => false
+ ];
+ }
+
+ if (
+ $authManager->canCreateAccounts()
+ && $this->getUser()->isAllowed( 'createaccount' )
+ && !$useCombinedLoginLink
+ ) {
+ $personal_urls['createaccount'] = $createaccount_url;
+ }
+
+ if ( $authManager->canAuthenticateNow() ) {
+ $key = User::groupHasPermission( '*', 'read' )
+ ? 'login'
+ : 'login-private';
+ $personal_urls[$key] = $login_url;
+ }
+ }
+
+ Hooks::runWithoutAbort( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
+ return $personal_urls;
+ }
+
+ /**
+ * Builds an array with tab definition
+ *
+ * @param Title $title Page Where the tab links to
+ * @param string|array $message Message key or an array of message keys (will fall back)
+ * @param bool $selected Display the tab as selected
+ * @param string $query Query string attached to tab URL
+ * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
+ *
+ * @return array
+ */
+ function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
+ $classes = [];
+ if ( $selected ) {
+ $classes[] = 'selected';
+ }
+ $exists = true;
+ if ( $checkEdit && !$title->isKnown() ) {
+ $classes[] = 'new';
+ $exists = false;
+ if ( $query !== '' ) {
+ $query = 'action=edit&redlink=1&' . $query;
+ } else {
+ $query = 'action=edit&redlink=1';
+ }
+ }
+
+ $linkClass = MediaWikiServices::getInstance()->getLinkRenderer()->getLinkClasses( $title );
+
+ // wfMessageFallback will nicely accept $message as an array of fallbacks
+ // or just a single key
+ $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
+ if ( is_array( $message ) ) {
+ // for hook compatibility just keep the last message name
+ $message = end( $message );
+ }
+ if ( $msg->exists() ) {
+ $text = $msg->text();
+ } else {
+ global $wgContLang;
+ $text = $wgContLang->getConverter()->convertNamespace(
+ MWNamespace::getSubject( $title->getNamespace() ) );
+ }
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ $result = [];
+ if ( !Hooks::run( 'SkinTemplateTabAction', [ &$skinTemplate,
+ $title, $message, $selected, $checkEdit,
+ &$classes, &$query, &$text, &$result ] ) ) {
+ return $result;
+ }
+
+ $result = [
+ 'class' => implode( ' ', $classes ),
+ 'text' => $text,
+ 'href' => $title->getLocalURL( $query ),
+ 'exists' => $exists,
+ 'primary' => true ];
+ if ( $linkClass !== '' ) {
+ $result['link-class'] = $linkClass;
+ }
+
+ return $result;
+ }
+
+ function makeTalkUrlDetails( $name, $urlaction = '' ) {
+ $title = Title::newFromText( $name );
+ if ( !is_object( $title ) ) {
+ throw new MWException( __METHOD__ . " given invalid pagename $name" );
+ }
+ $title = $title->getTalkPage();
+ self::checkTitle( $title, $name );
+ return [
+ 'href' => $title->getLocalURL( $urlaction ),
+ 'exists' => $title->isKnown(),
+ ];
+ }
+
+ /**
+ * @todo is this even used?
+ * @param string $name
+ * @param string $urlaction
+ * @return array
+ */
+ function makeArticleUrlDetails( $name, $urlaction = '' ) {
+ $title = Title::newFromText( $name );
+ $title = $title->getSubjectPage();
+ self::checkTitle( $title, $name );
+ return [
+ 'href' => $title->getLocalURL( $urlaction ),
+ 'exists' => $title->exists(),
+ ];
+ }
+
+ /**
+ * a structured array of links usually used for the tabs in a skin
+ *
+ * There are 4 standard sections
+ * namespaces: Used for namespace tabs like special, page, and talk namespaces
+ * views: Used for primary page views like read, edit, history
+ * actions: Used for most extra page actions like deletion, protection, etc...
+ * variants: Used to list the language variants for the page
+ *
+ * Each section's value is a key/value array of links for that section.
+ * The links themselves have these common keys:
+ * - class: The css classes to apply to the tab
+ * - text: The text to display on the tab
+ * - href: The href for the tab to point to
+ * - rel: An optional rel= for the tab's link
+ * - redundant: If true the tab will be dropped in skins using content_actions
+ * this is useful for tabs like "Read" which only have meaning in skins that
+ * take special meaning from the grouped structure of content_navigation
+ *
+ * Views also have an extra key which can be used:
+ * - primary: If this is not true skins like vector may try to hide the tab
+ * when the user has limited space in their browser window
+ *
+ * content_navigation using code also expects these ids to be present on the
+ * links, however these are usually automatically generated by SkinTemplate
+ * itself and are not necessary when using a hook. The only things these may
+ * matter to are people modifying content_navigation after it's initial creation:
+ * - id: A "preferred" id, most skins are best off outputting this preferred
+ * id for best compatibility.
+ * - tooltiponly: This is set to true for some tabs in cases where the system
+ * believes that the accesskey should not be added to the tab.
+ *
+ * @return array
+ */
+ protected function buildContentNavigationUrls() {
+ global $wgDisableLangConversion;
+
+ // Display tabs for the relevant title rather than always the title itself
+ $title = $this->getRelevantTitle();
+ $onPage = $title->equals( $this->getTitle() );
+
+ $out = $this->getOutput();
+ $request = $this->getRequest();
+ $user = $this->getUser();
+
+ $content_navigation = [
+ 'namespaces' => [],
+ 'views' => [],
+ 'actions' => [],
+ 'variants' => []
+ ];
+
+ // parameters
+ $action = $request->getVal( 'action', 'view' );
+
+ $userCanRead = $title->quickUserCan( 'read', $user );
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ $preventActiveTabs = false;
+ Hooks::run( 'SkinTemplatePreventOtherActiveTabs', [ &$skinTemplate, &$preventActiveTabs ] );
+
+ // Checks if page is some kind of content
+ if ( $title->canExist() ) {
+ // Gets page objects for the related namespaces
+ $subjectPage = $title->getSubjectPage();
+ $talkPage = $title->getTalkPage();
+
+ // Determines if this is a talk page
+ $isTalk = $title->isTalkPage();
+
+ // Generates XML IDs from namespace names
+ $subjectId = $title->getNamespaceKey( '' );
+
+ if ( $subjectId == 'main' ) {
+ $talkId = 'talk';
+ } else {
+ $talkId = "{$subjectId}_talk";
+ }
+
+ $skname = $this->skinname;
+
+ // Adds namespace links
+ $subjectMsg = [ "nstab-$subjectId" ];
+ if ( $subjectPage->isMainPage() ) {
+ array_unshift( $subjectMsg, 'mainpage-nstab' );
+ }
+ $content_navigation['namespaces'][$subjectId] = $this->tabAction(
+ $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
+ );
+ $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
+ $content_navigation['namespaces'][$talkId] = $this->tabAction(
+ $talkPage, [ "nstab-$talkId", 'talk' ], $isTalk && !$preventActiveTabs, '', $userCanRead
+ );
+ $content_navigation['namespaces'][$talkId]['context'] = 'talk';
+
+ if ( $userCanRead ) {
+ // Adds "view" view link
+ if ( $title->isKnown() ) {
+ $content_navigation['views']['view'] = $this->tabAction(
+ $isTalk ? $talkPage : $subjectPage,
+ [ "$skname-view-view", 'view' ],
+ ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
+ );
+ // signal to hide this from simple content_actions
+ $content_navigation['views']['view']['redundant'] = true;
+ }
+
+ $page = $this->canUseWikiPage() ? $this->getWikiPage() : false;
+ $isRemoteContent = $page && !$page->isLocal();
+
+ // If it is a non-local file, show a link to the file in its own repository
+ // @todo abstract this for remote content that isn't a file
+ if ( $isRemoteContent ) {
+ $content_navigation['views']['view-foreign'] = [
+ 'class' => '',
+ 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
+ setContext( $this->getContext() )->
+ params( $page->getWikiDisplayName() )->text(),
+ 'href' => $page->getSourceURL(),
+ 'primary' => false,
+ ];
+ }
+
+ // Checks if user can edit the current page if it exists or create it otherwise
+ if ( $title->quickUserCan( 'edit', $user )
+ && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
+ ) {
+ // Builds CSS class for talk page links
+ $isTalkClass = $isTalk ? ' istalk' : '';
+ // Whether the user is editing the page
+ $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
+ // Whether to show the "Add a new section" tab
+ // Checks if this is a current rev of talk page and is not forced to be hidden
+ $showNewSection = !$out->forceHideNewSectionLink()
+ && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
+ $section = $request->getVal( 'section' );
+
+ if ( $title->exists()
+ || ( $title->getNamespace() == NS_MEDIAWIKI
+ && $title->getDefaultMessageText() !== false
+ )
+ ) {
+ $msgKey = $isRemoteContent ? 'edit-local' : 'edit';
+ } else {
+ $msgKey = $isRemoteContent ? 'create-local' : 'create';
+ }
+ $content_navigation['views']['edit'] = [
+ 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
+ ? 'selected'
+ : ''
+ ) . $isTalkClass,
+ 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( $this->editUrlOptions() ),
+ 'primary' => !$isRemoteContent, // don't collapse this in vector
+ ];
+
+ // section link
+ if ( $showNewSection ) {
+ // Adds new section link
+ // $content_navigation['actions']['addsection']
+ $content_navigation['views']['addsection'] = [
+ 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( 'action=edit&section=new' )
+ ];
+ }
+ // Checks if the page has some kind of viewable source content
+ } elseif ( $title->hasSourceText() ) {
+ // Adds view source view link
+ $content_navigation['views']['viewsource'] = [
+ 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( $this->editUrlOptions() ),
+ 'primary' => true, // don't collapse this in vector
+ ];
+ }
+
+ // Checks if the page exists
+ if ( $title->exists() ) {
+ // Adds history view link
+ $content_navigation['views']['history'] = [
+ 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( 'action=history' ),
+ ];
+
+ if ( $title->quickUserCan( 'delete', $user ) ) {
+ $content_navigation['actions']['delete'] = [
+ 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( 'action=delete' )
+ ];
+ }
+
+ if ( $title->quickUserCan( 'move', $user ) ) {
+ $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
+ $content_navigation['actions']['move'] = [
+ 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-move", 'move' )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $moveTitle->getLocalURL()
+ ];
+ }
+ } else {
+ // article doesn't exist or is deleted
+ if ( $user->isAllowed( 'deletedhistory' ) ) {
+ $n = $title->isDeleted();
+ if ( $n ) {
+ $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
+ // If the user can't undelete but can view deleted
+ // history show them a "View .. deleted" tab instead.
+ $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
+ $content_navigation['actions']['undelete'] = [
+ 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
+ ->setContext( $this->getContext() )->numParams( $n )->text(),
+ 'href' => $undelTitle->getLocalURL()
+ ];
+ }
+ }
+ }
+
+ if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
+ MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
+ ) {
+ $mode = $title->isProtected() ? 'unprotect' : 'protect';
+ $content_navigation['actions'][$mode] = [
+ 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
+ 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
+ ->setContext( $this->getContext() )->text(),
+ 'href' => $title->getLocalURL( "action=$mode" )
+ ];
+ }
+
+ // Checks if the user is logged in
+ if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
+ /**
+ * The following actions use messages which, if made particular to
+ * the any specific skins, would break the Ajax code which makes this
+ * action happen entirely inline. OutputPage::getJSVars
+ * defines a set of messages in a javascript object - and these
+ * messages are assumed to be global for all skins. Without making
+ * a change to that procedure these messages will have to remain as
+ * the global versions.
+ */
+ $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
+ $content_navigation['actions'][$mode] = [
+ 'class' => 'mw-watchlink ' . (
+ $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : ''
+ ),
+ // uses 'watch' or 'unwatch' message
+ 'text' => $this->msg( $mode )->text(),
+ 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
+ // Set a data-mw=interface attribute, which the mediawiki.page.ajax
+ // module will look for to make sure it's a trusted link
+ 'data' => [
+ 'mw' => 'interface',
+ ],
+ ];
+ }
+ }
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ Hooks::runWithoutAbort(
+ 'SkinTemplateNavigation',
+ [ &$skinTemplate, &$content_navigation ]
+ );
+
+ if ( $userCanRead && !$wgDisableLangConversion ) {
+ $pageLang = $title->getPageLanguage();
+ // Gets list of language variants
+ $variants = $pageLang->getVariants();
+ // Checks that language conversion is enabled and variants exist
+ // And if it is not in the special namespace
+ if ( count( $variants ) > 1 ) {
+ // Gets preferred variant (note that user preference is
+ // only possible for wiki content language variant)
+ $preferred = $pageLang->getPreferredVariant();
+ if ( Action::getActionName( $this ) === 'view' ) {
+ $params = $request->getQueryValues();
+ unset( $params['title'] );
+ } else {
+ $params = [];
+ }
+ // Loops over each variant
+ foreach ( $variants as $code ) {
+ // Gets variant name from language code
+ $varname = $pageLang->getVariantname( $code );
+ // Appends variant link
+ $content_navigation['variants'][] = [
+ 'class' => ( $code == $preferred ) ? 'selected' : false,
+ 'text' => $varname,
+ 'href' => $title->getLocalURL( [ 'variant' => $code ] + $params ),
+ 'lang' => LanguageCode::bcp47( $code ),
+ 'hreflang' => LanguageCode::bcp47( $code ),
+ ];
+ }
+ }
+ }
+ } else {
+ // If it's not content, it's got to be a special page
+ $content_navigation['namespaces']['special'] = [
+ 'class' => 'selected',
+ 'text' => $this->msg( 'nstab-special' )->text(),
+ 'href' => $request->getRequestURL(), // @see: T4457, T4510
+ 'context' => 'subject'
+ ];
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ Hooks::runWithoutAbort( 'SkinTemplateNavigation::SpecialPage',
+ [ &$skinTemplate, &$content_navigation ] );
+ }
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ // Equiv to SkinTemplateContentActions
+ Hooks::runWithoutAbort( 'SkinTemplateNavigation::Universal',
+ [ &$skinTemplate, &$content_navigation ] );
+
+ // Setup xml ids and tooltip info
+ foreach ( $content_navigation as $section => &$links ) {
+ foreach ( $links as $key => &$link ) {
+ $xmlID = $key;
+ if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
+ $xmlID = 'ca-nstab-' . $xmlID;
+ } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
+ $xmlID = 'ca-talk';
+ $link['rel'] = 'discussion';
+ } elseif ( $section == 'variants' ) {
+ $xmlID = 'ca-varlang-' . $xmlID;
+ } else {
+ $xmlID = 'ca-' . $xmlID;
+ }
+ $link['id'] = $xmlID;
+ }
+ }
+
+ # We don't want to give the watch tab an accesskey if the
+ # page is being edited, because that conflicts with the
+ # accesskey on the watch checkbox. We also don't want to
+ # give the edit tab an accesskey, because that's fairly
+ # superfluous and conflicts with an accesskey (Ctrl-E) often
+ # used for editing in Safari.
+ if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
+ if ( isset( $content_navigation['views']['edit'] ) ) {
+ $content_navigation['views']['edit']['tooltiponly'] = true;
+ }
+ if ( isset( $content_navigation['actions']['watch'] ) ) {
+ $content_navigation['actions']['watch']['tooltiponly'] = true;
+ }
+ if ( isset( $content_navigation['actions']['unwatch'] ) ) {
+ $content_navigation['actions']['unwatch']['tooltiponly'] = true;
+ }
+ }
+
+ return $content_navigation;
+ }
+
+ /**
+ * an array of edit links by default used for the tabs
+ * @param array $content_navigation
+ * @return array
+ */
+ private function buildContentActionUrls( $content_navigation ) {
+ // content_actions has been replaced with content_navigation for backwards
+ // compatibility and also for skins that just want simple tabs content_actions
+ // is now built by flattening the content_navigation arrays into one
+
+ $content_actions = [];
+
+ foreach ( $content_navigation as $links ) {
+ foreach ( $links as $key => $value ) {
+ if ( isset( $value['redundant'] ) && $value['redundant'] ) {
+ // Redundant tabs are dropped from content_actions
+ continue;
+ }
+
+ // content_actions used to have ids built using the "ca-$key" pattern
+ // so the xmlID based id is much closer to the actual $key that we want
+ // for that reason we'll just strip out the ca- if present and use
+ // the latter potion of the "id" as the $key
+ if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
+ $key = substr( $value['id'], 3 );
+ }
+
+ if ( isset( $content_actions[$key] ) ) {
+ wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
+ "content_navigation into content_actions.\n" );
+ continue;
+ }
+
+ $content_actions[$key] = $value;
+ }
+ }
+
+ return $content_actions;
+ }
+
+ /**
+ * build array of common navigation links
+ * @return array
+ */
+ protected function buildNavUrls() {
+ global $wgUploadNavigationUrl;
+
+ $out = $this->getOutput();
+ $request = $this->getRequest();
+
+ $nav_urls = [];
+ $nav_urls['mainpage'] = [ 'href' => self::makeMainPageUrl() ];
+ if ( $wgUploadNavigationUrl ) {
+ $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
+ } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
+ $nav_urls['upload'] = [ 'href' => self::makeSpecialUrl( 'Upload' ) ];
+ } else {
+ $nav_urls['upload'] = false;
+ }
+ $nav_urls['specialpages'] = [ 'href' => self::makeSpecialUrl( 'Specialpages' ) ];
+
+ $nav_urls['print'] = false;
+ $nav_urls['permalink'] = false;
+ $nav_urls['info'] = false;
+ $nav_urls['whatlinkshere'] = false;
+ $nav_urls['recentchangeslinked'] = false;
+ $nav_urls['contributions'] = false;
+ $nav_urls['log'] = false;
+ $nav_urls['blockip'] = false;
+ $nav_urls['emailuser'] = false;
+ $nav_urls['userrights'] = false;
+
+ // A print stylesheet is attached to all pages, but nobody ever
+ // figures that out. :) Add a link...
+ if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
+ $nav_urls['print'] = [
+ 'text' => $this->msg( 'printableversion' )->text(),
+ 'href' => $this->getTitle()->getLocalURL(
+ $request->appendQueryValue( 'printable', 'yes' ) )
+ ];
+ }
+
+ if ( $out->isArticle() ) {
+ // Also add a "permalink" while we're at it
+ $revid = $this->getRevisionId();
+ if ( $revid ) {
+ $nav_urls['permalink'] = [
+ 'text' => $this->msg( 'permalink' )->text(),
+ 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
+ ];
+ }
+
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $skinTemplate = $this;
+ // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
+ Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
+ [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
+ }
+
+ if ( $out->isArticleRelated() ) {
+ $nav_urls['whatlinkshere'] = [
+ 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
+ ];
+
+ $nav_urls['info'] = [
+ 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
+ 'href' => $this->getTitle()->getLocalURL( "action=info" )
+ ];
+
+ if ( $this->getTitle()->exists() || $this->getTitle()->inNamespace( NS_CATEGORY ) ) {
+ $nav_urls['recentchangeslinked'] = [
+ 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
+ ];
+ }
+ }
+
+ $user = $this->getRelevantUser();
+ if ( $user ) {
+ $rootUser = $user->getName();
+
+ $nav_urls['contributions'] = [
+ 'text' => $this->msg( 'contributions', $rootUser )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
+ 'tooltip-params' => [ $rootUser ],
+ ];
+
+ $nav_urls['log'] = [
+ 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
+ ];
+
+ if ( $this->getUser()->isAllowed( 'block' ) ) {
+ $nav_urls['blockip'] = [
+ 'text' => $this->msg( 'blockip', $rootUser )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
+ ];
+ }
+
+ if ( $this->showEmailUser( $user ) ) {
+ $nav_urls['emailuser'] = [
+ 'text' => $this->msg( 'tool-link-emailuser', $rootUser )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
+ 'tooltip-params' => [ $rootUser ],
+ ];
+ }
+
+ if ( !$user->isAnon() ) {
+ $sur = new UserrightsPage;
+ $sur->setContext( $this->getContext() );
+ $canChange = $sur->userCanChangeRights( $user );
+ $nav_urls['userrights'] = [
+ 'text' => $this->msg(
+ $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
+ $rootUser
+ )->text(),
+ 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
+ ];
+ }
+ }
+
+ return $nav_urls;
+ }
+
+ /**
+ * Generate strings used for xml 'id' names
+ * @return string
+ */
+ protected function getNameSpaceKey() {
+ return $this->getTitle()->getNamespaceKey();
+ }
+}