Oh yeah, and you gotta include this too:
function str_replace_first($from, $to, $subject) {
$from = '/'.preg_quote($from, '/').'/';
return preg_replace($from, $to, $subject, 1);
}
On Wed, Jun 14, 2017 at 10:17 PM, Jean Valjean <[email protected]>
wrote:
> Since no one seems to have a copy, I just went ahead and re-implemented
> it. You put this code in your LocalSettings.php, and then any time you want
> to roll dice, you make an edit that includes @@ROLL@@ in the wikitext.
> The DiceRoller system user will then immediately make an edit replacing
> @@ROLL@@ with a number between 1 and 6, and link to the diff for easy
> auditing.
>
> function onDiceRoll( $article, $user, $content, $summary, $isMinor,
> $isWatch,
> $section, $flags, $revision, $status, $baseRevId ) {
> global $alreadyCheckedForDice;
> global $wgDiceRoller;
> if ( $alreadyCheckedForDice ) {
> return true;
> }
> $alreadyCheckedForDice = true;
> $text = ContentHandler::getContentText( $content );
> $diceCommand = '@@ROLL@@';
> $summary = 'Roll(s):';
> while ( true ) {
> if ( strpos( $text, $diceCommand ) === false ) {
> break;
> }
> $dieRoll = rand( 1, 6 );
> $revId = $revision->getId();
> $dieRollText = "[[Special:Diff/$revId/next|$dieRoll]]";
> $summary .= " $dieRoll";
> $text = str_replace_first( $diceCommand, $dieRollText,
> $text );
> }
> echo $text;
> $content = ContentHandler::makeContent( $text,
> $article->getTitle() );
> $user = User::newSystemUser( $wgDiceRoller ) ;
> if ( $user === false ) {
> return true;
> }
> $article->doEditContent( $content, $summary, 0, false, $user );
> return true;
> }
>
> $wgHooks['PageContentSaveComplete'][] = 'onDiceRoll';
> $alreadyCheckedForDice = false;
> $wgDiceRoller = 'DiceRoller';
>
> On Wed, Jun 14, 2017 at 8:42 PM, Jean Valjean <[email protected]>
> wrote:
>
>> Does anyone have a copy of the Dice extension? The download link is dead
>> at https://www.mediawiki.org/wiki/Extension:Dice
>>
>> It looks like they were going to mirror it, but I'm not sure that ever
>> happened: https://github.com/wikimedia/mediawiki-extensions-Dice
>>
>> Thanks.
>>
>
>
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l