r74381 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74380‎ | r74381 | r74382 >
Date:19:22, 6 October 2010
Author:yaron
Status:deferred
Tags:
Comment:
Fixed link to edit page to not include rev ID - now works for non-Vector skins as well; added warning to edit and 'edit with form' pages in case the approved rev is not the latest one
Modified paths:
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.i18n.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ApprovedRevs/ApprovedRevs.i18n.php
@@ -29,6 +29,7 @@
3030 'approvedrevs-approvedandlatest' => 'This is the approved revision of this page, as well as being the most recent.',
3131 'approvedrevs-viewlatest' => 'View most recent revision.',
3232 'approvedrevs-blankpageshown' => 'No revision has been approved for this page.',
 33+ 'approvedrevs-editwarning' => 'Please note that you are now editing the latest revision of this page, which is not the approved one shown by default.',
3334 'approvedpages' => 'Approved pages',
3435 'approvedrevs-approvedpages-docu' => 'The following are the pages in the wiki that have an approved revision.',
3536 'unapprovedpages' => 'Unapproved pages',
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.php
@@ -46,7 +46,10 @@
4747 $wgHooks['ArticleFromTitle'][] = 'ApprovedRevsHooks::showApprovedRevision';
4848 $wgHooks['ArticleAfterFetchContent'][] = 'ApprovedRevsHooks::showBlankIfUnapproved';
4949 $wgHooks['DisplayOldSubtitle'][] = 'ApprovedRevsHooks::setSubtitle';
50 -$wgHooks['SkinTemplateNavigation'][] = 'ApprovedRevsHooks::changeEditLink';
 50+// it's 'SkinTemplateNavigation' for the Vector skin, 'SkinTemplateTabs' for
 51+// most other skins
 52+$wgHooks['SkinTemplateTabs'][] = 'ApprovedRevsHooks::changeEditLink';
 53+$wgHooks['SkinTemplateNavigation'][] = 'ApprovedRevsHooks::changeEditLinkVector';
5154 $wgHooks['PageHistoryBeforeList'][] = 'ApprovedRevsHooks::storeApprovedRevisionForHistoryPage';
5255 $wgHooks['PageHistoryLineEnding'][] = 'ApprovedRevsHooks::addApprovalLink';
5356 $wgHooks['UnknownAction'][] = 'ApprovedRevsHooks::setAsApproved';
@@ -58,6 +61,8 @@
5962 $wgHooks['ParserBeforeTidy'][] = 'ApprovedRevsHooks::handleMagicWords';
6063 $wgHooks['AdminLinks'][] = 'ApprovedRevsHooks::addToAdminLinks';
6164 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApprovedRevsHooks::describeDBSchema';
 65+$wgHooks['EditPage::showEditForm:initial'][] = 'ApprovedRevsHooks::addWarningToEditPage';
 66+$wgHooks['sfHTMLBeforeForm'][] = 'ApprovedRevsHooks::addWarningToSFForm';
6267
6368 // logging
6469 $wgLogTypes['approval'] = 'approval';
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php
@@ -147,8 +147,46 @@
148148 $wgOut->setSubtitle( $text );
149149 return false;
150150 }
151 -
 151+
152152 /**
 153+ * Add a warning to the top of the 'edit' page if the approved
 154+ * revision is not the same as the latest one, so that users don't
 155+ * get confused, since they'll be seeing the latest one.
 156+ */
 157+ public static function addWarningToEditPage( &$editPage ) {
 158+ // only show the warning if it's not an old revision
 159+ global $wgRequest;
 160+ if ( $wgRequest->getCheck( 'oldid' ) ) {
 161+ return true;
 162+ }
 163+ $title = $editPage->getArticle()->getTitle();
 164+ $approvedRevID = ApprovedRevs::getApprovedRevID( $title );
 165+ $latestRevID = $title->getLatestRevID();
 166+ if ( ! empty( $approvedRevID ) && $approvedRevID != $latestRevID ) {
 167+ global $wgOut;
 168+ $wgOut->addHTML( '<p><strong>' . wfMsg( 'approvedrevs-editwarning' ) . "</strong></p>\n" );
 169+ }
 170+ return true;
 171+ }
 172+
 173+ /**
 174+ * Same as addWarningToEditPage(), but for the Semantic Foms
 175+ * 'edit with form' tab
 176+ */
 177+ public static function addWarningToSFForm( &$pageName, &$preFormHTML ) {
 178+ // The title could be obtained via $pageName in theory - the
 179+ // problem is that, pre-SF 2.0.2, that variable wasn't set
 180+ // correctly.
 181+ global $wgTitle;
 182+ $approvedRevID = ApprovedRevs::getApprovedRevID( $wgTitle );
 183+ $latestRevID = $wgTitle->getLatestRevID();
 184+ if ( ! empty( $approvedRevID ) && $approvedRevID != $latestRevID ) {
 185+ $preFormHTML .= '<p><strong>' . wfMsg( 'approvedrevs-editwarning' ) . "</strong></p>\n";
 186+ }
 187+ return true;
 188+ }
 189+
 190+ /**
153191 * If user is looking at a revision through a main 'view' URL (no
154192 * revision specified), have the 'edit' tab link to the basic
155193 * 'action=edit' URL (i.e., the latest revision), no matter which
@@ -163,17 +201,28 @@
164202 // the URL is the same regardless of whether the tab
165203 // is 'edit' or 'view source', but the "action" is
166204 // different
167 - if ( array_key_exists( 'edit', $contentActions['views'] ) ) {
168 - $contentActions['views']['edit']['href'] = $skin->getTitle()->getLocalUrl( array( 'action' => 'edit' ) );
 205+ if ( array_key_exists( 'edit', $contentActions ) ) {
 206+ $contentActions['edit']['href'] = $skin->getTitle()->getLocalUrl( array( 'action' => 'edit' ) );
169207 }
170 - if ( array_key_exists( 'viewsource', $contentActions['views'] ) ) {
171 - $contentActions['views']['viewsource']['href'] = $skin->getTitle()->getLocalUrl( array( 'action' => 'edit' ) );
 208+ if ( array_key_exists( 'viewsource', $contentActions ) ) {
 209+ $contentActions['viewsource']['href'] = $skin->getTitle()->getLocalUrl( array( 'action' => 'edit' ) );
172210 }
173211 }
174212 return true;
175213 }
176214
177215 /**
 216+ * Same as changedEditLink(), but only for the Vector skin (and
 217+ * related skins).
 218+ */
 219+ static function changeEditLinkVector( &$skin, &$links ) {
 220+ // the old '$content_actions' array is thankfully just a
 221+ // sub-array of this one
 222+ self::changeEditLink( $skin, $links['views'] );
 223+ return true;
 224+ }
 225+
 226+ /**
178227 * Store the approved revision ID, if any, directly in the object
179228 * for this article - this is called so that a query to the database
180229 * can be made just once for every view of a history page, instead
@@ -321,7 +370,7 @@
322371 */
323372 static function setTranscludedPageRev( $parser, &$title, &$skip, &$id ) {
324373 $revision_id = ApprovedRevs::getApprovedRevID( $title );
325 - if ( !is_null( $revision_id ) ) {
 374+ if ( ! empty( $revision_id ) ) {
326375 $id = $revision_id;
327376 }
328377 return true;

Status & tagging log