X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=30ee19cc5a863cfdb8ad0e1dd810ad467d22c52b;hb=1747b121776a150ac5f42c41355c284fe208140f;hp=fd553798c0fd7be6b394abad0316e09f8510d94e;hpb=c811e2c8c9f876f857cf6173049dfbc52cdd9a10;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index fd553798c0..30ee19cc5a 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -304,6 +304,11 @@ class OutputPage extends ContextSource { */ private $mEnableSectionEditLinks = true; + /** + * @var string|null The URL to send in a element with rel=copyright + */ + private $copyrightUrl; + /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -340,6 +345,18 @@ class OutputPage extends ContextSource { return $this->mRedirect; } + /** + * Set the copyright URL to send with the output. + * Empty string to omit, null to reset. + * + * @since 1.26 + * + * @param string|null $url + */ + public function setCopyrightUrl( $url ) { + $this->copyrightUrl = $url; + } + /** * Set the HTTP status code to send with the output. * @@ -600,7 +617,8 @@ class OutputPage extends ContextSource { $module = $resourceLoader->getModule( $val ); if ( $module instanceof ResourceLoaderModule && $module->isPositionDefault() ) { - $warning = __METHOD__ . ': style module should define its position explicitly: ' . $val . ' ' . get_class( $module ); + $warning = __METHOD__ . ': style module should define its position explicitly: ' . + $val . ' ' . get_class( $module ); wfDebugLog( 'resourceloader', $warning ); wfLogWarning( $warning ); } @@ -2264,7 +2282,6 @@ class OutputPage extends ContextSource { if ( $this->mArticleBodyOnly ) { echo $this->mBodytext; } else { - $sk = $this->getSkin(); // add skin specific modules $modules = $sk->getDefaultModules(); @@ -3423,26 +3440,30 @@ class OutputPage extends ContextSource { 'href' => $this->getTitle()->getLocalURL( array( 'variant' => $_v ) ) ) ); } + # x-default link per https://support.google.com/webmasters/answer/189077?hl=en + $tags["variant-x-default"] = Html::element( 'link', array( + 'rel' => 'alternate', + 'hreflang' => 'x-default', + 'href' => $this->getTitle()->getLocalURL() ) ); } - # x-default link per https://support.google.com/webmasters/answer/189077?hl=en - $tags["variant-x-default"] = Html::element( 'link', array( - 'rel' => 'alternate', - 'hreflang' => 'x-default', - 'href' => $this->getTitle()->getLocalURL() ) ); } # Copyright - $copyright = ''; - if ( $config->get( 'RightsPage' ) ) { - $copy = Title::newFromText( $config->get( 'RightsPage' ) ); + if ( $this->copyrightUrl !== null ) { + $copyright = $this->copyrightUrl; + } else { + $copyright = ''; + if ( $config->get( 'RightsPage' ) ) { + $copy = Title::newFromText( $config->get( 'RightsPage' ) ); - if ( $copy ) { - $copyright = $copy->getLocalURL(); + if ( $copy ) { + $copyright = $copy->getLocalURL(); + } } - } - if ( !$copyright && $config->get( 'RightsUrl' ) ) { - $copyright = $config->get( 'RightsUrl' ); + if ( !$copyright && $config->get( 'RightsUrl' ) ) { + $copyright = $config->get( 'RightsUrl' ); + } } if ( $copyright ) { @@ -3503,8 +3524,25 @@ class OutputPage extends ContextSource { if ( $canonicalUrl !== false ) { $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL ); } else { - $reqUrl = $this->getRequest()->getRequestURL(); - $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL ); + if ( $this->isArticleRelated() ) { + // This affects all requests where "setArticleRelated" is true. This is + // typically all requests that show content (query title, curid, oldid, diff), + // and all wikipage actions (edit, delete, purge, info, history etc.). + // It does not apply to File pages and Special pages. + // 'history' and 'info' actions address page metadata rather than the page + // content itself, so they may not be canonicalized to the view page url. + // TODO: this ought to be better encapsulated in the Action class. + $action = Action::getActionName( $this->getContext() ); + if ( in_array( $action, array( 'history', 'info' ) ) ) { + $query = "action={$action}"; + } else { + $query = ''; + } + $canonicalUrl = $this->getTitle()->getCanonicalURL( $query ); + } else { + $reqUrl = $this->getRequest()->getRequestURL(); + $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL ); + } } } if ( $canonicalUrl !== false ) {