r88873 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88872‎ | r88873 | r88874 >
Date:00:08, 26 May 2011
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
* (bug 29144) Move action=dublincore and action=creativecommons to extensions

Moved CreativeCommonsRDF out to extension
Modified paths:
  • /trunk/extensions/CreativeCommonsRdf (added) (history)
  • /trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf.php (added) (history)
  • /trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf_body.php (added) (history)
  • /trunk/extensions/DublinCoreRdf/DublinCoreRdf.php (modified) (history)
  • /trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Metadata.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2489,7 +2489,6 @@
24902490 'group-bureaucrat.js',
24912491 ),
24922492 'metadata_cc' => array(
2493 - 'nocreativecommons',
24942493 'notacceptable',
24952494 ),
24962495 'attribution' => array(
Index: trunk/phase3/includes/OutputPage.php
@@ -2703,7 +2703,6 @@
27042704 global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
27052705 $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
27062706 $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
2707 - $wgEnableCreativeCommonsRdf,
27082707 $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
27092708 $wgRightsPage, $wgRightsUrl;
27102709
@@ -2828,24 +2827,6 @@
28292828 ) );
28302829 }
28312830
2832 - # Metadata links
2833 - # - Creative Commons
2834 - # See http://wiki.creativecommons.org/Extend_Metadata.
2835 - # - Dublin Core
2836 - # Use hreflang to specify canonical and alternate links
2837 - # See http://www.google.com/support/webmasters/bin/answer.py?answer=189077
2838 - if ( $this->isArticleRelated() ) {
2839 - # note: buggy CC software only reads first "meta" link
2840 - if ( $wgEnableCreativeCommonsRdf ) {
2841 - $tags[] = Html::element( 'link', array(
2842 - 'rel' => $this->getMetadataAttribute(),
2843 - 'title' => 'Creative Commons',
2844 - 'type' => 'application/rdf+xml',
2845 - 'href' => $this->getTitle()->getLocalURL( 'action=creativecommons' ) )
2846 - );
2847 - }
2848 - }
2849 -
28502831 # Language variants
28512832 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
28522833 && $wgContLang->hasVariants() ) {
Index: trunk/phase3/includes/AutoLoader.php
@@ -49,7 +49,6 @@
5050 'ConfEditorToken' => 'includes/ConfEditor.php',
5151 'Cookie' => 'includes/Cookie.php',
5252 'CookieJar' => 'includes/Cookie.php',
53 - 'CreativeCommonsRdf' => 'includes/Metadata.php',
5453 'DiffHistoryBlob' => 'includes/HistoryBlob.php',
5554 'DjVuImage' => 'includes/DjVuImage.php',
5655 'DoubleReplacer' => 'includes/StringUtils.php',
Index: trunk/phase3/includes/Wiki.php
@@ -406,8 +406,7 @@
407407 * @param $article Article
408408 */
409409 private function performAction( $article ) {
410 - global $wgSquidMaxage, $wgUseExternalEditor,
411 - $wgEnableCreativeCommonsRdf;
 410+ global $wgSquidMaxage, $wgUseExternalEditor;
412411
413412 wfProfileIn( __METHOD__ );
414413
@@ -450,14 +449,6 @@
451450 case 'deletetrackback':
452451 $article->$act();
453452 break;
454 - case 'creativecommons':
455 - if ( !$wgEnableCreativeCommonsRdf ) {
456 - wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
457 - } else {
458 - $rdf = new CreativeCommonsRdf( $article );
459 - $rdf->show();
460 - }
461 - break;
462453 case 'submit':
463454 if ( session_id() == '' ) {
464455 // Send a cookie so anons get talk message notifications
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4406,9 +4406,6 @@
44074407 * @{
44084408 */
44094409
4410 -/** RDF metadata toggles */
4411 -$wgEnableCreativeCommonsRdf = false;
4412 -
44134410 /** Override for copyright metadata.
44144411 * TODO: these options need documentation
44154412 */
Index: trunk/phase3/includes/Metadata.php
@@ -198,86 +198,3 @@
199199 }
200200 }
201201
202 -class CreativeCommonsRdf extends RdfMetaData {
203 -
204 - public function show(){
205 - if( $this->setup() ){
206 - global $wgRightsUrl;
207 -
208 - $url = $this->reallyFullUrl();
209 -
210 - $this->prologue();
211 - $this->subPrologue('Work', $url);
212 -
213 - $this->basics();
214 - if( $wgRightsUrl ){
215 - $url = htmlspecialchars( $wgRightsUrl );
216 - print "\t\t<cc:license rdf:resource=\"$url\" />\n";
217 - }
218 -
219 - $this->subEpilogue('Work');
220 -
221 - if( $wgRightsUrl ){
222 - $terms = $this->getTerms( $wgRightsUrl );
223 - if( $terms ){
224 - $this->subPrologue( 'License', $wgRightsUrl );
225 - $this->license( $terms );
226 - $this->subEpilogue( 'License' );
227 - }
228 - }
229 - }
230 -
231 - $this->epilogue();
232 - }
233 -
234 - protected function prologue() {
235 - echo <<<PROLOGUE
236 -<?xml version='1.0' encoding="UTF-8" ?>
237 -<rdf:RDF xmlns:cc="http://web.resource.org/cc/"
238 - xmlns:dc="http://purl.org/dc/elements/1.1/"
239 - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
240 -
241 -PROLOGUE;
242 - }
243 -
244 - protected function subPrologue( $type, $url ){
245 - $url = htmlspecialchars( $url );
246 - echo "\t<cc:{$type} rdf:about=\"{$url}\">\n";
247 - }
248 -
249 - protected function subEpilogue($type) {
250 - echo "\t</cc:{$type}>\n";
251 - }
252 -
253 - protected function license($terms) {
254 -
255 - foreach( $terms as $term ){
256 - switch( $term ) {
257 - case 're':
258 - $this->term('permits', 'Reproduction'); break;
259 - case 'di':
260 - $this->term('permits', 'Distribution'); break;
261 - case 'de':
262 - $this->term('permits', 'DerivativeWorks'); break;
263 - case 'nc':
264 - $this->term('prohibits', 'CommercialUse'); break;
265 - case 'no':
266 - $this->term('requires', 'Notice'); break;
267 - case 'by':
268 - $this->term('requires', 'Attribution'); break;
269 - case 'sa':
270 - $this->term('requires', 'ShareAlike'); break;
271 - case 'sc':
272 - $this->term('requires', 'SourceCode'); break;
273 - }
274 - }
275 - }
276 -
277 - protected function term( $term, $name ){
278 - print "\t\t<cc:{$term} rdf:resource=\"http://web.resource.org/cc/{$name}\" />\n";
279 - }
280 -
281 - protected function epilogue() {
282 - echo "</rdf:RDF>\n";
283 - }
284 -}
Index: trunk/extensions/DublinCoreRdf/DublinCoreRdf.php
@@ -2,16 +2,16 @@
33
44 $wgExtensionCredits['other'][] = array(
55 'path' => __FILE__,
6 - 'name' => 'DublinCore',
 6+ 'name' => 'DublinCoreRdf',
77 'url' => '',
88 'author' => 'Evan Prodromou',
99 );
1010
11 -$wgHooks['MediaWikiPerformAction'][] = 'efDublinCorePreformAction';
 11+$wgHooks['MediaWikiPerformAction'][] = 'efDublinCorePerformAction';
1212
1313 $wgAutoloadClasses['DublinCoreRdf'] = $dir . 'DublinCoreRdf_body.php';
1414
15 -function efDublinCorePreformAction( $output, $article, $title, $user, $request, $mediaWiki ) {
 15+function efDublinCorePerformAction( $output, $article, $title, $user, $request, $mediaWiki ) {
1616 if ( $mediaWiki->getAction() !== 'dublincore' ) {
1717 return true;
1818 }
Index: trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php
@@ -65,6 +65,8 @@
6666
6767 /**
6868 * Register parser hook
 69+ *
 70+ * @param $parser Parser
6971 */
7072 function efSyntaxHighlight_GeSHiSetup( &$parser ) {
7173 $parser->setHook( 'source', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
Index: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf.php
@@ -0,0 +1,22 @@
 2+<?php
 3+
 4+$wgExtensionCredits['other'][] = array(
 5+ 'path' => __FILE__,
 6+ 'name' => 'CreativeCoreRdf',
 7+ 'url' => '',
 8+ 'author' => 'Evan Prodromou',
 9+);
 10+
 11+$wgHooks['MediaWikiPerformAction'][] = 'efCreativeCoreRdfPreformAction';
 12+
 13+$wgAutoloadClasses['CreativeCoreRdf'] = $dir . 'CreativeCoreRdf_body.php';
 14+
 15+function efCreativeCoreRdfPreformAction( $output, $article, $title, $user, $request, $mediaWiki ) {
 16+ if ( $mediaWiki->getAction() !== 'creativecommons' ) {
 17+ return true;
 18+ }
 19+
 20+ $rdf = new CreativeCommonsRdf( $article );
 21+ $rdf->show();
 22+ return false;
 23+}
\ No newline at end of file
Property changes on: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf.php
___________________________________________________________________
Added: svn:eol-style
124 + native
Index: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf_body.php
@@ -0,0 +1,283 @@
 2+<?php
 3+/**
 4+ * Provides CreativeCommons metadata
 5+ *
 6+ * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @author Evan Prodromou <evan@wikitravel.org>
 23+ * @file
 24+ */
 25+
 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+
 202+class CreativeCommonsRdf extends RdfMetaData {
 203+
 204+ public function show(){
 205+ if( $this->setup() ){
 206+ global $wgRightsUrl;
 207+
 208+ $url = $this->reallyFullUrl();
 209+
 210+ $this->prologue();
 211+ $this->subPrologue('Work', $url);
 212+
 213+ $this->basics();
 214+ if( $wgRightsUrl ){
 215+ $url = htmlspecialchars( $wgRightsUrl );
 216+ print "\t\t<cc:license rdf:resource=\"$url\" />\n";
 217+ }
 218+
 219+ $this->subEpilogue('Work');
 220+
 221+ if( $wgRightsUrl ){
 222+ $terms = $this->getTerms( $wgRightsUrl );
 223+ if( $terms ){
 224+ $this->subPrologue( 'License', $wgRightsUrl );
 225+ $this->license( $terms );
 226+ $this->subEpilogue( 'License' );
 227+ }
 228+ }
 229+ }
 230+
 231+ $this->epilogue();
 232+ }
 233+
 234+ protected function prologue() {
 235+ echo <<<PROLOGUE
 236+<?xml version='1.0' encoding="UTF-8" ?>
 237+<rdf:RDF xmlns:cc="http://web.resource.org/cc/"
 238+ xmlns:dc="http://purl.org/dc/elements/1.1/"
 239+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 240+
 241+PROLOGUE;
 242+ }
 243+
 244+ protected function subPrologue( $type, $url ){
 245+ $url = htmlspecialchars( $url );
 246+ echo "\t<cc:{$type} rdf:about=\"{$url}\">\n";
 247+ }
 248+
 249+ protected function subEpilogue($type) {
 250+ echo "\t</cc:{$type}>\n";
 251+ }
 252+
 253+ protected function license($terms) {
 254+
 255+ foreach( $terms as $term ){
 256+ switch( $term ) {
 257+ case 're':
 258+ $this->term('permits', 'Reproduction'); break;
 259+ case 'di':
 260+ $this->term('permits', 'Distribution'); break;
 261+ case 'de':
 262+ $this->term('permits', 'DerivativeWorks'); break;
 263+ case 'nc':
 264+ $this->term('prohibits', 'CommercialUse'); break;
 265+ case 'no':
 266+ $this->term('requires', 'Notice'); break;
 267+ case 'by':
 268+ $this->term('requires', 'Attribution'); break;
 269+ case 'sa':
 270+ $this->term('requires', 'ShareAlike'); break;
 271+ case 'sc':
 272+ $this->term('requires', 'SourceCode'); break;
 273+ }
 274+ }
 275+ }
 276+
 277+ protected function term( $term, $name ){
 278+ print "\t\t<cc:{$term} rdf:resource=\"http://web.resource.org/cc/{$name}\" />\n";
 279+ }
 280+
 281+ protected function epilogue() {
 282+ echo "</rdf:RDF>\n";
 283+ }
 284+}
Property changes on: trunk/extensions/CreativeCommonsRdf/CreativeCommonsRdf_body.php
___________________________________________________________________
Added: svn:keywords
1285 + Author Date Id Revision
Added: svn:eol-style
2286 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r88875Kill code from CreativeCommonsRdf_body.php that should've been removed in r88873...reedy00:44, 26 May 2011
r88876* (bug 29144) Move action=dublincore and action=creativecommons to extensions...reedy00:57, 26 May 2011
r89871Followup r88873, remove setting of $wgEnableCreativeCommonsRdf in LocalSettin...reedy07:33, 11 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88868* (bug 29144) Move action=dublincore and action=creativecommons to extensions...reedy23:55, 25 May 2011

Comments

#Comment by P858snake (talk | contribs)   00:38, 26 May 2011

Release Notes?

Also you can point the url para's to http://www.mediawiki.org/wiki/Extension:CreativeCoreRdf and http://www.mediawiki.org/wiki/Extension:DublinCoreRdf as appropriate.

#Comment by Reedy (talk | contribs)   00:39, 26 May 2011

Awesome, thanks for creating the pages!

I was going to do RELEASE-NOTES when I confirmed that the removal from core was done

#Comment by Bawolff (talk | contribs)   22:19, 10 June 2011

There's still references to this feature in the installer.

Status & tagging log