MediaWiki master
SkinComponentUtils.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Skin;
4
9
20 public static function addClassToClassList( $class, string $newClass ) {
21 if ( is_array( $class ) ) {
22 $class[] = $newClass;
23 } else {
24 $class .= ' ' . $newClass;
25 $class = trim( $class );
26 }
27 return $class;
28 }
29
39 public static function getReturnToParam( $title, $request, $authority ) {
40 # Due to T34276, if a user does not have read permissions,
41 # $this->getTitle() will just give Special:Badtitle, which is
42 # not especially useful as a returnto parameter. Use the title
43 # from the request instead, if there was one.
44 if ( $authority->isAllowed( 'read' ) ) {
45 $page = $title;
46 } else {
47 $page = Title::newFromText( $request->getVal( 'title', '' ) );
48 }
49 $page = $request->getVal( 'returnto', $page );
50
51 $query = [];
52 if ( !$request->wasPosted() ) {
53 $query = $request->getValues();
54 unset( $query['title'] );
55 unset( $query['returnto'] );
56 unset( $query['returntoquery'] );
57 }
58
59 $thisquery = wfArrayToCgi( $query );
60
61 $returnto = [];
62 if ( strval( $page ) !== '' ) {
63 $returnto['returnto'] = $page;
64 $query = $request->getVal( 'returntoquery', $thisquery );
65 $paramsArray = wfCgiToArray( $query );
66 $query = wfArrayToCgi( $paramsArray );
67 if ( $query != '' ) {
68 $returnto['returntoquery'] = $query;
69 }
70 }
71
72 return $returnto;
73 }
74
86 public static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
87 $title = SpecialPage::getSafeTitleFor( $name );
88 if ( $proto === null ) {
89 return $title->getLocalURL( $urlaction );
90 } else {
91 return $title->getFullURL( $urlaction, false, $proto );
92 }
93 }
94
101 public static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
102 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
103 return $title->getLocalURL( $urlaction );
104 }
105}
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
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:79
This interface represents the authority associated the current execution context, such as a web reque...
Definition Authority.php:37
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...