MediaWiki
REL1_22
|
00001 <?php 00026 abstract class RdfMetaData { 00027 const RDF_TYPE_PREFS = 'application/rdf+xml,text/xml;q=0.7,application/xml;q=0.5,text/rdf;q=0.1'; 00028 00033 public function __construct( Page $article ) { 00034 $this->mArticle = $article; 00035 } 00036 00037 abstract public function show(); 00038 00039 protected function setup() { 00040 global $wgOut, $wgRequest; 00041 00042 $httpaccept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : null; 00043 $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) ); 00044 00045 if ( !$rdftype ) { 00046 throw new HttpError( 406, wfMessage( 'notacceptable' ) ); 00047 } 00048 00049 $wgOut->disable(); 00050 $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" ); 00051 $wgOut->sendCacheControl(); 00052 return true; 00053 } 00054 00055 protected function reallyFullUrl() { 00056 return $this->mArticle->getTitle()->getFullURL(); 00057 } 00058 00059 protected function basics() { 00060 global $wgLanguageCode, $wgSitename; 00061 00062 $this->element( 'title', $this->mArticle->getTitle()->getText() ); 00063 $this->pageOrString( 'publisher', wfMessage( 'aboutpage' )->text(), $wgSitename ); 00064 $this->element( 'language', $wgLanguageCode ); 00065 $this->element( 'type', 'Text' ); 00066 $this->element( 'format', 'text/html' ); 00067 $this->element( 'identifier', $this->reallyFullUrl() ); 00068 $this->element( 'date', $this->date( $this->mArticle->getTimestamp() ) ); 00069 00070 $lastEditor = User::newFromId( $this->mArticle->getUser() ); 00071 $this->person( 'creator', $lastEditor ); 00072 00073 foreach ( $this->mArticle->getContributors() as $user ) { 00074 $this->person( 'contributor', $user ); 00075 } 00076 00077 $this->rights(); 00078 } 00079 00080 protected function element( $name, $value ) { 00081 $value = htmlspecialchars( $value ); 00082 print "\t\t<dc:{$name}>{$value}</dc:{$name}>\n"; 00083 } 00084 00085 protected function date( $timestamp ) { 00086 return substr( $timestamp, 0, 4 ) . '-' 00087 . substr( $timestamp, 4, 2 ) . '-' 00088 . substr( $timestamp, 6, 2 ); 00089 } 00090 00091 protected function pageOrString( $name, $page, $str ) { 00092 if ( $page instanceof Title ) { 00093 $nt = $page; 00094 } else { 00095 $nt = Title::newFromText( $page ); 00096 } 00097 00098 if ( !$nt || $nt->getArticleID() == 0 ) { 00099 $this->element( $name, $str ); 00100 } else { 00101 $this->page( $name, $nt ); 00102 } 00103 } 00104 00109 protected function page( $name, $title ) { 00110 $this->url( $name, $title->getFullURL() ); 00111 } 00112 00113 protected function url( $name, $url ) { 00114 $url = htmlspecialchars( $url ); 00115 print "\t\t<dc:{$name} rdf:resource=\"{$url}\" />\n"; 00116 } 00117 00118 protected function person( $name, User $user ) { 00119 global $wgHiddenPrefs; 00120 00121 if ( $user->isAnon() ) { 00122 $this->element( $name, wfMessage( 'anonymous' )->numParams( 1 )->text() ); 00123 } else { 00124 $real = $user->getRealName(); 00125 if ( $real && !in_array( 'realname', $wgHiddenPrefs ) ) { 00126 $this->element( $name, $real ); 00127 } else { 00128 $userName = $user->getName(); 00129 $this->pageOrString( 00130 $name, 00131 $user->getUserPage(), 00132 wfMessage( 'siteuser', $userName, $userName )->text() 00133 ); 00134 } 00135 } 00136 } 00137 00142 protected function rights() { 00143 global $wgRightsPage, $wgRightsUrl, $wgRightsText; 00144 00145 if ( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) ) 00146 && ( $nt->getArticleID() != 0 ) ) { 00147 $this->page( 'rights', $nt ); 00148 } elseif ( $wgRightsUrl ) { 00149 $this->url( 'rights', $wgRightsUrl ); 00150 } elseif ( $wgRightsText ) { 00151 $this->element( 'rights', $wgRightsText ); 00152 } 00153 } 00154 00155 protected function getTerms( $url ) { 00156 global $wgLicenseTerms; 00157 00158 if ( $wgLicenseTerms ) { 00159 return $wgLicenseTerms; 00160 } else { 00161 $known = $this->getKnownLicenses(); 00162 if ( isset( $known[$url] ) ) { 00163 return $known[$url]; 00164 } else { 00165 return array(); 00166 } 00167 } 00168 } 00169 00170 protected function getKnownLicenses() { 00171 $ccLicenses = array( 'by', 'by-nd', 'by-nd-nc', 'by-nc', 00172 'by-nc-sa', 'by-sa' ); 00173 $ccVersions = array( '1.0', '2.0' ); 00174 $knownLicenses = array(); 00175 00176 foreach ( $ccVersions as $version ) { 00177 foreach ( $ccLicenses as $license ) { 00178 if ( $version == '2.0' && substr( $license, 0, 2 ) != 'by' ) { 00179 # 2.0 dropped the non-attribs licenses 00180 continue; 00181 } 00182 $lurl = "http://creativecommons.org/licenses/{$license}/{$version}/"; 00183 $knownLicenses[$lurl] = explode( '-', $license ); 00184 $knownLicenses[$lurl][] = 're'; 00185 $knownLicenses[$lurl][] = 'di'; 00186 $knownLicenses[$lurl][] = 'no'; 00187 if ( !in_array( 'nd', $knownLicenses[$lurl] ) ) { 00188 $knownLicenses[$lurl][] = 'de'; 00189 } 00190 } 00191 } 00192 00193 /* Handle the GPL and LGPL, too. */ 00194 00195 $knownLicenses['http://creativecommons.org/licenses/GPL/2.0/'] = 00196 array( 'de', 're', 'di', 'no', 'sa', 'sc' ); 00197 $knownLicenses['http://creativecommons.org/licenses/LGPL/2.1/'] = 00198 array( 'de', 're', 'di', 'no', 'sa', 'sc' ); 00199 $knownLicenses['http://www.gnu.org/copyleft/fdl.html'] = 00200 array( 'de', 're', 'di', 'no', 'sa', 'sc' ); 00201 00202 return $knownLicenses; 00203 } 00204 }