+ /**
+ * 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;
+ // For small sizes no decimal places necessary
+ $round = 0;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ // For MB and bigger two decimal places are smarter
+ $round = 2;
+ if( $size > 1024 ) {
+ $size = $size / 1024;
+ $msg = 'size-gigabytes';
+ } else {
+ $msg = 'size-megabytes';
+ }
+ } else {
+ $msg = 'size-kilobytes';
+ }
+ } else {
+ $msg = 'size-bytes';
+ }
+ $size = round( $size, $round );
+ return wfMsgHtml( $msg, $wgLang->formatNum( $size ) );
+ }
+
+ /**
+ * Given the id of an interface element, constructs the appropriate title
+ * and accesskey attributes from the system messages. (Note, this is usu-
+ * ally the id but isn't always, because sometimes the accesskey needs to
+ * go on a different element than the id, for reverse-compatibility, etc.)
+ *
+ * @param string $name Id of the element, minus prefixes.
+ * @return string title and accesskey attributes, ready to drop in an
+ * element (e.g., ' title="This does something [x]" accesskey="x"').
+ */
+ public function tooltipAndAccesskey($name) {
+ $out = '';
+
+ $tooltip = wfMsg('tooltip-'.$name);
+ if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
+ // Compatibility: formerly some tooltips had [alt-.] hardcoded
+ $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
+ $out .= ' title="'.htmlspecialchars($tooltip);
+ }
+ $accesskey = wfMsg('accesskey-'.$name);
+ if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) {
+ if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\"";
+ else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\"";
+ } elseif ($out) {
+ $out .= '"';
+ }
+ return $out;
+ }
+
+ /**
+ * Given the id of an interface element, constructs the appropriate title
+ * attribute from the system messages. (Note, this is usually the id but
+ * isn't always, because sometimes the accesskey needs to go on a different
+ * element than the id, for reverse-compatibility, etc.)
+ *
+ * @param string $name Id of the element, minus prefixes.
+ * @return string title attribute, ready to drop in an element
+ * (e.g., ' title="This does something"').
+ */
+ public function tooltip($name) {
+ $out = '';
+
+ $tooltip = wfMsg('tooltip-'.$name);
+ if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
+ $out = ' title="'.htmlspecialchars($tooltip).'"';
+ }
+
+ return $out;
+ }