jenkins-bot has submitted this change and it was merged. Change subject: Get rid of some javascript mw.title related code ......................................................................
Get rid of some javascript mw.title related code mw.title is not reliable and throws parse exception on some valid titles. While it's being rewritten, we just use as much information from the API as possible. In the case of mw.title still being used, we would catch the exception and use some fallback that would keep the page going. -1 for now since this needs some more testing bug: 52683 Change-Id: I4ec92b4379c0120de4f575d36c482ef4a71eb615 --- M PageTriage.hooks.php M api/ApiPageTriageList.php M modules/ext.pageTriage.defaultDeletionTagsOptions/ext.pageTriage.defaultDeletionTagsOptions.js M modules/ext.pageTriage.models/ext.pageTriage.article.js M modules/ext.pageTriage.views.toolbar/ext.pageTriage.articleInfo.js M modules/ext.pageTriage.views.toolbar/ext.pageTriage.delete.js M modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js M modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js M modules/ext.pageTriage.views.toolbar/ext.pageTriage.wikilove.js 9 files changed, 163 insertions(+), 108 deletions(-) Approvals: Kaldari: Looks good to me, approved jenkins-bot: Verified diff --git a/PageTriage.hooks.php b/PageTriage.hooks.php index 528c442..48b3bc6 100644 --- a/PageTriage.hooks.php +++ b/PageTriage.hooks.php @@ -356,7 +356,8 @@ $wgOut->addModules( 'ext.pageTriage.toolbarStartup' ); // Set the config flags in JavaScript $globalVars = array( - 'wgPageTriagelastUseExpired' => $lastUseExpired + 'wgPageTriagelastUseExpired' => $lastUseExpired, + 'wgPageTriagePagePrefixedText' => $article->getTitle()->getPrefixedText() ); $wgOut->addJsConfigVars( $globalVars ); } else { diff --git a/api/ApiPageTriageList.php b/api/ApiPageTriageList.php index b48ddc3..0278fa5 100644 --- a/api/ApiPageTriageList.php +++ b/api/ApiPageTriageList.php @@ -30,23 +30,66 @@ $articleMetadata = new ArticleMetadata( $pages, $pageIdValidated, $pageIdValidateDb ); $metaData = $articleMetadata->getMetadata(); + $userPageStatus = PageTriageUtil::pageStatusForUser( $metaData ); + // Sort data according to page order returned by our query. Also convert it to a // slightly different format that's more Backbone-friendly. foreach ( $pages as $page ) { if ( isset( $metaData[$page] ) ) { $metaData[$page]['creation_date_utc'] = $metaData[$page]['creation_date']; $metaData[$page]['creation_date'] = $this->getContext()->getLanguage()->userAdjust( $metaData[$page]['creation_date'] ); + + // Page creator + $metaData[$page] += $this->createUserInfo( + $metaData[$page]['user_name'], + $userPageStatus, + 'creator' + ); + + // Page reviewer + if ( $metaData[$page]['reviewer'] ) { + $metaData[$page] += $this->createUserInfo( + $metaData[$page]['reviewer'], + $userPageStatus, + 'reviewer' + ); + } + $sortedMetaData[] = array( 'pageid' => $page ) + $metaData[$page]; } } } // Output the results - $result = array( 'result' => 'success', 'pages' => $sortedMetaData, 'userpagestatus' => PageTriageUtil::pageStatusForUser( $sortedMetaData ) ); + $result = array( 'result' => 'success', 'pages' => $sortedMetaData ); $this->getResult()->addValue( null, $this->getModuleName(), $result ); } /** + * Create user info like user page, user talk page, user contribution page + * @param $userName string a valid username + * @param $userPageStatus array an array of user page, user talk page existing status + * @param $prefix string array key prefix + * @return array + */ + private function createUserInfo( $userName, $userPageStatus, $prefix ) { + $userPage = Title::makeTitle( NS_USER, $userName ); + $userTalkPage = Title::makeTitle( NS_USER_TALK, $userName ); + $userContribsPage = SpecialPage::getTitleFor( 'Contributions', $userName ); + + return array ( + $prefix . '_user_page' => $userPage->getPrefixedText(), + $prefix . '_user_page_url' => $userPage->getFullURL(), + $prefix . '_user_page_exist' => isset( $userPageStatus[$userPage->getPrefixedDBkey()] ), + $prefix . '_user_talk_page' => $userTalkPage->getPrefixedText(), + $prefix . '_user_talk_page_url' => $userTalkPage->getFullURL(), + $prefix . '_user_talk_page_exist' => isset( $userPageStatus[$userTalkPage->getPrefixedDBkey()] ), + $prefix . '_contribution_page' => $userContribsPage->getPrefixedText(), + $prefix . '_contribution_page_url' => $userContribsPage->getFullURL() + ); + } + + /** * Return all the page ids in PageTraige matching the specified filters * @param $opts array of filtering options * @return array an array of ids diff --git a/modules/ext.pageTriage.defaultDeletionTagsOptions/ext.pageTriage.defaultDeletionTagsOptions.js b/modules/ext.pageTriage.defaultDeletionTagsOptions/ext.pageTriage.defaultDeletionTagsOptions.js index 8f466bf..e05adf9 100644 --- a/modules/ext.pageTriage.defaultDeletionTagsOptions/ext.pageTriage.defaultDeletionTagsOptions.js +++ b/modules/ext.pageTriage.defaultDeletionTagsOptions/ext.pageTriage.defaultDeletionTagsOptions.js @@ -28,7 +28,7 @@ label: '', input: 'automated', type: 'hidden', - value: new mw.Title( mw.config.get( 'wgPageName' ) ).getPrefixedText() + value: mw.config.get( 'wgPageTriagePagePrefixedText' ) } }; diff --git a/modules/ext.pageTriage.models/ext.pageTriage.article.js b/modules/ext.pageTriage.models/ext.pageTriage.article.js index a7ae051..b80f9e8 100644 --- a/modules/ext.pageTriage.models/ext.pageTriage.article.js +++ b/modules/ext.pageTriage.models/ext.pageTriage.article.js @@ -38,8 +38,6 @@ // TODO: What if userName doesn't exist? if( article.get( 'user_name' ) ) { - var info = this.userInfo( article.get( 'user_name' ) ); - // decide which byline message to use depending on if the editor is new or not // but don't show new editor for ip users if ( article.get( 'user_id' ) > '0' && article.get( 'user_autoconfirmed' ) < '1' ) { @@ -51,16 +49,40 @@ // put it all together in the byline var byline = mw.msg( bylineMessage, - info.userPageLink, - info.userTalkPageLink, + this.buildLinkTag( + article.get( 'creator_user_page_url' ), + article.get( 'user_name' ), + article.get( 'creator_user_page_exist' ) + ), + this.buildLinkTag( + article.get( 'creator_user_talk_page_url' ), + mw.msg( 'sp-contributions-talk' ), + article.get( 'creator_user_talk_page_exist' ) + ), mw.msg( 'pipe-separator' ), - info.userContribsLink + this.buildLinkTag( + article.get( 'creator_contribution_page_url' ), + mw.msg( 'contribslink' ), + true + ) ); article.set( 'author_byline', byline ); - article.set( 'user_title_url', this.buildRedLink( info.userTitle ) ); - article.set( 'user_talk_title_url', this.buildRedLink( info.userTalkTitle ) ); - article.set( 'user_contribs_title', info.userContribsTitle ); + article.set( + 'user_title_url', + this.buildRedLink( + article.get( 'creator_user_page_url' ), + article.get( 'creator_user_page_exist' ) + ) + ); + article.set( + 'user_talk_title_url', + this.buildRedLink( + article.get( 'creator_user_talk_page_url' ), + article.get( 'creator_user_talk_page_exist' ) + ) + ); + article.set( 'user_contribs_title', article.get( 'creator_contribution_page' ) ); } // set the article status @@ -78,16 +100,32 @@ // reviewed status } else { if ( article.get( 'ptrp_last_reviewed_by' ) != 0 && article.get( 'reviewer' ) ) { - var reviewerInfo = article.userInfo( article.get( 'reviewer' ) ); article.set( 'page_status', mw.msg( 'pagetriage-page-status-reviewed', - Date.parseExact( article.get( 'ptrp_reviewed_updated' ), 'yyyyMMddHHmmss' ).toString( mw.msg( 'pagetriage-info-timestamp-date-format' ) ), - reviewerInfo.userPageLink, - reviewerInfo.userTalkPageLink, + Date.parseExact( + article.get( 'ptrp_reviewed_updated' ), + 'yyyyMMddHHmmss' + ).toString( + mw.msg( 'pagetriage-info-timestamp-date-format' ) + ), + this.buildLinkTag( + article.get( 'reviewer_user_page_url' ), + article.get( 'reviewer' ), + article.get( 'reviewer_user_page_exist' ) + ), + this.buildLinkTag( + article.get( 'reviewer_user_talk_page_url' ), + mw.msg( 'sp-contributions-talk' ), + article.get( 'reviewer_user_talk_page_exist' ) + ), mw.msg( 'pipe-separator' ), - reviewerInfo.userContribsLink + this.buildLinkTag( + article.get( 'reviewer_contribution_page_url' ), + mw.msg( 'contribslink' ), + true + ) ) ); } else { @@ -102,52 +140,6 @@ titleUrl = this.buildLink( titleUrl, 'redirect=no' ); } article.set( 'title_url', titleUrl ); - }, - - /** - * Helper function that generates useful user data, this function will be accessed in - * multiple places - */ - userInfo: function ( userName ) { - var info = { - userTitle: new mw.Title( userName, mw.config.get('wgNamespaceIds')['user'] ), - userTalkTitle: new mw.Title( userName, mw.config.get('wgNamespaceIds')['user_talk'] ), - userContribsTitle: new mw.Title( mw.msg( 'pagetriage-special-contributions' ) + '/' + userName ) - }; - - userLinkClass = info.userTitle.exists() ? '' : 'new'; - userTalkLinkClass = info.userTalkTitle.exists() ? '' : 'new'; - - // build the user page link - info.userPageLink = mw.html.element( - 'a', - { - 'href': this.buildRedLink( info.userTitle ), - 'class': userLinkClass - }, - userName - ); - - // build the user talk page link - info.userTalkPageLink = mw.html.element( - 'a', - { - 'href': this.buildRedLink( info.userTalkTitle ), - 'class': userTalkLinkClass - }, - mw.msg( 'sp-contributions-talk' ) - ); - - // build the user contribs link - info.userContribsLink = mw.html.element( - 'a', - { - 'href': info.userContribsTitle.getUrl() - }, - mw.msg( 'contribslink' ) - ); - - return info; }, tagWarningNotice: function () { @@ -180,9 +172,24 @@ } }, - buildRedLink: function ( title ) { - var url = title.getUrl(); - if ( !title.exists() ) { + buildLinkTag: function ( url, text, exists ) { + var style = ''; + if ( !exists ) { + url = this.buildRedLink( url, exists ); + style = 'new'; + } + return mw.html.element( + 'a', + { + 'href': url, + 'class': style + }, + text + ); + }, + + buildRedLink: function ( url, exists ) { + if ( !exists ) { url = this.buildLink( url, 'action=edit&redlink=1' ); } return url; @@ -209,14 +216,8 @@ }, parse: function( response ) { - if( response.pagetriagelist ) { + if ( response.pagetriagelist !== undefined && response.pagetriagelist.pages !== undefined ) { // data came directly from the api - - // Check if user pages exist or should be redlinks - for ( var title in response.pagetriagelist.userpagestatus ) { - mw.Title.exist.set( title ); - } - // extract the useful bits of json. return response.pagetriagelist.pages[0]; } else { @@ -284,11 +285,6 @@ } else { // We have no more pages to load. this.moreToLoad = false; - } - - // Check if user pages exist or should be redlinks - for ( var title in response.pagetriagelist.userpagestatus ) { - mw.Title.exist.set( title ); } // extract the useful bits of json. return response.pagetriagelist.pages; diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.articleInfo.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.articleInfo.js index c94d186..03e8b23 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.articleInfo.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.articleInfo.js @@ -27,8 +27,6 @@ // creator information if ( this.model.get( 'user_name' ) ) { - var info = this.model.userInfo( this.model.get( 'user_name' ) ); - // show new editor message only if the user is not anonymous and not autoconfirmed if ( this.model.get( 'user_id' ) > '0' && this.model.get( 'user_autoconfirmed' ) == '0' ) { var bylineMessage = 'pagetriage-articleinfo-byline-new-editor'; @@ -39,11 +37,28 @@ // put it all together in the byline var articleByline = mw.msg( bylineMessage, - Date.parseExact( this.model.get( 'creation_date' ), 'yyyyMMddHHmmss' ).toString( mw.msg( 'pagetriage-info-timestamp-date-format' ) ), - info.userPageLink, - info.userTalkPageLink, + Date.parseExact( + this.model.get( 'creation_date' ), + 'yyyyMMddHHmmss' + ).toString( + mw.msg( 'pagetriage-info-timestamp-date-format' ) + ), + this.model.buildLinkTag( + this.model.get( 'creator_user_page_url' ), + this.model.get( 'user_name' ), + this.model.get( 'creator_user_page_exist' ) + ), + this.model.buildLinkTag( + this.model.get( 'creator_user_talk_page_url' ), + mw.msg( 'sp-contributions-talk' ), + this.model.get( 'creator_user_talk_page_exist' ) + ), mw.msg( 'pipe-separator' ), - info.userContribsLink + this.model.buildLinkTag( + this.model.get( 'creator_contribution_page_url' ), + mw.msg( 'contribslink' ), + true + ) ); this.model.set( 'articleByline', articleByline ); } @@ -145,8 +160,12 @@ // get a userlink. // can't set link color since no userpage status is returned by the history api if( historyItem.get( 'user' ) ) { - var userTitle = new mw.Title( historyItem.get( 'user' ), mw.config.get('wgNamespaceIds')['user'] ); - historyItem.set( 'user_title_url', userTitle.getUrl() ); + try { + var userTitle = new mw.Title( historyItem.get( 'user' ), mw.config.get('wgNamespaceIds')['user'] ); + historyItem.set( 'user_title_url', userTitle.getUrl() ); + } catch ( e ) { + historyItem.set( 'user_title_url', '' ); + } } historyItem.set( 'revision_url', mw.config.get( 'wgScriptPath' ) + '/index.php?title=' + diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.delete.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.delete.js index 9bdd929..d6802f0 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.delete.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.delete.js @@ -25,7 +25,7 @@ } }; - var pageName = new mw.Title( mw.config.get( 'wgPageName' ) ).getPrefixedText(); + var pageName = mw.config.get( 'wgPageTriagePagePrefixedText' ); // Deletion taggging var specialDeletionTagging = { @@ -711,14 +711,12 @@ template += ' ~~~~'; if ( this.model.get( 'user_name' ) ) { - var title = new mw.Title( this.model.get( 'user_name' ), mw.config.get( 'wgNamespaceIds' )['user_talk'] ); - $.ajax( { type: 'post', url: mw.util.wikiScript( 'api' ), data: { 'action': 'edit', - 'title': title.getPrefixedText(), + 'title': this.model.get( 'creator_user_talk_page' ), 'appendtext': "\n" + template, 'summary': mw.msg( 'pagetriage-del-talk-page-notify-summary', pageName ), 'token': mw.user.tokens.get('editToken'), diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js index f247d10..123bf65 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.mark.js @@ -77,7 +77,7 @@ talkPageNote: function( note, action ) { var _this = this, talkPageTitle, - pageTitle = new mw.Title( mw.config.get( 'wgPageName' ) ).getPrefixedText(); + pageTitle = mw.config.get( 'wgPageTriagePagePrefixedText' ); // mark as unreviewed if ( action !== 'reviewed' ) { @@ -85,10 +85,8 @@ if ( this.model.get( 'ptrp_last_reviewed_by' ) > 0 && mw.config.get( 'wgUserName' ) !== this.model.get( 'reviewer' ) ) { - talkPageTitle = new mw.Title( - this.model.get( 'reviewer' ), - mw.config.get( 'wgNamespaceIds' )['user_talk'] - ); + talkPageTitle = this.model.get( 'reviewer_user_talk_page' ); + if ( note ) { note = '{{subst:' + mw.config.get( 'wgTalkPageNoteTemplate' )['UnMark']['note'] + '|' + pageTitle @@ -111,10 +109,8 @@ _this.hideFlyout( action ); return; } - talkPageTitle = new mw.Title( - this.model.get( 'user_name' ), - mw.config.get( 'wgNamespaceIds' )['user_talk'] - ); + talkPageTitle = this.model.get( 'creator_user_talk_page' ); + note = '{{subst:' + mw.config.get( 'wgTalkPageNoteTemplate' )['Mark'] + '|' + pageTitle + '|' + mw.config.get( 'wgUserName' ) @@ -126,7 +122,7 @@ url: mw.util.wikiScript( 'api' ), data: { action: 'edit', - title: talkPageTitle.getPrefixedText(), + title: talkPageTitle, appendtext: "\n" + note, token: mw.user.tokens.get( 'editToken' ), format: 'json' diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js index f3fba3e..3028ac0 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.tags.js @@ -595,8 +595,7 @@ }, talkPageNote: function( note ) { - var _this = this, title = new mw.Title( this.model.get( 'user_name' ), mw.config.get( 'wgNamespaceIds' )['user_talk'] ), - pageName = new mw.Title( mw.config.get( 'wgPageName' ) ).getPrefixedText(); + var _this = this, pageName = mw.config.get( 'wgPageTriagePagePrefixedText' ); note = '{{subst:' + mw.config.get( 'wgTalkPageNoteTemplate' )['Tags'] + '|' + pageName @@ -609,7 +608,7 @@ url: mw.util.wikiScript( 'api' ), data: { 'action': 'edit', - 'title': title.getPrefixedText(), + 'title': this.model.get( 'creator_user_talk_page' ), 'appendtext': "\n" + note, 'token': mw.user.tokens.get('editToken'), 'summary': mw.msg( 'pagetriage-tags-note-edit-summary', pageName ), diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.wikilove.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.wikilove.js index 463f1c7..a3f69e0 100644 --- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.wikilove.js +++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.wikilove.js @@ -43,9 +43,7 @@ } // construct the info for the article creator - userTitle = new mw.Title( creator, mw.config.get('wgNamespaceIds')['user'] ); - linkUrl = userTitle.getUrl(); - link = mw.html.element( 'a', { 'href': linkUrl }, creator ); + link = mw.html.element( 'a', { 'href': this.model.get( 'creator_user_page_url' ) }, creator ); if ( $.inArray( creator, contributorArray ) > -1 ) { creatorContribCount = contributorCounts[creator]; @@ -73,9 +71,14 @@ this.bySortedValue( contributorCounts, function( name, count ) { // include up to 9 additional editors (this corresponds to the limit in WikiLove) if ( name !== creator && name !== mw.user.name() && x < 9 ) { - userTitle = new mw.Title( name, mw.config.get('wgNamespaceIds')['user'] ); - linkUrl = userTitle.getUrl(); - link = mw.html.element( 'a', { 'href': linkUrl }, name ); + try { + userTitle = new mw.Title( name, mw.config.get('wgNamespaceIds')['user'] ); + linkUrl = userTitle.getUrl(); + link = mw.html.element( 'a', { 'href': linkUrl }, name ); + } catch ( e ) { + link = _.escape( name ); + } + $( '#mwe-pt-article-contributor-list' ).append( '<input type="checkbox" class="mwe-pt-recipient-checkbox" value="' + _.escape( name ) + '"/>' + link + ' <span class="mwe-pt-info-text">– ' + -- To view, visit https://gerrit.wikimedia.org/r/82575 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4ec92b4379c0120de4f575d36c482ef4a71eb615 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/PageTriage Gerrit-Branch: master Gerrit-Owner: Bsitu <bs...@wikimedia.org> Gerrit-Reviewer: Bsitu <bs...@wikimedia.org> Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits