Extension talk:PerPageLicense

Jump to navigation Jump to search

About this board

Thomas Haselwanter (talkcontribs)

We use the extension with MW 1.27 and found out that the SQL query no longer works.

Add a patch that should work alll MW versions > 1.21:

--- extensions/PerPageLicense/PerPageLicense.php.orig 2016-09-22 12:21:22.686653279 +0200

+++ extensions/PerPageLicense/PerPageLicense.php 2016-09-22 12:23:00.478308387 +0200

@@ -25,6 +25,8 @@

* @file

* @ingroup Extensions

*/

+use MediaWiki\Logger\LoggerFactory;

+

if( !defined( 'MEDIAWIKI' ) ) {

echo( "This file is an extension to the MediaWiki software and cannot be used "

@@ -102,6 +104,9 @@

global $wgRightsIcon, $wgRightsUrl, $wgRightsText, $wgFooterIcons,

$wgPerPageLicenseLicenses, $wgPerPageLicenseTemplatePage,

$wgPerPageLicenseNamespaces, $wgVersion;

+

+                $logger = LoggerFactory::getInstance( 'per-page-license' );

+

// Sometimes this hook runs twice

static $hasRun = false;

if ( $hasRun ) {

@@ -128,7 +133,8 @@

if ( version_compare( $wgVersion, '1.21', '<' ) ) {

$contents = $licenseWikiPage->getText( Revision::RAW );

} else {

-                        $contents = $licenseWikiPage->getContent( Revision::RAW );

+                        $textObject = $licenseWikiPage->getContent( Revision::RAW );

+                        $contents = $textObject->getNativeData( );

}

if ( !$contents ) {

return true;

@@ -136,16 +142,16 @@

$lines = explode ( "\n", $contents );

$templates = array();

foreach ( $lines as $line ) {

-                        if ( substr ( $line, 0, 1 ) == '|' && trim ( $line ) != '|'

+                 if ( substr ( $line, 0, 1 ) == '|' && trim ( $line ) != '|'

&& trim ( $line ) != '|-' && trim ( $line ) != '|}' ) {

// Get rid of that |

$line = substr ( $line, 1, strlen( $line ) - 1);

$lineArr = explode ( '||', $line );

if ( isset ( $lineArr[1] ) && trim ( $lineArr[0] ) ) {

-                                        // Is it one of the acceptable licenses?

-                                        if ( isset ( $wgPerPageLicenseLicenses[trim (

+                                    // Is it one of the acceptable licenses?

+                                    if ( isset ( $wgPerPageLicenseLicenses[trim (

$lineArr[1] )] ) ) {

-                                                $templates[ucfirst ( str_replace

+                                                 $templates[ucfirst ( str_replace

( ' ', '_', trim ( $lineArr[0] ) ) ) ] =

trim ( $lineArr[1] );

}

@@ -155,26 +161,26 @@

if ( !$templates ) {

return true;

}

-                $id = $parser->getTitle()->getArticleID();

-                $sql = "tl_from=$id AND (";

-                $first = true;

-                foreach ( $templates as $key => $template ) {

-                        if ( !$first ) {

-                                $sql .= ' OR ';

-                        }

-                        $first = false;

-                        $sql .= "(tl_namespace=10 AND tl_title='$key')";

-                }

-                $sql .= ')';

-                $dbr = wfGetDB( DB_SLAVE );

-                $res = $dbr->selectRow( 'templatelinks', 'tl_title', array( $sql ) );

-                if ( $res ) {

-                        $license = $templates[$res->tl_title];

-                        $wgRightsText = $wgPerPageLicenseLicenses[$license]['alt'];

-                        $wgRightsIcon = $wgPerPageLicenseLicenses[$license]['src'];

-                        $wgRightsUrl = $wgPerPageLicenseLicenses[$license]['url'];

-                        $wgFooterIcons['copyright']['copyright'] =

-                                $wgPerPageLicenseLicenses[$license];

+                // get the templates for the page

+                $templateTitles = $parser->getTitle()->getTemplateLinksFrom();

+                if(count($templateTitles) > 0) {

+                 // get through the templates and check whether one is a license

+                 foreach ( $templateTitles as $license ) {

+                 $license = substr($license, strpos($license, ":"));                

+                 $license = substr($license, 1);

+                 $license =  str_replace( ' ', '_', trim ( $license ) );

+                 $logger->info("License Template to check: " . $license );

+                 // check whether one this template is a license template

+                 if ( isset ( $templates[$license] ) ) {

+             $license = $templates[$license];

+             $logger->info("License Template: " . $license );

+                $wgRightsText = $wgPerPageLicenseLicenses[$license]['alt'];

+            $wgRightsIcon = $wgPerPageLicenseLicenses[$license]['src'];

+            $wgRightsUrl = $wgPerPageLicenseLicenses[$license]['url'];

+            $wgFooterIcons['copyright']['copyright'] =

+            $wgPerPageLicenseLicenses[$license];

+         }

+                 }

}

return true;

}

Regards

Thomas

Reply to "usage with MW 1.27"
Leucosticte (talkcontribs)

There's a known getContent issue with MW 1.21. Thus far, I haven't figured out how to fix it, but I didn't try very hard either.

Thomas Haselwanter (talkcontribs)

Add

$contents = ContentHandler::getContentText( $contents );

after line 131 - directly after the call to getContent.

This makes the per page license work again.

Reply to "getContent issue with MW 1.21"
There are no older topics