Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / Metadata.php
blobcd77ef877979b2031e2be82ba35f8103e79d5951
1 <?php
2 /**
3 * Base code to format metadata.
5 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @author Evan Prodromou <evan@wikitravel.org>
23 * @file
26 abstract class RdfMetaData {
27 const RDF_TYPE_PREFS = 'application/rdf+xml,text/xml;q=0.7,application/xml;q=0.5,text/rdf;q=0.1';
29 /**
30 * Constructor
31 * @param $article Article object
33 public function __construct( Page $article ) {
34 $this->mArticle = $article;
37 abstract public function show();
39 protected function setup() {
40 global $wgOut, $wgRequest;
42 $httpaccept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : null;
43 $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) );
45 if ( !$rdftype ) {
46 throw new HttpError( 406, wfMessage( 'notacceptable' ) );
49 $wgOut->disable();
50 $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" );
51 $wgOut->sendCacheControl();
52 return true;
55 protected function reallyFullUrl() {
56 return $this->mArticle->getTitle()->getFullURL();
59 protected function basics() {
60 global $wgLanguageCode, $wgSitename;
62 $this->element( 'title', $this->mArticle->getTitle()->getText() );
63 $this->pageOrString( 'publisher', wfMessage( 'aboutpage' )->text(), $wgSitename );
64 $this->element( 'language', $wgLanguageCode );
65 $this->element( 'type', 'Text' );
66 $this->element( 'format', 'text/html' );
67 $this->element( 'identifier', $this->reallyFullUrl() );
68 $this->element( 'date', $this->date( $this->mArticle->getTimestamp() ) );
70 $lastEditor = User::newFromId( $this->mArticle->getUser() );
71 $this->person( 'creator', $lastEditor );
73 foreach ( $this->mArticle->getContributors() as $user ) {
74 $this->person( 'contributor', $user );
77 $this->rights();
80 protected function element( $name, $value ) {
81 $value = htmlspecialchars( $value );
82 print "\t\t<dc:{$name}>{$value}</dc:{$name}>\n";
85 protected function date( $timestamp ) {
86 return substr( $timestamp, 0, 4 ) . '-'
87 . substr( $timestamp, 4, 2 ) . '-'
88 . substr( $timestamp, 6, 2 );
91 protected function pageOrString( $name, $page, $str ) {
92 if ( $page instanceof Title ) {
93 $nt = $page;
94 } else {
95 $nt = Title::newFromText( $page );
98 if ( !$nt || $nt->getArticleID() == 0 ) {
99 $this->element( $name, $str );
100 } else {
101 $this->page( $name, $nt );
106 * @param $name string
107 * @param $title Title
109 protected function page( $name, $title ) {
110 $this->url( $name, $title->getFullURL() );
113 protected function url( $name, $url ) {
114 $url = htmlspecialchars( $url );
115 print "\t\t<dc:{$name} rdf:resource=\"{$url}\" />\n";
118 protected function person( $name, User $user ) {
119 if ( $user->isAnon() ) {
120 $this->element( $name, wfMessage( 'anonymous' )->numParams( 1 )->text() );
121 } else {
122 $real = $user->getRealName();
123 if ( $real ) {
124 $this->element( $name, $real );
125 } else {
126 $userName = $user->getName();
127 $this->pageOrString(
128 $name,
129 $user->getUserPage(),
130 wfMessage( 'siteuser', $userName, $userName )->text()
137 * Takes an arg, for future enhancement with different rights for
138 * different pages.
140 protected function rights() {
141 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
143 if ( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) )
144 && ( $nt->getArticleID() != 0 ) ) {
145 $this->page( 'rights', $nt );
146 } elseif ( $wgRightsUrl ) {
147 $this->url( 'rights', $wgRightsUrl );
148 } elseif ( $wgRightsText ) {
149 $this->element( 'rights', $wgRightsText );
153 protected function getTerms( $url ) {
154 global $wgLicenseTerms;
156 if ( $wgLicenseTerms ) {
157 return $wgLicenseTerms;
158 } else {
159 $known = $this->getKnownLicenses();
160 if ( isset( $known[$url] ) ) {
161 return $known[$url];
162 } else {
163 return array();
168 protected function getKnownLicenses() {
169 $ccLicenses = array( 'by', 'by-nd', 'by-nd-nc', 'by-nc',
170 'by-nc-sa', 'by-sa' );
171 $ccVersions = array( '1.0', '2.0' );
172 $knownLicenses = array();
174 foreach ( $ccVersions as $version ) {
175 foreach ( $ccLicenses as $license ) {
176 if ( $version == '2.0' && substr( $license, 0, 2 ) != 'by' ) {
177 # 2.0 dropped the non-attribs licenses
178 continue;
180 $lurl = "http://creativecommons.org/licenses/{$license}/{$version}/";
181 $knownLicenses[$lurl] = explode( '-', $license );
182 $knownLicenses[$lurl][] = 're';
183 $knownLicenses[$lurl][] = 'di';
184 $knownLicenses[$lurl][] = 'no';
185 if ( !in_array( 'nd', $knownLicenses[$lurl] ) ) {
186 $knownLicenses[$lurl][] = 'de';
191 /* Handle the GPL and LGPL, too. */
193 $knownLicenses['http://creativecommons.org/licenses/GPL/2.0/'] =
194 array( 'de', 're', 'di', 'no', 'sa', 'sc' );
195 $knownLicenses['http://creativecommons.org/licenses/LGPL/2.1/'] =
196 array( 'de', 're', 'di', 'no', 'sa', 'sc' );
197 $knownLicenses['http://www.gnu.org/copyleft/fdl.html'] =
198 array( 'de', 're', 'di', 'no', 'sa', 'sc' );
200 return $knownLicenses;