Siebrand has submitted this change and it was merged.

Change subject: Adding ViewFiles extension, v1.0.3.
......................................................................


Adding ViewFiles extension, v1.0.3.

Adds a [[Special:ViewFiles|special page]] to view the current
contents of a limited set of files.
For more info, see
https://www.mediawiki.org/wiki/Extension:ViewFiles

Change-Id: I9c1361644d5e9c13d340d39fef03744ad6b1bcb5
---
A SpecialViewFiles.php
A ViewFiles.alias.php
A ViewFiles.i18n.php
A ViewFiles.php
4 files changed, 176 insertions(+), 0 deletions(-)

Approvals:
  Siebrand: Verified; Looks good to me, approved



diff --git a/SpecialViewFiles.php b/SpecialViewFiles.php
new file mode 100644
index 0000000..9ef2481
--- /dev/null
+++ b/SpecialViewFiles.php
@@ -0,0 +1,67 @@
+<?php
+class SpecialViewFiles extends SpecialPage {
+       function __construct() {
+               parent::__construct( 'ViewFiles' );
+       }
+
+       function execute( $par ) {
+               global $wgViewFilesIntro, $wgViewFilesBegin, $wgViewFilesEnd,
+                       $wgViewFilesFileLangList, $wgViewFilesFilePathList,
+                       $wgViewFilesRobotPolicy;
+
+               $this->setHeaders();
+               $viewOutput = $this->getOutput();
+               $viewOutput->setRobotPolicy ( $wgViewFilesRobotPolicy );
+
+               // Bail if SyntaxHighlight isn't installed
+               if ( !class_exists ( 'SyntaxHighlight_GeSHi' )
+                       || !class_exists ( 'GeSHi' ) ) {
+                       $viewOutput->addWikiMsg ( 'viewfiles-no-geshi' );
+                       $viewOutput->addWikiText ( "\n" . '<pre>' . "\n"
+                               . 
'require_once("$IP/extensions/SyntaxHighlight_GeSHi/'
+                                       . 'SyntaxHighlight_GeSHi.php");' . "\n"
+                               . 
'require_once("$IP/extensions/SyntaxHighlight_GeSHi/'
+                                       . 'geshi/geshi.php");' . "\n" . 
'</pre>' );
+                       return;
+               }
+
+               // Bail if no files have been made available
+               if ( !$wgViewFilesFilePathList ) {
+                       $viewOutput->addWikiMsg ( 
'viewfiles-no-files-available' );
+                       return;
+               }
+
+               // Display introductory material
+               $output = $wgViewFilesIntro;
+               // Iterate through the list of files
+               foreach ( $wgViewFilesFilePathList as $filename => 
$pathFilename ) {
+                       // Display the filename
+                       $output .= "== $filename ==\n";
+                       // Set whatever file display format is appropriate 
given the filename
+                       if ( isset ( $wgViewFilesFileLangList[ $filename ] ) ) {
+                               $lang = $wgViewFilesFileLangList[ $filename ];
+                       } else {
+                               // If this particular filename has no selected 
format, then
+                               // go with what Geshi suggests, given the 
extension
+                               $geshi = new GeSHi;
+                               $lang = 
$geshi->get_language_name_from_extension(
+                                       pathinfo ( $filename, 
PATHINFO_EXTENSION ) );
+                       }
+                       $langOutput = str_replace ( '$1', $lang, 
$wgViewFilesBegin );
+                       // Read and display the file, if it exists
+                       if ( !file_exists ( $pathFilename ) ) {
+                               $output .= $this->msg( 'filenotfound',
+                                       $filename )->text() . "\n";
+                       } else {
+                               $output .= $langOutput;
+                               $handle = fopen( $pathFilename, "r" );
+                               $contents = file_get_contents ( $pathFilename );
+                               if ( $contents ) {
+                                       $output .= $contents;
+                               }
+                               $output .= $wgViewFilesEnd;
+                       }
+               }
+               $viewOutput->addWikiText( $output );
+       }
+}
diff --git a/ViewFiles.alias.php b/ViewFiles.alias.php
new file mode 100644
index 0000000..c8123a9
--- /dev/null
+++ b/ViewFiles.alias.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Aliases for ViewFiles
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$specialPageAliases = array();
+
+/** English
+ * @author Leucosticte
+ */
+$specialPageAliases['en'] = array(
+       'ViewFiles' => array( 'ViewFiles', 'View files' ),
+);
diff --git a/ViewFiles.i18n.php b/ViewFiles.i18n.php
new file mode 100644
index 0000000..15112b5
--- /dev/null
+++ b/ViewFiles.i18n.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Internationalisation for ViewFiles
+ *
+ * @file
+ * @ingroup Extensions
+ */
+$messages = array();
+
+/** English
+ * @author Leucosticte
+ */
+$messages['en'] = array(
+       'viewfiles' => 'View files',
+       'viewfiles-desc' => 'Adds a [[Special:ViewFiles|special page]] to view 
the current contents of a limited set of files',
+       'viewfiles-no-files-available' => 'No files have been made available 
for viewing.',
+       'viewfiles-no-geshi' => 'Error: You need to download and install the 
[https://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi GeSHi 
SyntaxHighlight extension].
+Be sure to add both these lines to your LocalSettings.php file:',
+);
+
+/** Message documentation
+ * @author Leucosticte
+ */
+$messages['qqq'] = array(
+       'viewfiles-desc' => '{{desc}}',
+       'viewfiles-no-files-available' => 'This is the message the user gets if 
no files have been made available by the system administrator for viewing.',
+       'viewfiles-no-geshi' => 'This is the message the user gets if the 
SyntaxHighlight GeSHi extension, upon which the ViewFiles extension depends, 
has not been installed properly.
+Following this message, the two require_once lines that the system 
administrator needs to add to LocalSettings.php are displayed.',
+);
diff --git a/ViewFiles.php b/ViewFiles.php
new file mode 100644
index 0000000..9bc2aa0
--- /dev/null
+++ b/ViewFiles.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * ViewFiles MediaWiki extension.
+ *
+ * This extension allows users to view the contents of a limited set of files.
+ *
+ * Written by Leucosticte
+ * http://www.mediawiki.org/wiki/User:Leucosticte
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+# Alert the user that this is not a valid entry point to MediaWiki if the user 
tries to access the
+# extension file directly.
+if (!defined('MEDIAWIKI')) {
+       die( 'This file is a MediaWiki extension. It is not a valid entry 
point' );
+}
+
+$wgExtensionCredits['specialpage'][] = array(
+       'path' => __FILE__,
+       'name' => 'ViewFiles',
+       'author' => '[https://www.mediawiki.org/wiki/User:Leucosticte 
Leucosticte]',
+       'url' => 'https://www.mediawiki.org/wiki/Extension:ViewFiles',
+       'descriptionmsg' => 'viewfiles-desc',
+       'version' => '1.0.3',
+);
+
+$wgAutoloadClasses['SpecialViewFiles'] = __DIR__ . '/SpecialViewFiles.php';
+$wgExtensionMessagesFiles['ViewFiles'] = __DIR__ . '/ViewFiles.i18n.php';
+$wgExtensionMessagesFiles['ViewFilesAlias'] = __DIR__ . '/ViewFiles.alias.php';
+$wgSpecialPages['ViewFiles'] = 'SpecialViewFiles';
+$wgSpecialPageGroups['ViewFiles'] = 'other';
+
+// Display this before any of the files
+$wgViewFilesIntro = '';
+// Display this before each file
+$wgViewFilesBegin = '<source lang="$1">' . "\n";
+// Display this after each file
+$wgViewFilesEnd = '</source>' . "\n";
+// This list of filenames and associated languages overrides GeSHi's extension 
lookup
+$wgViewFilesFileLangList = array (
+       '.htaccess' => 'apache',
+       'robots.txt' => 'robots',
+);
+// Change this to an array with 'filenames' as keys and 'paths/to/filenames' 
as values
+$wgViewFilesFilePathList = array();
+// Robot policy
+$wgViewFilesRobotPolicy = "index,follow";

-- 
To view, visit https://gerrit.wikimedia.org/r/28799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9c1361644d5e9c13d340d39fef03744ad6b1bcb5
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ViewFiles
Gerrit-Branch: master
Gerrit-Owner: leucosticte <nathanlarson3...@gmail.com>
Gerrit-Reviewer: Bpetty <br...@ibaku.net>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: leucosticte <nathanlarson3...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to