MediaWiki master
SkinComponentUtils.php
Go to the documentation of this file.
1<?php
2
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 $loginHelper = new LoginHelper( RequestContext::getMain() );
34 return $loginHelper->getPreservedParams( [ 'request' => $request, 'reset' => true ] );
35 }
36
37 # Due to T34276, if a user does not have read permissions,
38 # $this->getTitle() will just give Special:Badtitle, which is
39 # not especially useful as a returnto parameter. Use the title
40 # from the request instead, if there was one.
41 if ( $authority->isAllowed( 'read' ) ) {
42 $page = $title;
43 } else {
44 $page = Title::newFromText( $request->getVal( 'title', '' ) );
45 }
46
47 $query = [];
48 if ( !$request->wasPosted() ) {
49 $query = $request->getQueryValues();
50 unset( $query['title'] );
51 }
52
53 $params = [];
54 if ( $page ) {
55 $params['returnto'] = $page->getPrefixedText();
56 if ( $query ) {
57 $params['returntoquery'] = wfArrayToCgi( $query );
58 }
59 }
60
61 return $params;
62 }
63
75 public static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
76 $title = SpecialPage::getSafeTitleFor( $name );
77 if ( $proto === null ) {
78 return $title->getLocalURL( $urlaction );
79 } else {
80 return $title->getFullURL( $urlaction, false, $proto );
81 }
82 }
83
90 public static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
91 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
92 return $title->getLocalURL( $urlaction );
93 }
94}
95
97class_alias( SkinComponentUtils::class, 'MediaWiki\\Skin\\SkinComponentUtils' );
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Group all the pieces relevant to the context of a request into one instance.
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 makeSpecialUrl( $name, $urlaction='', $proto=null)
Make a URL for a Special Page using the given query and protocol.
static makeSpecialUrlSubpage( $name, $subpage, $urlaction='')
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.
Helper functions for the login form that need to be shared with other special pages (such as CentralA...
Represents a title within MediaWiki.
Definition Title.php:69
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23