r88875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88874‎ | r88875 | r88876 >
Date:00:44, 26 May 2011
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Kill code from CreativeCommonsRdf_body.php that should've been removed in r88873

Add URL, add one description

Fix class name of CreativeCommonsRdf
Modified paths:
  • /trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf.php (modified) (history)
  • /trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf_body.php (modified) (history)
  • /trunk/extensions/DublinCoreRdf/DublinCoreRdf.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DublinCoreRdf/DublinCoreRdf.php
@@ -3,8 +3,9 @@
44 $wgExtensionCredits['other'][] = array(
55 'path' => __FILE__,
66 'name' => 'DublinCoreRdf',
7 - 'url' => '',
 7+ 'url' => 'http://www.mediawiki.org/wiki/Extension:DublinCoreRdf',
88 'author' => 'Evan Prodromou',
 9+ 'descriptionmsg' => "Dublin Core RDF-metadata"
910 );
1011
1112 $wgHooks['MediaWikiPerformAction'][] = 'efDublinCorePerformAction';
Index: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf.php
@@ -3,15 +3,16 @@
44 $wgExtensionCredits['other'][] = array(
55 'path' => __FILE__,
66 'name' => 'CreativeCoreRdf',
7 - 'url' => '',
 7+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CreativeCoreRdf',
88 'author' => 'Evan Prodromou',
 9+ 'descriptionmsg' => "CreativeCommons RDF-metadata"
910 );
1011
11 -$wgHooks['MediaWikiPerformAction'][] = 'efCreativeCoreRdfPreformAction';
 12+$wgHooks['MediaWikiPerformAction'][] = 'efCreativeCommonsRdfPreformAction';
1213
13 -$wgAutoloadClasses['CreativeCoreRdf'] = $dir . 'CreativeCoreRdf_body.php';
 14+$wgAutoloadClasses['CreativeCommonsRdf'] = $dir . 'CreativeCommonsRdf_body.php';
1415
15 -function efCreativeCoreRdfPreformAction( $output, $article, $title, $user, $request, $mediaWiki ) {
 16+function efCreativeCommonsRdfPreformAction( $output, $article, $title, $user, $request, $mediaWiki ) {
1617 if ( $mediaWiki->getAction() !== 'creativecommons' ) {
1718 return true;
1819 }
Index: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf_body.php
@@ -22,182 +22,6 @@
2323 * @file
2424 */
2525
26 -abstract class RdfMetaData {
27 - const RDF_TYPE_PREFS = 'application/rdf+xml,text/xml;q=0.7,application/xml;q=0.5,text/rdf;q=0.1';
28 -
29 - /**
30 - * Constructor
31 - * @param $article Article object
32 - */
33 - public function __construct( Article $article ) {
34 - $this->mArticle = $article;
35 - }
36 -
37 - public abstract function show();
38 -
39 - /**
40 - *
41 - */
42 - protected function setup() {
43 - global $wgOut, $wgRequest;
44 -
45 - $httpaccept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : null;
46 - $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) );
47 -
48 - if( !$rdftype ){
49 - wfHttpError( 406, 'Not Acceptable', wfMsg( 'notacceptable' ) );
50 - return false;
51 - } else {
52 - $wgOut->disable();
53 - $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" );
54 - $wgOut->sendCacheControl();
55 - return true;
56 - }
57 - }
58 -
59 - /**
60 - *
61 - */
62 - protected function reallyFullUrl() {
63 - return $this->mArticle->getTitle()->getFullURL();
64 - }
65 -
66 - protected function basics() {
67 - global $wgLanguageCode, $wgSitename;
68 -
69 - $this->element( 'title', $this->mArticle->mTitle->getText() );
70 - $this->pageOrString( 'publisher', wfMsg( 'aboutpage' ), $wgSitename );
71 - $this->element( 'language', $wgLanguageCode );
72 - $this->element( 'type', 'Text' );
73 - $this->element( 'format', 'text/html' );
74 - $this->element( 'identifier', $this->reallyFullUrl() );
75 - $this->element( 'date', $this->date( $this->mArticle->getTimestamp() ) );
76 -
77 - $lastEditor = User::newFromId( $this->mArticle->getUser() );
78 - $this->person( 'creator', $lastEditor );
79 -
80 - foreach( $this->mArticle->getContributors() as $user ){
81 - $this->person( 'contributor', $user );
82 - }
83 -
84 - $this->rights();
85 - }
86 -
87 - protected function element( $name, $value ) {
88 - $value = htmlspecialchars( $value );
89 - print "\t\t<dc:{$name}>{$value}</dc:{$name}>\n";
90 - }
91 -
92 - protected function date($timestamp) {
93 - return substr($timestamp, 0, 4) . '-'
94 - . substr($timestamp, 4, 2) . '-'
95 - . substr($timestamp, 6, 2);
96 - }
97 -
98 - protected function pageOrString( $name, $page, $str ) {
99 - if( $page instanceof Title )
100 - $nt = $page;
101 - else
102 - $nt = Title::newFromText( $page );
103 -
104 - if( !$nt || $nt->getArticleID() == 0 ){
105 - $this->element( $name, $str );
106 - } else {
107 - $this->page( $name, $nt );
108 - }
109 - }
110 -
111 - protected function page( $name, $title ) {
112 - $this->url( $name, $title->getFullUrl() );
113 - }
114 -
115 - protected function url($name, $url) {
116 - $url = htmlspecialchars( $url );
117 - print "\t\t<dc:{$name} rdf:resource=\"{$url}\" />\n";
118 - }
119 -
120 - protected function person( $name, User $user ) {
121 - if( $user->isAnon() ){
122 - $this->element( $name, wfMsgExt( 'anonymous', array( 'parsemag' ), 1 ) );
123 - } else {
124 - $real = $user->getRealName();
125 - if( $real ) {
126 - $this->element( $name, $real );
127 - } else {
128 - $userName = $user->getName();
129 - $this->pageOrString( $name, $user->getUserPage(), wfMsgExt( 'siteuser', 'parsemag', $userName, $userName ) );
130 - }
131 - }
132 - }
133 -
134 - /**
135 - * Takes an arg, for future enhancement with different rights for
136 - * different pages.
137 - */
138 - protected function rights() {
139 - global $wgRightsPage, $wgRightsUrl, $wgRightsText;
140 -
141 - if( $wgRightsPage && ( $nt = Title::newFromText( $wgRightsPage ) )
142 - && ($nt->getArticleID() != 0)) {
143 - $this->page('rights', $nt);
144 - } else if( $wgRightsUrl ){
145 - $this->url('rights', $wgRightsUrl);
146 - } else if( $wgRightsText ){
147 - $this->element( 'rights', $wgRightsText );
148 - }
149 - }
150 -
151 - protected function getTerms( $url ){
152 - global $wgLicenseTerms;
153 -
154 - if( $wgLicenseTerms ){
155 - return $wgLicenseTerms;
156 - } else {
157 - $known = $this->getKnownLicenses();
158 - if( isset( $known[$url] ) ) {
159 - return $known[$url];
160 - } else {
161 - return array();
162 - }
163 - }
164 - }
165 -
166 - protected function getKnownLicenses() {
167 - $ccLicenses = array('by', 'by-nd', 'by-nd-nc', 'by-nc',
168 - 'by-nc-sa', 'by-sa');
169 - $ccVersions = array('1.0', '2.0');
170 - $knownLicenses = array();
171 -
172 - foreach ($ccVersions as $version) {
173 - foreach ($ccLicenses as $license) {
174 - if( $version == '2.0' && substr( $license, 0, 2) != 'by' ) {
175 - # 2.0 dropped the non-attribs licenses
176 - continue;
177 - }
178 - $lurl = "http://creativecommons.org/licenses/{$license}/{$version}/";
179 - $knownLicenses[$lurl] = explode('-', $license);
180 - $knownLicenses[$lurl][] = 're';
181 - $knownLicenses[$lurl][] = 'di';
182 - $knownLicenses[$lurl][] = 'no';
183 - if (!in_array('nd', $knownLicenses[$lurl])) {
184 - $knownLicenses[$lurl][] = 'de';
185 - }
186 - }
187 - }
188 -
189 - /* Handle the GPL and LGPL, too. */
190 -
191 - $knownLicenses['http://creativecommons.org/licenses/GPL/2.0/'] =
192 - array('de', 're', 'di', 'no', 'sa', 'sc');
193 - $knownLicenses['http://creativecommons.org/licenses/LGPL/2.1/'] =
194 - array('de', 're', 'di', 'no', 'sa', 'sc');
195 - $knownLicenses['http://www.gnu.org/copyleft/fdl.html'] =
196 - array('de', 're', 'di', 'no', 'sa', 'sc');
197 -
198 - return $knownLicenses;
199 - }
200 -}
201 -
20226 class CreativeCommonsRdf extends RdfMetaData {
20327
20428 public function show(){

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88873* (bug 29144) Move action=dublincore and action=creativecommons to extensions...reedy00:08, 26 May 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:16, 26 May 2011
+	'descriptionmsg' => "Dublin Core RDF-metadata"

Really?

#Comment by Reedy (talk | contribs)   12:53, 26 May 2011

Suggest something better? :P

#Comment by Nikerabbit (talk | contribs)   13:38, 26 May 2011

That is the message *key*?

#Comment by MZMcBride (talk | contribs)   13:56, 26 May 2011

I suggest RTFM. ;-)

#Comment by Bryan (talk | contribs)   16:50, 26 May 2011

PreformAction?

#Comment by Reedy (talk | contribs)   16:51, 26 May 2011
#Comment by Bryan (talk | contribs)   16:54, 26 May 2011

PreformAction != PerformAction

#Comment by Reedy (talk | contribs)   16:54, 26 May 2011

It's right on the hook side :P

Status & tagging log