Jump to content

Topic on Project:Support desk/Flow

problems after updateing wiht $wgHooks

15
Kyebert (talkcontribs)

I have an older script "Werbung.php" which was intecrated per

require_once( "$IP/extensions/Werbung/Werbung.php" );

$wgHooks['ParserBeforeStrip'][]='Werbung';

in the LocalSettings.php and now don't work under version 1.42.

Unfortunately I can't find any hint in error.log of PHP for the problem. What's the best way to fix this update-problem?

Thanks in advance.

TheDJ (talkcontribs)

It is probably no longer compatible. You would have to ask the author of Werbung.php to release a newer version, or update the code yourse to be conpatible with newer versions of Mediawiki.

Kyebert (talkcontribs)

Thank your for this information. The author is not available. Perhaps someone has a hint as to what should be adapted here (ins the (in the manageable code):

function getPOIs($cmd) { require_once("/usr/www/users/data.php"); 

$mysqli = new mysqli($DBHost, $DBUser, $DBPass, $DBName);

#Aufbau des Kommandos:<!-- Karte;latitude;longitude;zoom;NumberOfPOIs -->

$c = preg_split('/;/', $cmd[0]);
$latitude = $c[1];
$longitude = $c[2];
$zoom = $c[3];
$c4 = intval($c[4]); #30.5.15 Anzahl der POIs begrenzen
$maxNumberOfPOIs = $c4;
if ($c4 == 0)    $maxNumberOfPOIs =   50; # POI Anzahl
if ($c4 > 1500)  $maxNumberOfPOIs = 1500; 
$map = "{{#display_map:
";
$query = "select src from vaPOIs2 order by sqrt( power(lat-$latitude,2) + power(lon-$longitude,2) ) limit $maxNumberOfPOIs";
$result = $mysqli->query($query);
while($row = $result->fetch_row()) {
	$map .= $row[0] . "\n";
}
$map = trim ($map);
$map = trim ($map, ';');
$map .= "|service=openlayers|center=$latitude, $longitude|width=100%|zoom=$zoom}}";

return $map; } #funct getPOIs

function Werbung(&$parser, &$text) {	$text = preg_replace_callback ('/<!-- Karte.* -->/', "getPOIs", $text);	echo $text;	return(true); }
Osnard (talkcontribs)
Kyebert (talkcontribs)

Thanks for the tip. My idea with the board here was just to get an approach to solving the problem. I thought that some people would have to fix similar problems with an update...

Osnard (talkcontribs)
Kyebert (talkcontribs)

I had already tried a few things - unfortunately always without success:

1. with Manual:Hooks/de to replace $wgHooks['ParserBeforeStrip'][]='Werbung';

-> Werbung ( $parser, $text );

2. Manual:Hooks/ParserBeforeInternalParse extensions.json -> add:

   "HookHandlers": {

       "main": {

           "class": "MediaWiki\\Extension\\Werbung",

       }

   },

   "Hooks": {

       "ParserBeforeStrip": "Werbung",

       "services": [ "UserNameUtils" ]

   }

alternativ:

"Hooks": {

       "ParserBeforeStrip": "MediaWiki\\Extension\\Werbung\\Hooks::onParserBeforeStrip"

   },

(at least there was no error message with this version)

But I probably just don't have the right approach ?

Bawolff (talkcontribs)

The error probably went away because your changes made it fail before the error was encountered.

You should probably post any error message you got.

Kyebert (talkcontribs)

I have found the error messages of the function


function Werbung(&$parser, &$text) {

   $text = preg_replace_callback ('//', "getPOIs", $text);

   #echo $text;

   #echo "<br><brblblb lblbllbd lbalbab.<br><br>";

   return(true);

}

which I set in the LocalSettings.php

Werbung ( $parser, $text );

(instead of the old Hook #$wgHooks['ParserBeforeStrip'][]='Werbung';)


Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /usr/www/users/abc/archiv24/extensions/Werbung/Werbung.php on line 49

Notice: Headers already sent, should send headers earlier than require [Called from MediaWiki\Request\HeaderCallback::warnIfHeadersSent in /usr/www/users/veikkoc/archiv24/includes/Request/HeaderCallback.php at line 94] in /usr/www/users/abc/archiv24/includes/debug/MWDebug.php on line 492

Warning: session_name(): Session name cannot be changed after headers have already been sent in /usr/www/users/abc/archiv24/includes/Setup.php on line 472

Osnard (talkcontribs)

You can not call something like Werbung ( $parser, $text ); within LocalSettings.php. There is neither a $parser nor a $text in this context. You need to register the method as a hook handler.

The messages are (more or less) unrelated. I guess you have an empty line somewhere before a <?php or after a ?>.

Kyebert (talkcontribs)

I used the info in Manual:Hooks and changed, like

Function, no data $wgHooks['EventName'][] = 'efSomeFunction'; efSomeFunction( $param1, $param2 );

#$wgHooks['ParserBeforeStrip'][]='Werbung'; -> Werbung ( $parser, $text );

(old version -> new version 1.42)

But what exactly is missing?

Bawolff (talkcontribs)
Kyebert (talkcontribs)

Hello, thanks for your answer. I thought, if I change the script according to the instruction from Manual:Hooks , an uncomplicated adaption is possible. But if not, who could help me with this little scirpt?

Osnard (talkcontribs)

I guess, in case you want help from the community, you should consider making the whole code publicly available (e.g. on github.com). Make sure to use a proper open source license. There are no guarantees you will find a volunteer though.

Otherwise, check out Professional development and consulting.

Kyebert (talkcontribs)

Thanks for the tip.

I posted the complete code and how to call it above. That's all it is.

The script doesn't actually do anything else, like (for example)

Map;52.436758;13.550262;14;300;


with a collection of POIs that the following software (Maps, possibly with SemanticMediawiki ?) needs to insert a map.

This is what the page should look like when it works: https://www.veikkos-archiv.com/index.php?title=Adlershof

Who could help me with this?

PS: or is it also possible to work here completely without this hook?

Reply to "problems after updateing wiht $wgHooks"