r94312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94311‎ | r94312 | r94313 >
Date:00:26, 12 August 2011
Author:yuvipanda
Status:deferred
Tags:
Comment:
Added feature to modify revision
Modified paths:
  • /trunk/extensions/GPoC/SpecialSelection.php (modified) (history)
  • /trunk/extensions/GPoC/models/Selection.php (modified) (history)
  • /trunk/extensions/GPoC/schema/selections.sql (modified) (history)
  • /trunk/extensions/GPoC/templates/SelectionTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/schema/selections.sql
@@ -14,6 +14,9 @@
1515 s_timestamp binary(14) not null,
1616 -- timestamp when entry was added
1717
 18+ s_revision int unsigned,
 19+ -- manually set revision
 20+
1821 primary key (s_selection_name, s_namespace, s_article)
1922 ) /*$wgDBTableOptions*/;
2023
Index: trunk/extensions/GPoC/models/Selection.php
@@ -22,6 +22,23 @@
2323 }
2424 }
2525
 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+
2643 public static function getSelection( $name ) {
2744 $dbr = wfGetDB( DB_SLAVE );
2845
Index: trunk/extensions/GPoC/SpecialSelection.php
@@ -17,30 +17,52 @@
1818 $outstream = fopen( "php://output", "w" );
1919 $headers = array(
2020 'article',
 21+ 'revision',
2122 'added'
2223 );
2324 fputcsv( $outstream, $headers );
2425 foreach( $articles as $article ) {
2526 $row = array(
2627 $article['title']->getFullText(),
 28+ $article['s_revision'],
2729 wfTimeStamp( TS_ISO_8601, $article['s_timestamp'] )
2830 );
2931 fputcsv( $outstream, $row );
3032 }
3133 fclose( $outstream );
3234 }
 35+
 36+ public function onSubmit( $data ) {
 37+ var_dump($data);
 38+ }
 39+
3340 public function execute( $par ) {
3441 global $wgOut, $wgRequest;
3542
36 - $name = $wgRequest->getVal('name');
37 - $action = $wgRequest->getVal('action');
 43+ $name = $wgRequest->getVal( 'name' );
 44+ $format = $wgRequest->getVal( 'format' );
3845
 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+ }
3961 $entries = Selection::getSelection( $name );
4062 $this->setHeaders();
4163
4264 $wgOut->setPageTitle("Selection");
4365
44 - if( $action == 'csv' ) {
 66+ if( $format == 'csv' ) {
4567 $wgRequest->response()->header( 'Content-type: text/csv' );
4668 // Is there a security issue in letting the name be arbitrary?
4769 $wgRequest->response()->header(
@@ -51,7 +73,7 @@
5274 }
5375
5476 $csv_link = $this->getFullTitle()->getFullUrl( array(
55 - 'action' => 'csv',
 77+ 'format' => 'csv',
5678 'name' => $name
5779 ) );
5880 $template = new SelectionTemplate();
Index: trunk/extensions/GPoC/templates/SelectionTemplate.php
@@ -18,11 +18,26 @@
1919 <th>Article</th>
2020 <th>Added on</th>
2121 <th>Revision</th>
 22+ <th>Actions</th>
2223 </tr>
2324 <?php foreach( $articles as $article ) { ?>
2425 <tr>
2526 <td><a href="<?php echo $article['title']->getLinkURL(); ?>"><?php echo $article['s_article']; ?></a></td>
2627 <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>
2742 </tr>
2843 <?php } ?>
2944 </table>
@@ -31,7 +46,40 @@
3247 <?php } ?>
3348 </div>
3449
 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();
3565
 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+
3684 <?php
3785 } // execute()
3886 } // class

Status & tagging log