Skip to content

Commit

Permalink
Add Less CSS preprocessing engine
Browse files Browse the repository at this point in the history
Some refactoring in CopyPatrol.php
  • Loading branch information
MusikAnimal committed Jun 16, 2016
1 parent 9e13427 commit d6ac221
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.DS_Store
public_html/.DS_Store
vendor/*
.idea/*
replica.my.cnf
.env
.lighttpd.conf

src/Less/cache/*
!.gitkeep
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"require": {
"oyejorge/less.php": "~1.5",
"mediawiki/oauthclient": "~0.1",
"wikimedia/slimapp": "dev-master"
},
Expand Down
76 changes: 69 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public_html/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block stylesheets %}
<link href="//tools-static.wmflabs.org/cdnjs/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"
rel="stylesheet"/>
<link href="{{ siteUrl('css/index.css') }}" type="text/css" rel="stylesheet"/>
<link href="index.css" type="text/css" rel="stylesheet"/>
{% endblock %}
{% block scripts %}
<script src="//tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/1.12.0/jquery.min.js"
Expand Down
11 changes: 11 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Wikimedia\Slimapp\Config;
use Wikimedia\Slimapp\HeaderMiddleware;
use Wikimedia\Slimapp\Auth\AuthManager;
use Less_Cache;

class App extends AbstractApp {

Expand Down Expand Up @@ -198,6 +199,16 @@ function () use ( $slim ) {
$page( 'callback' );
} )->name( 'oauth_callback' );
} );
$slim->get( '/index.css',
function () use ( $slim ) {
// Compile LESS if need be, otherwise serve cached asset
// Cached files get automatically deleted if they are over a week old
$lessFiles = array( APP_ROOT . '/src/Less/index.less' => '/copypatrol/' );
$options = array( 'cache_dir' => APP_ROOT . '/src/Less/cache' );
$cssFileName = Less_Cache::Get( $lessFiles, $options );
$slim->response->headers->set( 'Content-Type', 'text/css' );
$slim->response->setBody( file_get_contents( APP_ROOT . '/src/Less/cache/' . $cssFileName ) );
} );
}


Expand Down
89 changes: 51 additions & 38 deletions src/Controllers/CopyPatrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,7 @@ public function setWikiprojectDao( $wikiprojectDao ) {
* editor_talk_dead: Bool. Is editor talk page non-existent?
*/
protected function handleGet() {
$userData = $this->authManager->getUserData();
$currentUser = $userData ? $userData->getName() : NULL;
$filter = 'open'; // this will be the default
$filterUser = NULL;

// set filter types and descriptions that will be rendered as checkboxes in the view
$filterTypes = array(
'all' => 'All cases',
'open' => 'Open cases',
'fixed' => 'All "page fixed" cases',
'noaction' => 'All "no action needed" cases'
);
// add 'My reviews' to filter options if user is logged in
if ( isset( $currentUser ) ) {
$filterTypes['mine'] = 'My reviews';
}

// use given filter if set, or the default 'open' if filter is 'mine' and user is logged out
if ( isset( $_GET['filter'] ) ) {
if ( $_GET['filter'] === 'mine' ) {
if ( isset( $currentUser ) ) {
$filter = 'mine';
$filterUser = $currentUser;
} else {
$this->flashNow( 'warning', 'You must be logged in to view your own reviews.' );
}
} else {
$filterTypeKeys = array_keys( $filterTypes );
if ( in_array( $_GET['filter'], $filterTypeKeys ) ) {
$filter = $_GET['filter'];
} else {
$this->flashNow( 'error', 'Invalid filter. Values must be one of: ' . join( $filterTypeKeys, ', ' ) );
}
}
}

$records = $this->dao->getPlagiarismRecords( 50, $filter, $filterUser );
$records = $this->getRecords();

foreach ( $records as $key => $record ) {
$editor = $this->enwikiDao->getUserDetails( $record['diff'] );
Expand Down Expand Up @@ -160,9 +124,58 @@ protected function handleGet() {
}

$this->view->set( 'records', $records );
$this->render( 'index.html' );
}


/**
* Get plagiarism records based on URL parameters and whether or not the user is logged in
* This function also sets view variables for the filters, which get rendered as radio options
* @return array collection of plagiarism records
*/
protected function getRecords() {
$userData = $this->authManager->getUserData();
$currentUser = $userData ? $userData->getName() : NULL;
$filter = 'open'; // this will be the default
$filterUser = NULL;

// set filter types and descriptions that will be rendered as checkboxes in the view
$filterTypes = array(
'all' => 'All cases',
'open' => 'Open cases',
'fixed' => 'All "page fixed" cases',
'noaction' => 'All "no action needed" cases'
);
// add 'My reviews' to filter options if user is logged in
if ( isset( $currentUser ) ) {
$filterTypes['mine'] = 'My reviews';
}

// use given filter if set, or the default 'open' if filter is 'mine' and user is logged out
if ( isset( $_GET['filter'] ) ) {
if ( $_GET['filter'] === 'mine' ) {
if ( isset( $currentUser ) ) {
$filter = 'mine';
$filterUser = $currentUser;
} else {
$this->flashNow( 'warning', 'You must be logged in to view your own reviews.' );
}
} else {
$filterTypeKeys = array_keys( $filterTypes );
if ( in_array( $_GET['filter'], $filterTypeKeys ) ) {
$filter = $_GET['filter'];
} else {
$this->flashNow( 'error', 'Invalid filter. Values must be one of: ' . join( $filterTypeKeys, ', ' ) );
}
}
}

$this->view->set( 'filter', $filter );
$this->view->set( 'filterTypes', $filterTypes );
$this->render( 'index.html' );

// make this easier when working locally
$numRecords = $_SERVER['HTTP_HOST'] === 'localhost' ? 5 : 50;
return $this->dao->getPlagiarismRecords( $numRecords, $filter, $filterUser );
}


Expand Down
Empty file added src/Less/cache/.gitkeep
Empty file.
5 changes: 4 additions & 1 deletion public_html/css/index.css → src/Less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@

.compare-links-container {
padding: 10px;
border-bottom: 1px dashed darkgrey;
}

.compare-pane {
Expand Down Expand Up @@ -140,6 +139,10 @@
/*padding-left: 20px;*/
}

.record {
border-bottom: 1px dashed darkgrey;
}

#body {
padding: 12px;
}
Expand Down

0 comments on commit d6ac221

Please sign in to comment.