MediaWiki master
SkinComponentUtils.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Skin;
4
11
13
23 public static function getReturnToParam( $title, $request, $authority ) {
24 // T379295/T381216: Preserve authentication query params so they don't get lost
25 // during switching between Login/Logout or CreateAccount pages where we need them.
26 // See AuthManagerSpecialPage/LoginSignupSpecialPage::getPreservedParams().
27 // This special case also avoids "nesting" returnto values on these pages.
28 if (
29 $title->isSpecial( 'Userlogin' )
30 || $title->isSpecial( 'CreateAccount' )
31 || $title->isSpecial( 'Userlogout' )
32 ) {
33 $params = [
34 'uselang' => $request->getVal( 'uselang' ),
35 'variant' => $request->getVal( 'variant' ),
36 'display' => $request->getVal( 'display' ),
37 'returnto' => $request->getVal( 'returnto' ),
38 'returntoquery' => $request->getVal( 'returntoquery' ),
39 'returntoanchor' => $request->getVal( 'returntoanchor' ),
40 ];
41 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
42 ->onAuthPreserveQueryParams( $params, [ 'request' => $request, 'reset' => true ] );
43 return array_filter( $params, static fn ( $val ) => $val !== null );
44 }
45
46 # Due to T34276, if a user does not have read permissions,
47 # $this->getTitle() will just give Special:Badtitle, which is
48 # not especially useful as a returnto parameter. Use the title
49 # from the request instead, if there was one.
50 if ( $authority->isAllowed( 'read' ) ) {
51 $page = $title;
52 } else {
53 $page = Title::newFromText( $request->getVal( 'title', '' ) );
54 }
55
56 $query = [];
57 if ( !$request->wasPosted() ) {
58 $query = $request->getQueryValues();
59 unset( $query['title'] );
60 }
61
62 $params = [];
63 if ( $page ) {
64 $params['returnto'] = $page->getPrefixedText();
65 if ( $query ) {
66 $params['returntoquery'] = wfArrayToCgi( $query );
67 }
68 }
69
70 return $params;
71 }
72
84 public static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
85 $title = SpecialPage::getSafeTitleFor( $name );
86 if ( $proto === null ) {
87 return $title->getLocalURL( $urlaction );
88 } else {
89 return $title->getFullURL( $urlaction, false, $proto );
90 }
91 }
92
99 public static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
100 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
101 return $title->getLocalURL( $urlaction );
102 }
103}
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
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 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...