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