-
-
Save PukupukuDragon/1da7ea60f4f25dc44580a9aaa9bdb6a2 to your computer and use it in GitHub Desktop.
WikiActivity Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Various helper functions for the main script. */ | |
class ActivityHelper { | |
/* Return a given message as plain text. */ | |
public static function getMessage ( $name, ...$params) { | |
return wfMessage( $name, $params)->plain(); | |
} | |
/* Get an HTML link to user's page from username. */ | |
public static function userLink ( $user ) { | |
return "<a href=\"/User:$user\">$user</a>"; | |
} | |
/* Get age of a timestamp in plain text. */ | |
public static function elapsedTime( $user, $timestamp ) { | |
$now = new DateTime(); | |
$old = DateTime::createFromFormat( 'U', wfTimestamp( TS_UNIX, $timestamp )); | |
$interval = $now->diff($old); | |
$msg = "wa-editedby-"; | |
$span = NULL; | |
$value = 0; | |
if ( $value = $interval->y ) { $msg .= 'year'; } | |
else if ( $value = $interval->m ) { $msg .= 'month'; } | |
else if ( $value = $interval->d ) { $msg .= 'day'; } | |
else if ( $value = $interval->h ) { $msg .= 'hour'; } | |
else if ( $value = $interval->i ) { $msg .= 'minute'; } | |
else if ( $value = $interval->s ) { $msg .= 'second'; } | |
$userlink = ActivityHelper::userLink( $user ); | |
if ( $value > 1 ) { | |
$msg .= 's'; | |
return ActivityHelper::getMessage($msg, $userlink, $value); | |
} else { | |
return ActivityHelper::getMessage($msg, $userlink); | |
} | |
} | |
/* Return the HTML for an OOUI icon. */ | |
public static function getIcon ( $name, $page, $blue ) { | |
$icon = new OOUI\IconWidget( [ | |
'icon' => $name, | |
'title' => $page ? $page : ucfirst($name), | |
'flags' => $blue ? 'progressive' : '' | |
] ); | |
if ($page) { | |
return "<a href=\"/$page\">$icon</a>"; | |
} else { | |
return $icon; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "WikiActivity", | |
"version": "0.0.0", | |
"author": "PukupukuDragon", | |
"descriptionmsg": "wikiactivity-desc", | |
"license-name": "GPL-2.0-or-later", | |
"type": "other", | |
"manifest_version": 1, | |
"AutoloadClasses": { | |
"WikiActivity": "WikiActivity.php", | |
"ActivityHelper": "ActivityHelper.php" | |
}, | |
"SpecialPages": { | |
"WikiActivity": "WikiActivity" | |
}, | |
"MessagesDirs": { | |
"WikiActivity": [ | |
"i18n" | |
] | |
}, | |
"ExtensionMessagesFiles": { | |
"WikiActivityAlias": "i18n/WikiActivity.i18n.alias.php" | |
}, | |
"ResourceModules": { | |
"ext.WikiActivity": { | |
"styles": "WikiActivity.css", | |
"dependencies": "oojs-ui" | |
} | |
}, | |
"ResourceFileModulePaths": { | |
"localBasePath": "", | |
"remoteExtPath": "WikiActivity" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cite { | |
color: #54595d; | |
font-size: 12px; | |
font-style: normal; | |
} | |
li { | |
border-top: 1px solid #a2a9b1; | |
padding-bottom: 7px; | |
padding-top: 10px; | |
} | |
span { | |
margin-left: -28px; | |
margin-right: 8px; | |
} | |
ul { | |
list-style: none; | |
} | |
.wa-title { | |
font-weight: bold; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WikiActivity extends SpecialPage { | |
function __construct() { | |
global $wgShowExceptionDetails, $wgShowDBErrorBacktrace, $wgShowSQLErrors; | |
$wgShowExceptionDetails = true; | |
$wgShowDBErrorBacktrace = true; | |
$wgShowSQLErrors = true; | |
parent::__construct( 'WikiActivity' ); | |
} | |
/* Main entrance point of extension. */ | |
function execute( $par ) { | |
$out = $this->getOutput(); | |
$out->enableOOUI(); | |
$out->addModuleStyles ( [ | |
'ext.WikiActivity', | |
'oojs-ui.styles.icons-moderation', | |
'oojs-ui.styles.icons-editing-core', | |
'oojs-ui.styles.icons-content' ] ); | |
$this->setHeaders(); | |
# Get request data from GET message | |
# $request = $this->getRequest(); | |
# $param = $request->getText( 'param' ); | |
# SELECT rc_user, rc_user_text, rc_title, rc_namespace, rc_timestamp FROM `recentchanges` ORDER BY `rc_timestamp` DESC LIMIT 50 | |
$dbr = wfGetDB( DB_REPLICA ); | |
$res = $dbr->select( | |
'recentchanges', | |
array( 'rc_user', | |
'rc_user_text', | |
'rc_title', | |
'rc_namespace', | |
'rc_timestamp', | |
'rc_this_oldid', | |
'rc_last_oldid' ), | |
'', | |
__METHOD__, | |
array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => '100' ) | |
); | |
$this->listStart( $out ); | |
foreach ( $res as $row) { | |
$this->listItem( $out, $row ); | |
} | |
$this->listEnd( $out ); | |
} | |
/* Add header to wiki activity list. */ | |
function listStart( $out ) { | |
$out->addWikitext( 'This is a work-in-progress extension being developed by [[User:PukupukuDragon|PukupukuDragon]] that will replicate Special:WikiActivity from the old site.<br>' ); | |
$out->addHTML('<ul>'); | |
} | |
/* Add footer to wiki activity list. */ | |
function listEnd( $out ) { | |
$out->addHTML('</ul>'); | |
} | |
/* Add header to wiki activity list. */ | |
function listItem( $out, $row ) { | |
$item = '<li>%s</li>'; | |
# Add page title to item | |
$html = '<a class="wa-title" href="/%s">%s%s</a><br>%%s'; | |
$namespace = MWNamespace::getCanonicalName( $row->rc_namespace ); | |
$title = $namespace ? $namespace . ':' . $row->rc_title : $row->rc_title; | |
$icon = ActivityHelper::getIcon( 'edit' ); | |
$html = sprintf( $html, $title, $icon, $title ); | |
$item = sprintf( $item, $html ); | |
# Add editor to item | |
$html = '<cite>%s %%s</cite>'; | |
$time = ActivityHelper::elapsedTime( $row->rc_user_text, $row->rc_timestamp ); | |
$html = sprintf( $html, $time ); | |
$item = sprintf( $item, $html ); | |
# Add revision icon to item | |
$html = '<a href="/%s?diff=%d&oldid=%d">%s</a>'; | |
$icon = ActivityHelper::getIcon( 'articleSearch', '', true ); | |
$html = sprintf( $html, $title, $row->rc_this_oldid, $row->rc_last_oldid, $icon ); | |
$item = sprintf( $item, $html); | |
$out->addHTML($item); | |
} | |
/* Get name of extension as it appears in Special:Version */ | |
function getGroupName( $out ) { | |
return 'changes'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment