73 parent::__construct(
'Redirect' );
77 $this->repoGroup = $repoGroup;
78 $this->userFactory = $userFactory;
87 $parts = $subpage !==
null ? explode(
'/', $subpage, 2 ) : [];
88 $this->mType = $parts[0] ??
null;
89 $this->mValue = $parts[1] ??
null;
98 if ( !ctype_digit( $this->mValue ) ) {
99 return Status::newFatal(
'redirect-not-numeric' );
101 $user = $this->userFactory->newFromId( (
int)$this->mValue );
103 if ( $user->isAnon() ) {
104 return Status::newFatal(
'redirect-not-exists' );
106 if ( $user->isHidden() && !$this->getAuthority()->isAllowed(
'hideuser' ) ) {
110 return Status::newGood( [
111 $user->getUserPage()->getFullURL(
'',
false,
PROTO_CURRENT ), 302
122 $title = Title::newFromTextThrow( $this->mValue,
NS_FILE );
123 if ( $title && !$title->inNamespace(
NS_FILE ) ) {
125 $title = Title::newFromTextThrow( Title::makeName(
NS_FILE, $this->mValue ) );
131 $file = $this->repoGroup->findFile( $title );
134 return Status::newFatal(
'redirect-not-exists' );
137 $url =
$file->getUrl();
139 $width = $request->getInt(
'width', -1 );
140 $height = $request->getInt(
'height', -1 );
143 if ( $width != -1 ) {
144 $mto =
$file->transform( [
'width' => $width,
'height' => $height ] );
146 if ( $mto && !$mto->isError() ) {
150 $url = [ $mto->getUrl(), $height === -1 ? 301 : 302 ];
154 return Status::newGood( $url );
165 if ( !ctype_digit( $oldid ) ) {
166 return Status::newFatal(
'redirect-not-numeric' );
168 $oldid = (int)$oldid;
169 if ( $oldid === 0 ) {
170 return Status::newFatal(
'redirect-not-exists' );
185 if ( !ctype_digit( $curid ) ) {
186 return Status::newFatal(
'redirect-not-numeric' );
188 $curid = (int)$curid;
189 if ( $curid === 0 ) {
190 return Status::newFatal(
'redirect-not-exists' );
207 if ( !ctype_digit( $logid ) ) {
208 return Status::newFatal(
'redirect-not-numeric' );
210 $logid = (int)$logid;
211 if ( $logid === 0 ) {
212 return Status::newFatal(
'redirect-not-exists' );
214 $query = [
'title' =>
'Special:Log',
'logid' => $logid ];
226 private function dispatch() {
228 switch ( $this->mType ) {
248 if ( $status && $status->isGood() ) {
251 $value = $status->getValue();
252 if ( is_array( $value ) ) {
253 [ $url, $code ] = $value;
258 if ( $code === 301 ) {
259 $this->
getOutput()->setCdnMaxage( 60 * 60 );
263 $this->
getOutput()->redirect( $url, $code );
267 if ( $this->mValue !==
null ) {
268 $this->
getOutput()->setStatusCode( 404 );
280 'user' =>
'redirect-user',
281 'page' =>
'redirect-page',
282 'revision' =>
'redirect-revision',
283 'file' =>
'redirect-file',
284 'logid' =>
'redirect-logid',
289 'label-message' =>
'redirect-lookup',
291 'default' => current( array_keys( $ns ) ),
293 foreach ( $ns as $n => $m ) {
294 $m = $this->
msg( $m )->text();
295 $a[
'type'][
'options'][$m] = $n;
299 'label-message' =>
'redirect-value'
302 if ( $this->mType ) {
305 if ( $this->mValue ) {
313 if ( !empty( $data[
'type'] ) && !empty( $data[
'value'] ) ) {
314 $this->
setParameter( $data[
'type'] .
'/' . $data[
'value'] );
318 return $this->dispatch();
365class_alias( SpecialRedirect::class,
'SpecialRedirect' );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
Special page which uses an HTMLForm to handle processing.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
Show an error when a user tries to do something they do not have the necessary permissions for.
Prioritized list of file repositories.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.