MediaWiki master
SkinComponentUtils.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Skin;
4
11
22 public static function addClassToClassList( $class, string $newClass ) {
23 if ( is_array( $class ) ) {
24 $class[] = $newClass;
25 } else {
26 $class .= ' ' . $newClass;
27 $class = trim( $class );
28 }
29 return $class;
30 }
31
41 public static function getReturnToParam( $title, $request, $authority ) {
42 // T379295/T381216: Preserve authentication query params so they don't get lost
43 // during switching between Login/Logout or CreateAccount pages where we need them.
44 // See AuthManagerSpecialPage/LoginSignupSpecialPage::getPreservedParams().
45 // This special case also avoids "nesting" returnto values on these pages.
46 if (
47 $title->isSpecial( 'Userlogin' )
48 || $title->isSpecial( 'CreateAccount' )
49 || $title->isSpecial( 'Userlogout' )
50 ) {
51 $params = [
52 'uselang' => $request->getVal( 'uselang' ),
53 'variant' => $request->getVal( 'variant' ),
54 'display' => $request->getVal( 'display' ),
55 'returnto' => $request->getVal( 'returnto' ),
56 'returntoquery' => $request->getVal( 'returntoquery' ),
57 'returntoanchor' => $request->getVal( 'returntoanchor' ),
58 ];
59 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
60 ->onAuthPreserveQueryParams( $params, [ 'reset' => true ] );
61 return array_filter( $params, fn ( $val ) => $val !== null );
62 }
63
64 # Due to T34276, if a user does not have read permissions,
65 # $this->getTitle() will just give Special:Badtitle, which is
66 # not especially useful as a returnto parameter. Use the title
67 # from the request instead, if there was one.
68 if ( $authority->isAllowed( 'read' ) ) {
69 $page = $title;
70 } else {
71 $page = Title::newFromText( $request->getVal( 'title', '' ) );
72 }
73
74 $query = [];
75 if ( !$request->wasPosted() ) {
76 $query = $request->getQueryValues();
77 unset( $query['title'] );
78 }
79
80 $params = [];
81 if ( $page ) {
82 $params['returnto'] = $page->getPrefixedText();
83 if ( $query ) {
84 $params['returntoquery'] = wfArrayToCgi( $query );
85 }
86 }
87
88 return $params;
89 }
90
102 public static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
103 $title = SpecialPage::getSafeTitleFor( $name );
104 if ( $proto === null ) {
105 return $title->getLocalURL( $urlaction );
106 } else {
107 return $title->getFullURL( $urlaction, false, $proto );
108 }
109 }
110
117 public static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
118 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
119 return $title->getLocalURL( $urlaction );
120 }
121}
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
array $params
The job parameters.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
static getReturnToParam( $title, $request, $authority)
Builds query params for the page to return to, used when building links.
static makeSpecialUrlSubpage( $name, $subpage, $urlaction='')
static addClassToClassList( $class, string $newClass)
Adds a class to the existing class value, supporting it as a string or array.
static makeSpecialUrl( $name, $urlaction='', $proto=null)
Make a URL for a Special Page using the given query and protocol.
Parent class for all special pages.
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage.
Represents a title within MediaWiki.
Definition Title.php:78
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...