+ /**
+ * Generate a rollback link for a given revision. Currently it's the
+ * caller's responsibility to ensure that the revision is the top one. If
+ * it's not, of course, the user will get an error message.
+ *
+ * If the calling page is called with the parameter &bot=1, all rollback
+ * links also get that parameter. It causes the edit itself and the rollback
+ * to be marked as "bot" edits. Bot edits are hidden by default from recent
+ * changes, so this allows sysops to combat a busy vandal without bothering
+ * other users.
+ *
+ * @param Revision $rev
+ */
+ function generateRollback( $rev ) {
+ global $wgUser, $wgRequest;
+ $title = $rev->getTitle();
+
+ $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
+ $extraRollback .= '&token=' . urlencode(
+ $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ) );
+ return '<span class="mw-rollback-link">['. $this->makeKnownLinkObj( $title,
+ wfMsg('rollbacklink'),
+ 'action=rollback&from=' . urlencode( $rev->getUserText() ) . $extraRollback ) .']</span>';
+ }
+
+ /**
+ * Returns HTML for the "templates used on this page" list.
+ *
+ * @param array $templates Array of templates from Article::getUsedTemplate
+ * or similar
+ * @param bool $preview Whether this is for a preview
+ * @param bool $section Whether this is for a section edit
+ * @return string HTML output
+ */
+ public function formatTemplates( $templates, $preview = false, $section = false) {
+ global $wgUser;
+ wfProfileIn( __METHOD__ );
+
+ $sk =& $wgUser->getSkin();
+
+ $outText = '';
+ if ( count( $templates ) > 0 ) {
+ # Do a batch existence check
+ $batch = new LinkBatch;
+ foreach( $templates as $title ) {
+ $batch->addObj( $title );
+ }
+ $batch->execute();
+
+ # Construct the HTML
+ $outText = '<div class="mw-templatesUsedExplanation">';
+ if ( $preview ) {
+ $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
+ } elseif ( $section ) {
+ $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
+ } else {
+ $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
+ }
+ $outText .= '</div><ul>';
+
+ foreach ( $templates as $titleObj ) {
+ $r = $titleObj->getRestrictions( 'edit' );
+ if ( in_array( 'sysop', $r ) ) {
+ $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
+ } elseif ( in_array( 'autoconfirmed', $r ) ) {
+ $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
+ } else {
+ $protected = '';
+ }
+ $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . ' ' . $protected . '</li>';
+ }
+ $outText .= '</ul>';
+ }
+ wfProfileOut( __METHOD__ );
+ return $outText;
+ }
+
+ /**
+ * Format a size in bytes for output, using an appropriate
+ * unit (B, KB, MB or GB) according to the magnitude in question
+ *
+ * @param $size Size to format
+ * @return string
+ */
+ public function formatSize( $size ) {
+ global $wgLang;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ $msg = 'size-gigabytes';
+ } else {
+ $msg = 'size-megabytes';
+ }
+ } else {
+ $msg = 'size-kilobytes';
+ }
+ } else {
+ $msg = 'size-bytes';
+ }
+ $size = round( $size, 0 );
+ return wfMsgHtml( $msg, $wgLang->formatNum( $size ) );
+ }
+