MediaWiki
REL1_20
|
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 public abstract 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 if( $user->isAnon() ){ 00120 $this->element( $name, wfMessage( 'anonymous' )->numParams( 1 )->text() ); 00121 } else { 00122 $real = $user->getRealName(); 00123 if( $real ) { 00124 $this->element( $name, $real ); 00125 } else { 00126 $userName = $user->getName(); 00127 $this->pageOrString( 00128 $name, 00129 $user->getUserPage(), 00130 wfMessage( 'siteuser', $userName, $userName )->text() 00131 ); 00132 } 00133 } 00134 } 00135 00140 protected function rights() { 00141 global $wgRightsPage, $wgRightsUrl, $wgRightsText; 00142 00143 if( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) ) 00144 && ($nt->getArticleID() != 0)) { 00145 $this->page('rights', $nt); 00146 } elseif( $wgRightsUrl ){ 00147 $this->url('rights', $wgRightsUrl); 00148 } elseif( $wgRightsText ){ 00149 $this->element( 'rights', $wgRightsText ); 00150 } 00151 } 00152 00153 protected function getTerms( $url ){ 00154 global $wgLicenseTerms; 00155 00156 if( $wgLicenseTerms ){ 00157 return $wgLicenseTerms; 00158 } else { 00159 $known = $this->getKnownLicenses(); 00160 if( isset( $known[$url] ) ) { 00161 return $known[$url]; 00162 } else { 00163 return array(); 00164 } 00165 } 00166 } 00167 00168 protected function getKnownLicenses() { 00169 $ccLicenses = array('by', 'by-nd', 'by-nd-nc', 'by-nc', 00170 'by-nc-sa', 'by-sa'); 00171 $ccVersions = array('1.0', '2.0'); 00172 $knownLicenses = array(); 00173 00174 foreach ($ccVersions as $version) { 00175 foreach ($ccLicenses as $license) { 00176 if( $version == '2.0' && substr( $license, 0, 2) != 'by' ) { 00177 # 2.0 dropped the non-attribs licenses 00178 continue; 00179 } 00180 $lurl = "http://creativecommons.org/licenses/{$license}/{$version}/"; 00181 $knownLicenses[$lurl] = explode('-', $license); 00182 $knownLicenses[$lurl][] = 're'; 00183 $knownLicenses[$lurl][] = 'di'; 00184 $knownLicenses[$lurl][] = 'no'; 00185 if (!in_array('nd', $knownLicenses[$lurl])) { 00186 $knownLicenses[$lurl][] = 'de'; 00187 } 00188 } 00189 } 00190 00191 /* Handle the GPL and LGPL, too. */ 00192 00193 $knownLicenses['http://creativecommons.org/licenses/GPL/2.0/'] = 00194 array('de', 're', 'di', 'no', 'sa', 'sc'); 00195 $knownLicenses['http://creativecommons.org/licenses/LGPL/2.1/'] = 00196 array('de', 're', 'di', 'no', 'sa', 'sc'); 00197 $knownLicenses['http://www.gnu.org/copyleft/fdl.html'] = 00198 array('de', 're', 'di', 'no', 'sa', 'sc'); 00199 00200 return $knownLicenses; 00201 } 00202 } 00203