X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FMetadata.php;h=0ca153933ae05f338159276e629bb679c86964e3;hb=d6cf07fac52fc9c4c1ccdd1d6b2f730993031c59;hp=3f959547095fab530ed44abca62ae04eac7055a9;hpb=a5c649c5072c91bdebf5e6ff35e299baa757f9af;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Metadata.php b/includes/Metadata.php index 3f95954709..0ca153933a 100644 --- a/includes/Metadata.php +++ b/includes/Metadata.php @@ -1,23 +1,26 @@ . * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html * * @author Evan Prodromou + * @file */ abstract class RdfMetaData { @@ -27,15 +30,12 @@ abstract class RdfMetaData { * Constructor * @param $article Article object */ - public function __construct( Article $article ){ + public function __construct( Page $article ) { $this->mArticle = $article; } public abstract function show(); - /** - * - */ protected function setup() { global $wgOut, $wgRequest; @@ -43,29 +43,25 @@ abstract class RdfMetaData { $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) ); if( !$rdftype ){ - wfHttpError( 406, 'Not Acceptable', wfMsg( 'notacceptable' ) ); - return false; - } else { - $wgOut->disable(); - $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" ); - $wgOut->sendCacheControl(); - return true; + throw new HttpError( 406, wfMessage( 'notacceptable' ) ); } + + $wgOut->disable(); + $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" ); + $wgOut->sendCacheControl(); + return true; } - /** - * - */ protected function reallyFullUrl() { return $this->mArticle->getTitle()->getFullURL(); } protected function basics() { - global $wgContLanguageCode, $wgSitename; + global $wgLanguageCode, $wgSitename; - $this->element( 'title', $this->mArticle->mTitle->getText() ); - $this->pageOrString( 'publisher', wfMsg( 'aboutpage' ), $wgSitename ); - $this->element( 'language', $wgContLanguageCode ); + $this->element( 'title', $this->mArticle->getTitle()->getText() ); + $this->pageOrString( 'publisher', wfMessage( 'aboutpage' )->text(), $wgSitename ); + $this->element( 'language', $wgLanguageCode ); $this->element( 'type', 'Text' ); $this->element( 'format', 'text/html' ); $this->element( 'identifier', $this->reallyFullUrl() ); @@ -92,11 +88,12 @@ abstract class RdfMetaData { . substr($timestamp, 6, 2); } - protected function pageOrString( $name, $page, $str ){ - if( $page instanceof Title ) + protected function pageOrString( $name, $page, $str ) { + if( $page instanceof Title ) { $nt = $page; - else + } else { $nt = Title::newFromText( $page ); + } if( !$nt || $nt->getArticleID() == 0 ){ $this->element( $name, $str ); @@ -105,7 +102,11 @@ abstract class RdfMetaData { } } - protected function page( $name, $title ){ + /** + * @param $name string + * @param $title Title + */ + protected function page( $name, $title ) { $this->url( $name, $title->getFullUrl() ); } @@ -114,16 +115,21 @@ abstract class RdfMetaData { print "\t\t\n"; } - protected function person($name, User $user ){ - global $wgContLang; - + protected function person( $name, User $user ) { if( $user->isAnon() ){ - $this->element( $name, wfMsgExt( 'anonymous', array( 'parsemag' ), 1 ) ); - } else if( $real = $user->getRealName() ) { - $this->element( $name, $real ); + $this->element( $name, wfMessage( 'anonymous' )->numParams( 1 )->text() ); } else { - $userName = $user->getName(); - $this->pageOrString( $name, $user->getUserPage(), wfMsgExt( 'siteuser', 'parsemag', $userName, $userName ) ); + $real = $user->getRealName(); + if( $real ) { + $this->element( $name, $real ); + } else { + $userName = $user->getName(); + $this->pageOrString( + $name, + $user->getUserPage(), + wfMessage( 'siteuser', $userName, $userName )->text() + ); + } } } @@ -137,9 +143,9 @@ abstract class RdfMetaData { if( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) ) && ($nt->getArticleID() != 0)) { $this->page('rights', $nt); - } else if( $wgRightsUrl ){ + } elseif( $wgRightsUrl ){ $this->url('rights', $wgRightsUrl); - } else if( $wgRightsText ){ + } elseif( $wgRightsText ){ $this->element( 'rights', $wgRightsText ); } } @@ -195,125 +201,3 @@ abstract class RdfMetaData { } } -class DublinCoreRdf extends RdfMetaData { - - public function show(){ - if( $this->setup() ){ - $this->prologue(); - $this->basics(); - $this->epilogue(); - } - } - - /** - * begin of the page - */ - protected function prologue() { - global $wgOutputEncoding; - - $url = htmlspecialchars( $this->reallyFullUrl() ); - print << - - - - -PROLOGUE; - } - - /** - * end of the page - */ - protected function epilogue() { - print << - -EPILOGUE; - } -} - -class CreativeCommonsRdf extends RdfMetaData { - - public function show(){ - if( $this->setup() ){ - global $wgRightsUrl; - - $url = $this->reallyFullUrl(); - - $this->prologue(); - $this->subPrologue('Work', $url); - - $this->basics(); - if( $wgRightsUrl ){ - $url = htmlspecialchars( $wgRightsUrl ); - print "\t\t\n"; - } - - $this->subEpilogue('Work'); - - if( $wgRightsUrl ){ - $terms = $this->getTerms( $wgRightsUrl ); - if( $terms ){ - $this->subPrologue( 'License', $wgRightsUrl ); - $this->license( $terms ); - $this->subEpilogue( 'License' ); - } - } - } - - $this->epilogue(); - } - - protected function prologue() { - global $wgOutputEncoding; - echo << - - -PROLOGUE; - } - - protected function subPrologue( $type, $url ){ - $url = htmlspecialchars( $url ); - echo "\t\n"; - } - - protected function subEpilogue($type) { - echo "\t\n"; - } - - protected function license($terms) { - - foreach( $terms as $term ){ - switch( $term ) { - case 're': - $this->term('permits', 'Reproduction'); break; - case 'di': - $this->term('permits', 'Distribution'); break; - case 'de': - $this->term('permits', 'DerivativeWorks'); break; - case 'nc': - $this->term('prohibits', 'CommercialUse'); break; - case 'no': - $this->term('requires', 'Notice'); break; - case 'by': - $this->term('requires', 'Attribution'); break; - case 'sa': - $this->term('requires', 'ShareAlike'); break; - case 'sc': - $this->term('requires', 'SourceCode'); break; - } - } - } - - protected function term( $term, $name ){ - print "\t\t\n"; - } - - protected function epilogue() { - echo "\n"; - } -} \ No newline at end of file