r98747 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98746‎ | r98747 | r98748 >
Date:10:42, 3 October 2011
Author:catrope
Status:old
Tags:
Comment:
1.17wmf1: MFT r98744, r98745
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/ExtensionDistributor/ExtensionDistributor_body.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/WikiMap.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/ExtensionDistributor/ExtensionDistributor_body.php
@@ -249,7 +249,7 @@
250250 }
251251 }
252252
253 - $url = "$wgExtDistTarUrl/$tarName";
 253+ $url = wfExpandUrl( "$wgExtDistTarUrl/$tarName", PROTO_CURRENT );
254254
255255 // Show a message
256256 $wgOut->addWikiMsg( 'extdist-created', $extension, "r$rev",
Index: branches/wmf/1.17wmf1/extensions/CentralAuth/CentralAuthHooks.php
@@ -137,7 +137,8 @@
138138 $wgMemc->set( CentralAuthUser::memcKey( 'login-token', $loginToken ), $data, 600 );
139139
140140 $wiki = WikiMap::getWiki( $wiki );
141 - $url = wfAppendQuery( $wiki->getUrl( 'Special:AutoLogin' ), "token=$loginToken" );
 141+ // Use WikiReference::getFullUrl(), returns a protocol-relative URL if needed
 142+ $url = wfAppendQuery( $wiki->getFullUrl( 'Special:AutoLogin' ), "token=$loginToken" );
142143
143144 $inject_html .= Xml::element( 'img',
144145 array(
Index: branches/wmf/1.17wmf1/includes/WikiMap.php
@@ -18,11 +18,13 @@
1919
2020 list( $major, $minor ) = $wgConf->siteFromDB( $wikiID );
2121 if( isset( $major ) ) {
22 - $server = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
 22+ $canonicalServer = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
2323 array( 'lang' => $minor, 'site' => $major ) );
 24+ $server = $wgConf->get( 'wgServer', $wikiID, $major,
 25+ array( 'lang' => $minor, 'site' => $major ) );
2426 $path = $wgConf->get( 'wgArticlePath', $wikiID, $major,
2527 array( 'lang' => $minor, 'site' => $major ) );
26 - return new WikiReference( $major, $minor, $server, $path );
 28+ return new WikiReference( $major, $minor, $canonicalServer, $path, $server );
2729 } else {
2830 return null;
2931 }
@@ -104,21 +106,23 @@
105107 class WikiReference {
106108 private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
107109 private $mMajor; ///< 'wiki', 'wiktionary', etc
108 - private $mServer; ///< server override, 'www.mediawiki.org'
109 - private $mPath; ///< path override, '/wiki/$1'
 110+ private $mCanonicalServer; ///< canonical server URL, e.g. 'http://www.mediawiki.org'
 111+ private $mServer; ///< server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
 112+ private $mPath; ///< path, '/wiki/$1'
110113
111 - public function __construct( $major, $minor, $server, $path ) {
 114+ public function __construct( $major, $minor, $canonicalServer, $path, $server = null ) {
112115 $this->mMajor = $major;
113116 $this->mMinor = $minor;
114 - $this->mServer = $server;
 117+ $this->mCanonicalServer = $canonicalServer;
115118 $this->mPath = $path;
 119+ $this->mServer = $server === null ? $canonicalServer : $server;
116120 }
117121
118122 public function getHostname() {
119123 $prefixes = array( 'http://', 'https://' );
120124 foreach ( $prefixes as $prefix ) {
121 - if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) {
122 - return substr( $this->mServer, strlen( $prefix ) );
 125+ if ( substr( $this->mCanonicalServer, 0, strlen( $prefix ) ) ) {
 126+ return substr( $this->mCanonicalServer, strlen( $prefix ) );
123127 }
124128 }
125129 throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
@@ -153,12 +157,32 @@
154158 }
155159
156160 /**
157 - * Get a URL to a page on this foreign wiki
 161+ * Get a canonical (i.e. based on $wgCanonicalServer) URL to a page on this foreign wiki
158162 *
159163 * @param $page String: page name (must be normalised before calling this function!)
160164 * @return String: Url
161165 */
 166+ public function getCanonicalUrl( $page ) {
 167+ return
 168+ $this->mCanonicalServer .
 169+ $this->getLocalUrl( $page );
 170+ }
 171+
 172+ /**
 173+ * Alias for getCanonicalUrl(), for backwards compatibility.
 174+ */
162175 public function getUrl( $page ) {
 176+ return $this->getCanonicalUrl( $page );
 177+ }
 178+
 179+ /**
 180+ * Get a URL based on $wgServer, like Title::getFullUrl() would produce
 181+ * when called locally on the wiki.
 182+ *
 183+ * @param $page String: page name (must be normalized before calling this function!)
 184+ * @return String: URL
 185+ */
 186+ public function getFullUrl( $page ) {
163187 return
164188 $this->mServer .
165189 $this->getLocalUrl( $page );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98744ExtensionDistributor: Don't display a protocol-relative URL in plain text (or...catrope10:24, 3 October 2011
r98745(bug 31320) CentralAuth uses http URLs for autologin images when logging in o...catrope10:27, 3 October 2011

Status & tagging log