(bug 35565) Special:Log/patrol doesn't indicate whether patrolling was automatic
[mediawiki.git] / includes / Metadata.php
blobe5e3296b3ba2c3ed1725f82dcf030b007d59d87f
1 <?php
2 /**
4 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @author Evan Prodromou <evan@wikitravel.org>
21 * @file
24 abstract class RdfMetaData {
25 const RDF_TYPE_PREFS = 'application/rdf+xml,text/xml;q=0.7,application/xml;q=0.5,text/rdf;q=0.1';
27 /**
28 * Constructor
29 * @param $article Article object
31 public function __construct( Page $article ) {
32 $this->mArticle = $article;
35 public abstract function show();
37 protected function setup() {
38 global $wgOut, $wgRequest;
40 $httpaccept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : null;
41 $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) );
43 if( !$rdftype ){
44 throw new HttpError( 406, wfMessage( 'notacceptable' ) );
47 $wgOut->disable();
48 $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" );
49 $wgOut->sendCacheControl();
50 return true;
53 protected function reallyFullUrl() {
54 return $this->mArticle->getTitle()->getFullURL();
57 protected function basics() {
58 global $wgLanguageCode, $wgSitename;
60 $this->element( 'title', $this->mArticle->getTitle()->getText() );
61 $this->pageOrString( 'publisher', wfMsg( 'aboutpage' ), $wgSitename );
62 $this->element( 'language', $wgLanguageCode );
63 $this->element( 'type', 'Text' );
64 $this->element( 'format', 'text/html' );
65 $this->element( 'identifier', $this->reallyFullUrl() );
66 $this->element( 'date', $this->date( $this->mArticle->getTimestamp() ) );
68 $lastEditor = User::newFromId( $this->mArticle->getUser() );
69 $this->person( 'creator', $lastEditor );
71 foreach( $this->mArticle->getContributors() as $user ){
72 $this->person( 'contributor', $user );
75 $this->rights();
78 protected function element( $name, $value ) {
79 $value = htmlspecialchars( $value );
80 print "\t\t<dc:{$name}>{$value}</dc:{$name}>\n";
83 protected function date($timestamp) {
84 return substr($timestamp, 0, 4) . '-'
85 . substr($timestamp, 4, 2) . '-'
86 . substr($timestamp, 6, 2);
89 protected function pageOrString( $name, $page, $str ) {
90 if( $page instanceof Title ) {
91 $nt = $page;
92 } else {
93 $nt = Title::newFromText( $page );
96 if( !$nt || $nt->getArticleID() == 0 ){
97 $this->element( $name, $str );
98 } else {
99 $this->page( $name, $nt );
104 * @param $name string
105 * @param $title Title
107 protected function page( $name, $title ) {
108 $this->url( $name, $title->getFullUrl() );
111 protected function url($name, $url) {
112 $url = htmlspecialchars( $url );
113 print "\t\t<dc:{$name} rdf:resource=\"{$url}\" />\n";
116 protected function person( $name, User $user ) {
117 if( $user->isAnon() ){
118 $this->element( $name, wfMsgExt( 'anonymous', array( 'parsemag' ), 1 ) );
119 } else {
120 $real = $user->getRealName();
121 if( $real ) {
122 $this->element( $name, $real );
123 } else {
124 $userName = $user->getName();
125 $this->pageOrString( $name, $user->getUserPage(), wfMsgExt( 'siteuser', 'parsemag', $userName, $userName ) );
131 * Takes an arg, for future enhancement with different rights for
132 * different pages.
134 protected function rights() {
135 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
137 if( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) )
138 && ($nt->getArticleID() != 0)) {
139 $this->page('rights', $nt);
140 } elseif( $wgRightsUrl ){
141 $this->url('rights', $wgRightsUrl);
142 } elseif( $wgRightsText ){
143 $this->element( 'rights', $wgRightsText );
147 protected function getTerms( $url ){
148 global $wgLicenseTerms;
150 if( $wgLicenseTerms ){
151 return $wgLicenseTerms;
152 } else {
153 $known = $this->getKnownLicenses();
154 if( isset( $known[$url] ) ) {
155 return $known[$url];
156 } else {
157 return array();
162 protected function getKnownLicenses() {
163 $ccLicenses = array('by', 'by-nd', 'by-nd-nc', 'by-nc',
164 'by-nc-sa', 'by-sa');
165 $ccVersions = array('1.0', '2.0');
166 $knownLicenses = array();
168 foreach ($ccVersions as $version) {
169 foreach ($ccLicenses as $license) {
170 if( $version == '2.0' && substr( $license, 0, 2) != 'by' ) {
171 # 2.0 dropped the non-attribs licenses
172 continue;
174 $lurl = "http://creativecommons.org/licenses/{$license}/{$version}/";
175 $knownLicenses[$lurl] = explode('-', $license);
176 $knownLicenses[$lurl][] = 're';
177 $knownLicenses[$lurl][] = 'di';
178 $knownLicenses[$lurl][] = 'no';
179 if (!in_array('nd', $knownLicenses[$lurl])) {
180 $knownLicenses[$lurl][] = 'de';
185 /* Handle the GPL and LGPL, too. */
187 $knownLicenses['http://creativecommons.org/licenses/GPL/2.0/'] =
188 array('de', 're', 'di', 'no', 'sa', 'sc');
189 $knownLicenses['http://creativecommons.org/licenses/LGPL/2.1/'] =
190 array('de', 're', 'di', 'no', 'sa', 'sc');
191 $knownLicenses['http://www.gnu.org/copyleft/fdl.html'] =
192 array('de', 're', 'di', 'no', 'sa', 'sc');
194 return $knownLicenses;