Last modified: 2013-12-17 09:53:29 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T59647, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 57647 - maintenance/rebuildFileCache.php fails when $wgEnableCanonicalServerLink is set to true
maintenance/rebuildFileCache.php fails when $wgEnableCanonicalServerLink is s...
Status: PATCH_TO_REVIEW
Product: MediaWiki
Classification: Unclassified
Maintenance scripts (Other open bugs)
1.22.0
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-11-27 12:05 UTC by 11fallingleaves
Modified: 2013-12-17 09:53 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description 11fallingleaves 2013-11-27 12:05:37 UTC
This is what I get when setting $wgEnableCanonicalServerLink to true in LocalSettings.php:

$ php maintenance/rebuildFileCache.php 
Building content page file cache from page 0!
Page 1 already cached
[057522cb] [no req]   Exception from line 1334 of /home/<username>/public_html/mediawiki/includes/WebRequest.php: FauxRequest::getRequestURL() not implemented
Backtrace:
#0 /home/<username>/public_html/mediawiki/includes/WebRequest.php(1385): FauxRequest->notImplemented(string)
#1 /home/<username>/public_html/mediawiki/includes/OutputPage.php(3298): FauxRequest->getRequestURL()
#2 /home/<username>/public_html/mediawiki/includes/OutputPage.php(3316): OutputPage->getHeadLinksArray()
#3 /home/<username>/public_html/mediawiki/includes/OutputPage.php(2518): OutputPage->getHeadLinks()
#4 /home/<username>/public_html/mediawiki/includes/SkinTemplate.php(498): OutputPage->headElement(SkinVector)
#5 /home/<username>/public_html/mediawiki/includes/OutputPage.php(2078): SkinTemplate->outputPage()
#6 /home/<username>/public_html/mediawiki/maintenance/rebuildFileCache.php(135): OutputPage->output()
#7 /home/<username>/public_html/mediawiki/maintenance/doMaintenance.php(113): RebuildFileCache->execute()
#8 /home/<username>/public_html/mediawiki/maintenance/rebuildFileCache.php(163): require_once(string)
#9 {main}

This change fixes the bug for me, but it seems kind of hackish:
diff --git a/includes/WebRequest.php b/includes/WebRequest.php
index b17cb9e..05ffae7 100644
--- a/includes/WebRequest.php
+++ b/includes/WebRequest.php
@@ -1382,7 +1382,8 @@ class FauxRequest extends WebRequest {
        }
 
        public function getRequestURL() {
-               $this->notImplemented( __METHOD__ );
+               global $wgTitle;
+               return $wgTitle->getLocalURL();
        }
 
        /**

It works, though:

$ php maintenance/rebuildFileCache.php 
Building content page file cache from page 0!
Cached page 1
Cached page 2
Done!

How should I submit this change?
Comment 1 11fallingleaves 2013-11-27 12:09:50 UTC
This is on branch master and REL1_22.
Comment 2 Bawolff (Brian Wolff) 2013-11-28 23:16:15 UTC
(In reply to comment #0)

> 
> This change fixes the bug for me, but it seems kind of hackish:
> diff --git a/includes/WebRequest.php b/includes/WebRequest.php
> index b17cb9e..05ffae7 100644
> --- a/includes/WebRequest.php
> +++ b/includes/WebRequest.php
> @@ -1382,7 +1382,8 @@ class FauxRequest extends WebRequest {
>         }
> 
>         public function getRequestURL() {
> -               $this->notImplemented( __METHOD__ );
> +               global $wgTitle;
> +               return $wgTitle->getLocalURL();
>         }
> 
>         /**
> 
> It works, though:
> 
> $ php maintenance/rebuildFileCache.php 
> Building content page file cache from page 0!
> Cached page 1
> Cached page 2
> Done!
> 
> How should I submit this change?

Sorry, but that's probably going to be too hacky to be accepted. ($wgTitle is not allowed to be used in new code).

I'm not entirely sure why we're outputting the WebRequest::getRequestUrl as the canonical url. Maybe it might make sense to change the OutputPage::getHeadLinksArray method to use $this->getTitle()->getLocalURL(); instead of $this->getRequest()->getRequestURL(). (I haven't looked at the code very much at all, but intuitively, the canonical link shouldn't have extra junk from the url anyway)


----

For reference, you can submit patches to our gerrit (https://gerrit.wikimedia.org) install. Accounts are free, and available by signing up at http://wikitech.wikimedia.org. There's detailed instructions at https://www.mediawiki.org/wiki/Gerrit/Tutorial . Alternatively you can upload a patch via http://tools.wmflabs.org/gerrit-patch-uploader/ without having to go through all the git set up.
Comment 3 11fallingleaves 2013-11-29 00:10:34 UTC
(In reply to comment #2)
> Sorry, but that's probably going to be too hacky to be accepted. ($wgTitle is
> not allowed to be used in new code).

Ok, of course. (For me it was a hack to get things working, so I didn't care).

> I'm not entirely sure why we're outputting the WebRequest::getRequestUrl as
> the
> canonical url. Maybe it might make sense to change the
> OutputPage::getHeadLinksArray method to use $this->getTitle()->getLocalURL();
> instead of $this->getRequest()->getRequestURL(). (I haven't looked at the
> code
> very much at all, but intuitively, the canonical link shouldn't have extra
> junk
> from the url anyway)

Seems like a good idea. I did a few changes which seem to work fine, but my MediaWiki installation is broken so I can't properly test right now.
I also changed something else (DRY), so it looks better to me.
I don't really like the variable re-use that's going on there. First, $canonicalUrl is used as a relative URL and later it's re-used as an absolute URL.

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index f1c7d5b..4238776 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3297,12 +3297,10 @@ $templates
                # Canonical URL
                global $wgEnableCanonicalServerLink;
                if ( $wgEnableCanonicalServerLink ) {
-                       if ( $canonicalUrl !== false ) {
-                               $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
-                       } else {
-                               $reqUrl = $this->getRequest()->getRequestURL();
-                               $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+                       if ( $canonicalUrl === false ) {
+                               $canonicalUrl = $this->getTitle()->getLocalURL();
                        }
+                       $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
                }
                if ( $canonicalUrl !== false ) {
                        $tags[] = Html::element( 'link', array(


Note, though, that Google recommends the canonical link to be absolute (this is the case with this change):
https://support.google.com/webmasters/answer/139394?hl=en
I think that might also be better when a wiki can be reached from multiple domain names or both HTTP and HTTPS.

Thanks for the git/gerrit information :) If I have the time I will properly test and submit a patch.
Comment 4 Gerrit Notification Bot 2013-12-12 02:16:03 UTC
Change 100952 had a related patch set uploaded by Leaves in Motion:
Use Title instead of Request for the canonical url

https://gerrit.wikimedia.org/r/100952

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links