"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/specials/SpecialRedirect.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

SpecialRedirect.php  (mediawiki-1.31.1):SpecialRedirect.php  (mediawiki-1.32.0)
skipping to change at line 71 skipping to change at line 71
function setParameter( $subpage ) { function setParameter( $subpage ) {
// parse $subpage to pull out the parts // parse $subpage to pull out the parts
$parts = explode( '/', $subpage, 2 ); $parts = explode( '/', $subpage, 2 );
$this->mType = count( $parts ) > 0 ? $parts[0] : null; $this->mType = count( $parts ) > 0 ? $parts[0] : null;
$this->mValue = count( $parts ) > 1 ? $parts[1] : null; $this->mValue = count( $parts ) > 1 ? $parts[1] : null;
} }
/** /**
* Handle Special:Redirect/user/xxxx (by redirecting to User:YYYY) * Handle Special:Redirect/user/xxxx (by redirecting to User:YYYY)
* *
* @return string|null Url to redirect to, or null if $mValue is invalid. * @return Status A good status contains the url to redirect to
*/ */
function dispatchUser() { function dispatchUser() {
if ( !ctype_digit( $this->mValue ) ) { if ( !ctype_digit( $this->mValue ) ) {
return null; // Message: redirect-not-numeric
return Status::newFatal( $this->getMessagePrefix() . '-no
t-numeric' );
} }
$user = User::newFromId( (int)$this->mValue ); $user = User::newFromId( (int)$this->mValue );
$username = $user->getName(); // load User as side-effect $username = $user->getName(); // load User as side-effect
if ( $user->isAnon() ) { if ( $user->isAnon() ) {
return null; // Message: redirect-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-no
t-exists' );
} }
$userpage = Title::makeTitle( NS_USER, $username ); $userpage = Title::makeTitle( NS_USER, $username );
return $userpage->getFullURL( '', false, PROTO_CURRENT ); return Status::newGood( $userpage->getFullURL( '', false, PROTO_C URRENT ) );
} }
/** /**
* Handle Special:Redirect/file/xxxx * Handle Special:Redirect/file/xxxx
* *
* @return string|null Url to redirect to, or null if $mValue is not foun d. * @return Status A good status contains the url to redirect to
*/ */
function dispatchFile() { function dispatchFile() {
$title = Title::makeTitleSafe( NS_FILE, $this->mValue ); try {
$title = Title::newFromTextThrow( $this->mValue, NS_FILE
if ( !$title instanceof Title ) { );
return null; if ( $title && !$title->inNamespace( NS_FILE ) ) {
// If the given value contains a namespace enforc
e file namespace
$title = Title::newFromTextThrow( Title::makeName
( NS_FILE, $this->mValue ) );
}
} catch ( MalformedTitleException $e ) {
return Status::newFatal( $e->getMessageObject() );
} }
$file = wfFindFile( $title ); $file = wfFindFile( $title );
if ( !$file || !$file->exists() ) { if ( !$file || !$file->exists() ) {
return null; // Message: redirect-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-no
t-exists' );
} }
// Default behavior: Use the direct link to the file. // Default behavior: Use the direct link to the file.
$url = $file->getUrl(); $url = $file->getUrl();
$request = $this->getRequest(); $request = $this->getRequest();
$width = $request->getInt( 'width', -1 ); $width = $request->getInt( 'width', -1 );
$height = $request->getInt( 'height', -1 ); $height = $request->getInt( 'height', -1 );
// If a width is requested... // If a width is requested...
if ( $width != -1 ) { if ( $width != -1 ) {
$mto = $file->transform( [ 'width' => $width, 'height' => $height ] ); $mto = $file->transform( [ 'width' => $width, 'height' => $height ] );
// ... and we can // ... and we can
if ( $mto && !$mto->isError() ) { if ( $mto && !$mto->isError() ) {
// ... change the URL to point to a thumbnail. // ... change the URL to point to a thumbnail.
$url = $mto->getUrl(); $url = $mto->getUrl();
} }
} }
return $url; return Status::newGood( $url );
} }
/** /**
* Handle Special:Redirect/revision/xxx * Handle Special:Redirect/revision/xxx
* (by redirecting to index.php?oldid=xxx) * (by redirecting to index.php?oldid=xxx)
* *
* @return string|null Url to redirect to, or null if $mValue is invalid. * @return Status A good status contains the url to redirect to
*/ */
function dispatchRevision() { function dispatchRevision() {
$oldid = $this->mValue; $oldid = $this->mValue;
if ( !ctype_digit( $oldid ) ) { if ( !ctype_digit( $oldid ) ) {
return null; // Message: redirect-not-numeric
return Status::newFatal( $this->getMessagePrefix() . '-no
t-numeric' );
} }
$oldid = (int)$oldid; $oldid = (int)$oldid;
if ( $oldid === 0 ) { if ( $oldid === 0 ) {
return null; // Message: redirect-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-no
t-exists' );
} }
return wfAppendQuery( wfScript( 'index' ), [ return Status::newGood( wfAppendQuery( wfScript( 'index' ), [
'oldid' => $oldid 'oldid' => $oldid
] ); ] ) );
} }
/** /**
* Handle Special:Redirect/page/xxx (by redirecting to index.php?curid=xx x) * Handle Special:Redirect/page/xxx (by redirecting to index.php?curid=xx x)
* *
* @return string|null Url to redirect to, or null if $mValue is invalid. * @return Status A good status contains the url to redirect to
*/ */
function dispatchPage() { function dispatchPage() {
$curid = $this->mValue; $curid = $this->mValue;
if ( !ctype_digit( $curid ) ) { if ( !ctype_digit( $curid ) ) {
return null; // Message: redirect-not-numeric
return Status::newFatal( $this->getMessagePrefix() . '-no
t-numeric' );
} }
$curid = (int)$curid; $curid = (int)$curid;
if ( $curid === 0 ) { if ( $curid === 0 ) {
return null; // Message: redirect-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-no
t-exists' );
} }
return wfAppendQuery( wfScript( 'index' ), [ return Status::newGood( wfAppendQuery( wfScript( 'index' ), [
'curid' => $curid 'curid' => $curid
] ); ] ) );
} }
/** /**
* Handle Special:Redirect/logid/xxx * Handle Special:Redirect/logid/xxx
* (by redirecting to index.php?title=Special:Log&logid=xxx) * (by redirecting to index.php?title=Special:Log&logid=xxx)
* *
* @since 1.27 * @since 1.27
* @return string|null Url to redirect to, or null if $mValue is invalid. * @return Status A good status contains the url to redirect to
*/ */
function dispatchLog() { function dispatchLog() {
$logid = $this->mValue; $logid = $this->mValue;
if ( !ctype_digit( $logid ) ) { if ( !ctype_digit( $logid ) ) {
return null; // Message: redirect-not-numeric
return Status::newFatal( $this->getMessagePrefix() . '-no
t-numeric' );
} }
$logid = (int)$logid; $logid = (int)$logid;
if ( $logid === 0 ) { if ( $logid === 0 ) {
return null; // Message: redirect-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-no
t-exists' );
} }
$query = [ 'title' => 'Special:Log', 'logid' => $logid ]; $query = [ 'title' => 'Special:Log', 'logid' => $logid ];
return wfAppendQuery( wfScript( 'index' ), $query ); return Status::newGood( wfAppendQuery( wfScript( 'index' ), $quer y ) );
} }
/** /**
* Use appropriate dispatch* method to obtain a redirection URL, * Use appropriate dispatch* method to obtain a redirection URL,
* and either: redirect, set a 404 error code and error message, * and either: redirect, set a 404 error code and error message,
* or do nothing (if $mValue wasn't set) allowing the form to be * or do nothing (if $mValue wasn't set) allowing the form to be
* displayed. * displayed.
* *
* @return bool True if a redirect was successfully handled. * @return Status|bool True if a redirect was successfully handled.
*/ */
function dispatch() { function dispatch() {
// the various namespaces supported by Special:Redirect // the various namespaces supported by Special:Redirect
switch ( $this->mType ) { switch ( $this->mType ) {
case 'user': case 'user':
$url = $this->dispatchUser(); $status = $this->dispatchUser();
break; break;
case 'file': case 'file':
$url = $this->dispatchFile(); $status = $this->dispatchFile();
break; break;
case 'revision': case 'revision':
$url = $this->dispatchRevision(); $status = $this->dispatchRevision();
break; break;
case 'page': case 'page':
$url = $this->dispatchPage(); $status = $this->dispatchPage();
break; break;
case 'logid': case 'logid':
$url = $this->dispatchLog(); $status = $this->dispatchLog();
break; break;
default: default:
$url = null; $status = null;
break; break;
} }
if ( $url ) { if ( $status && $status->isGood() ) {
$this->getOutput()->redirect( $url ); $this->getOutput()->redirect( $status->getValue() );
return true; return true;
} }
if ( !is_null( $this->mValue ) ) { if ( !is_null( $this->mValue ) ) {
$this->getOutput()->setStatusCode( 404 ); $this->getOutput()->setStatusCode( 404 );
// Message: redirect-not-exists
$msg = $this->getMessagePrefix() . '-not-exists';
return Status::newFatal( $msg ); return $status;
} }
return false; return false;
} }
protected function getFormFields() { protected function getFormFields() {
$mp = $this->getMessagePrefix(); $mp = $this->getMessagePrefix();
$ns = [ $ns = [
// subpage => message // subpage => message
// Messages: redirect-user, redirect-page, redirect-revis ion, // Messages: redirect-user, redirect-page, redirect-revis ion,
 End of changes. 32 change blocks. 
37 lines changed or deleted 60 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)