From: Happy-melon Date: Mon, 27 Dec 2010 00:03:35 +0000 (+0000) Subject: (bug 268) add Special:PermanentLink/### as an internally-linkable redirect to index... X-Git-Tag: 1.31.0-rc.0~33072 X-Git-Url: http://git.cyclocoop.org/%22.%20generer_url_ecrire%28%22sites_tous%22%2C%22%22%29.%20%22?a=commitdiff_plain;h=1afaa075d379a30560fcc0768e438f7144fd25f4;p=lhc%2Fweb%2Fwiklou.git (bug 268) add Special:PermanentLink/### as an internally-linkable redirect to index.php?oldid=###. Also refactor SpecialPage::getRedirectQuery() to return an associative array to pass to wfArrayToCGI(), rather than bodging the query string together internally. --- diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index e32fb87c06..64cd0d8064 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -192,6 +192,7 @@ class SpecialPage { 'Mypage' => 'SpecialMypage', 'Mytalk' => 'SpecialMytalk', 'Myuploads' => 'SpecialMyuploads', + 'PermanentLink' => 'SpecialPermanentLink', 'Revisiondelete' => 'SpecialRevisionDelete', 'RevisionMove' => 'SpecialRevisionMove', 'Specialpages' => 'SpecialSpecialpages', @@ -541,12 +542,18 @@ class SpecialPage { # Check for redirect if ( !$including ) { $redirect = $page->getRedirect( $par ); - if ( $redirect ) { - $query = $page->getRedirectQuery(); + $query = $page->getRedirectQuery(); + if ( $redirect instanceof Title ) { $url = $redirect->getFullUrl( $query ); $wgOut->redirect( $url ); wfProfileOut( __METHOD__ ); return $redirect; + } elseif( $redirect === true ) { + global $wgScript; + $url = $wgScript . '?' . wfArrayToCGI( $query ); + $wgOut->redirect( $url ); + wfProfileOut( __METHOD__ ); + return $redirect; } } @@ -929,16 +936,20 @@ class SpecialPage { function getRedirectQuery() { global $wgRequest; $params = array(); + foreach( $this->mAllowedRedirectParams as $arg ) { - if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null ) - $params[] = $arg . '=' . $val; + if( $wgRequest->getVal( $arg, null ) !== null ){ + $params[$arg] = $wgRequest->getVal( $arg ); + } } - + foreach( $this->mAddedRedirectParams as $arg => $val ) { - $params[] = $arg . '=' . $val; + $params[$arg] = $val; } - - return count( $params ) ? implode( '&', $params ) : false; + + return count( $params ) + ? $params + : false; } } @@ -988,7 +999,8 @@ class SpecialRedirectToSpecial extends UnlistedSpecialPage { } } -/** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages +/** + * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages * are used to get user independant links pointing to the user page, talk * page and list of contributions. * This can let us cache a single copy of any generated content for all @@ -1062,9 +1074,25 @@ class SpecialMyuploads extends UnlistedSpecialPage { parent::__construct( 'Myuploads' ); $this->mAllowedRedirectParams = array( 'limit' ); } - + function getRedirect( $subpage ) { global $wgUser; return SpecialPage::getTitleFor( 'Listfiles', $wgUser->getName() ); } } + +/** + * Redirect to Special:Listfiles?user=$wgUser + */ +class SpecialPermanentLink extends UnlistedSpecialPage { + function __construct() { + parent::__construct( 'PermanentLink' ); + $this->mAllowedRedirectParams = array(); + } + + function getRedirect( $subpage ) { + $subpage = intval( $subpage ); + $this->mAddedRedirectParams['oldid'] = $subpage; + return true; + } +} diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 388155ffe9..c13eb23bfa 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -445,6 +445,7 @@ $specialPageAliases = array( 'Mytalk' => array( 'MyTalk' ), 'Mycontributions' => array( 'MyContributions' ), 'Myuploads' => array( 'MyUploads' ), + 'PermanentLink' => array( 'PermanentLink' ), 'Listadmins' => array( 'ListAdmins' ), 'Listbots' => array( 'ListBots' ), 'Popularpages' => array( 'PopularPages' ),