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 );
133 if ( !$file || !$file->exists() ) {
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 );
281 'label-message' =>
'redirect-lookup',
282 'options-messages' => [
283 'redirect-user' =>
'user',
284 'redirect-page' =>
'page',
285 'redirect-revision' =>
'revision',
286 'redirect-file' =>
'file',
287 'redirect-logid' =>
'logid',
293 'label-message' =>
'redirect-value',
301 if ( !empty( $data[
'type'] ) && !empty( $data[
'value'] ) ) {
302 $this->
setParameter( $data[
'type'] .
'/' . $data[
'value'] );
306 return $this->dispatch();
353class_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.
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.