Index: trunk/extensions/GPoC/schema/selections.sql |
— | — | @@ -14,6 +14,9 @@ |
15 | 15 | s_timestamp binary(14) not null, |
16 | 16 | -- timestamp when entry was added |
17 | 17 | |
| 18 | + s_revision int unsigned, |
| 19 | + -- manually set revision |
| 20 | + |
18 | 21 | primary key (s_selection_name, s_namespace, s_article) |
19 | 22 | ) /*$wgDBTableOptions*/; |
20 | 23 | |
Index: trunk/extensions/GPoC/models/Selection.php |
— | — | @@ -22,6 +22,23 @@ |
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
| 26 | + public static function setRevision( $name, $namespace, $article, $revision ) { |
| 27 | + $dbw = wfGetDB( DB_MASTER ); |
| 28 | + $success = $dbw->update( |
| 29 | + 'selections', |
| 30 | + array( |
| 31 | + 's_revision' => $revision |
| 32 | + ), |
| 33 | + array( |
| 34 | + 's_selection_name' => $name, |
| 35 | + 's_namespace' => $namespace, |
| 36 | + 's_article' => $article |
| 37 | + ), |
| 38 | + __METHOD__ |
| 39 | + ); |
| 40 | + return $success; |
| 41 | + } |
| 42 | + |
26 | 43 | public static function getSelection( $name ) { |
27 | 44 | $dbr = wfGetDB( DB_SLAVE ); |
28 | 45 | |
Index: trunk/extensions/GPoC/SpecialSelection.php |
— | — | @@ -17,30 +17,52 @@ |
18 | 18 | $outstream = fopen( "php://output", "w" ); |
19 | 19 | $headers = array( |
20 | 20 | 'article', |
| 21 | + 'revision', |
21 | 22 | 'added' |
22 | 23 | ); |
23 | 24 | fputcsv( $outstream, $headers ); |
24 | 25 | foreach( $articles as $article ) { |
25 | 26 | $row = array( |
26 | 27 | $article['title']->getFullText(), |
| 28 | + $article['s_revision'], |
27 | 29 | wfTimeStamp( TS_ISO_8601, $article['s_timestamp'] ) |
28 | 30 | ); |
29 | 31 | fputcsv( $outstream, $row ); |
30 | 32 | } |
31 | 33 | fclose( $outstream ); |
32 | 34 | } |
| 35 | + |
| 36 | + public function onSubmit( $data ) { |
| 37 | + var_dump($data); |
| 38 | + } |
| 39 | + |
33 | 40 | public function execute( $par ) { |
34 | 41 | global $wgOut, $wgRequest; |
35 | 42 | |
36 | | - $name = $wgRequest->getVal('name'); |
37 | | - $action = $wgRequest->getVal('action'); |
| 43 | + $name = $wgRequest->getVal( 'name' ); |
| 44 | + $format = $wgRequest->getVal( 'format' ); |
38 | 45 | |
| 46 | + if( $wgRequest->wasPosted() ) { |
| 47 | + $wgOut->disable(); |
| 48 | + $namespace = $wgRequest->getVal( 'namespace' ); |
| 49 | + $article = $wgRequest->getVal( 'article' ); |
| 50 | + $revision = $wgRequest->getVal( 'revision' ); |
| 51 | + |
| 52 | + $success = Selection::setRevision( $name, $namespace, $article, $revision ); |
| 53 | + |
| 54 | + $return = array( |
| 55 | + 'status' => $success, |
| 56 | + 'revision' => $revision |
| 57 | + ); |
| 58 | + echo json_encode($return); |
| 59 | + return; |
| 60 | + } |
39 | 61 | $entries = Selection::getSelection( $name ); |
40 | 62 | $this->setHeaders(); |
41 | 63 | |
42 | 64 | $wgOut->setPageTitle("Selection"); |
43 | 65 | |
44 | | - if( $action == 'csv' ) { |
| 66 | + if( $format == 'csv' ) { |
45 | 67 | $wgRequest->response()->header( 'Content-type: text/csv' ); |
46 | 68 | // Is there a security issue in letting the name be arbitrary? |
47 | 69 | $wgRequest->response()->header( |
— | — | @@ -51,7 +73,7 @@ |
52 | 74 | } |
53 | 75 | |
54 | 76 | $csv_link = $this->getFullTitle()->getFullUrl( array( |
55 | | - 'action' => 'csv', |
| 77 | + 'format' => 'csv', |
56 | 78 | 'name' => $name |
57 | 79 | ) ); |
58 | 80 | $template = new SelectionTemplate(); |
Index: trunk/extensions/GPoC/templates/SelectionTemplate.php |
— | — | @@ -18,11 +18,26 @@ |
19 | 19 | <th>Article</th> |
20 | 20 | <th>Added on</th> |
21 | 21 | <th>Revision</th> |
| 22 | + <th>Actions</th> |
22 | 23 | </tr> |
23 | 24 | <?php foreach( $articles as $article ) { ?> |
24 | 25 | <tr> |
25 | 26 | <td><a href="<?php echo $article['title']->getLinkURL(); ?>"><?php echo $article['s_article']; ?></a></td> |
26 | 27 | <td><?php echo wfTimeStamp( TS_ISO_8601, $article['s_timestamp'] ); ?></td> |
| 28 | + <td><?php if($article['s_revision'] != null) { ?> |
| 29 | + <a href="<?php echo $article['title']->getLinkUrl(array('oldid' => $article['s_revision'])); ?>"><?php echo $article['s_revision']; ?></a> |
| 30 | + <?php } ?> |
| 31 | + </td> |
| 32 | + <td> |
| 33 | + <div class="item-actions" data-namespace="<?php echo $article['s_namespace']; ?>" data-article="<?php echo $article['s_article']; ?>"> |
| 34 | + <div class="revision-input" style="display:none"> |
| 35 | + <input type="text" class="revision-id" placeholder="Enter revision id" value="<?php echo $article['s_revision']; ?>" /> |
| 36 | + (<a href="#" class="revision-save">Save</a> | <a href="#" class="revision-cancel">Cancel</a>) |
| 37 | + </div> |
| 38 | + <a href="#" class="change-revision">Set Revision</a> | |
| 39 | + <a href="#" class="delete-article">Delete</a> |
| 40 | + </div> |
| 41 | + </td> |
27 | 42 | </tr> |
28 | 43 | <?php } ?> |
29 | 44 | </table> |
— | — | @@ -31,7 +46,40 @@ |
32 | 47 | <?php } ?> |
33 | 48 | </div> |
34 | 49 | |
| 50 | + <script type="text/javascript"> |
| 51 | + $(document).ready(function() { |
| 52 | + $(".change-revision").click(function() { |
| 53 | + var parent = $(this).parent("div.item-actions"); |
| 54 | + var input_box = parent.children(".revision-input"); |
| 55 | + input_box.fadeToggle(); |
| 56 | + return false; |
| 57 | + }); |
| 58 | + $(".revision-save").click(function() { |
| 59 | + var parent = $(this).parents("div.item-actions"); |
| 60 | + var ns = parent.attr("data-namespace"), |
| 61 | + article = parent.attr("data-article"); |
| 62 | + var input = $("input.revision-id", parent); |
| 63 | + var input_box = parent.children(".revision-input"); |
| 64 | + var revid = input.val(); |
35 | 65 | |
| 66 | + $.post('', { |
| 67 | + namespace: ns, |
| 68 | + article: article, |
| 69 | + revision: revid |
| 70 | + }, function() { |
| 71 | + input_box.fadeOut(); |
| 72 | + }); |
| 73 | + |
| 74 | + return false; |
| 75 | + }); |
| 76 | + $(".revision-cancel").click(function() { |
| 77 | + var parent = $(this).parents("div.item-actions"); |
| 78 | + var input_box = parent.children(".revision-input"); |
| 79 | + input_box.fadeOut(); |
| 80 | + }); |
| 81 | + }); |
| 82 | + </script> |
| 83 | + |
36 | 84 | <?php |
37 | 85 | } // execute() |
38 | 86 | } // class |