r94324 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94323‎ | r94324 | r94325 >
Date:05:59, 12 August 2011
Author:yuvipanda
Status:deferred
Tags:
Comment:
Add to selection is now ajaxy. Fixed gross misuse of POST vs GET
Modified paths:
  • /trunk/extensions/GPoC/SpecialFilterRatings.php (modified) (history)
  • /trunk/extensions/GPoC/SpecialSelection.php (modified) (history)
  • /trunk/extensions/GPoC/templates/FilterRatingsTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/SpecialFilterRatings.php
@@ -21,8 +21,6 @@
2222 $importance = $wgRequest->getVal('importance');
2323 $quality = $wgRequest->getVal('quality');
2424 $categories = $wgRequest->getVal('categories');
25 - $action = $wgRequest->getVal('action');
26 - $selection_name = $wgRequest->getVal('selection');
2725
2826 $filters = array(
2927 'r_project' => $project,
@@ -37,19 +35,33 @@
3836 }
3937 $entries = Rating::filterArticles($filters);
4038
 39+ if( $wgRequest->wasPosted() ) {
 40+ $wgOut->disable();
 41+
 42+ $action = $wgRequest->getVal('action');
 43+ $selection_name = $wgRequest->getVal('selection');
 44+
 45+ if( $action == 'addtoselection' ) {
 46+ $success = Selection::addEntries($selection_name, $entries);
 47+ $sel_page = new SpecialSelection();
 48+
 49+ $url = $sel_page->getTitle()->getLinkUrl( array( 'name' => $selection_name ) );
 50+ $return = array(
 51+ 'status' => $success,
 52+ 'selection_url' => $url
 53+ );
 54+ }
 55+ echo json_encode($return);
 56+ return;
 57+ }
 58+
4159 $this->setHeaders();
4260
4361 $wgOut->setPageTitle("Filter Articles by Ratings");
4462
45 - if( $action == 'addtoselection' ) {
46 - Selection::addEntries($selection_name, $entries);
47 - }
48 -
4963 $template = new FilterRatingsTemplate();
5064 $template->set( 'filters', $filters );
5165 $template->set( 'articles', $entries );
52 - $template->set( 'action', $action );
53 - $template->set( 'selection', $selection_name );
5466
5567 $wgOut->addTemplate( $template );
5668 }
Index: trunk/extensions/GPoC/SpecialSelection.php
@@ -32,10 +32,6 @@
3333 fclose( $outstream );
3434 }
3535
36 - public function onSubmit( $data ) {
37 - var_dump($data);
38 - }
39 -
4036 public function execute( $par ) {
4137 global $wgOut, $wgRequest;
4238
Index: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php
@@ -7,8 +7,6 @@
88 public function execute() {
99 $articles = $this->data['articles'];
1010 $filters = $this->data['filters'];
11 - $action = $this->data['action'];
12 - $selection = $this->data['selection'];
1311 ?>
1412
1513 <form method="GET" id="filterForm">
@@ -20,17 +18,13 @@
2119 Categories (comma separated): <input type="text" name="categories" value="<?php echo $filters['categories']?>" />
2220 <input type="submit" id="submit-query" />
2321 </p>
 22+</form>
2423 <div>
2524 Add to Selection:
2625 <input type="text" name="selection" id="selection" />
27 -<input type="hidden" name="action" id="action" />
2826 <input type="button" id="add-to-selection" value="Add" />
2927 </div>
30 -</form>
3128 <div id="notice">
32 -<?php if( $action == 'addtoselection' ) { ?>
33 -Articles successfully added to selection <?php echo $selection; ?>
34 -<?php } ?>
3529 </div>
3630 <div id="">
3731 <?php if( count($articles) > 0 ) { ?>
@@ -59,16 +53,16 @@
6054 <script type="text/javascript">
6155 // Should I use RL for tiny snippets like this too?
6256 $("#add-to-selection").click(function() {
63 - $("#action").val("addtoselection");
64 - $("#filterForm").submit();
 57+ var selection = $("#selection").val();
 58+ $.post("", {
 59+ action: "addtoselection",
 60+ selection: selection
 61+ }, function(raw_data) {
 62+ var data = $.parseJSON(raw_data);
 63+ $("#notice").html("Added to selection <a href='" + data.selection_url + "'>" + selection + "</a>");
 64+ });
6565 return false;
6666 });
67 - $("#submit-query").click(function() {
68 - $("#selection").val("");
69 - // Hitting submit shouldn't add to selection
70 - $("#filterForm").submit();
71 - return false;
72 - });
7367 </script>
7468
7569 <?php

Status & tagging log